diff options
author | alemate <alemate@chromium.org> | 2015-10-30 09:21:58 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-30 16:23:11 +0000 |
commit | cd06408625de9e0d5cf4c7c1ede412cb5c82542b (patch) | |
tree | 5f46a533381febd1b74d260624df0bcfa69e1d75 /components/user_manager | |
parent | 80004a8df9cf8b81f5b231696e3a24d190a8e05b (diff) | |
download | chromium_src-cd06408625de9e0d5cf4c7c1ede412cb5c82542b.zip chromium_src-cd06408625de9e0d5cf4c7c1ede412cb5c82542b.tar.gz chromium_src-cd06408625de9e0d5cf4c7c1ede412cb5c82542b.tar.bz2 |
This CL replaces user_manager::UserID with AccountId.
This CL replaces API of user_manager::UserManager, thus modifying API of all
child objects, and all calls to UserManager.
This is part of transition to AccountId.
BUG=468875
TEST=manual
Review URL: https://codereview.chromium.org/1412813003
Cr-Commit-Position: refs/heads/master@{#357119}
Diffstat (limited to 'components/user_manager')
-rw-r--r-- | components/user_manager/BUILD.gn | 3 | ||||
-rw-r--r-- | components/user_manager/DEPS | 1 | ||||
-rw-r--r-- | components/user_manager/empty_user_info.cc | 5 | ||||
-rw-r--r-- | components/user_manager/empty_user_info.h | 2 | ||||
-rw-r--r-- | components/user_manager/fake_user_manager.cc | 78 | ||||
-rw-r--r-- | components/user_manager/fake_user_manager.h | 64 | ||||
-rw-r--r-- | components/user_manager/user.cc | 71 | ||||
-rw-r--r-- | components/user_manager/user.h | 43 | ||||
-rw-r--r-- | components/user_manager/user_id.h | 17 | ||||
-rw-r--r-- | components/user_manager/user_info.h | 8 | ||||
-rw-r--r-- | components/user_manager/user_info_impl.cc | 5 | ||||
-rw-r--r-- | components/user_manager/user_info_impl.h | 2 | ||||
-rw-r--r-- | components/user_manager/user_manager.h | 142 | ||||
-rw-r--r-- | components/user_manager/user_manager_base.cc | 478 | ||||
-rw-r--r-- | components/user_manager/user_manager_base.h | 186 |
15 files changed, 562 insertions, 543 deletions
diff --git a/components/user_manager/BUILD.gn b/components/user_manager/BUILD.gn index 0dfc852..55ab2a2 100644 --- a/components/user_manager/BUILD.gn +++ b/components/user_manager/BUILD.gn @@ -6,7 +6,6 @@ component("user_manager") { sources = [ "empty_user_info.cc", "empty_user_info.h", - "user_id.h", "user_info.cc", "user_info.h", "user_info_impl.cc", @@ -16,6 +15,7 @@ component("user_manager") { deps = [ "//base", + "//components/signin/core/account_id", "//skia", "//ui/gfx", ] @@ -60,6 +60,7 @@ source_set("test_support") { deps = [ ":user_manager", "//base", + "//components/signin/core/account_id", "//skia", "//ui/base", ] diff --git a/components/user_manager/DEPS b/components/user_manager/DEPS index c21fe3c..5c77f80 100644 --- a/components/user_manager/DEPS +++ b/components/user_manager/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+chromeos/login/login_state.h", "+chromeos/login/user_names.h", "+components/session_manager/core/session_manager.h", +"+components/signin/core/account_id/account_id.h", "+google_apis/gaia/gaia_auth_util.h", "+third_party/skia/include", "+ui/base/l10n", diff --git a/components/user_manager/empty_user_info.cc b/components/user_manager/empty_user_info.cc index ab886f1..08d4a19 100644 --- a/components/user_manager/empty_user_info.cc +++ b/components/user_manager/empty_user_info.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "base/strings/utf_string_conversions.h" +#include "components/signin/core/account_id/account_id.h" namespace user_manager { @@ -30,9 +31,9 @@ std::string EmptyUserInfo::GetEmail() const { return std::string(); } -std::string EmptyUserInfo::GetUserID() const { +AccountId EmptyUserInfo::GetAccountId() const { NOTIMPLEMENTED(); - return std::string(); + return EmptyAccountId(); } const gfx::ImageSkia& EmptyUserInfo::GetImage() const { diff --git a/components/user_manager/empty_user_info.h b/components/user_manager/empty_user_info.h index 52d677c..76c0d16 100644 --- a/components/user_manager/empty_user_info.h +++ b/components/user_manager/empty_user_info.h @@ -25,7 +25,7 @@ class USER_MANAGER_EXPORT EmptyUserInfo : public UserInfo { base::string16 GetDisplayName() const override; base::string16 GetGivenName() const override; std::string GetEmail() const override; - std::string GetUserID() const override; + AccountId GetAccountId() const override; const gfx::ImageSkia& GetImage() const override; private: diff --git a/components/user_manager/fake_user_manager.cc b/components/user_manager/fake_user_manager.cc index 39f63f1..4caa1b3 100644 --- a/components/user_manager/fake_user_manager.cc +++ b/components/user_manager/fake_user_manager.cc @@ -31,28 +31,30 @@ namespace user_manager { FakeUserManager::FakeUserManager() : UserManagerBase(new FakeTaskRunner(), new FakeTaskRunner()), - primary_user_(NULL), - owner_email_(std::string()) { -} + primary_user_(nullptr) {} FakeUserManager::~FakeUserManager() { } -const user_manager::User* FakeUserManager::AddUser(const std::string& email) { - return AddUserWithAffiliation(email, false); +const user_manager::User* FakeUserManager::AddUser( + const AccountId& account_id) { + return AddUserWithAffiliation(account_id, false); } const user_manager::User* FakeUserManager::AddUserWithAffiliation( - const std::string& email, bool is_affiliated) { - user_manager::User* user = user_manager::User::CreateRegularUser(email); + const AccountId& account_id, + bool is_affiliated) { + user_manager::User* user = user_manager::User::CreateRegularUser(account_id); user->set_affiliation(is_affiliated); users_.push_back(user); return user; } -void FakeUserManager::RemoveUserFromList(const std::string& email) { +void FakeUserManager::RemoveUserFromList(const AccountId& account_id) { user_manager::UserList::iterator it = users_.begin(); - while (it != users_.end() && (*it)->email() != email) + // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId is + // passed. crbug.com/546876 + while (it != users_.end() && (*it)->GetEmail() != account_id.GetUserEmail()) ++it; if (it != users_.end()) { delete *it; @@ -79,7 +81,7 @@ const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const { return logged_in_users_; } -void FakeUserManager::UserLoggedIn(const std::string& email, +void FakeUserManager::UserLoggedIn(const AccountId& account_id, const std::string& username_hash, bool browser_restart) { for (user_manager::UserList::const_iterator it = users_.begin(); @@ -97,17 +99,20 @@ void FakeUserManager::UserLoggedIn(const std::string& email, } user_manager::User* FakeUserManager::GetActiveUserInternal() const { - if (users_.size()) { - if (!active_user_id_.empty()) { + if (!users_.empty()) { + if (active_account_id_.is_valid()) { for (user_manager::UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { - if ((*it)->email() == active_user_id_) + // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId + // is + // passed. crbug.com/546876 + if ((*it)->GetEmail() == active_account_id_.GetUserEmail()) return *it; } } return users_[0]; } - return NULL; + return nullptr; } const user_manager::User* FakeUserManager::GetActiveUser() const { @@ -118,14 +123,15 @@ user_manager::User* FakeUserManager::GetActiveUser() { return GetActiveUserInternal(); } -void FakeUserManager::SwitchActiveUser(const std::string& email) { -} +void FakeUserManager::SwitchActiveUser(const AccountId& account_id) {} -void FakeUserManager::SaveUserDisplayName(const std::string& username, +void FakeUserManager::SaveUserDisplayName(const AccountId& account_id, const base::string16& display_name) { for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); ++it) { - if ((*it)->email() == username) { + // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId is + // passed. crbug.com/546876 + if ((*it)->GetEmail() == account_id.GetUserEmail()) { (*it)->set_display_name(display_name); return; } @@ -140,36 +146,38 @@ user_manager::UserList FakeUserManager::GetUnlockUsers() const { return users_; } -const std::string& FakeUserManager::GetOwnerEmail() const { - return owner_email_; +const AccountId& FakeUserManager::GetOwnerAccountId() const { + return owner_account_id_; } -bool FakeUserManager::IsKnownUser(const std::string& email) const { +bool FakeUserManager::IsKnownUser(const AccountId& account_id) const { return true; } const user_manager::User* FakeUserManager::FindUser( - const std::string& email) const { + const AccountId& account_id) const { const user_manager::UserList& users = GetUsers(); for (user_manager::UserList::const_iterator it = users.begin(); it != users.end(); ++it) { - if ((*it)->email() == email) + // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId is + // passed. crbug.com/546876 + if ((*it)->GetEmail() == account_id.GetUserEmail()) return *it; } - return NULL; + return nullptr; } user_manager::User* FakeUserManager::FindUserAndModify( - const std::string& email) { - return NULL; + const AccountId& account_id) { + return nullptr; } const user_manager::User* FakeUserManager::GetLoggedInUser() const { - return NULL; + return nullptr; } user_manager::User* FakeUserManager::GetLoggedInUser() { - return NULL; + return nullptr; } const user_manager::User* FakeUserManager::GetPrimaryUser() const { @@ -177,12 +185,12 @@ const user_manager::User* FakeUserManager::GetPrimaryUser() const { } base::string16 FakeUserManager::GetUserDisplayName( - const std::string& username) const { + const AccountId& account_id) const { return base::string16(); } std::string FakeUserManager::GetUserDisplayEmail( - const std::string& username) const { + const AccountId& account_id) const { return std::string(); } @@ -238,7 +246,7 @@ bool FakeUserManager::IsSessionStarted() const { } bool FakeUserManager::IsUserNonCryptohomeDataEphemeral( - const std::string& email) const { + const AccountId& account_id) const { return false; } @@ -256,23 +264,23 @@ const std::string& FakeUserManager::GetApplicationLocale() const { } PrefService* FakeUserManager::GetLocalState() const { - return NULL; + return nullptr; } bool FakeUserManager::IsEnterpriseManaged() const { return false; } -bool FakeUserManager::IsDemoApp(const std::string& user_id) const { +bool FakeUserManager::IsDemoApp(const AccountId& account_id) const { return false; } -bool FakeUserManager::IsKioskApp(const std::string& user_id) const { +bool FakeUserManager::IsKioskApp(const AccountId& account_id) const { return false; } bool FakeUserManager::IsPublicAccountMarkedForRemoval( - const std::string& user_id) const { + const AccountId& account_id) const { return false; } diff --git a/components/user_manager/fake_user_manager.h b/components/user_manager/fake_user_manager.h index a40eed6..77f1649 100644 --- a/components/user_manager/fake_user_manager.h +++ b/components/user_manager/fake_user_manager.h @@ -9,6 +9,7 @@ #include <string> #include "base/memory/scoped_ptr.h" +#include "components/signin/core/account_id/account_id.h" #include "components/user_manager/user.h" #include "components/user_manager/user_manager_base.h" @@ -23,15 +24,16 @@ class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase { // Create and add a new user. Created user is not affiliated with the domain, // that owns the device. - virtual const user_manager::User* AddUser(const std::string& email); + virtual const user_manager::User* AddUser(const AccountId& account_id); // The same as AddUser() but allows to specify user affiliation with the // domain, that owns the device. virtual const user_manager::User* AddUserWithAffiliation( - const std::string& email, bool is_affiliated); + const AccountId& account_id, + bool is_affiliated); // Calculates the user name hash and calls UserLoggedIn to login a user. - void LoginUser(const std::string& email); + void LoginUser(const AccountId& account_id); // UserManager overrides. const user_manager::UserList& GetUsers() const override; @@ -39,42 +41,43 @@ class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase { const user_manager::UserList& GetLoggedInUsers() const override; // Set the user as logged in. - void UserLoggedIn(const std::string& email, + void UserLoggedIn(const AccountId& account_id, const std::string& username_hash, bool browser_restart) override; const user_manager::User* GetActiveUser() const override; user_manager::User* GetActiveUser() override; - void SwitchActiveUser(const std::string& email) override; - void SaveUserDisplayName(const std::string& username, + void SwitchActiveUser(const AccountId& account_id) override; + void SaveUserDisplayName(const AccountId& account_id, const base::string16& display_name) override; // Not implemented. - void UpdateUserAccountData(const std::string& user_id, + void UpdateUserAccountData(const AccountId& account_id, const UserAccountData& account_data) override {} void Shutdown() override {} const user_manager::UserList& GetLRULoggedInUsers() const override; user_manager::UserList GetUnlockUsers() const override; - const std::string& GetOwnerEmail() const override; + const AccountId& GetOwnerAccountId() const override; void SessionStarted() override {} - void RemoveUser(const std::string& email, + void RemoveUser(const AccountId& account_id, user_manager::RemoveUserDelegate* delegate) override {} - void RemoveUserFromList(const std::string& email) override; - bool IsKnownUser(const std::string& email) const override; - const user_manager::User* FindUser(const std::string& email) const override; - user_manager::User* FindUserAndModify(const std::string& email) override; + void RemoveUserFromList(const AccountId& account_id) override; + bool IsKnownUser(const AccountId& account_id) const override; + const user_manager::User* FindUser( + const AccountId& account_id) const override; + user_manager::User* FindUserAndModify(const AccountId& account_id) override; const user_manager::User* GetLoggedInUser() const override; user_manager::User* GetLoggedInUser() override; const user_manager::User* GetPrimaryUser() const override; void SaveUserOAuthStatus( - const std::string& username, + const AccountId& account_id, user_manager::User::OAuthTokenStatus oauth_token_status) override {} - void SaveForceOnlineSignin(const std::string& user_id, + void SaveForceOnlineSignin(const AccountId& account_id, bool force_online_signin) override {} - base::string16 GetUserDisplayName(const std::string& username) const override; - void SaveUserDisplayEmail(const std::string& username, + base::string16 GetUserDisplayName(const AccountId& account_id) const override; + void SaveUserDisplayEmail(const AccountId& account_id, const std::string& display_email) override {} - std::string GetUserDisplayEmail(const std::string& username) const override; + std::string GetUserDisplayEmail(const AccountId& account_id) const override; bool IsCurrentUserOwner() const override; bool IsCurrentUserNew() const override; bool IsCurrentUserNonCryptohomeDataEphemeral() const override; @@ -88,7 +91,7 @@ class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase { bool IsLoggedInAsStub() const override; bool IsSessionStarted() const override; bool IsUserNonCryptohomeDataEphemeral( - const std::string& email) const override; + const AccountId& account_id) const override; void AddObserver(Observer* obs) override {} void RemoveObserver(Observer* obs) override {} void AddSessionStateObserver(UserSessionStateObserver* obs) override {} @@ -101,37 +104,36 @@ class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase { const std::string& GetApplicationLocale() const override; PrefService* GetLocalState() const override; void HandleUserOAuthTokenStatusChange( - const std::string& user_id, + const AccountId& account_id, user_manager::User::OAuthTokenStatus status) const override {} bool IsEnterpriseManaged() const override; - void LoadPublicAccounts(std::set<std::string>* public_sessions_set) override { - } + void LoadPublicAccounts(std::set<AccountId>* public_sessions_set) override {} void PerformPreUserListLoadingActions() override {} void PerformPostUserListLoadingActions() override {} void PerformPostUserLoggedInActions(bool browser_restart) override {} - bool IsDemoApp(const std::string& user_id) const override; - bool IsKioskApp(const std::string& user_id) const override; + bool IsDemoApp(const AccountId& account_id) const override; + bool IsKioskApp(const AccountId& account_id) const override; bool IsPublicAccountMarkedForRemoval( - const std::string& user_id) const override; + const AccountId& account_id) const override; void DemoAccountLoggedIn() override {} - void KioskAppLoggedIn(const std::string& app_id) override {} + void KioskAppLoggedIn(const AccountId& kiosk_app_account_id) override {} void PublicAccountUserLoggedIn(user_manager::User* user) override {} - void SupervisedUserLoggedIn(const std::string& user_id) override {} - void OnUserRemoved(const std::string& user_id) override {} + void SupervisedUserLoggedIn(const AccountId& account_id) override {} + void OnUserRemoved(const AccountId& account_id) override {} protected: user_manager::User* primary_user_; // If set this is the active user. If empty, the first created user is the // active user. - std::string active_user_id_; + AccountId active_account_id_ = EmptyAccountId(); private: // We use this internal function for const-correctness. user_manager::User* GetActiveUserInternal() const; - // stub, always empty string. - std::string owner_email_; + // stub, always empty. + AccountId owner_account_id_ = EmptyAccountId(); DISALLOW_COPY_AND_ASSIGN(FakeUserManager); }; diff --git a/components/user_manager/user.cc b/components/user_manager/user.cc index defc117..39ef430 100644 --- a/components/user_manager/user.cc +++ b/components/user_manager/user.cc @@ -9,6 +9,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_restrictions.h" #include "chromeos/login/user_names.h" +#include "components/signin/core/account_id/account_id.h" #include "components/user_manager/user_image/default_user_images.h" #include "google_apis/gaia/gaia_auth_util.h" #include "ui/base/resource/resource_bundle.h" @@ -34,10 +35,14 @@ bool User::TypeHasGaiaAccount(UserType user_type) { user_type == USER_TYPE_CHILD; } +const std::string& User::email() const { + return account_id_.GetUserEmail(); +} + // Also used for regular supervised users. class RegularUser : public User { public: - explicit RegularUser(const std::string& email); + explicit RegularUser(const AccountId& account_id); ~RegularUser() override; // Overridden from User: @@ -46,7 +51,7 @@ class RegularUser : public User { void SetIsChild(bool is_child) override; private: - bool is_child_; + bool is_child_ = false; DISALLOW_COPY_AND_ASSIGN(RegularUser); }; @@ -65,7 +70,7 @@ class GuestUser : public User { class KioskAppUser : public User { public: - explicit KioskAppUser(const std::string& app_id); + explicit KioskAppUser(const AccountId& kiosk_app_account_id); ~KioskAppUser() override; // Overridden from User: @@ -77,7 +82,7 @@ class KioskAppUser : public User { class SupervisedUser : public User { public: - explicit SupervisedUser(const std::string& username); + explicit SupervisedUser(const AccountId& account_id); ~SupervisedUser() override; // Overridden from User: @@ -90,7 +95,7 @@ class SupervisedUser : public User { class PublicAccountUser : public User { public: - explicit PublicAccountUser(const std::string& email); + explicit PublicAccountUser(const AccountId& account_id); ~PublicAccountUser() override; // Overridden from User: @@ -118,8 +123,9 @@ const gfx::ImageSkia& User::GetImage() const { return user_image_.image(); } -UserID User::GetUserID() const { - return gaia::CanonicalizeEmail(gaia::SanitizeEmail(email())); +AccountId User::GetAccountId() const { + return AccountId::FromUserEmail( + gaia::CanonicalizeEmail(gaia::SanitizeEmail(email()))); } void User::SetIsChild(bool is_child) { @@ -144,7 +150,7 @@ std::string User::GetAccountName(bool use_display_email) const { if (use_display_email && !display_email_.empty()) return GetUserName(display_email_); else - return GetUserName(email_); + return GetUserName(account_id_.GetUserEmail()); } bool User::HasDefaultImage() const { @@ -175,39 +181,27 @@ bool User::is_active() const { return is_active_; } -User* User::CreateRegularUser(const std::string& email) { - return new RegularUser(email); +User* User::CreateRegularUser(const AccountId& account_id) { + return new RegularUser(account_id); } User* User::CreateGuestUser() { return new GuestUser; } -User* User::CreateKioskAppUser(const std::string& kiosk_app_username) { - return new KioskAppUser(kiosk_app_username); +User* User::CreateKioskAppUser(const AccountId& kiosk_app_account_id) { + return new KioskAppUser(kiosk_app_account_id); } -User* User::CreateSupervisedUser(const std::string& username) { - return new SupervisedUser(username); +User* User::CreateSupervisedUser(const AccountId& account_id) { + return new SupervisedUser(account_id); } -User* User::CreatePublicAccountUser(const std::string& email) { - return new PublicAccountUser(email); +User* User::CreatePublicAccountUser(const AccountId& account_id) { + return new PublicAccountUser(account_id); } -User::User(const std::string& email) - : email_(email), - oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), - force_online_signin_(false), - image_index_(USER_IMAGE_INVALID), - image_is_stub_(false), - image_is_loading_(false), - can_lock_(false), - is_logged_in_(false), - is_active_(false), - profile_is_created_(false), - is_affiliated_(false){ -} +User::User(const AccountId& account_id) : account_id_(account_id) {} User::~User() { } @@ -237,10 +231,9 @@ void User::SetStubImage(const UserImage& stub_user_image, image_is_loading_ = is_loading; } -RegularUser::RegularUser(const std::string& email) - : User(email), is_child_(false) { +RegularUser::RegularUser(const AccountId& account_id) : User(account_id) { set_can_lock(true); - set_display_email(email); + set_display_email(account_id.GetUserEmail()); } RegularUser::~RegularUser() { @@ -260,7 +253,7 @@ void RegularUser::SetIsChild(bool is_child) { is_child_ = is_child; } -GuestUser::GuestUser() : User(chromeos::login::kGuestUserName) { +GuestUser::GuestUser() : User(chromeos::login::GuestAccountId()) { set_display_email(std::string()); } @@ -271,9 +264,9 @@ UserType GuestUser::GetType() const { return user_manager::USER_TYPE_GUEST; } -KioskAppUser::KioskAppUser(const std::string& kiosk_app_username) - : User(kiosk_app_username) { - set_display_email(kiosk_app_username); +KioskAppUser::KioskAppUser(const AccountId& kiosk_app_account_id) + : User(kiosk_app_account_id) { + set_display_email(kiosk_app_account_id.GetUserEmail()); } KioskAppUser::~KioskAppUser() { @@ -283,7 +276,7 @@ UserType KioskAppUser::GetType() const { return user_manager::USER_TYPE_KIOSK_APP; } -SupervisedUser::SupervisedUser(const std::string& username) : User(username) { +SupervisedUser::SupervisedUser(const AccountId& account_id) : User(account_id) { set_can_lock(true); } @@ -298,8 +291,8 @@ std::string SupervisedUser::display_email() const { return base::UTF16ToUTF8(display_name()); } -PublicAccountUser::PublicAccountUser(const std::string& email) : User(email) { -} +PublicAccountUser::PublicAccountUser(const AccountId& account_id) + : User(account_id) {} PublicAccountUser::~PublicAccountUser() { } diff --git a/components/user_manager/user.h b/components/user_manager/user.h index d961acf..fe0899e 100644 --- a/components/user_manager/user.h +++ b/components/user_manager/user.h @@ -10,7 +10,7 @@ #include "base/basictypes.h" #include "base/strings/string16.h" -#include "components/user_manager/user_id.h" +#include "components/signin/core/account_id/account_id.h" #include "components/user_manager/user_image/user_image.h" #include "components/user_manager/user_info.h" #include "components/user_manager/user_manager_export.h" @@ -83,7 +83,8 @@ class USER_MANAGER_EXPORT User : public UserInfo { virtual UserType GetType() const = 0; // The email the user used to log in. - const std::string& email() const { return email_; } + // TODO(alemate): rename this to GetUserEmail() (see crbug.com/548923) + const std::string& email() const; // The displayed user name. base::string16 display_name() const { return display_name_; } @@ -96,7 +97,7 @@ class USER_MANAGER_EXPORT User : public UserInfo { base::string16 GetDisplayName() const override; base::string16 GetGivenName() const override; const gfx::ImageSkia& GetImage() const override; - UserID GetUserID() const override; + AccountId GetAccountId() const override; // Allows managing child status of the user. Used for RegularUser. virtual void SetIsChild(bool is_child); @@ -182,13 +183,13 @@ class USER_MANAGER_EXPORT User : public UserInfo { friend class chromeos::UserAddingScreenTest; // Do not allow anyone else to create new User instances. - static User* CreateRegularUser(const UserID& email); + static User* CreateRegularUser(const AccountId& account_id); static User* CreateGuestUser(); - static User* CreateKioskAppUser(const UserID& kiosk_app_username); - static User* CreateSupervisedUser(const UserID& username); - static User* CreatePublicAccountUser(const UserID& email); + static User* CreateKioskAppUser(const AccountId& kiosk_app_account_id); + static User* CreateSupervisedUser(const AccountId& account_id); + static User* CreatePublicAccountUser(const AccountId& account_id); - explicit User(const std::string& email); + explicit User(const AccountId& account_id); ~User() override; const std::string* GetAccountLocale() const { return account_locale_.get(); } @@ -251,15 +252,15 @@ class USER_MANAGER_EXPORT User : public UserInfo { } private: - std::string email_; + AccountId account_id_; base::string16 display_name_; base::string16 given_name_; // The displayed user email, defaults to |email_|. std::string display_email_; - bool using_saml_; + bool using_saml_ = false; UserImage user_image_; - OAuthTokenStatus oauth_token_status_; - bool force_online_signin_; + OAuthTokenStatus oauth_token_status_ = OAUTH_TOKEN_STATUS_UNKNOWN; + bool force_online_signin_ = false; // This is set to chromeos locale if account data has been downloaded. // (Or failed to download, but at least one download attempt finished). @@ -272,34 +273,34 @@ class USER_MANAGER_EXPORT User : public UserInfo { // Either index of a default image for the user, |USER_IMAGE_EXTERNAL| or // |USER_IMAGE_PROFILE|. - int image_index_; + int image_index_ = USER_IMAGE_INVALID; // True if current user image is a stub set by a |SetStubImage| call. - bool image_is_stub_; + bool image_is_stub_ = false; // True if current user image is being loaded from file. - bool image_is_loading_; + bool image_is_loading_ = false; // True if user is able to lock screen. - bool can_lock_; + bool can_lock_ = false; // True if user is currently logged in in current session. - bool is_logged_in_; + bool is_logged_in_ = false; // True if user is currently logged in and active in current session. - bool is_active_; + bool is_active_ = false; // True if user Profile is created - bool profile_is_created_; + bool profile_is_created_ = false; // True if the user is affiliated to the device. - bool is_affiliated_; + bool is_affiliated_ = false; DISALLOW_COPY_AND_ASSIGN(User); }; // List of known users. -typedef std::vector<User*> UserList; +using UserList = std::vector<User*>; } // namespace user_manager diff --git a/components/user_manager/user_id.h b/components/user_manager/user_id.h deleted file mode 100644 index bf8730a..0000000 --- a/components/user_manager/user_id.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_USER_MANAGER_USER_ID_H_ -#define COMPONENTS_USER_MANAGER_USER_ID_H_ - -#include <string> - -namespace user_manager { - -// Type that contains enough information to identify user on ChromeOS. -typedef std::string UserID; - -} // namespace user_manager - -#endif // COMPONENTS_USER_MANAGER_USER_ID_H_ diff --git a/components/user_manager/user_info.h b/components/user_manager/user_info.h index cc613c1..2f0cf19 100644 --- a/components/user_manager/user_info.h +++ b/components/user_manager/user_info.h @@ -8,9 +8,10 @@ #include <string> #include "base/strings/string16.h" -#include "components/user_manager/user_id.h" #include "components/user_manager/user_manager_export.h" +class AccountId; + namespace gfx { class ImageSkia; } @@ -34,9 +35,8 @@ class USER_MANAGER_EXPORT UserInfo { // as well as capitalized letters. For example: "Foo.Bar@mock.com". virtual std::string GetEmail() const = 0; - // Gets the user id (sanitized email address) for the user. - // The function would return something like "foobar@mock.com". - virtual UserID GetUserID() const = 0; + // Returns AccountId for the user. + virtual AccountId GetAccountId() const = 0; // Gets the avatar image for the user. virtual const gfx::ImageSkia& GetImage() const = 0; diff --git a/components/user_manager/user_info_impl.cc b/components/user_manager/user_info_impl.cc index 6aa21a8..cf6d2ad 100644 --- a/components/user_manager/user_info_impl.cc +++ b/components/user_manager/user_info_impl.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "base/strings/utf_string_conversions.h" +#include "components/signin/core/account_id/account_id.h" namespace user_manager { @@ -27,8 +28,8 @@ std::string UserInfoImpl::GetEmail() const { return "stub-user@domain.com"; } -std::string UserInfoImpl::GetUserID() const { - return GetEmail(); +AccountId UserInfoImpl::GetAccountId() const { + return AccountId::FromUserEmail(GetEmail()); } const gfx::ImageSkia& UserInfoImpl::GetImage() const { diff --git a/components/user_manager/user_info_impl.h b/components/user_manager/user_info_impl.h index d23ca0c..4922e36 100644 --- a/components/user_manager/user_info_impl.h +++ b/components/user_manager/user_info_impl.h @@ -24,7 +24,7 @@ class USER_MANAGER_EXPORT UserInfoImpl : public UserInfo { base::string16 GetDisplayName() const override; base::string16 GetGivenName() const override; std::string GetEmail() const override; - std::string GetUserID() const override; + AccountId GetAccountId() const override; const gfx::ImageSkia& GetImage() const override; private: diff --git a/components/user_manager/user_manager.h b/components/user_manager/user_manager.h index 24b8c9a..03a08d7 100644 --- a/components/user_manager/user_manager.h +++ b/components/user_manager/user_manager.h @@ -8,10 +8,11 @@ #include <string> #include "components/user_manager/user.h" -#include "components/user_manager/user_id.h" #include "components/user_manager/user_manager_export.h" #include "components/user_manager/user_type.h" +class AccountId; + namespace base { class DictionaryValue; } @@ -54,7 +55,7 @@ class USER_MANAGER_EXPORT UserManager { virtual void UserAddedToSession(const User* added_user); // Called right before notifying on user change so that those who rely - // on user_id hash would be accessing up-to-date value. + // on account_id hash would be accessing up-to-date value. virtual void ActiveUserHashChanged(const std::string& hash); // Called when child status has changed. @@ -138,21 +139,22 @@ class USER_MANAGER_EXPORT UserManager { // All users that are unable to perform unlock are excluded from this list. virtual UserList GetUnlockUsers() const = 0; - // Returns the email of the owner user. Returns an empty string if there is + // Returns account Id of the owner user. Returns an empty Id if there is // no owner for the device. - virtual const std::string& GetOwnerEmail() const = 0; + virtual const AccountId& GetOwnerAccountId() const = 0; - // Indicates that a user with the given |user_id| has just logged in. The + // Indicates that a user with the given |account_id| has just logged in. The // persistent list is updated accordingly if the user is not ephemeral. // |browser_restart| is true when reloading Chrome after crash to distinguish // from normal sign in flow. // |username_hash| is used to identify homedir mount point. - virtual void UserLoggedIn(const std::string& user_id, + virtual void UserLoggedIn(const AccountId& account_id, const std::string& username_hash, bool browser_restart) = 0; - // Switches to active user identified by |user_id|. User has to be logged in. - virtual void SwitchActiveUser(const std::string& user_id) = 0; + // Switches to active user identified by |account_id|. User has to be logged + // in. + virtual void SwitchActiveUser(const AccountId& account_id) = 0; // Switches to the last active user (called after crash happens and session // restore has completed). @@ -170,25 +172,25 @@ class USER_MANAGER_EXPORT UserManager { // Removes the user from the device. Note, it will verify that the given user // isn't the owner, so calling this method for the owner will take no effect. // Note, |delegate| can be NULL. - virtual void RemoveUser(const std::string& user_id, + virtual void RemoveUser(const AccountId& account_id, RemoveUserDelegate* delegate) = 0; // Removes the user from the persistent list only. Also removes the user's // picture. - virtual void RemoveUserFromList(const std::string& user_id) = 0; + virtual void RemoveUserFromList(const AccountId& account_id) = 0; - // Returns true if a user with the given user id is found in the persistent + // Returns true if a user with the given account id is found in the persistent // list or currently logged in as ephemeral. - virtual bool IsKnownUser(const std::string& user_id) const = 0; + virtual bool IsKnownUser(const AccountId& account_id) const = 0; - // Returns the user with the given user id if found in the persistent + // Returns the user with the given account id if found in the persistent // list or currently logged in as ephemeral. Returns |NULL| otherwise. - virtual const User* FindUser(const std::string& user_id) const = 0; + virtual const User* FindUser(const AccountId& account_id) const = 0; - // Returns the user with the given user id if found in the persistent + // Returns the user with the given account id if found in the persistent // list or currently logged in as ephemeral. Returns |NULL| otherwise. // Same as FindUser but returns non-const pointer to User object. - virtual User* FindUserAndModify(const std::string& user_id) = 0; + virtual User* FindUserAndModify(const AccountId& account_id) = 0; // Returns the logged-in user. // TODO(nkostylev): Deprecate this call, move clients to GetActiveUser(). @@ -208,42 +210,43 @@ class USER_MANAGER_EXPORT UserManager { // Saves user's oauth token status in local state preferences. virtual void SaveUserOAuthStatus( - const std::string& user_id, + const AccountId& account_id, User::OAuthTokenStatus oauth_token_status) = 0; // Saves a flag indicating whether online authentication against GAIA should // be enforced during the user's next sign-in. - virtual void SaveForceOnlineSignin(const std::string& user_id, + virtual void SaveForceOnlineSignin(const AccountId& account_id, bool force_online_signin) = 0; // Saves user's displayed name in local state preferences. // Ignored If there is no such user. - virtual void SaveUserDisplayName(const std::string& user_id, + virtual void SaveUserDisplayName(const AccountId& account_id, const base::string16& display_name) = 0; // Updates data upon User Account download. - virtual void UpdateUserAccountData(const std::string& user_id, + virtual void UpdateUserAccountData(const AccountId& account_id, const UserAccountData& account_data) = 0; - // Returns the display name for user |user_id| if it is known (was + // Returns the display name for user |account_id| if it is known (was // previously set by a |SaveUserDisplayName| call). // Otherwise, returns an empty string. virtual base::string16 GetUserDisplayName( - const std::string& user_id) const = 0; + const AccountId& account_id) const = 0; // Saves user's displayed (non-canonical) email in local state preferences. // Ignored If there is no such user. - virtual void SaveUserDisplayEmail(const std::string& user_id, + virtual void SaveUserDisplayEmail(const AccountId& account_id, const std::string& display_email) = 0; - // Returns the display email for user |user_id| if it is known (was + // Returns the display email for user |account_id| if it is known (was // previously set by a |SaveUserDisplayEmail| call). - // Otherwise, returns |user_id| itself. - virtual std::string GetUserDisplayEmail(const std::string& user_id) const = 0; + // Otherwise, returns |account_id| itself. + virtual std::string GetUserDisplayEmail( + const AccountId& account_id) const = 0; - // Saves user's type for user |user_id| into local state preferences. + // Saves user's type for user |account_id| into local state preferences. // Ignored If there is no such user. - virtual void SaveUserType(const std::string& user_id, + virtual void SaveUserType(const AccountId& account_id, const UserType& user_type) = 0; // Returns true if current user is an owner. @@ -290,11 +293,12 @@ class USER_MANAGER_EXPORT UserManager { // or restart after crash. virtual bool IsSessionStarted() const = 0; - // Returns true if data stored or cached for the user with the given user id + // Returns true if data stored or cached for the user with the given + // |account_id| // address outside that user's cryptohome (wallpaper, avatar, OAuth token // status, display name, display email) is to be treated as ephemeral. virtual bool IsUserNonCryptohomeDataEphemeral( - const std::string& user_id) const = 0; + const AccountId& account_id) const = 0; virtual void AddObserver(Observer* obs) = 0; virtual void RemoveObserver(Observer* obs) = 0; @@ -313,95 +317,101 @@ class USER_MANAGER_EXPORT UserManager { // Methods for storage/retrieval of per-user properties in Local State. - // Performs a lookup of properties associated with |user_id|. If found, + // Performs a lookup of properties associated with |account_id|. If found, // returns |true| and fills |out_value|. |out_value| can be NULL, if // only existence check is required. - virtual bool FindKnownUserPrefs(const UserID& user_id, + virtual bool FindKnownUserPrefs(const AccountId& account_id, const base::DictionaryValue** out_value) = 0; - // Updates (or creates) properties associated with |user_id| based + // Updates (or creates) properties associated with |account_id| based // on |values|. |clear| defines if existing properties are cleared (|true|) // or if it is just a incremental update (|false|). - virtual void UpdateKnownUserPrefs(const UserID& user_id, + virtual void UpdateKnownUserPrefs(const AccountId& account_id, const base::DictionaryValue& values, bool clear) = 0; - // Returns true if |user_id| preference by |path| does exist, + // Returns true if |account_id| preference by |path| does exist, // fills in |out_value|. Otherwise returns false. - virtual bool GetKnownUserStringPref(const UserID& user_id, + virtual bool GetKnownUserStringPref(const AccountId& account_id, const std::string& path, std::string* out_value) = 0; - // Updates user's identified by |user_id| string preference |path|. - virtual void SetKnownUserStringPref(const UserID& user_id, + // Updates user's identified by |account_id| string preference |path|. + virtual void SetKnownUserStringPref(const AccountId& account_id, const std::string& path, const std::string& in_value) = 0; - // Returns true if |user_id| preference by |path| does exist, + // Returns true if |account_id| preference by |path| does exist, // fills in |out_value|. Otherwise returns false. - virtual bool GetKnownUserBooleanPref(const UserID& user_id, + virtual bool GetKnownUserBooleanPref(const AccountId& account_id, const std::string& path, bool* out_value) = 0; - // Updates user's identified by |user_id| boolean preference |path|. - virtual void SetKnownUserBooleanPref(const UserID& user_id, + // Updates user's identified by |account_id| boolean preference |path|. + virtual void SetKnownUserBooleanPref(const AccountId& account_id, const std::string& path, const bool in_value) = 0; - // Returns true if |user_id| preference by |path| does exist, + // Returns true if |account_id| preference by |path| does exist, // fills in |out_value|. Otherwise returns false. - virtual bool GetKnownUserIntegerPref(const UserID& user_id, + virtual bool GetKnownUserIntegerPref(const AccountId& account_id, const std::string& path, int* out_value) = 0; - // Updates user's identified by |user_id| integer preference |path|. - virtual void SetKnownUserIntegerPref(const UserID& user_id, + // Updates user's identified by |account_id| integer preference |path|. + virtual void SetKnownUserIntegerPref(const AccountId& account_id, const std::string& path, const int in_value) = 0; - // Returns true if user's canonical email was found. - // Returns it in |out_email|. - virtual bool GetKnownUserCanonicalEmail(const UserID& user_id, - std::string* out_email) = 0; + // Returns true if user's AccountId was found. + // Returns it in |out_account_id|. + virtual bool GetKnownUserAccountId(const AccountId& authenticated_account_id, + AccountId* out_account_id) = 0; - // Updates |gaia_id| for user with |user_id|. - // TODO(antrim): Update this once UserID contains GAIA ID. - virtual void UpdateGaiaID(const UserID& user_id, + // Updates |gaia_id| for user with |account_id|. + // TODO(alemate): Update this once AccountId contains GAIA ID + // (crbug.com/548926). + virtual void UpdateGaiaID(const AccountId& account_id, const std::string& gaia_id) = 0; - // Find GAIA ID for user with |user_id|, fill in |out_value| and return true + // Find GAIA ID for user with |account_id|, fill in |out_value| and return + // true // if GAIA ID was found or false otherwise. - // TODO(antrim): Update this once UserID contains GAIA ID. - virtual bool FindGaiaID(const UserID& user_id, std::string* out_value) = 0; + // TODO(antrim): Update this once AccountId contains GAIA ID + // (crbug.com/548926). + virtual bool FindGaiaID(const AccountId& account_id, + std::string* out_value) = 0; // Saves whether the user authenticates using SAML. - virtual void UpdateUsingSAML(const UserID& user_id, + virtual void UpdateUsingSAML(const AccountId& account_id, const bool using_saml) = 0; // Returns if SAML needs to be used for authentication of the user with - // |user_id|, if it is known (was set by a |UpdateUsingSaml| call). Otherwise + // |account_id|, if it is known (was set by a |UpdateUsingSaml| call). + // Otherwise // returns false. - virtual bool FindUsingSAML(const UserID& user_id) = 0; + virtual bool FindUsingSAML(const AccountId& account_id) = 0; // Setter and getter for DeviceId known user string preference. - virtual void SetKnownUserDeviceId(const UserID& user_id, + virtual void SetKnownUserDeviceId(const AccountId& account_id, const std::string& device_id) = 0; - virtual std::string GetKnownUserDeviceId(const UserID& user_id) = 0; + virtual std::string GetKnownUserDeviceId(const AccountId& account_id) = 0; // Setter and getter for GAPSCookie known user string preference. - virtual void SetKnownUserGAPSCookie(const UserID& user_id, + virtual void SetKnownUserGAPSCookie(const AccountId& account_id, const std::string& gaps_cookie) = 0; - virtual std::string GetKnownUserGAPSCookie(const UserID& user_id) = 0; + virtual std::string GetKnownUserGAPSCookie(const AccountId& account_id) = 0; // Saves why the user has to go through re-auth flow. - virtual void UpdateReauthReason(const UserID& user_id, + virtual void UpdateReauthReason(const AccountId& account_id, const int reauth_reason) = 0; - // Returns the reason why the user with |user_id| has to go through the + // Returns the reason why the user with |account_id| has to go through the // re-auth flow. Returns true if such a reason was recorded or false // otherwise. - virtual bool FindReauthReason(const UserID& user_id, int* out_value) = 0; + virtual bool FindReauthReason(const AccountId& account_id, + int* out_value) = 0; protected: // Sets UserManager instance. diff --git a/components/user_manager/user_manager_base.cc b/components/user_manager/user_manager_base.cc index 3bcb61c..81a68ff 100644 --- a/components/user_manager/user_manager_base.cc +++ b/components/user_manager/user_manager_base.cc @@ -115,25 +115,26 @@ void ResolveLocale(const std::string& raw_locale, ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); } -// Checks if values in |dict| correspond with |user_id| identity. -bool UserMatches(const UserID& user_id, const base::DictionaryValue& dict) { +// Checks if values in |dict| correspond with |account_id| identity. +bool UserMatches(const AccountId& account_id, + const base::DictionaryValue& dict) { std::string value; bool has_email = dict.GetString(kCanonicalEmail, &value); - if (has_email && user_id == value) + if (has_email && account_id.GetUserEmail() == value) return true; // TODO(antrim): update code once user id is really a struct. bool has_gaia_id = dict.GetString(kGAIAIdKey, &value); - if (has_gaia_id && user_id == value) + if (has_gaia_id && account_id.GetUserEmail() == value) return true; return false; } -// Fills relevant |dict| values based on |user_id|. -void UpdateIdentity(const UserID& user_id, base::DictionaryValue& dict) { - dict.SetString(kCanonicalEmail, user_id); +// Fills relevant |dict| values based on |account_id|. +void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) { + dict.SetString(kCanonicalEmail, account_id.GetUserEmail()); } } // namespace @@ -155,17 +156,7 @@ void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { UserManagerBase::UserManagerBase( scoped_refptr<base::TaskRunner> task_runner, scoped_refptr<base::TaskRunner> blocking_task_runner) - : active_user_(NULL), - primary_user_(NULL), - user_loading_stage_(STAGE_NOT_LOADED), - session_started_(false), - is_current_user_owner_(false), - is_current_user_new_(false), - is_current_user_ephemeral_regular_user_(false), - ephemeral_users_enabled_(false), - manager_creation_time_(base::TimeTicks::Now()), - last_session_active_user_initialized_(false), - task_runner_(task_runner), + : task_runner_(task_runner), blocking_task_runner_(blocking_task_runner), weak_factory_(this) { UpdateLoginState(); @@ -201,21 +192,22 @@ const UserList& UserManagerBase::GetLRULoggedInUsers() const { return lru_logged_in_users_; } -const std::string& UserManagerBase::GetOwnerEmail() const { - return owner_email_; +const AccountId& UserManagerBase::GetOwnerAccountId() const { + return owner_account_id_; } -void UserManagerBase::UserLoggedIn(const std::string& user_id, +void UserManagerBase::UserLoggedIn(const AccountId& account_id, const std::string& username_hash, bool browser_restart) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); - if (!last_session_active_user_initialized_) { - last_session_active_user_ = GetLocalState()->GetString(kLastActiveUser); - last_session_active_user_initialized_ = true; + if (!last_session_active_account_id_initialized_) { + last_session_active_account_id_ = + AccountId::FromUserEmail(GetLocalState()->GetString(kLastActiveUser)); + last_session_active_account_id_initialized_ = true; } - User* user = FindUserInListAndModify(user_id); + User* user = FindUserInListAndModify(account_id); if (active_user_ && user) { user->set_is_logged_in(true); user->set_username_hash(username_hash); @@ -229,11 +221,11 @@ void UserManagerBase::UserLoggedIn(const std::string& user_id, return; } - if (user_id == chromeos::login::kGuestUserName) { + if (account_id == chromeos::login::GuestAccountId()) { GuestUserLoggedIn(); - } else if (IsKioskApp(user_id)) { - KioskAppLoggedIn(user_id); - } else if (IsDemoApp(user_id)) { + } else if (IsKioskApp(account_id)) { + KioskAppLoggedIn(account_id); + } else if (IsDemoApp(account_id)) { DemoAccountLoggedIn(); } else { EnsureUsersLoaded(); @@ -242,16 +234,16 @@ void UserManagerBase::UserLoggedIn(const std::string& user_id, PublicAccountUserLoggedIn(user); } else if ((user && user->GetType() == USER_TYPE_SUPERVISED) || (!user && - gaia::ExtractDomainName(user_id) == + gaia::ExtractDomainName(account_id.GetUserEmail()) == chromeos::login::kSupervisedUserDomain)) { - SupervisedUserLoggedIn(user_id); - } else if (browser_restart && IsPublicAccountMarkedForRemoval(user_id)) { - PublicAccountUserLoggedIn(User::CreatePublicAccountUser(user_id)); - } else if (user_id != GetOwnerEmail() && !user && + SupervisedUserLoggedIn(account_id); + } else if (browser_restart && IsPublicAccountMarkedForRemoval(account_id)) { + PublicAccountUserLoggedIn(User::CreatePublicAccountUser(account_id)); + } else if (account_id != GetOwnerAccountId() && !user && (AreEphemeralUsersEnabled() || browser_restart)) { - RegularUserLoggedInAsEphemeral(user_id); + RegularUserLoggedInAsEphemeral(account_id); } else { - RegularUserLoggedIn(user_id); + RegularUserLoggedIn(account_id); } } @@ -267,21 +259,22 @@ void UserManagerBase::UserLoggedIn(const std::string& user_id, if (!primary_user_) { primary_user_ = active_user_; if (primary_user_->HasGaiaAccount()) - SendGaiaUserLoginMetrics(user_id); + SendGaiaUserLoginMetrics(account_id); } UMA_HISTOGRAM_ENUMERATION( "UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES); GetLocalState()->SetString( - kLastLoggedInGaiaUser, active_user_->HasGaiaAccount() ? user_id : ""); + kLastLoggedInGaiaUser, + active_user_->HasGaiaAccount() ? account_id.GetUserEmail() : ""); NotifyOnLogin(); PerformPostUserLoggedInActions(browser_restart); } -void UserManagerBase::SwitchActiveUser(const std::string& user_id) { - User* user = FindUserAndModify(user_id); +void UserManagerBase::SwitchActiveUser(const AccountId& account_id) { + User* user = FindUserAndModify(account_id); if (!user) { NOTREACHED() << "Switching to a non-existing user"; return; @@ -317,14 +310,15 @@ void UserManagerBase::SwitchActiveUser(const std::string& user_id) { } void UserManagerBase::SwitchToLastActiveUser() { - if (last_session_active_user_.empty()) + if (!last_session_active_account_id_.is_valid()) return; - if (GetActiveUser()->email() != last_session_active_user_) - SwitchActiveUser(last_session_active_user_); + if (AccountId::FromUserEmail(GetActiveUser()->email()) != + last_session_active_account_id_) + SwitchActiveUser(last_session_active_account_id_); // Make sure that this function gets run only once. - last_session_active_user_.clear(); + last_session_active_account_id_.clear(); } void UserManagerBase::SessionStarted() { @@ -341,47 +335,48 @@ void UserManagerBase::SessionStarted() { } } -void UserManagerBase::RemoveUser(const std::string& user_id, +void UserManagerBase::RemoveUser(const AccountId& account_id, RemoveUserDelegate* delegate) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); - if (!CanUserBeRemoved(FindUser(user_id))) + if (!CanUserBeRemoved(FindUser(account_id))) return; - RemoveUserInternal(user_id, delegate); + RemoveUserInternal(account_id, delegate); } -void UserManagerBase::RemoveUserInternal(const std::string& user_email, +void UserManagerBase::RemoveUserInternal(const AccountId& account_id, RemoveUserDelegate* delegate) { - RemoveNonOwnerUserInternal(user_email, delegate); + RemoveNonOwnerUserInternal(account_id, delegate); } -void UserManagerBase::RemoveNonOwnerUserInternal(const std::string& user_email, +void UserManagerBase::RemoveNonOwnerUserInternal(const AccountId& account_id, RemoveUserDelegate* delegate) { if (delegate) - delegate->OnBeforeUserRemoved(user_email); - RemoveUserFromList(user_email); + delegate->OnBeforeUserRemoved(account_id.GetUserEmail()); + RemoveUserFromList(account_id); cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( - user_email, base::Bind(&OnRemoveUserComplete, user_email)); + account_id.GetUserEmail(), + base::Bind(&OnRemoveUserComplete, account_id.GetUserEmail())); if (delegate) - delegate->OnUserRemoved(user_email); + delegate->OnUserRemoved(account_id.GetUserEmail()); } -void UserManagerBase::RemoveUserFromList(const std::string& user_id) { +void UserManagerBase::RemoveUserFromList(const AccountId& account_id) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); - RemoveNonCryptohomeData(user_id); + RemoveNonCryptohomeData(account_id); if (user_loading_stage_ == STAGE_LOADED) { - DeleteUser(RemoveRegularOrSupervisedUserFromList(user_id)); + DeleteUser(RemoveRegularOrSupervisedUserFromList(account_id)); } else if (user_loading_stage_ == STAGE_LOADING) { - DCHECK(gaia::ExtractDomainName(user_id) == + DCHECK(gaia::ExtractDomainName(account_id.GetUserEmail()) == chromeos::login::kSupervisedUserDomain || - HasPendingBootstrap(user_id)); + HasPendingBootstrap(account_id)); // Special case, removing partially-constructed supervised user or // boostrapping user during user list loading. ListPrefUpdate users_update(GetLocalState(), kRegularUsers); - users_update->Remove(base::StringValue(user_id), NULL); - OnUserRemoved(user_id); + users_update->Remove(base::StringValue(account_id.GetUserEmail()), nullptr); + OnUserRemoved(account_id); } else { NOTREACHED() << "Users are not loaded yet."; return; @@ -391,22 +386,22 @@ void UserManagerBase::RemoveUserFromList(const std::string& user_id) { GetLocalState()->CommitPendingWrite(); } -bool UserManagerBase::IsKnownUser(const std::string& user_id) const { - return FindUser(user_id) != NULL; +bool UserManagerBase::IsKnownUser(const AccountId& account_id) const { + return FindUser(account_id) != nullptr; } -const User* UserManagerBase::FindUser(const std::string& user_id) const { +const User* UserManagerBase::FindUser(const AccountId& account_id) const { DCHECK(task_runner_->RunsTasksOnCurrentThread()); - if (active_user_ && active_user_->email() == user_id) + if (active_user_ && active_user_->GetAccountId() == account_id) return active_user_; - return FindUserInList(user_id); + return FindUserInList(account_id); } -User* UserManagerBase::FindUserAndModify(const std::string& user_id) { +User* UserManagerBase::FindUserAndModify(const AccountId& account_id) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); - if (active_user_ && active_user_->email() == user_id) + if (active_user_ && active_user_->GetAccountId() == account_id) return active_user_; - return FindUserInListAndModify(user_id); + return FindUserInListAndModify(account_id); } const User* UserManagerBase::GetLoggedInUser() const { @@ -435,73 +430,73 @@ const User* UserManagerBase::GetPrimaryUser() const { } void UserManagerBase::SaveUserOAuthStatus( - const std::string& user_id, + const AccountId& account_id, User::OAuthTokenStatus oauth_token_status) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); DVLOG(1) << "Saving user OAuth token status in Local State"; - User* user = FindUserAndModify(user_id); + User* user = FindUserAndModify(account_id); if (user) user->set_oauth_token_status(oauth_token_status); // Do not update local state if data stored or cached outside the user's // cryptohome is to be treated as ephemeral. - if (IsUserNonCryptohomeDataEphemeral(user_id)) + if (IsUserNonCryptohomeDataEphemeral(account_id)) return; DictionaryPrefUpdate oauth_status_update(GetLocalState(), kUserOAuthTokenStatus); oauth_status_update->SetWithoutPathExpansion( - user_id, + account_id.GetUserEmail(), new base::FundamentalValue(static_cast<int>(oauth_token_status))); } -void UserManagerBase::SaveForceOnlineSignin(const std::string& user_id, +void UserManagerBase::SaveForceOnlineSignin(const AccountId& account_id, bool force_online_signin) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); // Do not update local state if data stored or cached outside the user's // cryptohome is to be treated as ephemeral. - if (IsUserNonCryptohomeDataEphemeral(user_id)) + if (IsUserNonCryptohomeDataEphemeral(account_id)) return; DictionaryPrefUpdate force_online_update(GetLocalState(), kUserForceOnlineSignin); - force_online_update->SetBooleanWithoutPathExpansion(user_id, + force_online_update->SetBooleanWithoutPathExpansion(account_id.GetUserEmail(), force_online_signin); } -void UserManagerBase::SaveUserDisplayName(const std::string& user_id, +void UserManagerBase::SaveUserDisplayName(const AccountId& account_id, const base::string16& display_name) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); - if (User* user = FindUserAndModify(user_id)) { + if (User* user = FindUserAndModify(account_id)) { user->set_display_name(display_name); // Do not update local state if data stored or cached outside the user's // cryptohome is to be treated as ephemeral. - if (!IsUserNonCryptohomeDataEphemeral(user_id)) { + if (!IsUserNonCryptohomeDataEphemeral(account_id)) { DictionaryPrefUpdate display_name_update(GetLocalState(), kUserDisplayName); display_name_update->SetWithoutPathExpansion( - user_id, new base::StringValue(display_name)); + account_id.GetUserEmail(), new base::StringValue(display_name)); } } } base::string16 UserManagerBase::GetUserDisplayName( - const std::string& user_id) const { - const User* user = FindUser(user_id); + const AccountId& account_id) const { + const User* user = FindUser(account_id); return user ? user->display_name() : base::string16(); } -void UserManagerBase::SaveUserDisplayEmail(const std::string& user_id, +void UserManagerBase::SaveUserDisplayEmail(const AccountId& account_id, const std::string& display_email) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); - User* user = FindUserAndModify(user_id); + User* user = FindUserAndModify(account_id); if (!user) { - LOG(ERROR) << "User not found: " << user_id; + LOG(ERROR) << "User not found: " << account_id.GetUserEmail(); return; // Ignore if there is no such user. } @@ -509,88 +504,89 @@ void UserManagerBase::SaveUserDisplayEmail(const std::string& user_id, // Do not update local state if data stored or cached outside the user's // cryptohome is to be treated as ephemeral. - if (IsUserNonCryptohomeDataEphemeral(user_id)) + if (IsUserNonCryptohomeDataEphemeral(account_id)) return; DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail); display_email_update->SetWithoutPathExpansion( - user_id, new base::StringValue(display_email)); + account_id.GetUserEmail(), new base::StringValue(display_email)); } std::string UserManagerBase::GetUserDisplayEmail( - const std::string& user_id) const { - const User* user = FindUser(user_id); - return user ? user->display_email() : user_id; + const AccountId& account_id) const { + const User* user = FindUser(account_id); + return user ? user->display_email() : account_id.GetUserEmail(); } -void UserManagerBase::SaveUserType(const std::string& user_id, +void UserManagerBase::SaveUserType(const AccountId& account_id, const UserType& user_type) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); - User* user = FindUserAndModify(user_id); + User* user = FindUserAndModify(account_id); if (!user) { - LOG(ERROR) << "User not found: " << user_id; + LOG(ERROR) << "User not found: " << account_id.GetUserEmail(); return; // Ignore if there is no such user. } // Do not update local state if data stored or cached outside the user's // cryptohome is to be treated as ephemeral. - if (IsUserNonCryptohomeDataEphemeral(user_id)) + if (IsUserNonCryptohomeDataEphemeral(account_id)) return; DictionaryPrefUpdate user_type_update(GetLocalState(), kUserType); user_type_update->SetWithoutPathExpansion( - user_id, new base::FundamentalValue(static_cast<int>(user_type))); + account_id.GetUserEmail(), + new base::FundamentalValue(static_cast<int>(user_type))); GetLocalState()->CommitPendingWrite(); } -void UserManagerBase::UpdateUsingSAML(const std::string& user_id, +void UserManagerBase::UpdateUsingSAML(const AccountId& account_id, const bool using_saml) { - SetKnownUserBooleanPref(user_id, kUsingSAMLKey, using_saml); + SetKnownUserBooleanPref(account_id, kUsingSAMLKey, using_saml); } -bool UserManagerBase::FindUsingSAML(const std::string& user_id) { +bool UserManagerBase::FindUsingSAML(const AccountId& account_id) { bool using_saml; - if (GetKnownUserBooleanPref(user_id, kUsingSAMLKey, &using_saml)) + if (GetKnownUserBooleanPref(account_id, kUsingSAMLKey, &using_saml)) return using_saml; return false; } -void UserManagerBase::UpdateReauthReason(const std::string& user_id, +void UserManagerBase::UpdateReauthReason(const AccountId& account_id, const int reauth_reason) { - SetKnownUserIntegerPref(user_id, kReauthReasonKey, reauth_reason); + SetKnownUserIntegerPref(account_id, kReauthReasonKey, reauth_reason); } -bool UserManagerBase::FindReauthReason(const std::string& user_id, +bool UserManagerBase::FindReauthReason(const AccountId& account_id, int* out_value) { - return GetKnownUserIntegerPref(user_id, kReauthReasonKey, out_value); + return GetKnownUserIntegerPref(account_id, kReauthReasonKey, out_value); } void UserManagerBase::UpdateUserAccountData( - const std::string& user_id, + const AccountId& account_id, const UserAccountData& account_data) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); - SaveUserDisplayName(user_id, account_data.display_name()); + SaveUserDisplayName(account_id, account_data.display_name()); - if (User* user = FindUserAndModify(user_id)) { + if (User* user = FindUserAndModify(account_id)) { base::string16 given_name = account_data.given_name(); user->set_given_name(given_name); - if (!IsUserNonCryptohomeDataEphemeral(user_id)) { + if (!IsUserNonCryptohomeDataEphemeral(account_id)) { DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); given_name_update->SetWithoutPathExpansion( - user_id, new base::StringValue(given_name)); + account_id.GetUserEmail(), new base::StringValue(given_name)); } } - UpdateUserAccountLocale(user_id, account_data.locale()); + UpdateUserAccountLocale(account_id, account_data.locale()); } // static void UserManagerBase::ParseUserList(const base::ListValue& users_list, - const std::set<std::string>& existing_users, - std::vector<std::string>* users_vector, - std::set<std::string>* users_set) { + const std::set<AccountId>& existing_users, + std::vector<AccountId>* users_vector, + std::set<AccountId>* users_set) { users_vector->clear(); users_set->clear(); for (size_t i = 0; i < users_list.GetSize(); ++i) { @@ -599,12 +595,13 @@ void UserManagerBase::ParseUserList(const base::ListValue& users_list, LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; continue; } - if (existing_users.find(email) != existing_users.end() || - !users_set->insert(email).second) { + const AccountId account_id(AccountId::FromUserEmail(email)); + if (existing_users.find(account_id) != existing_users.end() || + !users_set->insert(account_id).second) { LOG(ERROR) << "Duplicate user: " << email; continue; } - users_vector->push_back(email); + users_vector->push_back(account_id); } } @@ -631,7 +628,7 @@ bool UserManagerBase::IsCurrentUserNew() const { bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const { DCHECK(task_runner_->RunsTasksOnCurrentThread()); return IsUserLoggedIn() && - IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->email()); + IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->GetAccountId()); } bool UserManagerBase::CanCurrentUserLock() const { @@ -687,17 +684,17 @@ bool UserManagerBase::IsSessionStarted() const { } bool UserManagerBase::IsUserNonCryptohomeDataEphemeral( - const std::string& user_id) const { + const AccountId& account_id) const { // Data belonging to the guest and stub users is always ephemeral. - if (user_id == chromeos::login::kGuestUserName || - user_id == chromeos::login::kStubUser) { + if (account_id == chromeos::login::GuestAccountId() || + account_id == chromeos::login::StubAccountId()) { return true; } // Data belonging to the owner, anyone found on the user list and obsolete // public accounts whose data has not been removed yet is not ephemeral. - if (user_id == GetOwnerEmail() || UserExistsInList(user_id) || - IsPublicAccountMarkedForRemoval(user_id)) { + if (account_id == GetOwnerAccountId() || UserExistsInList(account_id) || + IsPublicAccountMarkedForRemoval(account_id)) { return false; } @@ -706,7 +703,7 @@ bool UserManagerBase::IsUserNonCryptohomeDataEphemeral( // policy was enabled. // - or - // b) The user logged into any other account type. - if (IsUserLoggedIn() && (user_id == GetLoggedInUser()->email()) && + if (IsUserLoggedIn() && (account_id == GetLoggedInUser()->GetAccountId()) && (is_current_user_ephemeral_regular_user_ || !IsLoggedInAsUserWithGaiaAccount())) { return true; @@ -786,20 +783,20 @@ void UserManagerBase::SetIsCurrentUserNew(bool is_new) { is_current_user_new_ = is_new; } -bool UserManagerBase::HasPendingBootstrap(const std::string& user_id) const { +bool UserManagerBase::HasPendingBootstrap(const AccountId& account_id) const { return false; } -void UserManagerBase::SetOwnerEmail(const std::string& owner_user_id) { - owner_email_ = owner_user_id; +void UserManagerBase::SetOwnerId(const AccountId& owner_account_id) { + owner_account_id_ = owner_account_id; } -const std::string& UserManagerBase::GetPendingUserSwitchID() const { +const AccountId& UserManagerBase::GetPendingUserSwitchID() const { return pending_user_switch_; } -void UserManagerBase::SetPendingUserSwitchID(const std::string& user_id) { - pending_user_switch_ = user_id; +void UserManagerBase::SetPendingUserSwitchId(const AccountId& account_id) { + pending_user_switch_ = account_id; } void UserManagerBase::EnsureUsersLoaded() { @@ -827,27 +824,27 @@ void UserManagerBase::EnsureUsersLoaded() { local_state->GetDictionary(kUserType); // Load public sessions first. - std::set<std::string> public_sessions_set; + std::set<AccountId> public_sessions_set; LoadPublicAccounts(&public_sessions_set); // Load regular users and supervised users. - std::vector<std::string> regular_users; - std::set<std::string> regular_users_set; + std::vector<AccountId> regular_users; + std::set<AccountId> regular_users_set; ParseUserList(*prefs_regular_users, public_sessions_set, ®ular_users, ®ular_users_set); - for (std::vector<std::string>::const_iterator it = regular_users.begin(); - it != regular_users.end(); - ++it) { - User* user = NULL; - const std::string domain = gaia::ExtractDomainName(*it); + for (std::vector<AccountId>::const_iterator it = regular_users.begin(); + it != regular_users.end(); ++it) { + User* user = nullptr; + const std::string domain = gaia::ExtractDomainName(it->GetUserEmail()); if (domain == chromeos::login::kSupervisedUserDomain) { user = User::CreateSupervisedUser(*it); } else { user = User::CreateRegularUser(*it); int user_type; - if (prefs_user_types->GetIntegerWithoutPathExpansion(*it, &user_type) && + if (prefs_user_types->GetIntegerWithoutPathExpansion(it->GetUserEmail(), + &user_type) && user_type == USER_TYPE_CHILD) { ChangeUserChildStatus(user, true /* is child */); } @@ -858,18 +855,19 @@ void UserManagerBase::EnsureUsersLoaded() { users_.push_back(user); base::string16 display_name; - if (prefs_display_names->GetStringWithoutPathExpansion(*it, + if (prefs_display_names->GetStringWithoutPathExpansion(it->GetUserEmail(), &display_name)) { user->set_display_name(display_name); } base::string16 given_name; - if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) { + if (prefs_given_names->GetStringWithoutPathExpansion(it->GetUserEmail(), + &given_name)) { user->set_given_name(given_name); } std::string display_email; - if (prefs_display_emails->GetStringWithoutPathExpansion(*it, + if (prefs_display_emails->GetStringWithoutPathExpansion(it->GetUserEmail(), &display_email)) { user->set_display_email(display_email); } @@ -885,32 +883,32 @@ UserList& UserManagerBase::GetUsersAndModify() { return users_; } -const User* UserManagerBase::FindUserInList(const std::string& user_id) const { +const User* UserManagerBase::FindUserInList(const AccountId& account_id) const { const UserList& users = GetUsers(); for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { - if ((*it)->email() == user_id) + if ((*it)->GetAccountId() == account_id) return *it; } - return NULL; + return nullptr; } -bool UserManagerBase::UserExistsInList(const std::string& user_id) const { +bool UserManagerBase::UserExistsInList(const AccountId& account_id) const { const base::ListValue* user_list = GetLocalState()->GetList(kRegularUsers); for (size_t i = 0; i < user_list->GetSize(); ++i) { std::string email; - if (user_list->GetString(i, &email) && (user_id == email)) + if (user_list->GetString(i, &email) && (account_id.GetUserEmail() == email)) return true; } return false; } -User* UserManagerBase::FindUserInListAndModify(const std::string& user_id) { +User* UserManagerBase::FindUserInListAndModify(const AccountId& account_id) { UserList& users = GetUsersAndModify(); for (UserList::iterator it = users.begin(); it != users.end(); ++it) { - if ((*it)->email() == user_id) + if ((*it)->GetAccountId() == account_id) return *it; } - return NULL; + return nullptr; } void UserManagerBase::GuestUserLoggedIn() { @@ -925,16 +923,16 @@ void UserManagerBase::AddUserRecord(User* user) { users_.insert(users_.begin(), user); } -void UserManagerBase::RegularUserLoggedIn(const std::string& user_id) { +void UserManagerBase::RegularUserLoggedIn(const AccountId& account_id) { // Remove the user from the user list. - active_user_ = RemoveRegularOrSupervisedUserFromList(user_id); + active_user_ = RemoveRegularOrSupervisedUserFromList(account_id); // If the user was not found on the user list, create a new user. SetIsCurrentUserNew(!active_user_); if (IsCurrentUserNew()) { - active_user_ = User::CreateRegularUser(user_id); - active_user_->set_oauth_token_status(LoadUserOAuthStatus(user_id)); - SaveUserDisplayName(active_user_->email(), + active_user_ = User::CreateRegularUser(account_id); + active_user_->set_oauth_token_status(LoadUserOAuthStatus(account_id)); + SaveUserDisplayName(active_user_->GetAccountId(), base::UTF8ToUTF16(active_user_->GetAccountName(true))); } @@ -945,11 +943,11 @@ void UserManagerBase::RegularUserLoggedIn(const std::string& user_id) { } void UserManagerBase::RegularUserLoggedInAsEphemeral( - const std::string& user_id) { + const AccountId& account_id) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); SetIsCurrentUserNew(true); is_current_user_ephemeral_regular_user_ = true; - active_user_ = User::CreateRegularUser(user_id); + active_user_ = User::CreateRegularUser(account_id); } void UserManagerBase::NotifyOnLogin() { @@ -961,77 +959,83 @@ void UserManagerBase::NotifyOnLogin() { } User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus( - const std::string& user_id) const { + const AccountId& account_id) const { DCHECK(task_runner_->RunsTasksOnCurrentThread()); const base::DictionaryValue* prefs_oauth_status = GetLocalState()->GetDictionary(kUserOAuthTokenStatus); int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; if (prefs_oauth_status && - prefs_oauth_status->GetIntegerWithoutPathExpansion(user_id, - &oauth_token_status)) { + prefs_oauth_status->GetIntegerWithoutPathExpansion( + account_id.GetUserEmail(), &oauth_token_status)) { User::OAuthTokenStatus status = static_cast<User::OAuthTokenStatus>(oauth_token_status); - HandleUserOAuthTokenStatusChange(user_id, status); + HandleUserOAuthTokenStatusChange(account_id, status); return status; } return User::OAUTH_TOKEN_STATUS_UNKNOWN; } -bool UserManagerBase::LoadForceOnlineSignin(const std::string& user_id) const { +bool UserManagerBase::LoadForceOnlineSignin(const AccountId& account_id) const { DCHECK(task_runner_->RunsTasksOnCurrentThread()); const base::DictionaryValue* prefs_force_online = GetLocalState()->GetDictionary(kUserForceOnlineSignin); bool force_online_signin = false; if (prefs_force_online) { - prefs_force_online->GetBooleanWithoutPathExpansion(user_id, - &force_online_signin); + prefs_force_online->GetBooleanWithoutPathExpansion( + account_id.GetUserEmail(), &force_online_signin); } return force_online_signin; } -void UserManagerBase::RemoveNonCryptohomeData(const std::string& user_id) { +void UserManagerBase::RemoveNonCryptohomeData(const AccountId& account_id) { PrefService* prefs = GetLocalState(); DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName); - prefs_display_name_update->RemoveWithoutPathExpansion(user_id, NULL); + prefs_display_name_update->RemoveWithoutPathExpansion( + account_id.GetUserEmail(), nullptr); DictionaryPrefUpdate prefs_given_name_update(prefs, kUserGivenName); - prefs_given_name_update->RemoveWithoutPathExpansion(user_id, NULL); + prefs_given_name_update->RemoveWithoutPathExpansion(account_id.GetUserEmail(), + nullptr); DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); - prefs_display_email_update->RemoveWithoutPathExpansion(user_id, NULL); + prefs_display_email_update->RemoveWithoutPathExpansion( + account_id.GetUserEmail(), nullptr); DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); - prefs_oauth_update->RemoveWithoutPathExpansion(user_id, NULL); + prefs_oauth_update->RemoveWithoutPathExpansion(account_id.GetUserEmail(), + nullptr); DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin); - prefs_force_online_update->RemoveWithoutPathExpansion(user_id, NULL); + prefs_force_online_update->RemoveWithoutPathExpansion( + account_id.GetUserEmail(), nullptr); - RemoveKnownUserPrefs(user_id); + RemoveKnownUserPrefs(account_id); - std::string last_active_user = GetLocalState()->GetString(kLastActiveUser); - if (user_id == last_active_user) + const AccountId last_active_user = + AccountId::FromUserEmail(GetLocalState()->GetString(kLastActiveUser)); + if (account_id == last_active_user) GetLocalState()->SetString(kLastActiveUser, std::string()); } bool UserManagerBase::FindKnownUserPrefs( - const UserID& user_id, + const AccountId& account_id, const base::DictionaryValue** out_value) { PrefService* local_state = GetLocalState(); // Local State may not be initialized in tests. if (!local_state) return false; - if (IsUserNonCryptohomeDataEphemeral(user_id)) + if (IsUserNonCryptohomeDataEphemeral(account_id)) return false; const base::ListValue* known_users = local_state->GetList(kKnownUsers); for (size_t i = 0; i < known_users->GetSize(); ++i) { const base::DictionaryValue* element = nullptr; if (known_users->GetDictionary(i, &element)) { - if (UserMatches(user_id, *element)) { + if (UserMatches(account_id, *element)) { known_users->GetDictionary(i, out_value); return true; } @@ -1040,7 +1044,7 @@ bool UserManagerBase::FindKnownUserPrefs( return false; } -void UserManagerBase::UpdateKnownUserPrefs(const UserID& user_id, +void UserManagerBase::UpdateKnownUserPrefs(const AccountId& account_id, const base::DictionaryValue& values, bool clear) { PrefService* local_state = GetLocalState(); @@ -1049,39 +1053,39 @@ void UserManagerBase::UpdateKnownUserPrefs(const UserID& user_id, if (!local_state) return; - if (IsUserNonCryptohomeDataEphemeral(user_id)) + if (IsUserNonCryptohomeDataEphemeral(account_id)) return; ListPrefUpdate update(local_state, kKnownUsers); for (size_t i = 0; i < update->GetSize(); ++i) { base::DictionaryValue* element = nullptr; if (update->GetDictionary(i, &element)) { - if (UserMatches(user_id, *element)) { + if (UserMatches(account_id, *element)) { if (clear) element->Clear(); element->MergeDictionary(&values); - UpdateIdentity(user_id, *element); + UpdateIdentity(account_id, *element); return; } } } scoped_ptr<base::DictionaryValue> new_value(new base::DictionaryValue()); new_value->MergeDictionary(&values); - UpdateIdentity(user_id, *new_value); + UpdateIdentity(account_id, *new_value); update->Append(new_value.release()); } -bool UserManagerBase::GetKnownUserStringPref(const UserID& user_id, +bool UserManagerBase::GetKnownUserStringPref(const AccountId& account_id, const std::string& path, std::string* out_value) { const base::DictionaryValue* user_pref_dict = nullptr; - if (!FindKnownUserPrefs(user_id, &user_pref_dict)) + if (!FindKnownUserPrefs(account_id, &user_pref_dict)) return false; return user_pref_dict->GetString(path, out_value); } -void UserManagerBase::SetKnownUserStringPref(const UserID& user_id, +void UserManagerBase::SetKnownUserStringPref(const AccountId& account_id, const std::string& path, const std::string& in_value) { PrefService* local_state = GetLocalState(); @@ -1093,20 +1097,20 @@ void UserManagerBase::SetKnownUserStringPref(const UserID& user_id, ListPrefUpdate update(local_state, kKnownUsers); base::DictionaryValue dict; dict.SetString(path, in_value); - UpdateKnownUserPrefs(user_id, dict, false); + UpdateKnownUserPrefs(account_id, dict, false); } -bool UserManagerBase::GetKnownUserBooleanPref(const UserID& user_id, +bool UserManagerBase::GetKnownUserBooleanPref(const AccountId& account_id, const std::string& path, bool* out_value) { const base::DictionaryValue* user_pref_dict = nullptr; - if (!FindKnownUserPrefs(user_id, &user_pref_dict)) + if (!FindKnownUserPrefs(account_id, &user_pref_dict)) return false; return user_pref_dict->GetBoolean(path, out_value); } -void UserManagerBase::SetKnownUserBooleanPref(const UserID& user_id, +void UserManagerBase::SetKnownUserBooleanPref(const AccountId& account_id, const std::string& path, const bool in_value) { PrefService* local_state = GetLocalState(); @@ -1118,19 +1122,19 @@ void UserManagerBase::SetKnownUserBooleanPref(const UserID& user_id, ListPrefUpdate update(local_state, kKnownUsers); base::DictionaryValue dict; dict.SetBoolean(path, in_value); - UpdateKnownUserPrefs(user_id, dict, false); + UpdateKnownUserPrefs(account_id, dict, false); } -bool UserManagerBase::GetKnownUserIntegerPref(const UserID& user_id, +bool UserManagerBase::GetKnownUserIntegerPref(const AccountId& account_id, const std::string& path, int* out_value) { const base::DictionaryValue* user_pref_dict = nullptr; - if (!FindKnownUserPrefs(user_id, &user_pref_dict)) + if (!FindKnownUserPrefs(account_id, &user_pref_dict)) return false; return user_pref_dict->GetInteger(path, out_value); } -void UserManagerBase::SetKnownUserIntegerPref(const UserID& user_id, +void UserManagerBase::SetKnownUserIntegerPref(const AccountId& account_id, const std::string& path, const int in_value) { PrefService* local_state = GetLocalState(); @@ -1142,80 +1146,92 @@ void UserManagerBase::SetKnownUserIntegerPref(const UserID& user_id, ListPrefUpdate update(local_state, kKnownUsers); base::DictionaryValue dict; dict.SetInteger(path, in_value); - UpdateKnownUserPrefs(user_id, dict, false); + UpdateKnownUserPrefs(account_id, dict, false); } -bool UserManagerBase::GetKnownUserCanonicalEmail(const UserID& user_id, - std::string* out_email) { - return GetKnownUserStringPref(user_id, kCanonicalEmail, out_email); +bool UserManagerBase::GetKnownUserAccountId( + const AccountId& authenticated_account_id, + AccountId* out_account_id) { + DCHECK(!authenticated_account_id.GetGaiaId().empty()); + std::string canonical_email; + if (!GetKnownUserStringPref( + AccountId::FromGaiaId(authenticated_account_id.GetGaiaId()), + kCanonicalEmail, &canonical_email)) + return false; + + *out_account_id = authenticated_account_id; + out_account_id->SetUserEmail(canonical_email); + return true; } -void UserManagerBase::UpdateGaiaID(const UserID& user_id, +void UserManagerBase::UpdateGaiaID(const AccountId& account_id, const std::string& gaia_id) { - SetKnownUserStringPref(user_id, kGAIAIdKey, gaia_id); + SetKnownUserStringPref(account_id, kGAIAIdKey, gaia_id); } -bool UserManagerBase::FindGaiaID(const UserID& user_id, +bool UserManagerBase::FindGaiaID(const AccountId& account_id, std::string* out_value) { - return GetKnownUserStringPref(user_id, kGAIAIdKey, out_value); + return GetKnownUserStringPref(account_id, kGAIAIdKey, out_value); } -void UserManagerBase::SetKnownUserDeviceId(const UserID& user_id, +void UserManagerBase::SetKnownUserDeviceId(const AccountId& account_id, const std::string& device_id) { - const std::string known_device_id = GetKnownUserDeviceId(user_id); + const std::string known_device_id = GetKnownUserDeviceId(account_id); if (!known_device_id.empty() && device_id != known_device_id) { NOTREACHED() << "Trying to change device ID for known user."; } - SetKnownUserStringPref(user_id, kDeviceId, device_id); + SetKnownUserStringPref(account_id, kDeviceId, device_id); } -std::string UserManagerBase::GetKnownUserDeviceId(const UserID& user_id) { +std::string UserManagerBase::GetKnownUserDeviceId(const AccountId& account_id) { std::string device_id; - if (GetKnownUserStringPref(user_id, kDeviceId, &device_id)) { + if (GetKnownUserStringPref(account_id, kDeviceId, &device_id)) { return device_id; } return std::string(); } -void UserManagerBase::SetKnownUserGAPSCookie(const UserID& user_id, +void UserManagerBase::SetKnownUserGAPSCookie(const AccountId& account_id, const std::string& gaps_cookie) { - SetKnownUserStringPref(user_id, kGAPSCookie, gaps_cookie); + SetKnownUserStringPref(account_id, kGAPSCookie, gaps_cookie); } -std::string UserManagerBase::GetKnownUserGAPSCookie(const UserID& user_id) { +std::string UserManagerBase::GetKnownUserGAPSCookie( + const AccountId& account_id) { std::string gaps_cookie; - if (GetKnownUserStringPref(user_id, kGAPSCookie, &gaps_cookie)) { + if (GetKnownUserStringPref(account_id, kGAPSCookie, &gaps_cookie)) { return gaps_cookie; } return std::string(); } User* UserManagerBase::RemoveRegularOrSupervisedUserFromList( - const std::string& user_id) { + const AccountId& account_id) { ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); prefs_users_update->Clear(); - User* user = NULL; + User* user = nullptr; for (UserList::iterator it = users_.begin(); it != users_.end();) { - const std::string user_email = (*it)->email(); - if (user_email == user_id) { + if ((*it)->GetAccountId() == account_id) { user = *it; it = users_.erase(it); } else { - if ((*it)->HasGaiaAccount() || (*it)->IsSupervised()) + if ((*it)->HasGaiaAccount() || (*it)->IsSupervised()) { + const std::string user_email = (*it)->email(); prefs_users_update->Append(new base::StringValue(user_email)); + } ++it; } } - OnUserRemoved(user_id); + OnUserRemoved(account_id); return user; } -void UserManagerBase::RemoveKnownUserPrefs(const UserID& user_id) { +void UserManagerBase::RemoveKnownUserPrefs(const AccountId& account_id) { ListPrefUpdate update(GetLocalState(), kKnownUsers); for (size_t i = 0; i < update->GetSize(); ++i) { base::DictionaryValue* element = nullptr; if (update->GetDictionary(i, &element)) { - if (UserMatches(user_id, *element)) { + if (UserMatches(account_id, *element)) { update->Remove(i, nullptr); break; } @@ -1250,8 +1266,9 @@ void UserManagerBase::ChangeUserChildStatus(User* user, bool is_child) { if (user->IsSupervised() == is_child) return; user->SetIsChild(is_child); - SaveUserType(user->email(), is_child ? user_manager::USER_TYPE_CHILD - : user_manager::USER_TYPE_REGULAR); + SaveUserType(user->GetAccountId(), is_child + ? user_manager::USER_TYPE_CHILD + : user_manager::USER_TYPE_REGULAR); FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, session_state_observer_list_, UserChangedChildStatus(user)); @@ -1301,7 +1318,7 @@ void UserManagerBase::SetLRUUser(User* user) { lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); } -void UserManagerBase::SendGaiaUserLoginMetrics(const std::string& user_id) { +void UserManagerBase::SendGaiaUserLoginMetrics(const AccountId& account_id) { // If this isn't the first time Chrome was run after the system booted, // assume that Chrome was restarted because a previous session ended. if (!base::CommandLine::ForCurrentProcess()->HasSwitch( @@ -1310,7 +1327,8 @@ void UserManagerBase::SendGaiaUserLoginMetrics(const std::string& user_id) { GetLocalState()->GetString(kLastLoggedInGaiaUser); const base::TimeDelta time_to_login = base::TimeTicks::Now() - manager_creation_time_; - if (!last_email.empty() && user_id != last_email && + if (!last_email.empty() && + account_id != AccountId::FromUserEmail(last_email) && time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", time_to_login.InSeconds(), @@ -1321,31 +1339,29 @@ void UserManagerBase::SendGaiaUserLoginMetrics(const std::string& user_id) { } } -void UserManagerBase::UpdateUserAccountLocale(const std::string& user_id, +void UserManagerBase::UpdateUserAccountLocale(const AccountId& account_id, const std::string& locale) { scoped_ptr<std::string> resolved_locale(new std::string()); if (!locale.empty() && locale != GetApplicationLocale()) { - // base::Pased will NULL out |resolved_locale|, so cache the underlying ptr. + // base::Pased will nullptr out |resolved_locale|, so cache the underlying + // ptr. std::string* raw_resolved_locale = resolved_locale.get(); blocking_task_runner_->PostTaskAndReply( - FROM_HERE, - base::Bind(ResolveLocale, - locale, - base::Unretained(raw_resolved_locale)), + FROM_HERE, base::Bind(ResolveLocale, locale, + base::Unretained(raw_resolved_locale)), base::Bind(&UserManagerBase::DoUpdateAccountLocale, - weak_factory_.GetWeakPtr(), - user_id, + weak_factory_.GetWeakPtr(), account_id, base::Passed(&resolved_locale))); } else { resolved_locale.reset(new std::string(locale)); - DoUpdateAccountLocale(user_id, resolved_locale.Pass()); + DoUpdateAccountLocale(account_id, resolved_locale.Pass()); } } void UserManagerBase::DoUpdateAccountLocale( - const std::string& user_id, + const AccountId& account_id, scoped_ptr<std::string> resolved_locale) { - User* user = FindUserAndModify(user_id); + User* user = FindUserAndModify(account_id); if (user && resolved_locale) user->SetAccountLocale(*resolved_locale); } @@ -1354,7 +1370,7 @@ void UserManagerBase::DeleteUser(User* user) { const bool is_active_user = (user == active_user_); delete user; if (is_active_user) - active_user_ = NULL; + active_user_ = nullptr; } } // namespace user_manager diff --git a/components/user_manager/user_manager_base.h b/components/user_manager/user_manager_base.h index a5f5f8f..ead7d44 100644 --- a/components/user_manager/user_manager_base.h +++ b/components/user_manager/user_manager_base.h @@ -15,8 +15,8 @@ #include "base/observer_list.h" #include "base/synchronization/lock.h" #include "base/time/time.h" +#include "components/signin/core/account_id/account_id.h" #include "components/user_manager/user.h" -#include "components/user_manager/user_id.h" #include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager_export.h" #include "components/user_manager/user_type.h" @@ -51,37 +51,37 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { const UserList& GetUsers() const override; const UserList& GetLoggedInUsers() const override; const UserList& GetLRULoggedInUsers() const override; - const std::string& GetOwnerEmail() const override; - void UserLoggedIn(const std::string& user_id, + const AccountId& GetOwnerAccountId() const override; + void UserLoggedIn(const AccountId& account_id, const std::string& user_id_hash, bool browser_restart) override; - void SwitchActiveUser(const std::string& user_id) override; + void SwitchActiveUser(const AccountId& account_id) override; void SwitchToLastActiveUser() override; void SessionStarted() override; - void RemoveUser(const std::string& user_id, + void RemoveUser(const AccountId& account_id, RemoveUserDelegate* delegate) override; - void RemoveUserFromList(const std::string& user_id) override; - bool IsKnownUser(const std::string& user_id) const override; - const User* FindUser(const std::string& user_id) const override; - User* FindUserAndModify(const std::string& user_id) override; + void RemoveUserFromList(const AccountId& account_id) override; + bool IsKnownUser(const AccountId& account_id) const override; + const User* FindUser(const AccountId& account_id) const override; + User* FindUserAndModify(const AccountId& account_id) override; const User* GetLoggedInUser() const override; User* GetLoggedInUser() override; const User* GetActiveUser() const override; User* GetActiveUser() override; const User* GetPrimaryUser() const override; - void SaveUserOAuthStatus(const std::string& user_id, + void SaveUserOAuthStatus(const AccountId& account_id, User::OAuthTokenStatus oauth_token_status) override; - void SaveForceOnlineSignin(const std::string& user_id, + void SaveForceOnlineSignin(const AccountId& account_id, bool force_online_signin) override; - void SaveUserDisplayName(const std::string& user_id, + void SaveUserDisplayName(const AccountId& account_id, const base::string16& display_name) override; - base::string16 GetUserDisplayName(const std::string& user_id) const override; - void SaveUserDisplayEmail(const std::string& user_id, + base::string16 GetUserDisplayName(const AccountId& account_id) const override; + void SaveUserDisplayEmail(const AccountId& account_id, const std::string& display_email) override; - std::string GetUserDisplayEmail(const std::string& user_id) const override; - void SaveUserType(const std::string& user_id, + std::string GetUserDisplayEmail(const AccountId& account_id) const override; + void SaveUserType(const AccountId& account_id, const UserType& user_type) override; - void UpdateUserAccountData(const std::string& user_id, + void UpdateUserAccountData(const AccountId& account_id, const UserAccountData& account_data) override; bool IsCurrentUserOwner() const override; bool IsCurrentUserNew() const override; @@ -97,7 +97,7 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { bool IsLoggedInAsStub() const override; bool IsSessionStarted() const override; bool IsUserNonCryptohomeDataEphemeral( - const std::string& user_id) const override; + const AccountId& account_id) const override; void AddObserver(UserManager::Observer* obs) override; void RemoveObserver(UserManager::Observer* obs) override; void AddSessionStateObserver( @@ -106,58 +106,61 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { UserManager::UserSessionStateObserver* obs) override; void NotifyLocalStateChanged() override; void ChangeUserChildStatus(User* user, bool is_child) override; - bool FindKnownUserPrefs(const UserID& user_id, + bool FindKnownUserPrefs(const AccountId& account_id, const base::DictionaryValue** out_value) override; - void UpdateKnownUserPrefs(const UserID& user_id, + void UpdateKnownUserPrefs(const AccountId& account_id, const base::DictionaryValue& values, bool clear) override; - bool GetKnownUserStringPref(const UserID& user_id, + bool GetKnownUserStringPref(const AccountId& account_id, const std::string& path, std::string* out_value) override; - void SetKnownUserStringPref(const UserID& user_id, + void SetKnownUserStringPref(const AccountId& account_id, const std::string& path, const std::string& in_value) override; - bool GetKnownUserBooleanPref(const UserID& user_id, + bool GetKnownUserBooleanPref(const AccountId& account_id, const std::string& path, bool* out_value) override; - void SetKnownUserBooleanPref(const UserID& user_id, + void SetKnownUserBooleanPref(const AccountId& account_id, const std::string& path, const bool in_value) override; - bool GetKnownUserIntegerPref(const UserID& user_id, + bool GetKnownUserIntegerPref(const AccountId& account_id, const std::string& path, int* out_value) override; - void SetKnownUserIntegerPref(const UserID& user_id, + void SetKnownUserIntegerPref(const AccountId& account_id, const std::string& path, - const int in_value) override; - bool GetKnownUserCanonicalEmail(const UserID& user_id, - std::string* out_email) override; - void UpdateGaiaID(const UserID& user_id, const std::string& gaia_id) override; - bool FindGaiaID(const UserID& user_id, std::string* out_value) override; - void UpdateUsingSAML(const std::string& user_id, + int in_value) override; + bool GetKnownUserAccountId(const AccountId& authenticated_account_id, + AccountId* out_account_id) override; + void UpdateGaiaID(const AccountId& account_id, + const std::string& gaia_id) override; + bool FindGaiaID(const AccountId& account_id, std::string* out_value) override; + void UpdateUsingSAML(const AccountId& account_id, const bool using_saml) override; - bool FindUsingSAML(const std::string& user_id) override; - void SetKnownUserDeviceId(const UserID& user_id, + bool FindUsingSAML(const AccountId& account_id) override; + void SetKnownUserDeviceId(const AccountId& account_id, const std::string& device_id) override; - std::string GetKnownUserDeviceId(const UserID& user_id) override; - void SetKnownUserGAPSCookie(const UserID& user_id, + std::string GetKnownUserDeviceId(const AccountId& account_id) override; + void SetKnownUserGAPSCookie(const AccountId& account_id, const std::string& gaps_cookie) override; - std::string GetKnownUserGAPSCookie(const UserID& user_id) override; - void UpdateReauthReason(const std::string& user_id, - const int reauth_reason) override; - bool FindReauthReason(const std::string& user_id, int* out_value) override; + std::string GetKnownUserGAPSCookie(const AccountId& account_id) override; + void UpdateReauthReason(const AccountId& account_id, + int reauth_reason) override; + bool FindReauthReason(const AccountId& account_id, int* out_value) override; + // This method updates "User was added to the device in this session nad is + // not full initialized yet" flag. virtual void SetIsCurrentUserNew(bool is_new); // TODO(xiyuan): Figure out a better way to expose this info. - virtual bool HasPendingBootstrap(const std::string& user_id) const; + virtual bool HasPendingBootstrap(const AccountId& account_id) const; // Helper function that copies users from |users_list| to |users_vector| and // |users_set|. Duplicates and users already present in |existing_users| are // skipped. static void ParseUserList(const base::ListValue& users_list, - const std::set<std::string>& existing_users, - std::vector<std::string>* users_vector, - std::set<std::string>* users_set); + const std::set<AccountId>& existing_users, + std::vector<AccountId>* users_vector, + std::set<AccountId>* users_set); // Returns true if trusted device policies have successfully been retrieved // and ephemeral users are enabled. @@ -185,9 +188,9 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { // Subsequent calls have no effect. Must be called on the UI thread. virtual void EnsureUsersLoaded(); - // Handle OAuth token |status| change for |user_id|. + // Handle OAuth token |status| change for |account_id|. virtual void HandleUserOAuthTokenStatusChange( - const std::string& user_id, + const AccountId& account_id, User::OAuthTokenStatus status) const = 0; // Returns true if device is enterprise managed. @@ -198,8 +201,7 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { // skipped. // Loads public accounts from the Local state and fills in // |public_sessions_set|. - virtual void LoadPublicAccounts( - std::set<std::string>* public_sessions_set) = 0; + virtual void LoadPublicAccounts(std::set<AccountId>* public_sessions_set) = 0; // Notifies that user has logged in. virtual void NotifyOnLogin(); @@ -224,36 +226,36 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { // Implementation for RemoveUser method. It is synchronous. It is called from // RemoveUserInternal after owner check. - virtual void RemoveNonOwnerUserInternal(const std::string& user_email, + virtual void RemoveNonOwnerUserInternal(const AccountId& account_id, RemoveUserDelegate* delegate); // Removes a regular or supervised user from the user list. // Returns the user if found or NULL otherwise. // Also removes the user from the persistent user list. - User* RemoveRegularOrSupervisedUserFromList(const std::string& user_id); + User* RemoveRegularOrSupervisedUserFromList(const AccountId& account_id); // Implementation for RemoveUser method. This is an asynchronous part of the // method, that verifies that owner will not get deleted, and calls // |RemoveNonOwnerUserInternal|. - virtual void RemoveUserInternal(const std::string& user_email, + virtual void RemoveUserInternal(const AccountId& account_id, RemoveUserDelegate* delegate); // Removes data stored or cached outside the user's cryptohome (wallpaper, // avatar, OAuth token status, display name, display email). - virtual void RemoveNonCryptohomeData(const std::string& user_id); + virtual void RemoveNonCryptohomeData(const AccountId& account_id); // Check for a particular user type. - // Returns true if |user_id| represents demo app. - virtual bool IsDemoApp(const std::string& user_id) const = 0; + // Returns true if |account_id| represents demo app. + virtual bool IsDemoApp(const AccountId& account_id) const = 0; - // Returns true if |user_id| represents kiosk app. - virtual bool IsKioskApp(const std::string& user_id) const = 0; + // Returns true if |account_id| represents kiosk app. + virtual bool IsKioskApp(const AccountId& account_id) const = 0; - // Returns true if |user_id| represents public account that has been marked + // Returns true if |account_id| represents public account that has been marked // for deletion. virtual bool IsPublicAccountMarkedForRemoval( - const std::string& user_id) const = 0; + const AccountId& account_id) const = 0; // These methods are called when corresponding user type has signed in. @@ -264,22 +266,22 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { virtual void GuestUserLoggedIn(); // Indicates that a kiosk app robot just logged in. - virtual void KioskAppLoggedIn(const std::string& app_id) = 0; + virtual void KioskAppLoggedIn(const AccountId& kiosk_app_account_id) = 0; // Indicates that a user just logged into a public session. virtual void PublicAccountUserLoggedIn(User* user) = 0; // Indicates that a regular user just logged in. - virtual void RegularUserLoggedIn(const std::string& user_id); + virtual void RegularUserLoggedIn(const AccountId& account_id); // Indicates that a regular user just logged in as ephemeral. - virtual void RegularUserLoggedInAsEphemeral(const std::string& user_id); + virtual void RegularUserLoggedInAsEphemeral(const AccountId& account_id); // Indicates that a supervised user just logged in. - virtual void SupervisedUserLoggedIn(const std::string& user_id) = 0; + virtual void SupervisedUserLoggedIn(const AccountId& account_id) = 0; // Should be called when regular user was removed. - virtual void OnUserRemoved(const std::string& user_id) = 0; + virtual void OnUserRemoved(const AccountId& account_id) = 0; // Getters/setters for private members. @@ -288,20 +290,20 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { virtual bool GetEphemeralUsersEnabled() const; virtual void SetEphemeralUsersEnabled(bool enabled); - virtual void SetOwnerEmail(const std::string& owner_user_id); + virtual void SetOwnerId(const AccountId& owner_account_id); - virtual const std::string& GetPendingUserSwitchID() const; - virtual void SetPendingUserSwitchID(const std::string& user_id); + virtual const AccountId& GetPendingUserSwitchID() const; + virtual void SetPendingUserSwitchId(const AccountId& account_id); // The logged-in user that is currently active in current session. // NULL until a user has logged in, then points to one // of the User instances in |users_|, the |guest_user_| instance or an // ephemeral user instance. - User* active_user_; + User* active_user_ = nullptr; // The primary user of the current session. It is recorded for the first // signed-in user and does not change thereafter. - User* primary_user_; + User* primary_user_ = nullptr; // List of all known users. User instances are owned by |this|. Regular users // are removed by |RemoveUserFromList|, public accounts by @@ -328,21 +330,21 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { // Returns the user with the given email address if found in the persistent // list. Returns |NULL| otherwise. - const User* FindUserInList(const std::string& user_id) const; + const User* FindUserInList(const AccountId& account_id) const; // Returns |true| if user with the given id is found in the persistent list. // Returns |false| otherwise. Does not trigger user loading. - bool UserExistsInList(const std::string& user_id) const; + bool UserExistsInList(const AccountId& account_id) const; // Same as FindUserInList but returns non-const pointer to User object. - User* FindUserInListAndModify(const std::string& user_id); + User* FindUserInListAndModify(const AccountId& account_id); // Reads user's oauth token status from local state preferences. - User::OAuthTokenStatus LoadUserOAuthStatus(const std::string& user_id) const; + User::OAuthTokenStatus LoadUserOAuthStatus(const AccountId& account_id) const; // Read a flag indicating whether online authentication against GAIA should // be enforced during the user's next sign-in from local state preferences. - bool LoadForceOnlineSignin(const std::string& user_id) const; + bool LoadForceOnlineSignin(const AccountId& account_id) const; // Notifies observers that merge session state had changed. void NotifyMergeSessionStateChanged(); @@ -350,7 +352,7 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { // Notifies observers that active user has changed. void NotifyActiveUserChanged(const User* active_user); - // Notifies observers that active user_id hash has changed. + // Notifies observers that active account_id hash has changed. void NotifyActiveUserHashChanged(const std::string& hash); // Update the global LoginState. @@ -360,49 +362,49 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { void SetLRUUser(User* user); // Sends metrics in response to a user with gaia account (regular) logging in. - void SendGaiaUserLoginMetrics(const std::string& user_id); + void SendGaiaUserLoginMetrics(const AccountId& account_id); - // Sets account locale for user with id |user_id|. - virtual void UpdateUserAccountLocale(const std::string& user_id, + // Sets account locale for user with id |account_id|. + virtual void UpdateUserAccountLocale(const AccountId& account_id, const std::string& locale); // Updates user account after locale was resolved. - void DoUpdateAccountLocale(const std::string& user_id, + void DoUpdateAccountLocale(const AccountId& account_id, scoped_ptr<std::string> resolved_locale); - // Removes all user preferences associated with |user_id|. - void RemoveKnownUserPrefs(const UserID& user_id); + // Removes all user preferences associated with |account_id|. + void RemoveKnownUserPrefs(const AccountId& account_id); // Indicates stage of loading user from prefs. - UserLoadStage user_loading_stage_; + UserLoadStage user_loading_stage_ = STAGE_NOT_LOADED; // True if SessionStarted() has been called. - bool session_started_; + bool session_started_ = false; // Cached flag of whether currently logged-in user is owner or not. // May be accessed on different threads, requires locking. - bool is_current_user_owner_; + bool is_current_user_owner_ = false; mutable base::Lock is_current_user_owner_lock_; // Cached flag of whether the currently logged-in user existed before this // login. - bool is_current_user_new_; + bool is_current_user_new_ = false; // Cached flag of whether the currently logged-in user is a regular user who // logged in as ephemeral. Storage of persistent information is avoided for // such users by not adding them to the persistent user list, not downloading // their custom avatars and mounting their cryptohomes using tmpfs. Defaults // to |false|. - bool is_current_user_ephemeral_regular_user_; + bool is_current_user_ephemeral_regular_user_ = false; // Cached flag indicating whether the ephemeral user policy is enabled. // Defaults to |false| if the value has not been read from trusted device // policy yet. - bool ephemeral_users_enabled_; + bool ephemeral_users_enabled_ = false; - // Cached name of device owner. Defaults to empty string if the value has not + // Cached name of device owner. Defaults to empty if the value has not // been read from trusted device policy yet. - std::string owner_email_; + AccountId owner_account_id_ = EmptyAccountId(); base::ObserverList<UserManager::Observer> observer_list_; @@ -411,17 +413,17 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { session_state_observer_list_; // Time at which this object was created. - base::TimeTicks manager_creation_time_; + base::TimeTicks manager_creation_time_ = base::TimeTicks::Now(); // ID of the user just added to the session that needs to be activated // as soon as user's profile is loaded. - std::string pending_user_switch_; + AccountId pending_user_switch_ = EmptyAccountId(); // ID of the user that was active in the previous session. // Preference value is stored here before first user signs in // because pref will be overidden once session restore starts. - std::string last_session_active_user_; - bool last_session_active_user_initialized_; + AccountId last_session_active_account_id_ = EmptyAccountId(); + bool last_session_active_account_id_initialized_ = false; // TaskRunner for UI thread. scoped_refptr<base::TaskRunner> task_runner_; |