| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_USER_MANAGER_USER_MANAGER_BASE_H_ | 5 #ifndef COMPONENTS_USER_MANAGER_USER_MANAGER_BASE_H_ |
| 6 #define COMPONENTS_USER_MANAGER_USER_MANAGER_BASE_H_ | 6 #define COMPONENTS_USER_MANAGER_USER_MANAGER_BASE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "components/signin/core/account_id/account_id.h" |
| 18 #include "components/user_manager/user.h" | 19 #include "components/user_manager/user.h" |
| 19 #include "components/user_manager/user_id.h" | |
| 20 #include "components/user_manager/user_manager.h" | 20 #include "components/user_manager/user_manager.h" |
| 21 #include "components/user_manager/user_manager_export.h" | 21 #include "components/user_manager/user_manager_export.h" |
| 22 #include "components/user_manager/user_type.h" | 22 #include "components/user_manager/user_type.h" |
| 23 | 23 |
| 24 class PrefService; | 24 class PrefService; |
| 25 class PrefRegistrySimple; | 25 class PrefRegistrySimple; |
| 26 | 26 |
| 27 namespace base { | 27 namespace base { |
| 28 class DictionaryValue; | 28 class DictionaryValue; |
| 29 class ListValue; | 29 class ListValue; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 44 ~UserManagerBase() override; | 44 ~UserManagerBase() override; |
| 45 | 45 |
| 46 // Registers UserManagerBase preferences. | 46 // Registers UserManagerBase preferences. |
| 47 static void RegisterPrefs(PrefRegistrySimple* registry); | 47 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 48 | 48 |
| 49 // UserManager implementation: | 49 // UserManager implementation: |
| 50 void Shutdown() override; | 50 void Shutdown() override; |
| 51 const UserList& GetUsers() const override; | 51 const UserList& GetUsers() const override; |
| 52 const UserList& GetLoggedInUsers() const override; | 52 const UserList& GetLoggedInUsers() const override; |
| 53 const UserList& GetLRULoggedInUsers() const override; | 53 const UserList& GetLRULoggedInUsers() const override; |
| 54 const std::string& GetOwnerEmail() const override; | 54 const AccountId& GetOwnerAccountId() const override; |
| 55 void UserLoggedIn(const std::string& user_id, | 55 void UserLoggedIn(const AccountId& account_id, |
| 56 const std::string& user_id_hash, | 56 const std::string& user_id_hash, |
| 57 bool browser_restart) override; | 57 bool browser_restart) override; |
| 58 void SwitchActiveUser(const std::string& user_id) override; | 58 void SwitchActiveUser(const AccountId& account_id) override; |
| 59 void SwitchToLastActiveUser() override; | 59 void SwitchToLastActiveUser() override; |
| 60 void SessionStarted() override; | 60 void SessionStarted() override; |
| 61 void RemoveUser(const std::string& user_id, | 61 void RemoveUser(const AccountId& account_id, |
| 62 RemoveUserDelegate* delegate) override; | 62 RemoveUserDelegate* delegate) override; |
| 63 void RemoveUserFromList(const std::string& user_id) override; | 63 void RemoveUserFromList(const AccountId& account_id) override; |
| 64 bool IsKnownUser(const std::string& user_id) const override; | 64 bool IsKnownUser(const AccountId& account_id) const override; |
| 65 const User* FindUser(const std::string& user_id) const override; | 65 const User* FindUser(const AccountId& account_id) const override; |
| 66 User* FindUserAndModify(const std::string& user_id) override; | 66 User* FindUserAndModify(const AccountId& account_id) override; |
| 67 const User* GetLoggedInUser() const override; | 67 const User* GetLoggedInUser() const override; |
| 68 User* GetLoggedInUser() override; | 68 User* GetLoggedInUser() override; |
| 69 const User* GetActiveUser() const override; | 69 const User* GetActiveUser() const override; |
| 70 User* GetActiveUser() override; | 70 User* GetActiveUser() override; |
| 71 const User* GetPrimaryUser() const override; | 71 const User* GetPrimaryUser() const override; |
| 72 void SaveUserOAuthStatus(const std::string& user_id, | 72 void SaveUserOAuthStatus(const AccountId& account_id, |
| 73 User::OAuthTokenStatus oauth_token_status) override; | 73 User::OAuthTokenStatus oauth_token_status) override; |
| 74 void SaveForceOnlineSignin(const std::string& user_id, | 74 void SaveForceOnlineSignin(const AccountId& account_id, |
| 75 bool force_online_signin) override; | 75 bool force_online_signin) override; |
| 76 void SaveUserDisplayName(const std::string& user_id, | 76 void SaveUserDisplayName(const AccountId& account_id, |
| 77 const base::string16& display_name) override; | 77 const base::string16& display_name) override; |
| 78 base::string16 GetUserDisplayName(const std::string& user_id) const override; | 78 base::string16 GetUserDisplayName(const AccountId& account_id) const override; |
| 79 void SaveUserDisplayEmail(const std::string& user_id, | 79 void SaveUserDisplayEmail(const AccountId& account_id, |
| 80 const std::string& display_email) override; | 80 const std::string& display_email) override; |
| 81 std::string GetUserDisplayEmail(const std::string& user_id) const override; | 81 std::string GetUserDisplayEmail(const AccountId& account_id) const override; |
| 82 void SaveUserType(const std::string& user_id, | 82 void SaveUserType(const AccountId& account_id, |
| 83 const UserType& user_type) override; | 83 const UserType& user_type) override; |
| 84 void UpdateUserAccountData(const std::string& user_id, | 84 void UpdateUserAccountData(const AccountId& account_id, |
| 85 const UserAccountData& account_data) override; | 85 const UserAccountData& account_data) override; |
| 86 bool IsCurrentUserOwner() const override; | 86 bool IsCurrentUserOwner() const override; |
| 87 bool IsCurrentUserNew() const override; | 87 bool IsCurrentUserNew() const override; |
| 88 bool IsCurrentUserNonCryptohomeDataEphemeral() const override; | 88 bool IsCurrentUserNonCryptohomeDataEphemeral() const override; |
| 89 bool CanCurrentUserLock() const override; | 89 bool CanCurrentUserLock() const override; |
| 90 bool IsUserLoggedIn() const override; | 90 bool IsUserLoggedIn() const override; |
| 91 bool IsLoggedInAsUserWithGaiaAccount() const override; | 91 bool IsLoggedInAsUserWithGaiaAccount() const override; |
| 92 bool IsLoggedInAsChildUser() const override; | 92 bool IsLoggedInAsChildUser() const override; |
| 93 bool IsLoggedInAsPublicAccount() const override; | 93 bool IsLoggedInAsPublicAccount() const override; |
| 94 bool IsLoggedInAsGuest() const override; | 94 bool IsLoggedInAsGuest() const override; |
| 95 bool IsLoggedInAsSupervisedUser() const override; | 95 bool IsLoggedInAsSupervisedUser() const override; |
| 96 bool IsLoggedInAsKioskApp() const override; | 96 bool IsLoggedInAsKioskApp() const override; |
| 97 bool IsLoggedInAsStub() const override; | 97 bool IsLoggedInAsStub() const override; |
| 98 bool IsSessionStarted() const override; | 98 bool IsSessionStarted() const override; |
| 99 bool IsUserNonCryptohomeDataEphemeral( | 99 bool IsUserNonCryptohomeDataEphemeral( |
| 100 const std::string& user_id) const override; | 100 const AccountId& account_id) const override; |
| 101 void AddObserver(UserManager::Observer* obs) override; | 101 void AddObserver(UserManager::Observer* obs) override; |
| 102 void RemoveObserver(UserManager::Observer* obs) override; | 102 void RemoveObserver(UserManager::Observer* obs) override; |
| 103 void AddSessionStateObserver( | 103 void AddSessionStateObserver( |
| 104 UserManager::UserSessionStateObserver* obs) override; | 104 UserManager::UserSessionStateObserver* obs) override; |
| 105 void RemoveSessionStateObserver( | 105 void RemoveSessionStateObserver( |
| 106 UserManager::UserSessionStateObserver* obs) override; | 106 UserManager::UserSessionStateObserver* obs) override; |
| 107 void NotifyLocalStateChanged() override; | 107 void NotifyLocalStateChanged() override; |
| 108 void ChangeUserChildStatus(User* user, bool is_child) override; | 108 void ChangeUserChildStatus(User* user, bool is_child) override; |
| 109 bool FindKnownUserPrefs(const UserID& user_id, | 109 bool FindKnownUserPrefs(const AccountId& account_id, |
| 110 const base::DictionaryValue** out_value) override; | 110 const base::DictionaryValue** out_value) override; |
| 111 void UpdateKnownUserPrefs(const UserID& user_id, | 111 void UpdateKnownUserPrefs(const AccountId& account_id, |
| 112 const base::DictionaryValue& values, | 112 const base::DictionaryValue& values, |
| 113 bool clear) override; | 113 bool clear) override; |
| 114 bool GetKnownUserStringPref(const UserID& user_id, | 114 bool GetKnownUserStringPref(const AccountId& account_id, |
| 115 const std::string& path, | 115 const std::string& path, |
| 116 std::string* out_value) override; | 116 std::string* out_value) override; |
| 117 void SetKnownUserStringPref(const UserID& user_id, | 117 void SetKnownUserStringPref(const AccountId& account_id, |
| 118 const std::string& path, | 118 const std::string& path, |
| 119 const std::string& in_value) override; | 119 const std::string& in_value) override; |
| 120 bool GetKnownUserBooleanPref(const UserID& user_id, | 120 bool GetKnownUserBooleanPref(const AccountId& account_id, |
| 121 const std::string& path, | 121 const std::string& path, |
| 122 bool* out_value) override; | 122 bool* out_value) override; |
| 123 void SetKnownUserBooleanPref(const UserID& user_id, | 123 void SetKnownUserBooleanPref(const AccountId& account_id, |
| 124 const std::string& path, | 124 const std::string& path, |
| 125 const bool in_value) override; | 125 const bool in_value) override; |
| 126 bool GetKnownUserIntegerPref(const UserID& user_id, | 126 bool GetKnownUserIntegerPref(const AccountId& account_id, |
| 127 const std::string& path, | 127 const std::string& path, |
| 128 int* out_value) override; | 128 int* out_value) override; |
| 129 void SetKnownUserIntegerPref(const UserID& user_id, | 129 void SetKnownUserIntegerPref(const AccountId& account_id, |
| 130 const std::string& path, | 130 const std::string& path, |
| 131 const int in_value) override; | 131 int in_value) override; |
| 132 bool GetKnownUserCanonicalEmail(const UserID& user_id, | 132 bool GetKnownUserAccountId(const AccountId& authenticated_account_id, |
| 133 std::string* out_email) override; | 133 AccountId* out_account_id) override; |
| 134 void UpdateGaiaID(const UserID& user_id, const std::string& gaia_id) override; | 134 void UpdateGaiaID(const AccountId& account_id, |
| 135 bool FindGaiaID(const UserID& user_id, std::string* out_value) override; | 135 const std::string& gaia_id) override; |
| 136 void UpdateUsingSAML(const std::string& user_id, | 136 bool FindGaiaID(const AccountId& account_id, std::string* out_value) override; |
| 137 void UpdateUsingSAML(const AccountId& account_id, |
| 137 const bool using_saml) override; | 138 const bool using_saml) override; |
| 138 bool FindUsingSAML(const std::string& user_id) override; | 139 bool FindUsingSAML(const AccountId& account_id) override; |
| 139 void SetKnownUserDeviceId(const UserID& user_id, | 140 void SetKnownUserDeviceId(const AccountId& account_id, |
| 140 const std::string& device_id) override; | 141 const std::string& device_id) override; |
| 141 std::string GetKnownUserDeviceId(const UserID& user_id) override; | 142 std::string GetKnownUserDeviceId(const AccountId& account_id) override; |
| 142 void SetKnownUserGAPSCookie(const UserID& user_id, | 143 void SetKnownUserGAPSCookie(const AccountId& account_id, |
| 143 const std::string& gaps_cookie) override; | 144 const std::string& gaps_cookie) override; |
| 144 std::string GetKnownUserGAPSCookie(const UserID& user_id) override; | 145 std::string GetKnownUserGAPSCookie(const AccountId& account_id) override; |
| 145 void UpdateReauthReason(const std::string& user_id, | 146 void UpdateReauthReason(const AccountId& account_id, |
| 146 const int reauth_reason) override; | 147 int reauth_reason) override; |
| 147 bool FindReauthReason(const std::string& user_id, int* out_value) override; | 148 bool FindReauthReason(const AccountId& account_id, int* out_value) override; |
| 148 | 149 |
| 150 // This method updates "User was added to the device in this session nad is |
| 151 // not full initialized yet" flag. |
| 149 virtual void SetIsCurrentUserNew(bool is_new); | 152 virtual void SetIsCurrentUserNew(bool is_new); |
| 150 | 153 |
| 151 // TODO(xiyuan): Figure out a better way to expose this info. | 154 // TODO(xiyuan): Figure out a better way to expose this info. |
| 152 virtual bool HasPendingBootstrap(const std::string& user_id) const; | 155 virtual bool HasPendingBootstrap(const AccountId& account_id) const; |
| 153 | 156 |
| 154 // Helper function that copies users from |users_list| to |users_vector| and | 157 // Helper function that copies users from |users_list| to |users_vector| and |
| 155 // |users_set|. Duplicates and users already present in |existing_users| are | 158 // |users_set|. Duplicates and users already present in |existing_users| are |
| 156 // skipped. | 159 // skipped. |
| 157 static void ParseUserList(const base::ListValue& users_list, | 160 static void ParseUserList(const base::ListValue& users_list, |
| 158 const std::set<std::string>& existing_users, | 161 const std::set<AccountId>& existing_users, |
| 159 std::vector<std::string>* users_vector, | 162 std::vector<AccountId>* users_vector, |
| 160 std::set<std::string>* users_set); | 163 std::set<AccountId>* users_set); |
| 161 | 164 |
| 162 // Returns true if trusted device policies have successfully been retrieved | 165 // Returns true if trusted device policies have successfully been retrieved |
| 163 // and ephemeral users are enabled. | 166 // and ephemeral users are enabled. |
| 164 virtual bool AreEphemeralUsersEnabled() const = 0; | 167 virtual bool AreEphemeralUsersEnabled() const = 0; |
| 165 | 168 |
| 166 protected: | 169 protected: |
| 167 // Adds |user| to users list, and adds it to front of LRU list. It is assumed | 170 // Adds |user| to users list, and adds it to front of LRU list. It is assumed |
| 168 // that there is no user with same id. | 171 // that there is no user with same id. |
| 169 virtual void AddUserRecord(User* user); | 172 virtual void AddUserRecord(User* user); |
| 170 | 173 |
| 171 // Returns true if user may be removed. | 174 // Returns true if user may be removed. |
| 172 virtual bool CanUserBeRemoved(const User* user) const; | 175 virtual bool CanUserBeRemoved(const User* user) const; |
| 173 | 176 |
| 174 // A wrapper around C++ delete operator. Deletes |user|, and when |user| | 177 // A wrapper around C++ delete operator. Deletes |user|, and when |user| |
| 175 // equals to active_user_, active_user_ is reset to NULL. | 178 // equals to active_user_, active_user_ is reset to NULL. |
| 176 virtual void DeleteUser(User* user); | 179 virtual void DeleteUser(User* user); |
| 177 | 180 |
| 178 // Returns the locale used by the application. | 181 // Returns the locale used by the application. |
| 179 virtual const std::string& GetApplicationLocale() const = 0; | 182 virtual const std::string& GetApplicationLocale() const = 0; |
| 180 | 183 |
| 181 // Returns "Local State" PrefService instance. | 184 // Returns "Local State" PrefService instance. |
| 182 virtual PrefService* GetLocalState() const = 0; | 185 virtual PrefService* GetLocalState() const = 0; |
| 183 | 186 |
| 184 // Loads |users_| from Local State if the list has not been loaded yet. | 187 // Loads |users_| from Local State if the list has not been loaded yet. |
| 185 // Subsequent calls have no effect. Must be called on the UI thread. | 188 // Subsequent calls have no effect. Must be called on the UI thread. |
| 186 virtual void EnsureUsersLoaded(); | 189 virtual void EnsureUsersLoaded(); |
| 187 | 190 |
| 188 // Handle OAuth token |status| change for |user_id|. | 191 // Handle OAuth token |status| change for |account_id|. |
| 189 virtual void HandleUserOAuthTokenStatusChange( | 192 virtual void HandleUserOAuthTokenStatusChange( |
| 190 const std::string& user_id, | 193 const AccountId& account_id, |
| 191 User::OAuthTokenStatus status) const = 0; | 194 User::OAuthTokenStatus status) const = 0; |
| 192 | 195 |
| 193 // Returns true if device is enterprise managed. | 196 // Returns true if device is enterprise managed. |
| 194 virtual bool IsEnterpriseManaged() const = 0; | 197 virtual bool IsEnterpriseManaged() const = 0; |
| 195 | 198 |
| 196 // Helper function that copies users from |users_list| to |users_vector| and | 199 // Helper function that copies users from |users_list| to |users_vector| and |
| 197 // |users_set|. Duplicates and users already present in |existing_users| are | 200 // |users_set|. Duplicates and users already present in |existing_users| are |
| 198 // skipped. | 201 // skipped. |
| 199 // Loads public accounts from the Local state and fills in | 202 // Loads public accounts from the Local state and fills in |
| 200 // |public_sessions_set|. | 203 // |public_sessions_set|. |
| 201 virtual void LoadPublicAccounts( | 204 virtual void LoadPublicAccounts(std::set<AccountId>* public_sessions_set) = 0; |
| 202 std::set<std::string>* public_sessions_set) = 0; | |
| 203 | 205 |
| 204 // Notifies that user has logged in. | 206 // Notifies that user has logged in. |
| 205 virtual void NotifyOnLogin(); | 207 virtual void NotifyOnLogin(); |
| 206 | 208 |
| 207 // Notifies observers that another user was added to the session. | 209 // Notifies observers that another user was added to the session. |
| 208 // If |user_switch_pending| is true this means that user has not been fully | 210 // If |user_switch_pending| is true this means that user has not been fully |
| 209 // initialized yet like waiting for profile to be loaded. | 211 // initialized yet like waiting for profile to be loaded. |
| 210 virtual void NotifyUserAddedToSession(const User* added_user, | 212 virtual void NotifyUserAddedToSession(const User* added_user, |
| 211 bool user_switch_pending); | 213 bool user_switch_pending); |
| 212 | 214 |
| 213 // Performs any additional actions before user list is loaded. | 215 // Performs any additional actions before user list is loaded. |
| 214 virtual void PerformPreUserListLoadingActions() = 0; | 216 virtual void PerformPreUserListLoadingActions() = 0; |
| 215 | 217 |
| 216 // Performs any additional actions after user list is loaded. | 218 // Performs any additional actions after user list is loaded. |
| 217 virtual void PerformPostUserListLoadingActions() = 0; | 219 virtual void PerformPostUserListLoadingActions() = 0; |
| 218 | 220 |
| 219 // Performs any additional actions after UserLoggedIn() execution has been | 221 // Performs any additional actions after UserLoggedIn() execution has been |
| 220 // completed. | 222 // completed. |
| 221 // |browser_restart| is true when reloading Chrome after crash to distinguish | 223 // |browser_restart| is true when reloading Chrome after crash to distinguish |
| 222 // from normal sign in flow. | 224 // from normal sign in flow. |
| 223 virtual void PerformPostUserLoggedInActions(bool browser_restart) = 0; | 225 virtual void PerformPostUserLoggedInActions(bool browser_restart) = 0; |
| 224 | 226 |
| 225 // Implementation for RemoveUser method. It is synchronous. It is called from | 227 // Implementation for RemoveUser method. It is synchronous. It is called from |
| 226 // RemoveUserInternal after owner check. | 228 // RemoveUserInternal after owner check. |
| 227 virtual void RemoveNonOwnerUserInternal(const std::string& user_email, | 229 virtual void RemoveNonOwnerUserInternal(const AccountId& account_id, |
| 228 RemoveUserDelegate* delegate); | 230 RemoveUserDelegate* delegate); |
| 229 | 231 |
| 230 // Removes a regular or supervised user from the user list. | 232 // Removes a regular or supervised user from the user list. |
| 231 // Returns the user if found or NULL otherwise. | 233 // Returns the user if found or NULL otherwise. |
| 232 // Also removes the user from the persistent user list. | 234 // Also removes the user from the persistent user list. |
| 233 User* RemoveRegularOrSupervisedUserFromList(const std::string& user_id); | 235 User* RemoveRegularOrSupervisedUserFromList(const AccountId& account_id); |
| 234 | 236 |
| 235 // Implementation for RemoveUser method. This is an asynchronous part of the | 237 // Implementation for RemoveUser method. This is an asynchronous part of the |
| 236 // method, that verifies that owner will not get deleted, and calls | 238 // method, that verifies that owner will not get deleted, and calls |
| 237 // |RemoveNonOwnerUserInternal|. | 239 // |RemoveNonOwnerUserInternal|. |
| 238 virtual void RemoveUserInternal(const std::string& user_email, | 240 virtual void RemoveUserInternal(const AccountId& account_id, |
| 239 RemoveUserDelegate* delegate); | 241 RemoveUserDelegate* delegate); |
| 240 | 242 |
| 241 // Removes data stored or cached outside the user's cryptohome (wallpaper, | 243 // Removes data stored or cached outside the user's cryptohome (wallpaper, |
| 242 // avatar, OAuth token status, display name, display email). | 244 // avatar, OAuth token status, display name, display email). |
| 243 virtual void RemoveNonCryptohomeData(const std::string& user_id); | 245 virtual void RemoveNonCryptohomeData(const AccountId& account_id); |
| 244 | 246 |
| 245 // Check for a particular user type. | 247 // Check for a particular user type. |
| 246 | 248 |
| 247 // Returns true if |user_id| represents demo app. | 249 // Returns true if |account_id| represents demo app. |
| 248 virtual bool IsDemoApp(const std::string& user_id) const = 0; | 250 virtual bool IsDemoApp(const AccountId& account_id) const = 0; |
| 249 | 251 |
| 250 // Returns true if |user_id| represents kiosk app. | 252 // Returns true if |account_id| represents kiosk app. |
| 251 virtual bool IsKioskApp(const std::string& user_id) const = 0; | 253 virtual bool IsKioskApp(const AccountId& account_id) const = 0; |
| 252 | 254 |
| 253 // Returns true if |user_id| represents public account that has been marked | 255 // Returns true if |account_id| represents public account that has been marked |
| 254 // for deletion. | 256 // for deletion. |
| 255 virtual bool IsPublicAccountMarkedForRemoval( | 257 virtual bool IsPublicAccountMarkedForRemoval( |
| 256 const std::string& user_id) const = 0; | 258 const AccountId& account_id) const = 0; |
| 257 | 259 |
| 258 // These methods are called when corresponding user type has signed in. | 260 // These methods are called when corresponding user type has signed in. |
| 259 | 261 |
| 260 // Indicates that the demo account has just logged in. | 262 // Indicates that the demo account has just logged in. |
| 261 virtual void DemoAccountLoggedIn() = 0; | 263 virtual void DemoAccountLoggedIn() = 0; |
| 262 | 264 |
| 263 // Indicates that a user just logged in as guest. | 265 // Indicates that a user just logged in as guest. |
| 264 virtual void GuestUserLoggedIn(); | 266 virtual void GuestUserLoggedIn(); |
| 265 | 267 |
| 266 // Indicates that a kiosk app robot just logged in. | 268 // Indicates that a kiosk app robot just logged in. |
| 267 virtual void KioskAppLoggedIn(const std::string& app_id) = 0; | 269 virtual void KioskAppLoggedIn(const AccountId& kiosk_app_account_id) = 0; |
| 268 | 270 |
| 269 // Indicates that a user just logged into a public session. | 271 // Indicates that a user just logged into a public session. |
| 270 virtual void PublicAccountUserLoggedIn(User* user) = 0; | 272 virtual void PublicAccountUserLoggedIn(User* user) = 0; |
| 271 | 273 |
| 272 // Indicates that a regular user just logged in. | 274 // Indicates that a regular user just logged in. |
| 273 virtual void RegularUserLoggedIn(const std::string& user_id); | 275 virtual void RegularUserLoggedIn(const AccountId& account_id); |
| 274 | 276 |
| 275 // Indicates that a regular user just logged in as ephemeral. | 277 // Indicates that a regular user just logged in as ephemeral. |
| 276 virtual void RegularUserLoggedInAsEphemeral(const std::string& user_id); | 278 virtual void RegularUserLoggedInAsEphemeral(const AccountId& account_id); |
| 277 | 279 |
| 278 // Indicates that a supervised user just logged in. | 280 // Indicates that a supervised user just logged in. |
| 279 virtual void SupervisedUserLoggedIn(const std::string& user_id) = 0; | 281 virtual void SupervisedUserLoggedIn(const AccountId& account_id) = 0; |
| 280 | 282 |
| 281 // Should be called when regular user was removed. | 283 // Should be called when regular user was removed. |
| 282 virtual void OnUserRemoved(const std::string& user_id) = 0; | 284 virtual void OnUserRemoved(const AccountId& account_id) = 0; |
| 283 | 285 |
| 284 // Getters/setters for private members. | 286 // Getters/setters for private members. |
| 285 | 287 |
| 286 virtual void SetCurrentUserIsOwner(bool is_current_user_owner); | 288 virtual void SetCurrentUserIsOwner(bool is_current_user_owner); |
| 287 | 289 |
| 288 virtual bool GetEphemeralUsersEnabled() const; | 290 virtual bool GetEphemeralUsersEnabled() const; |
| 289 virtual void SetEphemeralUsersEnabled(bool enabled); | 291 virtual void SetEphemeralUsersEnabled(bool enabled); |
| 290 | 292 |
| 291 virtual void SetOwnerEmail(const std::string& owner_user_id); | 293 virtual void SetOwnerId(const AccountId& owner_account_id); |
| 292 | 294 |
| 293 virtual const std::string& GetPendingUserSwitchID() const; | 295 virtual const AccountId& GetPendingUserSwitchID() const; |
| 294 virtual void SetPendingUserSwitchID(const std::string& user_id); | 296 virtual void SetPendingUserSwitchId(const AccountId& account_id); |
| 295 | 297 |
| 296 // The logged-in user that is currently active in current session. | 298 // The logged-in user that is currently active in current session. |
| 297 // NULL until a user has logged in, then points to one | 299 // NULL until a user has logged in, then points to one |
| 298 // of the User instances in |users_|, the |guest_user_| instance or an | 300 // of the User instances in |users_|, the |guest_user_| instance or an |
| 299 // ephemeral user instance. | 301 // ephemeral user instance. |
| 300 User* active_user_; | 302 User* active_user_ = nullptr; |
| 301 | 303 |
| 302 // The primary user of the current session. It is recorded for the first | 304 // The primary user of the current session. It is recorded for the first |
| 303 // signed-in user and does not change thereafter. | 305 // signed-in user and does not change thereafter. |
| 304 User* primary_user_; | 306 User* primary_user_ = nullptr; |
| 305 | 307 |
| 306 // List of all known users. User instances are owned by |this|. Regular users | 308 // List of all known users. User instances are owned by |this|. Regular users |
| 307 // are removed by |RemoveUserFromList|, public accounts by | 309 // are removed by |RemoveUserFromList|, public accounts by |
| 308 // |UpdateAndCleanUpPublicAccounts|. | 310 // |UpdateAndCleanUpPublicAccounts|. |
| 309 UserList users_; | 311 UserList users_; |
| 310 | 312 |
| 311 // List of all users that are logged in current session. These point to User | 313 // List of all users that are logged in current session. These point to User |
| 312 // instances in |users_|. Only one of them could be marked as active. | 314 // instances in |users_|. Only one of them could be marked as active. |
| 313 UserList logged_in_users_; | 315 UserList logged_in_users_; |
| 314 | 316 |
| 315 // A list of all users that are logged in the current session. In contrast to | 317 // A list of all users that are logged in the current session. In contrast to |
| 316 // |logged_in_users|, the order of this list is least recently used so that | 318 // |logged_in_users|, the order of this list is least recently used so that |
| 317 // the active user should always be the first one in the list. | 319 // the active user should always be the first one in the list. |
| 318 UserList lru_logged_in_users_; | 320 UserList lru_logged_in_users_; |
| 319 | 321 |
| 320 private: | 322 private: |
| 321 // Stages of loading user list from preferences. Some methods can have | 323 // Stages of loading user list from preferences. Some methods can have |
| 322 // different behavior depending on stage. | 324 // different behavior depending on stage. |
| 323 enum UserLoadStage { STAGE_NOT_LOADED = 0, STAGE_LOADING, STAGE_LOADED }; | 325 enum UserLoadStage { STAGE_NOT_LOADED = 0, STAGE_LOADING, STAGE_LOADED }; |
| 324 | 326 |
| 325 // Returns a list of users who have logged into this device previously. | 327 // Returns a list of users who have logged into this device previously. |
| 326 // Same as GetUsers but used if you need to modify User from that list. | 328 // Same as GetUsers but used if you need to modify User from that list. |
| 327 UserList& GetUsersAndModify(); | 329 UserList& GetUsersAndModify(); |
| 328 | 330 |
| 329 // Returns the user with the given email address if found in the persistent | 331 // Returns the user with the given email address if found in the persistent |
| 330 // list. Returns |NULL| otherwise. | 332 // list. Returns |NULL| otherwise. |
| 331 const User* FindUserInList(const std::string& user_id) const; | 333 const User* FindUserInList(const AccountId& account_id) const; |
| 332 | 334 |
| 333 // Returns |true| if user with the given id is found in the persistent list. | 335 // Returns |true| if user with the given id is found in the persistent list. |
| 334 // Returns |false| otherwise. Does not trigger user loading. | 336 // Returns |false| otherwise. Does not trigger user loading. |
| 335 bool UserExistsInList(const std::string& user_id) const; | 337 bool UserExistsInList(const AccountId& account_id) const; |
| 336 | 338 |
| 337 // Same as FindUserInList but returns non-const pointer to User object. | 339 // Same as FindUserInList but returns non-const pointer to User object. |
| 338 User* FindUserInListAndModify(const std::string& user_id); | 340 User* FindUserInListAndModify(const AccountId& account_id); |
| 339 | 341 |
| 340 // Reads user's oauth token status from local state preferences. | 342 // Reads user's oauth token status from local state preferences. |
| 341 User::OAuthTokenStatus LoadUserOAuthStatus(const std::string& user_id) const; | 343 User::OAuthTokenStatus LoadUserOAuthStatus(const AccountId& account_id) const; |
| 342 | 344 |
| 343 // Read a flag indicating whether online authentication against GAIA should | 345 // Read a flag indicating whether online authentication against GAIA should |
| 344 // be enforced during the user's next sign-in from local state preferences. | 346 // be enforced during the user's next sign-in from local state preferences. |
| 345 bool LoadForceOnlineSignin(const std::string& user_id) const; | 347 bool LoadForceOnlineSignin(const AccountId& account_id) const; |
| 346 | 348 |
| 347 // Notifies observers that merge session state had changed. | 349 // Notifies observers that merge session state had changed. |
| 348 void NotifyMergeSessionStateChanged(); | 350 void NotifyMergeSessionStateChanged(); |
| 349 | 351 |
| 350 // Notifies observers that active user has changed. | 352 // Notifies observers that active user has changed. |
| 351 void NotifyActiveUserChanged(const User* active_user); | 353 void NotifyActiveUserChanged(const User* active_user); |
| 352 | 354 |
| 353 // Notifies observers that active user_id hash has changed. | 355 // Notifies observers that active account_id hash has changed. |
| 354 void NotifyActiveUserHashChanged(const std::string& hash); | 356 void NotifyActiveUserHashChanged(const std::string& hash); |
| 355 | 357 |
| 356 // Update the global LoginState. | 358 // Update the global LoginState. |
| 357 void UpdateLoginState(); | 359 void UpdateLoginState(); |
| 358 | 360 |
| 359 // Insert |user| at the front of the LRU user list. | 361 // Insert |user| at the front of the LRU user list. |
| 360 void SetLRUUser(User* user); | 362 void SetLRUUser(User* user); |
| 361 | 363 |
| 362 // Sends metrics in response to a user with gaia account (regular) logging in. | 364 // Sends metrics in response to a user with gaia account (regular) logging in. |
| 363 void SendGaiaUserLoginMetrics(const std::string& user_id); | 365 void SendGaiaUserLoginMetrics(const AccountId& account_id); |
| 364 | 366 |
| 365 // Sets account locale for user with id |user_id|. | 367 // Sets account locale for user with id |account_id|. |
| 366 virtual void UpdateUserAccountLocale(const std::string& user_id, | 368 virtual void UpdateUserAccountLocale(const AccountId& account_id, |
| 367 const std::string& locale); | 369 const std::string& locale); |
| 368 | 370 |
| 369 // Updates user account after locale was resolved. | 371 // Updates user account after locale was resolved. |
| 370 void DoUpdateAccountLocale(const std::string& user_id, | 372 void DoUpdateAccountLocale(const AccountId& account_id, |
| 371 scoped_ptr<std::string> resolved_locale); | 373 scoped_ptr<std::string> resolved_locale); |
| 372 | 374 |
| 373 // Removes all user preferences associated with |user_id|. | 375 // Removes all user preferences associated with |account_id|. |
| 374 void RemoveKnownUserPrefs(const UserID& user_id); | 376 void RemoveKnownUserPrefs(const AccountId& account_id); |
| 375 | 377 |
| 376 // Indicates stage of loading user from prefs. | 378 // Indicates stage of loading user from prefs. |
| 377 UserLoadStage user_loading_stage_; | 379 UserLoadStage user_loading_stage_ = STAGE_NOT_LOADED; |
| 378 | 380 |
| 379 // True if SessionStarted() has been called. | 381 // True if SessionStarted() has been called. |
| 380 bool session_started_; | 382 bool session_started_ = false; |
| 381 | 383 |
| 382 // Cached flag of whether currently logged-in user is owner or not. | 384 // Cached flag of whether currently logged-in user is owner or not. |
| 383 // May be accessed on different threads, requires locking. | 385 // May be accessed on different threads, requires locking. |
| 384 bool is_current_user_owner_; | 386 bool is_current_user_owner_ = false; |
| 385 mutable base::Lock is_current_user_owner_lock_; | 387 mutable base::Lock is_current_user_owner_lock_; |
| 386 | 388 |
| 387 // Cached flag of whether the currently logged-in user existed before this | 389 // Cached flag of whether the currently logged-in user existed before this |
| 388 // login. | 390 // login. |
| 389 bool is_current_user_new_; | 391 bool is_current_user_new_ = false; |
| 390 | 392 |
| 391 // Cached flag of whether the currently logged-in user is a regular user who | 393 // Cached flag of whether the currently logged-in user is a regular user who |
| 392 // logged in as ephemeral. Storage of persistent information is avoided for | 394 // logged in as ephemeral. Storage of persistent information is avoided for |
| 393 // such users by not adding them to the persistent user list, not downloading | 395 // such users by not adding them to the persistent user list, not downloading |
| 394 // their custom avatars and mounting their cryptohomes using tmpfs. Defaults | 396 // their custom avatars and mounting their cryptohomes using tmpfs. Defaults |
| 395 // to |false|. | 397 // to |false|. |
| 396 bool is_current_user_ephemeral_regular_user_; | 398 bool is_current_user_ephemeral_regular_user_ = false; |
| 397 | 399 |
| 398 // Cached flag indicating whether the ephemeral user policy is enabled. | 400 // Cached flag indicating whether the ephemeral user policy is enabled. |
| 399 // Defaults to |false| if the value has not been read from trusted device | 401 // Defaults to |false| if the value has not been read from trusted device |
| 400 // policy yet. | 402 // policy yet. |
| 401 bool ephemeral_users_enabled_; | 403 bool ephemeral_users_enabled_ = false; |
| 402 | 404 |
| 403 // Cached name of device owner. Defaults to empty string if the value has not | 405 // Cached name of device owner. Defaults to empty if the value has not |
| 404 // been read from trusted device policy yet. | 406 // been read from trusted device policy yet. |
| 405 std::string owner_email_; | 407 AccountId owner_account_id_ = EmptyAccountId(); |
| 406 | 408 |
| 407 base::ObserverList<UserManager::Observer> observer_list_; | 409 base::ObserverList<UserManager::Observer> observer_list_; |
| 408 | 410 |
| 409 // TODO(nkostylev): Merge with session state refactoring CL. | 411 // TODO(nkostylev): Merge with session state refactoring CL. |
| 410 base::ObserverList<UserManager::UserSessionStateObserver> | 412 base::ObserverList<UserManager::UserSessionStateObserver> |
| 411 session_state_observer_list_; | 413 session_state_observer_list_; |
| 412 | 414 |
| 413 // Time at which this object was created. | 415 // Time at which this object was created. |
| 414 base::TimeTicks manager_creation_time_; | 416 base::TimeTicks manager_creation_time_ = base::TimeTicks::Now(); |
| 415 | 417 |
| 416 // ID of the user just added to the session that needs to be activated | 418 // ID of the user just added to the session that needs to be activated |
| 417 // as soon as user's profile is loaded. | 419 // as soon as user's profile is loaded. |
| 418 std::string pending_user_switch_; | 420 AccountId pending_user_switch_ = EmptyAccountId(); |
| 419 | 421 |
| 420 // ID of the user that was active in the previous session. | 422 // ID of the user that was active in the previous session. |
| 421 // Preference value is stored here before first user signs in | 423 // Preference value is stored here before first user signs in |
| 422 // because pref will be overidden once session restore starts. | 424 // because pref will be overidden once session restore starts. |
| 423 std::string last_session_active_user_; | 425 AccountId last_session_active_account_id_ = EmptyAccountId(); |
| 424 bool last_session_active_user_initialized_; | 426 bool last_session_active_account_id_initialized_ = false; |
| 425 | 427 |
| 426 // TaskRunner for UI thread. | 428 // TaskRunner for UI thread. |
| 427 scoped_refptr<base::TaskRunner> task_runner_; | 429 scoped_refptr<base::TaskRunner> task_runner_; |
| 428 | 430 |
| 429 // TaskRunner for SequencedWorkerPool. | 431 // TaskRunner for SequencedWorkerPool. |
| 430 scoped_refptr<base::TaskRunner> blocking_task_runner_; | 432 scoped_refptr<base::TaskRunner> blocking_task_runner_; |
| 431 | 433 |
| 432 base::WeakPtrFactory<UserManagerBase> weak_factory_; | 434 base::WeakPtrFactory<UserManagerBase> weak_factory_; |
| 433 | 435 |
| 434 DISALLOW_COPY_AND_ASSIGN(UserManagerBase); | 436 DISALLOW_COPY_AND_ASSIGN(UserManagerBase); |
| 435 }; | 437 }; |
| 436 | 438 |
| 437 } // namespace user_manager | 439 } // namespace user_manager |
| 438 | 440 |
| 439 #endif // COMPONENTS_USER_MANAGER_USER_MANAGER_BASE_H_ | 441 #endif // COMPONENTS_USER_MANAGER_USER_MANAGER_BASE_H_ |
| OLD | NEW |