[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 5 | #ifndef COMPONENTS_USER_MANAGER_USER_MANAGER_BASE_H_ |
| 6 | #define COMPONENTS_USER_MANAGER_USER_MANAGER_BASE_H_ |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 7 | |
alemate | 16e470e | 2015-04-14 15:55:40 | [diff] [blame] | 8 | #include <map> |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 9 | #include <memory> |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 10 | #include <set> |
| 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
| 16 | #include "base/observer_list.h" |
| 17 | #include "base/synchronization/lock.h" |
| 18 | #include "base/time/time.h" |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 19 | #include "components/signin/core/account_id/account_id.h" |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 20 | #include "components/user_manager/user.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 21 | #include "components/user_manager/user_manager.h" |
| 22 | #include "components/user_manager/user_manager_export.h" |
merkulova | b82b713 | 2014-11-17 11:06:50 | [diff] [blame] | 23 | #include "components/user_manager/user_type.h" |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 24 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 25 | class PrefRegistrySimple; |
| 26 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 27 | namespace base { |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 28 | class ListValue; |
| 29 | class TaskRunner; |
| 30 | } |
| 31 | |
| 32 | namespace user_manager { |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 33 | |
| 34 | class RemoveUserDelegate; |
| 35 | |
| 36 | // Base implementation of the UserManager interface. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 37 | class USER_MANAGER_EXPORT UserManagerBase : public UserManager { |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 38 | public: |
[email protected] | ac58eaf7 | 2014-08-19 13:06:42 | [diff] [blame] | 39 | // Creates UserManagerBase with |task_runner| for UI thread and |
| 40 | // |blocking_task_runner| for SequencedWorkerPool. |
alemate | 33433e2 | 2016-01-13 14:50:30 | [diff] [blame] | 41 | explicit UserManagerBase(scoped_refptr<base::TaskRunner> task_runner); |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 42 | ~UserManagerBase() override; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 43 | |
| 44 | // Registers UserManagerBase preferences. |
| 45 | static void RegisterPrefs(PrefRegistrySimple* registry); |
| 46 | |
| 47 | // UserManager implementation: |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 48 | void Shutdown() override; |
| 49 | const UserList& GetUsers() const override; |
| 50 | const UserList& GetLoggedInUsers() const override; |
| 51 | const UserList& GetLRULoggedInUsers() const override; |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 52 | const AccountId& GetOwnerAccountId() const override; |
| 53 | void UserLoggedIn(const AccountId& account_id, |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 54 | const std::string& user_id_hash, |
| 55 | bool browser_restart) override; |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 56 | void SwitchActiveUser(const AccountId& account_id) override; |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 57 | void SwitchToLastActiveUser() override; |
xiyuan | 834f3bc | 2016-10-26 19:40:53 | [diff] [blame] | 58 | void OnSessionStarted() override; |
atwilson | d5a7eabf | 2017-03-09 13:18:39 | [diff] [blame] | 59 | void OnProfileInitialized(User* user) override; |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 60 | void RemoveUser(const AccountId& account_id, |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 61 | RemoveUserDelegate* delegate) override; |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 62 | void RemoveUserFromList(const AccountId& account_id) override; |
| 63 | bool IsKnownUser(const AccountId& account_id) const override; |
| 64 | const User* FindUser(const AccountId& account_id) const override; |
| 65 | User* FindUserAndModify(const AccountId& account_id) override; |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 66 | const User* GetActiveUser() const override; |
| 67 | User* GetActiveUser() override; |
| 68 | const User* GetPrimaryUser() const override; |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 69 | void SaveUserOAuthStatus(const AccountId& account_id, |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 70 | User::OAuthTokenStatus oauth_token_status) override; |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 71 | void SaveForceOnlineSignin(const AccountId& account_id, |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 72 | bool force_online_signin) override; |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 73 | void SaveUserDisplayName(const AccountId& account_id, |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 74 | const base::string16& display_name) override; |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 75 | base::string16 GetUserDisplayName(const AccountId& account_id) const override; |
| 76 | void SaveUserDisplayEmail(const AccountId& account_id, |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 77 | const std::string& display_email) override; |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 78 | std::string GetUserDisplayEmail(const AccountId& account_id) const override; |
| 79 | void SaveUserType(const AccountId& account_id, |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 80 | const UserType& user_type) override; |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 81 | void UpdateUserAccountData(const AccountId& account_id, |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 82 | const UserAccountData& account_data) override; |
| 83 | bool IsCurrentUserOwner() const override; |
| 84 | bool IsCurrentUserNew() const override; |
| 85 | bool IsCurrentUserNonCryptohomeDataEphemeral() const override; |
rsorokin | 79e9344 | 2016-04-29 07:54:12 | [diff] [blame] | 86 | bool IsCurrentUserCryptohomeDataEphemeral() const override; |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 87 | bool CanCurrentUserLock() const override; |
| 88 | bool IsUserLoggedIn() const override; |
| 89 | bool IsLoggedInAsUserWithGaiaAccount() const override; |
| 90 | bool IsLoggedInAsChildUser() const override; |
| 91 | bool IsLoggedInAsPublicAccount() const override; |
| 92 | bool IsLoggedInAsGuest() const override; |
| 93 | bool IsLoggedInAsSupervisedUser() const override; |
| 94 | bool IsLoggedInAsKioskApp() const override; |
peletskyi | 53c440d | 2016-10-25 15:09:55 | [diff] [blame] | 95 | bool IsLoggedInAsArcKioskApp() const override; |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 96 | bool IsLoggedInAsStub() const override; |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 97 | bool IsUserNonCryptohomeDataEphemeral( |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 98 | const AccountId& account_id) const override; |
rsorokin | 79e9344 | 2016-04-29 07:54:12 | [diff] [blame] | 99 | bool IsUserCryptohomeDataEphemeral( |
| 100 | const AccountId& account_id) const override; |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 101 | void AddObserver(UserManager::Observer* obs) override; |
| 102 | void RemoveObserver(UserManager::Observer* obs) override; |
| 103 | void AddSessionStateObserver( |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 104 | UserManager::UserSessionStateObserver* obs) override; |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 105 | void RemoveSessionStateObserver( |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 106 | UserManager::UserSessionStateObserver* obs) override; |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 107 | void NotifyLocalStateChanged() override; |
xiyuan | 66e4177 | 2016-12-13 21:57:58 | [diff] [blame] | 108 | void NotifyUserImageChanged(const User& user) override; |
| 109 | void NotifyUserProfileImageUpdateFailed(const User& user) override; |
| 110 | void NotifyUserProfileImageUpdated( |
| 111 | const User& user, |
| 112 | const gfx::ImageSkia& profile_image) override; |
dcheng | bd5bd4f | 2015-01-23 16:01:38 | [diff] [blame] | 113 | void ChangeUserChildStatus(User* user, bool is_child) override; |
Pavol Marko | a9808a6 | 2017-08-31 16:22:37 | [diff] [blame^] | 114 | void ResetProfileEverInitialized(const AccountId& account_id) override; |
alemate | 33433e2 | 2016-01-13 14:50:30 | [diff] [blame] | 115 | void Initialize() override; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 116 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 117 | // This method updates "User was added to the device in this session nad is |
| 118 | // not full initialized yet" flag. |
alemate | e66a496 | 2015-02-26 16:12:00 | [diff] [blame] | 119 | virtual void SetIsCurrentUserNew(bool is_new); |
| 120 | |
xiyuan | 3237cef | 2015-03-06 20:44:45 | [diff] [blame] | 121 | // TODO(xiyuan): Figure out a better way to expose this info. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 122 | virtual bool HasPendingBootstrap(const AccountId& account_id) const; |
xiyuan | 3237cef | 2015-03-06 20:44:45 | [diff] [blame] | 123 | |
hcarmona | b1723ed3 | 2015-11-18 21:52:58 | [diff] [blame] | 124 | // Helper function that converts users from |users_list| to |users_vector| and |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 125 | // |users_set|. Duplicates and users already present in |existing_users| are |
| 126 | // skipped. |
hcarmona | b1723ed3 | 2015-11-18 21:52:58 | [diff] [blame] | 127 | void ParseUserList(const base::ListValue& users_list, |
| 128 | const std::set<AccountId>& existing_users, |
| 129 | std::vector<AccountId>* users_vector, |
| 130 | std::set<AccountId>* users_set); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 131 | |
alemate | 0242b47 | 2015-04-20 09:53:40 | [diff] [blame] | 132 | // Returns true if trusted device policies have successfully been retrieved |
| 133 | // and ephemeral users are enabled. |
| 134 | virtual bool AreEphemeralUsersEnabled() const = 0; |
| 135 | |
isandrk | 98a3e4a1 | 2017-05-26 21:14:50 | [diff] [blame] | 136 | void AddUserRecordForTesting(User* user) { |
| 137 | return AddUserRecord(user); |
| 138 | } |
| 139 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 140 | protected: |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 141 | // Adds |user| to users list, and adds it to front of LRU list. It is assumed |
| 142 | // that there is no user with same id. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 143 | virtual void AddUserRecord(User* user); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 144 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 145 | // Returns true if user may be removed. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 146 | virtual bool CanUserBeRemoved(const User* user) const; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 147 | |
| 148 | // A wrapper around C++ delete operator. Deletes |user|, and when |user| |
| 149 | // equals to active_user_, active_user_ is reset to NULL. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 150 | virtual void DeleteUser(User* user); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 151 | |
| 152 | // Returns the locale used by the application. |
| 153 | virtual const std::string& GetApplicationLocale() const = 0; |
| 154 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 155 | // Loads |users_| from Local State if the list has not been loaded yet. |
| 156 | // Subsequent calls have no effect. Must be called on the UI thread. |
merkulova | 793f302 | 2015-02-04 10:18:30 | [diff] [blame] | 157 | virtual void EnsureUsersLoaded(); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 158 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 159 | // Handle OAuth token |status| change for |account_id|. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 160 | virtual void HandleUserOAuthTokenStatusChange( |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 161 | const AccountId& account_id, |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 162 | User::OAuthTokenStatus status) const = 0; |
| 163 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 164 | // Returns true if device is enterprise managed. |
| 165 | virtual bool IsEnterpriseManaged() const = 0; |
| 166 | |
xiyuan | d4f0457 | 2016-04-19 18:22:53 | [diff] [blame] | 167 | // Loads device local accounts from the Local state and fills in |
| 168 | // |device_local_accounts_set|. |
| 169 | virtual void LoadDeviceLocalAccounts( |
| 170 | std::set<AccountId>* device_local_accounts_set) = 0; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 171 | |
| 172 | // Notifies that user has logged in. |
| 173 | virtual void NotifyOnLogin(); |
| 174 | |
| 175 | // Notifies observers that another user was added to the session. |
| 176 | // If |user_switch_pending| is true this means that user has not been fully |
| 177 | // initialized yet like waiting for profile to be loaded. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 178 | virtual void NotifyUserAddedToSession(const User* added_user, |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 179 | bool user_switch_pending); |
| 180 | |
| 181 | // Performs any additional actions before user list is loaded. |
| 182 | virtual void PerformPreUserListLoadingActions() = 0; |
| 183 | |
| 184 | // Performs any additional actions after user list is loaded. |
| 185 | virtual void PerformPostUserListLoadingActions() = 0; |
| 186 | |
| 187 | // Performs any additional actions after UserLoggedIn() execution has been |
| 188 | // completed. |
| 189 | // |browser_restart| is true when reloading Chrome after crash to distinguish |
| 190 | // from normal sign in flow. |
| 191 | virtual void PerformPostUserLoggedInActions(bool browser_restart) = 0; |
| 192 | |
| 193 | // Implementation for RemoveUser method. It is synchronous. It is called from |
| 194 | // RemoveUserInternal after owner check. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 195 | virtual void RemoveNonOwnerUserInternal(const AccountId& account_id, |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 196 | RemoveUserDelegate* delegate); |
| 197 | |
| 198 | // Removes a regular or supervised user from the user list. |
| 199 | // Returns the user if found or NULL otherwise. |
| 200 | // Also removes the user from the persistent user list. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 201 | User* RemoveRegularOrSupervisedUserFromList(const AccountId& account_id); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 202 | |
| 203 | // Implementation for RemoveUser method. This is an asynchronous part of the |
| 204 | // method, that verifies that owner will not get deleted, and calls |
| 205 | // |RemoveNonOwnerUserInternal|. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 206 | virtual void RemoveUserInternal(const AccountId& account_id, |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 207 | RemoveUserDelegate* delegate); |
| 208 | |
| 209 | // Removes data stored or cached outside the user's cryptohome (wallpaper, |
| 210 | // avatar, OAuth token status, display name, display email). |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 211 | virtual void RemoveNonCryptohomeData(const AccountId& account_id); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 212 | |
| 213 | // Check for a particular user type. |
| 214 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 215 | // Returns true if |account_id| represents demo app. |
| 216 | virtual bool IsDemoApp(const AccountId& account_id) const = 0; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 217 | |
xiyuan | d4f0457 | 2016-04-19 18:22:53 | [diff] [blame] | 218 | // Returns true if |account_id| represents a device local account that has |
| 219 | // been marked for deletion. |
| 220 | virtual bool IsDeviceLocalAccountMarkedForRemoval( |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 221 | const AccountId& account_id) const = 0; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 222 | |
| 223 | // These methods are called when corresponding user type has signed in. |
| 224 | |
| 225 | // Indicates that the demo account has just logged in. |
| 226 | virtual void DemoAccountLoggedIn() = 0; |
| 227 | |
| 228 | // Indicates that a user just logged in as guest. |
| 229 | virtual void GuestUserLoggedIn(); |
| 230 | |
| 231 | // Indicates that a kiosk app robot just logged in. |
xiyuan | d4f0457 | 2016-04-19 18:22:53 | [diff] [blame] | 232 | virtual void KioskAppLoggedIn(User* user) = 0; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 233 | |
poromov | 008f8d0 | 2016-11-17 16:34:19 | [diff] [blame] | 234 | // Indicates that an ARC kiosk app robot just logged in. |
| 235 | virtual void ArcKioskAppLoggedIn(User* user) = 0; |
| 236 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 237 | // Indicates that a user just logged into a public session. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 238 | virtual void PublicAccountUserLoggedIn(User* user) = 0; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 239 | |
| 240 | // Indicates that a regular user just logged in. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 241 | virtual void RegularUserLoggedIn(const AccountId& account_id); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 242 | |
| 243 | // Indicates that a regular user just logged in as ephemeral. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 244 | virtual void RegularUserLoggedInAsEphemeral(const AccountId& account_id); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 245 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 246 | // Indicates that a supervised user just logged in. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 247 | virtual void SupervisedUserLoggedIn(const AccountId& account_id) = 0; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 248 | |
peletskyi | 2b8c9d23 | 2015-07-31 16:23:58 | [diff] [blame] | 249 | // Should be called when regular user was removed. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 250 | virtual void OnUserRemoved(const AccountId& account_id) = 0; |
peletskyi | 2b8c9d23 | 2015-07-31 16:23:58 | [diff] [blame] | 251 | |
alemate | 33433e2 | 2016-01-13 14:50:30 | [diff] [blame] | 252 | // Update the global LoginState. |
| 253 | virtual void UpdateLoginState(const User* active_user, |
| 254 | const User* primary_user, |
| 255 | bool is_current_user_owner) const = 0; |
| 256 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 257 | // Getters/setters for private members. |
| 258 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 259 | virtual bool GetEphemeralUsersEnabled() const; |
| 260 | virtual void SetEphemeralUsersEnabled(bool enabled); |
| 261 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 262 | virtual void SetOwnerId(const AccountId& owner_account_id); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 263 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 264 | virtual const AccountId& GetPendingUserSwitchID() const; |
| 265 | virtual void SetPendingUserSwitchId(const AccountId& account_id); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 266 | |
| 267 | // The logged-in user that is currently active in current session. |
| 268 | // NULL until a user has logged in, then points to one |
| 269 | // of the User instances in |users_|, the |guest_user_| instance or an |
| 270 | // ephemeral user instance. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 271 | User* active_user_ = nullptr; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 272 | |
| 273 | // The primary user of the current session. It is recorded for the first |
| 274 | // signed-in user and does not change thereafter. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 275 | User* primary_user_ = nullptr; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 276 | |
| 277 | // List of all known users. User instances are owned by |this|. Regular users |
xiyuan | d4f0457 | 2016-04-19 18:22:53 | [diff] [blame] | 278 | // are removed by |RemoveUserFromList|, device local accounts by |
| 279 | // |UpdateAndCleanUpDeviceLocalAccounts|. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 280 | UserList users_; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 281 | |
merkulova | 793f302 | 2015-02-04 10:18:30 | [diff] [blame] | 282 | // List of all users that are logged in current session. These point to User |
| 283 | // instances in |users_|. Only one of them could be marked as active. |
| 284 | UserList logged_in_users_; |
| 285 | |
| 286 | // A list of all users that are logged in the current session. In contrast to |
| 287 | // |logged_in_users|, the order of this list is least recently used so that |
| 288 | // the active user should always be the first one in the list. |
| 289 | UserList lru_logged_in_users_; |
| 290 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 291 | private: |
| 292 | // Stages of loading user list from preferences. Some methods can have |
| 293 | // different behavior depending on stage. |
| 294 | enum UserLoadStage { STAGE_NOT_LOADED = 0, STAGE_LOADING, STAGE_LOADED }; |
| 295 | |
| 296 | // Returns a list of users who have logged into this device previously. |
| 297 | // Same as GetUsers but used if you need to modify User from that list. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 298 | UserList& GetUsersAndModify(); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 299 | |
| 300 | // Returns the user with the given email address if found in the persistent |
| 301 | // list. Returns |NULL| otherwise. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 302 | const User* FindUserInList(const AccountId& account_id) const; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 303 | |
| 304 | // Returns |true| if user with the given id is found in the persistent list. |
| 305 | // Returns |false| otherwise. Does not trigger user loading. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 306 | bool UserExistsInList(const AccountId& account_id) const; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 307 | |
| 308 | // Same as FindUserInList but returns non-const pointer to User object. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 309 | User* FindUserInListAndModify(const AccountId& account_id); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 310 | |
| 311 | // Reads user's oauth token status from local state preferences. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 312 | User::OAuthTokenStatus LoadUserOAuthStatus(const AccountId& account_id) const; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 313 | |
| 314 | // Read a flag indicating whether online authentication against GAIA should |
| 315 | // be enforced during the user's next sign-in from local state preferences. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 316 | bool LoadForceOnlineSignin(const AccountId& account_id) const; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 317 | |
atwilson | d5a7eabf | 2017-03-09 13:18:39 | [diff] [blame] | 318 | // Read a flag indicating whether session initialization has completed at |
| 319 | // least once. |
| 320 | bool LoadSessionInitialized(const AccountId& account_id) const; |
| 321 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 322 | // Notifies observers that merge session state had changed. |
| 323 | void NotifyMergeSessionStateChanged(); |
| 324 | |
| 325 | // Notifies observers that active user has changed. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 326 | void NotifyActiveUserChanged(const User* active_user); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 327 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 328 | // Notifies observers that active account_id hash has changed. |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 329 | void NotifyActiveUserHashChanged(const std::string& hash); |
| 330 | |
alemate | 33433e2 | 2016-01-13 14:50:30 | [diff] [blame] | 331 | // Call UpdateLoginState. |
| 332 | void CallUpdateLoginState(); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 333 | |
| 334 | // Insert |user| at the front of the LRU user list. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 335 | void SetLRUUser(User* user); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 336 | |
merkulova | c3ae44d | 2014-11-17 09:35:07 | [diff] [blame] | 337 | // Sends metrics in response to a user with gaia account (regular) logging in. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 338 | void SendGaiaUserLoginMetrics(const AccountId& account_id); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 339 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 340 | // Sets account locale for user with id |account_id|. |
| 341 | virtual void UpdateUserAccountLocale(const AccountId& account_id, |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 342 | const std::string& locale); |
| 343 | |
| 344 | // Updates user account after locale was resolved. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 345 | void DoUpdateAccountLocale(const AccountId& account_id, |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 346 | std::unique_ptr<std::string> resolved_locale); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 347 | |
| 348 | // Indicates stage of loading user from prefs. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 349 | UserLoadStage user_loading_stage_ = STAGE_NOT_LOADED; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 350 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 351 | // Cached flag of whether the currently logged-in user existed before this |
| 352 | // login. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 353 | bool is_current_user_new_ = false; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 354 | |
| 355 | // Cached flag of whether the currently logged-in user is a regular user who |
| 356 | // logged in as ephemeral. Storage of persistent information is avoided for |
| 357 | // such users by not adding them to the persistent user list, not downloading |
| 358 | // their custom avatars and mounting their cryptohomes using tmpfs. Defaults |
| 359 | // to |false|. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 360 | bool is_current_user_ephemeral_regular_user_ = false; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 361 | |
| 362 | // Cached flag indicating whether the ephemeral user policy is enabled. |
| 363 | // Defaults to |false| if the value has not been read from trusted device |
| 364 | // policy yet. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 365 | bool ephemeral_users_enabled_ = false; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 366 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 367 | // Cached name of device owner. Defaults to empty if the value has not |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 368 | // been read from trusted device policy yet. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 369 | AccountId owner_account_id_ = EmptyAccountId(); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 370 | |
brettw | 236d317 | 2015-06-03 16:31:43 | [diff] [blame] | 371 | base::ObserverList<UserManager::Observer> observer_list_; |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 372 | |
| 373 | // TODO(nkostylev): Merge with session state refactoring CL. |
brettw | 236d317 | 2015-06-03 16:31:43 | [diff] [blame] | 374 | base::ObserverList<UserManager::UserSessionStateObserver> |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 375 | session_state_observer_list_; |
| 376 | |
| 377 | // Time at which this object was created. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 378 | base::TimeTicks manager_creation_time_ = base::TimeTicks::Now(); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 379 | |
| 380 | // ID of the user just added to the session that needs to be activated |
| 381 | // as soon as user's profile is loaded. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 382 | AccountId pending_user_switch_ = EmptyAccountId(); |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 383 | |
nkostylev | 5df7e99 | 2014-09-26 09:03:47 | [diff] [blame] | 384 | // ID of the user that was active in the previous session. |
| 385 | // Preference value is stored here before first user signs in |
| 386 | // because pref will be overidden once session restore starts. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 387 | AccountId last_session_active_account_id_ = EmptyAccountId(); |
| 388 | bool last_session_active_account_id_initialized_ = false; |
nkostylev | 5df7e99 | 2014-09-26 09:03:47 | [diff] [blame] | 389 | |
[email protected] | ac58eaf7 | 2014-08-19 13:06:42 | [diff] [blame] | 390 | // TaskRunner for UI thread. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 391 | scoped_refptr<base::TaskRunner> task_runner_; |
[email protected] | ac58eaf7 | 2014-08-19 13:06:42 | [diff] [blame] | 392 | |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 393 | base::WeakPtrFactory<UserManagerBase> weak_factory_; |
| 394 | |
| 395 | DISALLOW_COPY_AND_ASSIGN(UserManagerBase); |
| 396 | }; |
| 397 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 398 | } // namespace user_manager |
[email protected] | babc148 | 2014-08-02 05:44:13 | [diff] [blame] | 399 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 400 | #endif // COMPONENTS_USER_MANAGER_USER_MANAGER_BASE_H_ |