Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: components/user_manager/user_manager.h

Issue 444903002: [cros] user_manager component - move UserManagerBase and UserManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: similarity Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_H_ 5 #ifndef COMPONENTS_USER_MANAGER_USER_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_H_ 6 #define COMPONENTS_USER_MANAGER_USER_MANAGER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "chrome/browser/chromeos/login/user_flow.h"
11 #include "components/user_manager/user.h" 10 #include "components/user_manager/user.h"
12 11 #include "components/user_manager/user_manager_export.h"
13 class PrefRegistrySimple;
14 12
15 namespace chromeos { 13 namespace chromeos {
14 class ScopedUserManagerEnabler;
15 }
16 16
17 class MultiProfileUserController; 17 namespace user_manager {
18
18 class RemoveUserDelegate; 19 class RemoveUserDelegate;
19 class UserImageManager;
20 class SupervisedUserManager;
21 20
22 // Interface for UserManagerBase - provides a mechanism for discovering users 21 // Interface for UserManagerBase - provides a mechanism for discovering users
23 // who have logged into this Chrome OS device before and updating that list. 22 // who have logged into this Chrome OS device before and updating that list.
24 class UserManager { 23 class USER_MANAGER_EXPORT UserManager {
25 public: 24 public:
26 // Interface that observers of UserManager must implement in order 25 // Interface that observers of UserManager must implement in order
27 // to receive notification when local state preferences is changed 26 // to receive notification when local state preferences is changed
28 class Observer { 27 class Observer {
29 public: 28 public:
30 // Called when the local state preferences is changed. 29 // Called when the local state preferences is changed.
31 virtual void LocalStateChanged(UserManager* user_manager); 30 virtual void LocalStateChanged(UserManager* user_manager);
32 31
33 protected: 32 protected:
34 virtual ~Observer(); 33 virtual ~Observer();
35 }; 34 };
36 35
37 // TODO(nkostylev): Refactor and move this observer out of UserManager. 36 // TODO(nkostylev): Refactor and move this observer out of UserManager.
38 // Observer interface that defines methods used to notify on user session / 37 // Observer interface that defines methods used to notify on user session /
39 // active user state changes. Default implementation is empty. 38 // active user state changes. Default implementation is empty.
40 class UserSessionStateObserver { 39 class UserSessionStateObserver {
41 public: 40 public:
42 // Called when active user has changed. 41 // Called when active user has changed.
43 virtual void ActiveUserChanged(const user_manager::User* active_user); 42 virtual void ActiveUserChanged(const User* active_user);
44 43
45 // Called when another user got added to the existing session. 44 // Called when another user got added to the existing session.
46 virtual void UserAddedToSession(const user_manager::User* added_user); 45 virtual void UserAddedToSession(const User* added_user);
47 46
48 // Called right before notifying on user change so that those who rely 47 // Called right before notifying on user change so that those who rely
49 // on user_id hash would be accessing up-to-date value. 48 // on user_id hash would be accessing up-to-date value.
50 virtual void ActiveUserHashChanged(const std::string& hash); 49 virtual void ActiveUserHashChanged(const std::string& hash);
51 50
52 protected: 51 protected:
53 virtual ~UserSessionStateObserver(); 52 virtual ~UserSessionStateObserver();
54 }; 53 };
55 54
56 // Data retrieved from user account. 55 // Data retrieved from user account.
57 class UserAccountData { 56 class UserAccountData {
58 public: 57 public:
59 UserAccountData(const base::string16& display_name, 58 UserAccountData(const base::string16& display_name,
60 const base::string16& given_name, 59 const base::string16& given_name,
61 const std::string& locale); 60 const std::string& locale);
62 ~UserAccountData(); 61 ~UserAccountData();
63 const base::string16& display_name() const { return display_name_; } 62 const base::string16& display_name() const { return display_name_; }
64 const base::string16& given_name() const { return given_name_; } 63 const base::string16& given_name() const { return given_name_; }
65 const std::string& locale() const { return locale_; } 64 const std::string& locale() const { return locale_; }
66 65
67 private: 66 private:
68 const base::string16 display_name_; 67 const base::string16 display_name_;
69 const base::string16 given_name_; 68 const base::string16 given_name_;
70 const std::string locale_; 69 const std::string locale_;
71 70
72 DISALLOW_COPY_AND_ASSIGN(UserAccountData); 71 DISALLOW_COPY_AND_ASSIGN(UserAccountData);
73 }; 72 };
74 73
75 // Creates the singleton instance. This method is not thread-safe and must be 74 // Initializes UserManager instance to this. Normally should be called right
76 // called from the main UI thread. 75 // after creation so that user_manager::UserManager::Get() doesn't fail.
77 static void Initialize(); 76 // Tests could call this later especially if they are replacing existing
77 // UserManager instance with their own test instance.
78 void Initialize();
78 79
79 // Checks whether the singleton instance has been created already. This method 80 // Checks whether the UserManager instance has been created already.
80 // is not thread-safe and must be called from the main UI thread. 81 // This method is not thread-safe and must be called from the main UI thread.
81 static bool IsInitialized(); 82 static bool IsInitialized();
82 83
83 // Shuts down the UserManager. After this method has been called, the 84 // Shuts down the UserManager. After this method has been called, the
84 // singleton has unregistered itself as an observer but remains available so 85 // singleton has unregistered itself as an observer but remains available so
85 // that other classes can access it during their shutdown. This method is not 86 // that other classes can access it during their shutdown. This method is not
86 // thread-safe and must be called from the main UI thread. 87 // thread-safe and must be called from the main UI thread.
87 virtual void Shutdown() = 0; 88 virtual void Shutdown() = 0;
88 89
89 // Destroys the singleton instance. Always call Shutdown() first. This method 90 // Sets UserManager instance to NULL. Always call Shutdown() first.
90 // is not thread-safe and must be called from the main UI thread. 91 // This method is not thread-safe and must be called from the main UI thread.
91 static void Destroy(); 92 void Destroy();
92 93
93 // Returns the singleton instance or |NULL| if the singleton has either not 94 // Returns UserManager instance or |NULL| if it has either not
94 // been created yet or is already destroyed. This method is not thread-safe 95 // been created yet or is already destroyed. This method is not thread-safe
95 // and must be called from the main UI thread. 96 // and must be called from the main UI thread.
96 static UserManager* Get(); 97 static UserManager* Get();
97 98
98 // Registers user manager preferences.
99 static void RegisterPrefs(PrefRegistrySimple* registry);
100
101 virtual ~UserManager(); 99 virtual ~UserManager();
102 100
103 virtual MultiProfileUserController* GetMultiProfileUserController() = 0;
104 virtual UserImageManager* GetUserImageManager(const std::string& user_id) = 0;
105 virtual SupervisedUserManager* GetSupervisedUserManager() = 0;
106
107 // Returns a list of users who have logged into this device previously. This 101 // Returns a list of users who have logged into this device previously. This
108 // is sorted by last login date with the most recent user at the beginning. 102 // is sorted by last login date with the most recent user at the beginning.
109 virtual const user_manager::UserList& GetUsers() const = 0; 103 virtual const UserList& GetUsers() const = 0;
110 104
111 // Returns list of users admitted for logging in into multi-profile session. 105 // Returns list of users admitted for logging in into multi-profile session.
112 // Users that have a policy that prevents them from being added to the 106 // Users that have a policy that prevents them from being added to the
113 // multi-profile session will still be part of this list as long as they 107 // multi-profile session will still be part of this list as long as they
114 // are regular users (i.e. not a public session/supervised etc.). 108 // are regular users (i.e. not a public session/supervised etc.).
115 // Returns an empty list in case when primary user is not a regular one or 109 // Returns an empty list in case when primary user is not a regular one or
116 // has a policy that prohibids it to be part of multi-profile session. 110 // has a policy that prohibids it to be part of multi-profile session.
117 virtual user_manager::UserList GetUsersAdmittedForMultiProfile() const = 0; 111 virtual UserList GetUsersAdmittedForMultiProfile() const = 0;
118 112
119 // Returns a list of users who are currently logged in. 113 // Returns a list of users who are currently logged in.
120 virtual const user_manager::UserList& GetLoggedInUsers() const = 0; 114 virtual const UserList& GetLoggedInUsers() const = 0;
121 115
122 // Returns a list of users who are currently logged in in the LRU order - 116 // Returns a list of users who are currently logged in in the LRU order -
123 // so the active user is the first one in the list. If there is no user logged 117 // so the active user is the first one in the list. If there is no user logged
124 // in, the current user will be returned. 118 // in, the current user will be returned.
125 virtual const user_manager::UserList& GetLRULoggedInUsers() const = 0; 119 virtual const UserList& GetLRULoggedInUsers() const = 0;
126 120
127 // Returns a list of users who can unlock the device. 121 // Returns a list of users who can unlock the device.
128 // This list is based on policy and whether user is able to do unlock. 122 // This list is based on policy and whether user is able to do unlock.
129 // Policy: 123 // Policy:
130 // * If user has primary-only policy then it is the only user in unlock users. 124 // * If user has primary-only policy then it is the only user in unlock users.
131 // * Otherwise all users with unrestricted policy are added to this list. 125 // * Otherwise all users with unrestricted policy are added to this list.
132 // All users that are unable to perform unlock are excluded from this list. 126 // All users that are unable to perform unlock are excluded from this list.
133 virtual user_manager::UserList GetUnlockUsers() const = 0; 127 virtual UserList GetUnlockUsers() const = 0;
134 128
135 // Returns the email of the owner user. Returns an empty string if there is 129 // Returns the email of the owner user. Returns an empty string if there is
136 // no owner for the device. 130 // no owner for the device.
137 virtual const std::string& GetOwnerEmail() const = 0; 131 virtual const std::string& GetOwnerEmail() const = 0;
138 132
139 // Indicates that a user with the given |user_id| has just logged in. The 133 // Indicates that a user with the given |user_id| has just logged in. The
140 // persistent list is updated accordingly if the user is not ephemeral. 134 // persistent list is updated accordingly if the user is not ephemeral.
141 // |browser_restart| is true when reloading Chrome after crash to distinguish 135 // |browser_restart| is true when reloading Chrome after crash to distinguish
142 // from normal sign in flow. 136 // from normal sign in flow.
143 // |username_hash| is used to identify homedir mount point. 137 // |username_hash| is used to identify homedir mount point.
(...skipping 22 matching lines...) Expand all
166 // Removes the user from the persistent list only. Also removes the user's 160 // Removes the user from the persistent list only. Also removes the user's
167 // picture. 161 // picture.
168 virtual void RemoveUserFromList(const std::string& user_id) = 0; 162 virtual void RemoveUserFromList(const std::string& user_id) = 0;
169 163
170 // Returns true if a user with the given user id is found in the persistent 164 // Returns true if a user with the given user id is found in the persistent
171 // list or currently logged in as ephemeral. 165 // list or currently logged in as ephemeral.
172 virtual bool IsKnownUser(const std::string& user_id) const = 0; 166 virtual bool IsKnownUser(const std::string& user_id) const = 0;
173 167
174 // Returns the user with the given user id if found in the persistent 168 // Returns the user with the given user id if found in the persistent
175 // list or currently logged in as ephemeral. Returns |NULL| otherwise. 169 // list or currently logged in as ephemeral. Returns |NULL| otherwise.
176 virtual const user_manager::User* FindUser( 170 virtual const User* FindUser(const std::string& user_id) const = 0;
177 const std::string& user_id) const = 0;
178 171
179 // Returns the user with the given user id if found in the persistent 172 // Returns the user with the given user id if found in the persistent
180 // list or currently logged in as ephemeral. Returns |NULL| otherwise. 173 // list or currently logged in as ephemeral. Returns |NULL| otherwise.
181 // Same as FindUser but returns non-const pointer to User object. 174 // Same as FindUser but returns non-const pointer to User object.
182 virtual user_manager::User* FindUserAndModify(const std::string& user_id) = 0; 175 virtual User* FindUserAndModify(const std::string& user_id) = 0;
183 176
184 // Returns the logged-in user. 177 // Returns the logged-in user.
185 // TODO(nkostylev): Deprecate this call, move clients to GetActiveUser(). 178 // TODO(nkostylev): Deprecate this call, move clients to GetActiveUser().
186 // http://crbug.com/230852 179 // http://crbug.com/230852
187 virtual const user_manager::User* GetLoggedInUser() const = 0; 180 virtual const User* GetLoggedInUser() const = 0;
188 virtual user_manager::User* GetLoggedInUser() = 0; 181 virtual User* GetLoggedInUser() = 0;
189 182
190 // Returns the logged-in user that is currently active within this session. 183 // Returns the logged-in user that is currently active within this session.
191 // There could be multiple users logged in at the the same but for now 184 // There could be multiple users logged in at the the same but for now
192 // we support only one of them being active. 185 // we support only one of them being active.
193 virtual const user_manager::User* GetActiveUser() const = 0; 186 virtual const User* GetActiveUser() const = 0;
194 virtual user_manager::User* GetActiveUser() = 0; 187 virtual User* GetActiveUser() = 0;
195 188
196 // Returns the primary user of the current session. It is recorded for the 189 // Returns the primary user of the current session. It is recorded for the
197 // first signed-in user and does not change thereafter. 190 // first signed-in user and does not change thereafter.
198 virtual const user_manager::User* GetPrimaryUser() const = 0; 191 virtual const User* GetPrimaryUser() const = 0;
199 192
200 // Saves user's oauth token status in local state preferences. 193 // Saves user's oauth token status in local state preferences.
201 virtual void SaveUserOAuthStatus( 194 virtual void SaveUserOAuthStatus(
202 const std::string& user_id, 195 const std::string& user_id,
203 user_manager::User::OAuthTokenStatus oauth_token_status) = 0; 196 User::OAuthTokenStatus oauth_token_status) = 0;
204 197
205 // Saves a flag indicating whether online authentication against GAIA should 198 // Saves a flag indicating whether online authentication against GAIA should
206 // be enforced during the user's next sign-in. 199 // be enforced during the user's next sign-in.
207 virtual void SaveForceOnlineSignin(const std::string& user_id, 200 virtual void SaveForceOnlineSignin(const std::string& user_id,
208 bool force_online_signin) = 0; 201 bool force_online_signin) = 0;
209 202
210 // Saves user's displayed name in local state preferences. 203 // Saves user's displayed name in local state preferences.
211 // Ignored If there is no such user. 204 // Ignored If there is no such user.
212 virtual void SaveUserDisplayName(const std::string& user_id, 205 virtual void SaveUserDisplayName(const std::string& user_id,
213 const base::string16& display_name) = 0; 206 const base::string16& display_name) = 0;
214 207
215 // Updates data upon User Account download. 208 // Updates data upon User Account download.
216 virtual void UpdateUserAccountData(const std::string& user_id, 209 virtual void UpdateUserAccountData(const std::string& user_id,
217 const UserAccountData& account_data) = 0; 210 const UserAccountData& account_data) = 0;
218 211
219 // Returns the display name for user |user_id| if it is known (was 212 // Returns the display name for user |user_id| if it is known (was
220 // previously set by a |SaveUserDisplayName| call). 213 // previously set by a |SaveUserDisplayName| call).
221 // Otherwise, returns an empty string. 214 // Otherwise, returns an empty string.
222 virtual base::string16 GetUserDisplayName( 215 virtual base::string16 GetUserDisplayName(
223 const std::string& user_id) const = 0; 216 const std::string& user_id) const = 0;
224 217
225 // Saves user's displayed (non-canonical) email in local state preferences. 218 // Saves user's displayed (non-canonical) email in local state preferences.
226 // Ignored If there is no such user. 219 // Ignored If there is no such user.
227 virtual void SaveUserDisplayEmail(const std::string& user_id, 220 virtual void SaveUserDisplayEmail(const std::string& user_id,
228 const std::string& display_email) = 0; 221 const std::string& display_email) = 0;
229 222
230 // Returns the display email for user |user_id| if it is known (was 223 // Returns the display email for user |user_id| if it is known (was
231 // previously set by a |SaveUserDisplayEmail| call). 224 // previously set by a |SaveUserDisplayEmail| call).
232 // Otherwise, returns |user_id| itself. 225 // Otherwise, returns |user_id| itself.
233 virtual std::string GetUserDisplayEmail( 226 virtual std::string GetUserDisplayEmail(const std::string& user_id) const = 0;
234 const std::string& user_id) const = 0;
235 227
236 // Returns true if current user is an owner. 228 // Returns true if current user is an owner.
237 virtual bool IsCurrentUserOwner() const = 0; 229 virtual bool IsCurrentUserOwner() const = 0;
238 230
239 // Returns true if current user is not existing one (hasn't signed in before). 231 // Returns true if current user is not existing one (hasn't signed in before).
240 virtual bool IsCurrentUserNew() const = 0; 232 virtual bool IsCurrentUserNew() const = 0;
241 233
242 // Returns true if data stored or cached for the current user outside that 234 // Returns true if data stored or cached for the current user outside that
243 // user's cryptohome (wallpaper, avatar, OAuth token status, display name, 235 // user's cryptohome (wallpaper, avatar, OAuth token status, display name,
244 // display email) is ephemeral. 236 // display email) is ephemeral.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // browser_creator.LaunchBrowser(...) was called after sign in 268 // browser_creator.LaunchBrowser(...) was called after sign in
277 // or restart after crash. 269 // or restart after crash.
278 virtual bool IsSessionStarted() const = 0; 270 virtual bool IsSessionStarted() const = 0;
279 271
280 // Returns true if data stored or cached for the user with the given user id 272 // Returns true if data stored or cached for the user with the given user id
281 // address outside that user's cryptohome (wallpaper, avatar, OAuth token 273 // address outside that user's cryptohome (wallpaper, avatar, OAuth token
282 // status, display name, display email) is to be treated as ephemeral. 274 // status, display name, display email) is to be treated as ephemeral.
283 virtual bool IsUserNonCryptohomeDataEphemeral( 275 virtual bool IsUserNonCryptohomeDataEphemeral(
284 const std::string& user_id) const = 0; 276 const std::string& user_id) const = 0;
285 277
286 // Method that allows to set |flow| for user identified by |user_id|.
287 // Flow should be set before login attempt.
288 // Takes ownership of the |flow|, |flow| will be deleted in case of login
289 // failure.
290 virtual void SetUserFlow(const std::string& user_id, UserFlow* flow) = 0;
291
292 // Return user flow for current user. Returns instance of DefaultUserFlow if
293 // no flow was defined for current user, or user is not logged in.
294 // Returned value should not be cached.
295 virtual UserFlow* GetCurrentUserFlow() const = 0;
296
297 // Return user flow for user identified by |user_id|. Returns instance of
298 // DefaultUserFlow if no flow was defined for user.
299 // Returned value should not be cached.
300 virtual UserFlow* GetUserFlow(const std::string& user_id) const = 0;
301
302 // Resets user flow for user identified by |user_id|.
303 virtual void ResetUserFlow(const std::string& user_id) = 0;
304
305 virtual void AddObserver(Observer* obs) = 0; 278 virtual void AddObserver(Observer* obs) = 0;
306 virtual void RemoveObserver(Observer* obs) = 0; 279 virtual void RemoveObserver(Observer* obs) = 0;
307 280
308 virtual void AddSessionStateObserver(UserSessionStateObserver* obs) = 0; 281 virtual void AddSessionStateObserver(UserSessionStateObserver* obs) = 0;
309 virtual void RemoveSessionStateObserver(UserSessionStateObserver* obs) = 0; 282 virtual void RemoveSessionStateObserver(UserSessionStateObserver* obs) = 0;
310 283
311 virtual void NotifyLocalStateChanged() = 0; 284 virtual void NotifyLocalStateChanged() = 0;
312 285
313 // Returns true if supervised users allowed. 286 // Returns true if supervised users allowed.
314 virtual bool AreSupervisedUsersAllowed() const = 0; 287 virtual bool AreSupervisedUsersAllowed() const = 0;
315 288
289 protected:
290 // Sets UserManager instance.
291 static void SetInstance(UserManager* user_manager);
292
293 // Pointer to the existing UserManager instance (if any).
294 // Set in ctor, reset in dtor. Not owned since specific implementation of
295 // UserManager should decide on its own appropriate owner.
296 // For src/chrome implementation such place is
297 // g_browser_process->platform_part().
298 static UserManager* instance;
299
316 private: 300 private:
317 friend class ScopedUserManagerEnabler; 301 friend class chromeos::ScopedUserManagerEnabler;
318 302
319 // Sets the singleton to the given |user_manager|, taking ownership. Returns 303 // Sets UserManager instance to the given |user_manager|.
320 // the previous value of the singleton, passing ownership. 304 // Returns the previous value of the instance, passing ownership.
305 static UserManager* GetForTesting();
321 static UserManager* SetForTesting(UserManager* user_manager); 306 static UserManager* SetForTesting(UserManager* user_manager);
322 }; 307 };
323 308
324 // Helper class for unit tests. Initializes the UserManager singleton to the 309 } // namespace user_manager
325 // given |user_manager| and tears it down again on destruction. If the singleton
326 // had already been initialized, its previous value is restored after tearing
327 // down |user_manager|.
328 class ScopedUserManagerEnabler {
329 public:
330 // Takes ownership of |user_manager|.
331 explicit ScopedUserManagerEnabler(UserManager* user_manager);
332 ~ScopedUserManagerEnabler();
333 310
334 private: 311 #endif // COMPONENTS_USER_MANAGER_USER_MANAGER_H_
335 UserManager* previous_user_manager_;
336
337 DISALLOW_COPY_AND_ASSIGN(ScopedUserManagerEnabler);
338 };
339
340 // Helper class for unit tests. Initializes the UserManager singleton on
341 // construction and tears it down again on destruction.
342 class ScopedTestUserManager {
343 public:
344 ScopedTestUserManager();
345 ~ScopedTestUserManager();
346
347 private:
348 DISALLOW_COPY_AND_ASSIGN(ScopedTestUserManager);
349 };
350
351 } // namespace chromeos
352
353 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698