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