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 <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 class RemoveUserDelegate; | 32 class RemoveUserDelegate; |
33 | 33 |
34 // Base implementation of the UserManager interface. | 34 // Base implementation of the UserManager interface. |
35 class USER_MANAGER_EXPORT UserManagerBase : public UserManager { | 35 class USER_MANAGER_EXPORT UserManagerBase : public UserManager { |
36 public: | 36 public: |
37 // Creates UserManagerBase with |task_runner| for UI thread and | 37 // Creates UserManagerBase with |task_runner| for UI thread and |
38 // |blocking_task_runner| for SequencedWorkerPool. | 38 // |blocking_task_runner| for SequencedWorkerPool. |
39 UserManagerBase(scoped_refptr<base::TaskRunner> task_runner, | 39 UserManagerBase(scoped_refptr<base::TaskRunner> task_runner, |
40 scoped_refptr<base::TaskRunner> blocking_task_runner); | 40 scoped_refptr<base::TaskRunner> blocking_task_runner); |
41 virtual ~UserManagerBase(); | 41 ~UserManagerBase() override; |
42 | 42 |
43 // Registers UserManagerBase preferences. | 43 // Registers UserManagerBase preferences. |
44 static void RegisterPrefs(PrefRegistrySimple* registry); | 44 static void RegisterPrefs(PrefRegistrySimple* registry); |
45 | 45 |
46 // UserManager implementation: | 46 // UserManager implementation: |
47 virtual void Shutdown() override; | 47 void Shutdown() override; |
48 virtual const UserList& GetUsers() const override; | 48 const UserList& GetUsers() const override; |
49 virtual const UserList& GetLoggedInUsers() const override; | 49 const UserList& GetLoggedInUsers() const override; |
50 virtual const UserList& GetLRULoggedInUsers() const override; | 50 const UserList& GetLRULoggedInUsers() const override; |
51 virtual const std::string& GetOwnerEmail() const override; | 51 const std::string& GetOwnerEmail() const override; |
52 virtual void UserLoggedIn(const std::string& user_id, | 52 void UserLoggedIn(const std::string& user_id, |
53 const std::string& user_id_hash, | 53 const std::string& user_id_hash, |
54 bool browser_restart) override; | 54 bool browser_restart) override; |
55 virtual void SwitchActiveUser(const std::string& user_id) override; | 55 void SwitchActiveUser(const std::string& user_id) override; |
56 virtual void SwitchToLastActiveUser() override; | 56 void SwitchToLastActiveUser() override; |
57 virtual void SessionStarted() override; | 57 void SessionStarted() override; |
58 virtual void RemoveUser(const std::string& user_id, | 58 void RemoveUser(const std::string& user_id, |
59 RemoveUserDelegate* delegate) override; | 59 RemoveUserDelegate* delegate) override; |
60 virtual void RemoveUserFromList(const std::string& user_id) override; | 60 void RemoveUserFromList(const std::string& user_id) override; |
61 virtual bool IsKnownUser(const std::string& user_id) const override; | 61 bool IsKnownUser(const std::string& user_id) const override; |
62 virtual const User* FindUser(const std::string& user_id) const override; | 62 const User* FindUser(const std::string& user_id) const override; |
63 virtual User* FindUserAndModify(const std::string& user_id) override; | 63 User* FindUserAndModify(const std::string& user_id) override; |
64 virtual const User* GetLoggedInUser() const override; | 64 const User* GetLoggedInUser() const override; |
65 virtual User* GetLoggedInUser() override; | 65 User* GetLoggedInUser() override; |
66 virtual const User* GetActiveUser() const override; | 66 const User* GetActiveUser() const override; |
67 virtual User* GetActiveUser() override; | 67 User* GetActiveUser() override; |
68 virtual const User* GetPrimaryUser() const override; | 68 const User* GetPrimaryUser() const override; |
69 virtual void SaveUserOAuthStatus( | 69 void SaveUserOAuthStatus(const std::string& user_id, |
70 const std::string& user_id, | 70 User::OAuthTokenStatus oauth_token_status) override; |
71 User::OAuthTokenStatus oauth_token_status) override; | 71 void SaveForceOnlineSignin(const std::string& user_id, |
72 virtual void SaveForceOnlineSignin(const std::string& user_id, | 72 bool force_online_signin) override; |
73 bool force_online_signin) override; | 73 void SaveUserDisplayName(const std::string& user_id, |
74 virtual void SaveUserDisplayName(const std::string& user_id, | 74 const base::string16& display_name) override; |
75 const base::string16& display_name) override; | 75 base::string16 GetUserDisplayName(const std::string& user_id) const override; |
76 virtual base::string16 GetUserDisplayName( | 76 void SaveUserDisplayEmail(const std::string& user_id, |
| 77 const std::string& display_email) override; |
| 78 std::string GetUserDisplayEmail(const std::string& user_id) const override; |
| 79 void SaveUserType(const std::string& user_id, |
| 80 const UserType& user_type) override; |
| 81 void UpdateUserAccountData(const std::string& user_id, |
| 82 const UserAccountData& account_data) override; |
| 83 bool IsCurrentUserOwner() const override; |
| 84 bool IsCurrentUserNew() const override; |
| 85 bool IsCurrentUserNonCryptohomeDataEphemeral() const override; |
| 86 bool CanCurrentUserLock() const override; |
| 87 bool IsUserLoggedIn() const override; |
| 88 bool IsLoggedInAsUserWithGaiaAccount() const override; |
| 89 bool IsLoggedInAsChildUser() const override; |
| 90 bool IsLoggedInAsPublicAccount() const override; |
| 91 bool IsLoggedInAsGuest() const override; |
| 92 bool IsLoggedInAsSupervisedUser() const override; |
| 93 bool IsLoggedInAsKioskApp() const override; |
| 94 bool IsLoggedInAsStub() const override; |
| 95 bool IsSessionStarted() const override; |
| 96 bool IsUserNonCryptohomeDataEphemeral( |
77 const std::string& user_id) const override; | 97 const std::string& user_id) const override; |
78 virtual void SaveUserDisplayEmail(const std::string& user_id, | 98 void AddObserver(UserManager::Observer* obs) override; |
79 const std::string& display_email) override; | 99 void RemoveObserver(UserManager::Observer* obs) override; |
80 virtual std::string GetUserDisplayEmail( | 100 void AddSessionStateObserver( |
81 const std::string& user_id) const override; | |
82 virtual void SaveUserType(const std::string& user_id, | |
83 const UserType& user_type) override; | |
84 virtual void UpdateUserAccountData( | |
85 const std::string& user_id, | |
86 const UserAccountData& account_data) override; | |
87 virtual bool IsCurrentUserOwner() const override; | |
88 virtual bool IsCurrentUserNew() const override; | |
89 virtual bool IsCurrentUserNonCryptohomeDataEphemeral() const override; | |
90 virtual bool CanCurrentUserLock() const override; | |
91 virtual bool IsUserLoggedIn() const override; | |
92 virtual bool IsLoggedInAsUserWithGaiaAccount() const override; | |
93 virtual bool IsLoggedInAsChildUser() const override; | |
94 virtual bool IsLoggedInAsPublicAccount() const override; | |
95 virtual bool IsLoggedInAsGuest() const override; | |
96 virtual bool IsLoggedInAsSupervisedUser() const override; | |
97 virtual bool IsLoggedInAsKioskApp() const override; | |
98 virtual bool IsLoggedInAsStub() const override; | |
99 virtual bool IsSessionStarted() const override; | |
100 virtual bool IsUserNonCryptohomeDataEphemeral( | |
101 const std::string& user_id) const override; | |
102 virtual void AddObserver(UserManager::Observer* obs) override; | |
103 virtual void RemoveObserver(UserManager::Observer* obs) override; | |
104 virtual void AddSessionStateObserver( | |
105 UserManager::UserSessionStateObserver* obs) override; | 101 UserManager::UserSessionStateObserver* obs) override; |
106 virtual void RemoveSessionStateObserver( | 102 void RemoveSessionStateObserver( |
107 UserManager::UserSessionStateObserver* obs) override; | 103 UserManager::UserSessionStateObserver* obs) override; |
108 virtual void NotifyLocalStateChanged() override; | 104 void NotifyLocalStateChanged() override; |
109 virtual void ChangeUserChildStatus(User* user, bool is_child) override; | 105 void ChangeUserChildStatus(User* user, bool is_child) override; |
110 | 106 |
111 // Helper function that copies users from |users_list| to |users_vector| and | 107 // Helper function that copies users from |users_list| to |users_vector| and |
112 // |users_set|. Duplicates and users already present in |existing_users| are | 108 // |users_set|. Duplicates and users already present in |existing_users| are |
113 // skipped. | 109 // skipped. |
114 static void ParseUserList(const base::ListValue& users_list, | 110 static void ParseUserList(const base::ListValue& users_list, |
115 const std::set<std::string>& existing_users, | 111 const std::set<std::string>& existing_users, |
116 std::vector<std::string>* users_vector, | 112 std::vector<std::string>* users_vector, |
117 std::set<std::string>* users_set); | 113 std::set<std::string>* users_set); |
118 | 114 |
119 protected: | 115 protected: |
(...skipping 13 matching lines...) Expand all Loading... |
133 virtual void DeleteUser(User* user); | 129 virtual void DeleteUser(User* user); |
134 | 130 |
135 // Returns the locale used by the application. | 131 // Returns the locale used by the application. |
136 virtual const std::string& GetApplicationLocale() const = 0; | 132 virtual const std::string& GetApplicationLocale() const = 0; |
137 | 133 |
138 // Returns "Local State" PrefService instance. | 134 // Returns "Local State" PrefService instance. |
139 virtual PrefService* GetLocalState() const = 0; | 135 virtual PrefService* GetLocalState() const = 0; |
140 | 136 |
141 // Loads |users_| from Local State if the list has not been loaded yet. | 137 // Loads |users_| from Local State if the list has not been loaded yet. |
142 // Subsequent calls have no effect. Must be called on the UI thread. | 138 // Subsequent calls have no effect. Must be called on the UI thread. |
143 void EnsureUsersLoaded(); | 139 virtual void EnsureUsersLoaded(); |
144 | 140 |
145 // Handle OAuth token |status| change for |user_id|. | 141 // Handle OAuth token |status| change for |user_id|. |
146 virtual void HandleUserOAuthTokenStatusChange( | 142 virtual void HandleUserOAuthTokenStatusChange( |
147 const std::string& user_id, | 143 const std::string& user_id, |
148 User::OAuthTokenStatus status) const = 0; | 144 User::OAuthTokenStatus status) const = 0; |
149 | 145 |
150 // Returns true if device is enterprise managed. | 146 // Returns true if device is enterprise managed. |
151 virtual bool IsEnterpriseManaged() const = 0; | 147 virtual bool IsEnterpriseManaged() const = 0; |
152 | 148 |
153 // Helper function that copies users from |users_list| to |users_vector| and | 149 // Helper function that copies users from |users_list| to |users_vector| and |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 253 |
258 // The primary user of the current session. It is recorded for the first | 254 // The primary user of the current session. It is recorded for the first |
259 // signed-in user and does not change thereafter. | 255 // signed-in user and does not change thereafter. |
260 User* primary_user_; | 256 User* primary_user_; |
261 | 257 |
262 // List of all known users. User instances are owned by |this|. Regular users | 258 // List of all known users. User instances are owned by |this|. Regular users |
263 // are removed by |RemoveUserFromList|, public accounts by | 259 // are removed by |RemoveUserFromList|, public accounts by |
264 // |UpdateAndCleanUpPublicAccounts|. | 260 // |UpdateAndCleanUpPublicAccounts|. |
265 UserList users_; | 261 UserList users_; |
266 | 262 |
| 263 // List of all users that are logged in current session. These point to User |
| 264 // instances in |users_|. Only one of them could be marked as active. |
| 265 UserList logged_in_users_; |
| 266 |
| 267 // A list of all users that are logged in the current session. In contrast to |
| 268 // |logged_in_users|, the order of this list is least recently used so that |
| 269 // the active user should always be the first one in the list. |
| 270 UserList lru_logged_in_users_; |
| 271 |
267 private: | 272 private: |
268 // Stages of loading user list from preferences. Some methods can have | 273 // Stages of loading user list from preferences. Some methods can have |
269 // different behavior depending on stage. | 274 // different behavior depending on stage. |
270 enum UserLoadStage { STAGE_NOT_LOADED = 0, STAGE_LOADING, STAGE_LOADED }; | 275 enum UserLoadStage { STAGE_NOT_LOADED = 0, STAGE_LOADING, STAGE_LOADED }; |
271 | 276 |
272 // Returns a list of users who have logged into this device previously. | 277 // Returns a list of users who have logged into this device previously. |
273 // Same as GetUsers but used if you need to modify User from that list. | 278 // Same as GetUsers but used if you need to modify User from that list. |
274 UserList& GetUsersAndModify(); | 279 UserList& GetUsersAndModify(); |
275 | 280 |
276 // Returns the user with the given email address if found in the persistent | 281 // Returns the user with the given email address if found in the persistent |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 virtual void UpdateUserAccountLocale(const std::string& user_id, | 318 virtual void UpdateUserAccountLocale(const std::string& user_id, |
314 const std::string& locale); | 319 const std::string& locale); |
315 | 320 |
316 // Updates user account after locale was resolved. | 321 // Updates user account after locale was resolved. |
317 void DoUpdateAccountLocale(const std::string& user_id, | 322 void DoUpdateAccountLocale(const std::string& user_id, |
318 scoped_ptr<std::string> resolved_locale); | 323 scoped_ptr<std::string> resolved_locale); |
319 | 324 |
320 // Indicates stage of loading user from prefs. | 325 // Indicates stage of loading user from prefs. |
321 UserLoadStage user_loading_stage_; | 326 UserLoadStage user_loading_stage_; |
322 | 327 |
323 // List of all users that are logged in current session. These point to User | |
324 // instances in |users_|. Only one of them could be marked as active. | |
325 UserList logged_in_users_; | |
326 | |
327 // A list of all users that are logged in the current session. In contrast to | |
328 // |logged_in_users|, the order of this list is least recently used so that | |
329 // the active user should always be the first one in the list. | |
330 UserList lru_logged_in_users_; | |
331 | |
332 // True if SessionStarted() has been called. | 328 // True if SessionStarted() has been called. |
333 bool session_started_; | 329 bool session_started_; |
334 | 330 |
335 // Cached flag of whether currently logged-in user is owner or not. | 331 // Cached flag of whether currently logged-in user is owner or not. |
336 // May be accessed on different threads, requires locking. | 332 // May be accessed on different threads, requires locking. |
337 bool is_current_user_owner_; | 333 bool is_current_user_owner_; |
338 mutable base::Lock is_current_user_owner_lock_; | 334 mutable base::Lock is_current_user_owner_lock_; |
339 | 335 |
340 // Cached flag of whether the currently logged-in user existed before this | 336 // Cached flag of whether the currently logged-in user existed before this |
341 // login. | 337 // login. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 scoped_refptr<base::TaskRunner> blocking_task_runner_; | 379 scoped_refptr<base::TaskRunner> blocking_task_runner_; |
384 | 380 |
385 base::WeakPtrFactory<UserManagerBase> weak_factory_; | 381 base::WeakPtrFactory<UserManagerBase> weak_factory_; |
386 | 382 |
387 DISALLOW_COPY_AND_ASSIGN(UserManagerBase); | 383 DISALLOW_COPY_AND_ASSIGN(UserManagerBase); |
388 }; | 384 }; |
389 | 385 |
390 } // namespace user_manager | 386 } // namespace user_manager |
391 | 387 |
392 #endif // COMPONENTS_USER_MANAGER_USER_MANAGER_BASE_H_ | 388 #endif // COMPONENTS_USER_MANAGER_USER_MANAGER_BASE_H_ |
OLD | NEW |