#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_MANAGED_USER_CREATION_CONTROLLER_NEW_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_MANAGED_USER_CREATION_CONTROLLER_NEW_H_
#include <string>
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "base/timer/timer.h"
#include "base/values.h"
#include "chrome/browser/chromeos/login/extended_authenticator.h"
#include "chrome/browser/chromeos/login/managed/managed_user_creation_controller.h"
#include "chrome/browser/managed_mode/managed_user_registration_utility.h"
class Profile;
namespace chromeos {
class ManagedUserCreationControllerNew
: public ManagedUserCreationController,
public ExtendedAuthenticator::AuthStatusConsumer {
public:
ManagedUserCreationControllerNew(StatusConsumer* consumer,
const std::string& manager_id);
virtual ~ManagedUserCreationControllerNew();
static ManagedUserCreationControllerNew* current_controller() {
return current_controller_;
}
virtual void StartCreation(const base::string16& display_name,
const std::string& password,
int avatar_index) OVERRIDE;
virtual void StartImport(const base::string16& display_name,
const std::string& password,
int avatar_index,
const std::string& sync_id,
const std::string& master_key) OVERRIDE;
virtual void StartImport(const base::string16& display_name,
int avatar_index,
const std::string& sync_id,
const std::string& master_key,
const base::DictionaryValue* password_data,
const std::string& encryption_key,
const std::string& signature_key) OVERRIDE;
virtual void SetManagerProfile(Profile* manager_profile) OVERRIDE;
virtual Profile* GetManagerProfile() OVERRIDE;
virtual void CancelCreation() OVERRIDE;
virtual void FinishCreation() OVERRIDE;
virtual std::string GetManagedUserId() OVERRIDE;
private:
enum Stage {
STAGE_INITIAL,
TRANSACTION_STARTED,
KEYS_GENERATED,
CRYPTOHOME_CREATED,
DASHBOARD_CREATED,
TOKEN_WRITTEN,
TRANSACTION_COMMITTED,
STAGE_ERROR,
};
enum CreationType { NEW_USER, USER_IMPORT_OLD, USER_IMPORT_NEW, };
struct UserCreationContext {
UserCreationContext();
~UserCreationContext();
base::string16 display_name;
int avatar_index;
std::string manager_id;
std::string local_user_id;
std::string sync_user_id;
std::string master_key;
std::string signature_key;
std::string encryption_key;
std::string salted_password;
std::string password;
std::string salted_master_key;
std::string mount_hash;
std::string token;
CreationType creation_type;
base::DictionaryValue password_data;
Profile* manager_profile;
scoped_ptr<ManagedUserRegistrationUtility> registration_utility;
};
virtual void OnAuthenticationFailure(ExtendedAuthenticator::AuthState error)
OVERRIDE;
void OnMountSuccess(const std::string& mount_hash);
void OnAddKeySuccess();
void OnPasswordHashingSuccess(const std::string& password_hash);
void StartCreationImpl();
void CreationTimedOut();
void RegistrationCallback(const GoogleServiceAuthError& error,
const std::string& token);
void OnManagedUserFilesStored(bool success);
static ManagedUserCreationControllerNew* current_controller_;
Stage stage_;
scoped_refptr<ExtendedAuthenticator> authenticator_;
scoped_ptr<UserCreationContext> creation_context_;
base::OneShotTimer<ManagedUserCreationControllerNew> timeout_timer_;
base::WeakPtrFactory<ManagedUserCreationControllerNew> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ManagedUserCreationControllerNew);
};
}
#endif