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

Side by Side Diff: chrome/browser/chromeos/login/users/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: rebase 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
(Empty)
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
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_H_
7
8 #include <string>
9
10 #include "chrome/browser/chromeos/login/user_flow.h"
11 #include "components/user_manager/user.h"
12
13 class PrefRegistrySimple;
14
15 namespace chromeos {
16
17 class MultiProfileUserController;
18 class RemoveUserDelegate;
19 class UserImageManager;
20 class SupervisedUserManager;
21
22 // Interface for UserManagerBase - provides a mechanism for discovering users
23 // who have logged into this Chrome OS device before and updating that list.
24 class UserManager {
25 public:
26 // Interface that observers of UserManager must implement in order
27 // to receive notification when local state preferences is changed
28 class Observer {
29 public:
30 // Called when the local state preferences is changed.
31 virtual void LocalStateChanged(UserManager* user_manager);
32
33 protected:
34 virtual ~Observer();
35 };
36
37 // TODO(nkostylev): Refactor and move this observer out of UserManager.
38 // Observer interface that defines methods used to notify on user session /
39 // active user state changes. Default implementation is empty.
40 class UserSessionStateObserver {
41 public:
42 // Called when active user has changed.
43 virtual void ActiveUserChanged(const user_manager::User* active_user);
44
45 // Called when another user got added to the existing session.
46 virtual void UserAddedToSession(const user_manager::User* added_user);
47
48 // Called right before notifying on user change so that those who rely
49 // on user_id hash would be accessing up-to-date value.
50 virtual void ActiveUserHashChanged(const std::string& hash);
51
52 protected:
53 virtual ~UserSessionStateObserver();
54 };
55
56 // Data retrieved from user account.
57 class UserAccountData {
58 public:
59 UserAccountData(const base::string16& display_name,
60 const base::string16& given_name,
61 const std::string& locale);
62 ~UserAccountData();
63 const base::string16& display_name() const { return display_name_; }
64 const base::string16& given_name() const { return given_name_; }
65 const std::string& locale() const { return locale_; }
66
67 private:
68 const base::string16 display_name_;
69 const base::string16 given_name_;
70 const std::string locale_;
71
72 DISALLOW_COPY_AND_ASSIGN(UserAccountData);
73 };
74
75 // Creates the singleton instance. This method is not thread-safe and must be
76 // called from the main UI thread.
77 static void Initialize();
78
79 // Checks whether the singleton instance has been created already. This method
80 // is not thread-safe and must be called from the main UI thread.
81 static bool IsInitialized();
82
83 // Shuts down the UserManager. After this method has been called, the
84 // 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 // thread-safe and must be called from the main UI thread.
87 virtual void Shutdown() = 0;
88
89 // Destroys the singleton instance. Always call Shutdown() first. This method
90 // is not thread-safe and must be called from the main UI thread.
91 static void Destroy();
92
93 // Returns the singleton instance or |NULL| if the singleton has either not
94 // been created yet or is already destroyed. This method is not thread-safe
95 // and must be called from the main UI thread.
96 static UserManager* Get();
97
98 // Registers user manager preferences.
99 static void RegisterPrefs(PrefRegistrySimple* registry);
100
101 virtual ~UserManager();
102
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
108 // is sorted by last login date with the most recent user at the beginning.
109 virtual const user_manager::UserList& GetUsers() const = 0;
110
111 // 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
113 // 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.).
115 // 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.
117 virtual user_manager::UserList GetUsersAdmittedForMultiProfile() const = 0;
118
119 // Returns a list of users who are currently logged in.
120 virtual const user_manager::UserList& GetLoggedInUsers() const = 0;
121
122 // 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
124 // in, the current user will be returned.
125 virtual const user_manager::UserList& GetLRULoggedInUsers() const = 0;
126
127 // 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.
129 // Policy:
130 // * 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.
132 // All users that are unable to perform unlock are excluded from this list.
133 virtual user_manager::UserList GetUnlockUsers() const = 0;
134
135 // Returns the email of the owner user. Returns an empty string if there is
136 // no owner for the device.
137 virtual const std::string& GetOwnerEmail() const = 0;
138
139 // 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.
141 // |browser_restart| is true when reloading Chrome after crash to distinguish
142 // from normal sign in flow.
143 // |username_hash| is used to identify homedir mount point.
144 virtual void UserLoggedIn(const std::string& user_id,
145 const std::string& username_hash,
146 bool browser_restart) = 0;
147
148 // Switches to active user identified by |user_id|. User has to be logged in.
149 virtual void SwitchActiveUser(const std::string& user_id) = 0;
150
151 // Called when browser session is started i.e. after
152 // browser_creator.LaunchBrowser(...) was called after user sign in.
153 // When user is at the image screen IsUserLoggedIn() will return true
154 // but IsSessionStarted() will return false. During the kiosk splash screen,
155 // we perform additional initialization after the user is logged in but
156 // before the session has been started.
157 // Fires NOTIFICATION_SESSION_STARTED.
158 virtual void SessionStarted() = 0;
159
160 // Removes the user from the device. Note, it will verify that the given user
161 // isn't the owner, so calling this method for the owner will take no effect.
162 // Note, |delegate| can be NULL.
163 virtual void RemoveUser(const std::string& user_id,
164 RemoveUserDelegate* delegate) = 0;
165
166 // Removes the user from the persistent list only. Also removes the user's
167 // picture.
168 virtual void RemoveUserFromList(const std::string& user_id) = 0;
169
170 // Returns true if a user with the given user id is found in the persistent
171 // list or currently logged in as ephemeral.
172 virtual bool IsKnownUser(const std::string& user_id) const = 0;
173
174 // Returns the user with the given user id if found in the persistent
175 // list or currently logged in as ephemeral. Returns |NULL| otherwise.
176 virtual const user_manager::User* FindUser(
177 const std::string& user_id) const = 0;
178
179 // Returns the user with the given user id if found in the persistent
180 // list or currently logged in as ephemeral. Returns |NULL| otherwise.
181 // Same as FindUser but returns non-const pointer to User object.
182 virtual user_manager::User* FindUserAndModify(const std::string& user_id) = 0;
183
184 // Returns the logged-in user.
185 // TODO(nkostylev): Deprecate this call, move clients to GetActiveUser().
186 // http://crbug.com/230852
187 virtual const user_manager::User* GetLoggedInUser() const = 0;
188 virtual user_manager::User* GetLoggedInUser() = 0;
189
190 // 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
192 // we support only one of them being active.
193 virtual const user_manager::User* GetActiveUser() const = 0;
194 virtual user_manager::User* GetActiveUser() = 0;
195
196 // Returns the primary user of the current session. It is recorded for the
197 // first signed-in user and does not change thereafter.
198 virtual const user_manager::User* GetPrimaryUser() const = 0;
199
200 // Saves user's oauth token status in local state preferences.
201 virtual void SaveUserOAuthStatus(
202 const std::string& user_id,
203 user_manager::User::OAuthTokenStatus oauth_token_status) = 0;
204
205 // Saves a flag indicating whether online authentication against GAIA should
206 // be enforced during the user's next sign-in.
207 virtual void SaveForceOnlineSignin(const std::string& user_id,
208 bool force_online_signin) = 0;
209
210 // Saves user's displayed name in local state preferences.
211 // Ignored If there is no such user.
212 virtual void SaveUserDisplayName(const std::string& user_id,
213 const base::string16& display_name) = 0;
214
215 // Updates data upon User Account download.
216 virtual void UpdateUserAccountData(const std::string& user_id,
217 const UserAccountData& account_data) = 0;
218
219 // Returns the display name for user |user_id| if it is known (was
220 // previously set by a |SaveUserDisplayName| call).
221 // Otherwise, returns an empty string.
222 virtual base::string16 GetUserDisplayName(
223 const std::string& user_id) const = 0;
224
225 // Saves user's displayed (non-canonical) email in local state preferences.
226 // Ignored If there is no such user.
227 virtual void SaveUserDisplayEmail(const std::string& user_id,
228 const std::string& display_email) = 0;
229
230 // Returns the display email for user |user_id| if it is known (was
231 // previously set by a |SaveUserDisplayEmail| call).
232 // Otherwise, returns |user_id| itself.
233 virtual std::string GetUserDisplayEmail(
234 const std::string& user_id) const = 0;
235
236 // Returns true if current user is an owner.
237 virtual bool IsCurrentUserOwner() const = 0;
238
239 // Returns true if current user is not existing one (hasn't signed in before).
240 virtual bool IsCurrentUserNew() const = 0;
241
242 // Returns true if data stored or cached for the current user outside that
243 // user's cryptohome (wallpaper, avatar, OAuth token status, display name,
244 // display email) is ephemeral.
245 virtual bool IsCurrentUserNonCryptohomeDataEphemeral() const = 0;
246
247 // Returns true if the current user's session can be locked (i.e. the user has
248 // a password with which to unlock the session).
249 virtual bool CanCurrentUserLock() const = 0;
250
251 // Returns true if at least one user has signed in.
252 virtual bool IsUserLoggedIn() const = 0;
253
254 // Returns true if we're logged in as a regular user.
255 virtual bool IsLoggedInAsRegularUser() const = 0;
256
257 // Returns true if we're logged in as a demo user.
258 virtual bool IsLoggedInAsDemoUser() const = 0;
259
260 // Returns true if we're logged in as a public account.
261 virtual bool IsLoggedInAsPublicAccount() const = 0;
262
263 // Returns true if we're logged in as a Guest.
264 virtual bool IsLoggedInAsGuest() const = 0;
265
266 // Returns true if we're logged in as a supervised user.
267 virtual bool IsLoggedInAsSupervisedUser() const = 0;
268
269 // Returns true if we're logged in as a kiosk app.
270 virtual bool IsLoggedInAsKioskApp() const = 0;
271
272 // Returns true if we're logged in as the stub user used for testing on Linux.
273 virtual bool IsLoggedInAsStub() const = 0;
274
275 // Returns true if we're logged in and browser has been started i.e.
276 // browser_creator.LaunchBrowser(...) was called after sign in
277 // or restart after crash.
278 virtual bool IsSessionStarted() const = 0;
279
280 // 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
282 // status, display name, display email) is to be treated as ephemeral.
283 virtual bool IsUserNonCryptohomeDataEphemeral(
284 const std::string& user_id) const = 0;
285
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;
306 virtual void RemoveObserver(Observer* obs) = 0;
307
308 virtual void AddSessionStateObserver(UserSessionStateObserver* obs) = 0;
309 virtual void RemoveSessionStateObserver(UserSessionStateObserver* obs) = 0;
310
311 virtual void NotifyLocalStateChanged() = 0;
312
313 // Returns true if supervised users allowed.
314 virtual bool AreSupervisedUsersAllowed() const = 0;
315
316 private:
317 friend class ScopedUserManagerEnabler;
318
319 // Sets the singleton to the given |user_manager|, taking ownership. Returns
320 // the previous value of the singleton, passing ownership.
321 static UserManager* SetForTesting(UserManager* user_manager);
322 };
323
324 // Helper class for unit tests. Initializes the UserManager singleton to the
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
334 private:
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