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

Side by Side Diff: chrome/browser/chromeos/login/user_manager.h

Issue 286933002: [cros login] Split login related classes into subfolders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix includes in new tests Created 6 years, 7 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 (c) 2012 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_USER_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_
7
8 #include <string>
9
10 #include "chrome/browser/chromeos/base/locale_util.h"
11 #include "chrome/browser/chromeos/login/user.h"
12 #include "chrome/browser/chromeos/login/user_flow.h"
13
14 class PrefRegistrySimple;
15
16 namespace chromeos {
17
18 class MultiProfileUserController;
19 class RemoveUserDelegate;
20 class UserImageManager;
21 class SupervisedUserManager;
22
23 // Base class for UserManagerImpl - provides a mechanism for discovering users
24 // who have logged into this Chrome OS device before and updating that list.
25 class UserManager {
26 public:
27 // Interface that observers of UserManager must implement in order
28 // to receive notification when local state preferences is changed
29 class Observer {
30 public:
31 // Called when the local state preferences is changed.
32 virtual void LocalStateChanged(UserManager* user_manager);
33
34 protected:
35 virtual ~Observer();
36 };
37
38 // TODO(nkostylev): Refactor and move this observer out of UserManager.
39 // Observer interface that defines methods used to notify on user session /
40 // active user state changes. Default implementation is empty.
41 class UserSessionStateObserver {
42 public:
43 // Called when active user has changed.
44 virtual void ActiveUserChanged(const User* active_user);
45
46 // Called when another user got added to the existing session.
47 virtual void UserAddedToSession(const User* added_user);
48
49 // Called right before notifying on user change so that those who rely
50 // on user_id hash would be accessing up-to-date value.
51 virtual void ActiveUserHashChanged(const std::string& hash);
52
53 // Called when UserManager finishes restoring user sessions after crash.
54 virtual void PendingUserSessionsRestoreFinished();
55
56 protected:
57 virtual ~UserSessionStateObserver();
58 };
59
60 // Data retrieved from user account.
61 class UserAccountData {
62 public:
63 UserAccountData(const base::string16& display_name,
64 const base::string16& given_name,
65 const std::string& locale);
66 ~UserAccountData();
67 const base::string16& display_name() const { return display_name_; }
68 const base::string16& given_name() const { return given_name_; }
69 const std::string& locale() const { return locale_; }
70
71 private:
72 const base::string16 display_name_;
73 const base::string16 given_name_;
74 const std::string locale_;
75
76 DISALLOW_COPY_AND_ASSIGN(UserAccountData);
77 };
78
79 // Username for stub login when not running on ChromeOS.
80 static const char kStubUser[];
81
82 // Username for the login screen. It is only used to identify login screen
83 // tries to set default wallpaper. It is not a real user.
84 static const char kSignInUser[];
85
86 // Magic e-mail addresses are bad. They exist here because some code already
87 // depends on them and it is hard to figure out what. Any user types added in
88 // the future should be identified by a new |UserType|, not a new magic e-mail
89 // address.
90 // Username for Guest session user.
91 static const char kGuestUserName[];
92
93 // Domain that is used for all locally managed users.
94 static const char kLocallyManagedUserDomain[];
95
96 // The retail mode user has a magic, domainless e-mail address.
97 static const char kRetailModeUserName[];
98
99 // Creates the singleton instance. This method is not thread-safe and must be
100 // called from the main UI thread.
101 static void Initialize();
102
103 // Checks whether the singleton instance has been created already. This method
104 // is not thread-safe and must be called from the main UI thread.
105 static bool IsInitialized();
106
107 // Shuts down the UserManager. After this method has been called, the
108 // singleton has unregistered itself as an observer but remains available so
109 // that other classes can access it during their shutdown. This method is not
110 // thread-safe and must be called from the main UI thread.
111 virtual void Shutdown() = 0;
112
113 // Destroys the singleton instance. Always call Shutdown() first. This method
114 // is not thread-safe and must be called from the main UI thread.
115 static void Destroy();
116
117 // Returns the singleton instance or |NULL| if the singleton has either not
118 // been created yet or is already destroyed. This method is not thread-safe
119 // and must be called from the main UI thread.
120 static UserManager* Get();
121
122 // Registers user manager preferences.
123 static void RegisterPrefs(PrefRegistrySimple* registry);
124
125 virtual ~UserManager();
126
127 virtual MultiProfileUserController* GetMultiProfileUserController() = 0;
128 virtual UserImageManager* GetUserImageManager(const std::string& user_id) = 0;
129 virtual SupervisedUserManager* GetSupervisedUserManager() = 0;
130
131 // Returns a list of users who have logged into this device previously. This
132 // is sorted by last login date with the most recent user at the beginning.
133 virtual const UserList& GetUsers() const = 0;
134
135 // Returns list of users admitted for logging in into multiprofile session.
136 virtual UserList GetUsersAdmittedForMultiProfile() const = 0;
137
138 // Returns a list of users who are currently logged in.
139 virtual const UserList& GetLoggedInUsers() const = 0;
140
141 // Returns a list of users who are currently logged in in the LRU order -
142 // so the active user is the first one in the list. If there is no user logged
143 // in, the current user will be returned.
144 virtual const UserList& GetLRULoggedInUsers() = 0;
145
146 // Returns a list of users who can unlock the device.
147 // This list is based on policy and whether user is able to do unlock.
148 // Policy:
149 // * If user has primary-only policy then it is the only user in unlock users.
150 // * Otherwise all users with unrestricted policy are added to this list.
151 // All users that are unable to perform unlock are excluded from this list.
152 virtual UserList GetUnlockUsers() const = 0;
153
154 // Returns the email of the owner user. Returns an empty string if there is
155 // no owner for the device.
156 virtual const std::string& GetOwnerEmail() = 0;
157
158 // Indicates that a user with the given |user_id| has just logged in. The
159 // persistent list is updated accordingly if the user is not ephemeral.
160 // |browser_restart| is true when reloading Chrome after crash to distinguish
161 // from normal sign in flow.
162 // |username_hash| is used to identify homedir mount point.
163 virtual void UserLoggedIn(const std::string& user_id,
164 const std::string& username_hash,
165 bool browser_restart) = 0;
166
167 // Switches to active user identified by |user_id|. User has to be logged in.
168 virtual void SwitchActiveUser(const std::string& user_id) = 0;
169
170 // Called when browser session is started i.e. after
171 // browser_creator.LaunchBrowser(...) was called after user sign in.
172 // When user is at the image screen IsUserLoggedIn() will return true
173 // but IsSessionStarted() will return false. During the kiosk splash screen,
174 // we perform additional initialization after the user is logged in but
175 // before the session has been started.
176 // Fires NOTIFICATION_SESSION_STARTED.
177 virtual void SessionStarted() = 0;
178
179 // Usually is called when Chrome is restarted after a crash and there's an
180 // active session. First user (one that is passed with --login-user) Chrome
181 // session has been already restored at this point. This method asks session
182 // manager for all active user sessions, marks them as logged in
183 // and notifies observers.
184 virtual void RestoreActiveSessions() = 0;
185
186 // Removes the user from the device. Note, it will verify that the given user
187 // isn't the owner, so calling this method for the owner will take no effect.
188 // Note, |delegate| can be NULL.
189 virtual void RemoveUser(const std::string& user_id,
190 RemoveUserDelegate* delegate) = 0;
191
192 // Removes the user from the persistent list only. Also removes the user's
193 // picture.
194 virtual void RemoveUserFromList(const std::string& user_id) = 0;
195
196 // Returns true if a user with the given user id is found in the persistent
197 // list or currently logged in as ephemeral.
198 virtual bool IsKnownUser(const std::string& user_id) const = 0;
199
200 // Returns the user with the given user id if found in the persistent
201 // list or currently logged in as ephemeral. Returns |NULL| otherwise.
202 virtual const User* FindUser(const std::string& user_id) const = 0;
203
204 // Returns the user with the given user id if found in the persistent
205 // list or currently logged in as ephemeral. Returns |NULL| otherwise.
206 // Same as FindUser but returns non-const pointer to User object.
207 virtual User* FindUserAndModify(const std::string& user_id) = 0;
208
209 // Returns the logged-in user.
210 // TODO(nkostylev): Deprecate this call, move clients to GetActiveUser().
211 // http://crbug.com/230852
212 virtual const User* GetLoggedInUser() const = 0;
213 virtual User* GetLoggedInUser() = 0;
214
215 // Returns the logged-in user that is currently active within this session.
216 // There could be multiple users logged in at the the same but for now
217 // we support only one of them being active.
218 virtual const User* GetActiveUser() const = 0;
219 virtual User* GetActiveUser() = 0;
220
221 // Returns the primary user of the current session. It is recorded for the
222 // first signed-in user and does not change thereafter.
223 virtual const User* GetPrimaryUser() const = 0;
224
225 // Returns NULL if User is not created.
226 virtual User* GetUserByProfile(Profile* profile) const = 0;
227
228 /// Returns NULL if profile for user is not found or is not fully loaded.
229 virtual Profile* GetProfileByUser(const User* user) const = 0;
230
231 // Saves user's oauth token status in local state preferences.
232 virtual void SaveUserOAuthStatus(
233 const std::string& user_id,
234 User::OAuthTokenStatus oauth_token_status) = 0;
235
236 // Saves a flag indicating whether online authentication against GAIA should
237 // be enforced during the user's next sign-in.
238 virtual void SaveForceOnlineSignin(const std::string& user_id,
239 bool force_online_signin) = 0;
240
241 // Saves user's displayed name in local state preferences.
242 // Ignored If there is no such user.
243 virtual void SaveUserDisplayName(const std::string& user_id,
244 const base::string16& display_name) = 0;
245
246 // Updates data upon User Account download.
247 virtual void UpdateUserAccountData(const std::string& user_id,
248 const UserAccountData& account_data) = 0;
249
250 // Returns the display name for user |user_id| if it is known (was
251 // previously set by a |SaveUserDisplayName| call).
252 // Otherwise, returns an empty string.
253 virtual base::string16 GetUserDisplayName(
254 const std::string& user_id) const = 0;
255
256 // Saves user's displayed (non-canonical) email in local state preferences.
257 // Ignored If there is no such user.
258 virtual void SaveUserDisplayEmail(const std::string& user_id,
259 const std::string& display_email) = 0;
260
261 // Returns the display email for user |user_id| if it is known (was
262 // previously set by a |SaveUserDisplayEmail| call).
263 // Otherwise, returns |user_id| itself.
264 virtual std::string GetUserDisplayEmail(
265 const std::string& user_id) const = 0;
266
267 // Returns true if current user is an owner.
268 virtual bool IsCurrentUserOwner() const = 0;
269
270 // Returns true if current user is not existing one (hasn't signed in before).
271 virtual bool IsCurrentUserNew() const = 0;
272
273 // Returns true if data stored or cached for the current user outside that
274 // user's cryptohome (wallpaper, avatar, OAuth token status, display name,
275 // display email) is ephemeral.
276 virtual bool IsCurrentUserNonCryptohomeDataEphemeral() const = 0;
277
278 // Returns true if the current user's session can be locked (i.e. the user has
279 // a password with which to unlock the session).
280 virtual bool CanCurrentUserLock() const = 0;
281
282 // Returns true if at least one user has signed in.
283 virtual bool IsUserLoggedIn() const = 0;
284
285 // Returns true if we're logged in as a regular user.
286 virtual bool IsLoggedInAsRegularUser() const = 0;
287
288 // Returns true if we're logged in as a demo user.
289 virtual bool IsLoggedInAsDemoUser() const = 0;
290
291 // Returns true if we're logged in as a public account.
292 virtual bool IsLoggedInAsPublicAccount() const = 0;
293
294 // Returns true if we're logged in as a Guest.
295 virtual bool IsLoggedInAsGuest() const = 0;
296
297 // Returns true if we're logged in as a locally managed user.
298 virtual bool IsLoggedInAsLocallyManagedUser() const = 0;
299
300 // Returns true if we're logged in as a kiosk app.
301 virtual bool IsLoggedInAsKioskApp() const = 0;
302
303 // Returns true if we're logged in as the stub user used for testing on Linux.
304 virtual bool IsLoggedInAsStub() const = 0;
305
306 // Returns true if we're logged in and browser has been started i.e.
307 // browser_creator.LaunchBrowser(...) was called after sign in
308 // or restart after crash.
309 virtual bool IsSessionStarted() const = 0;
310
311 // Returns true iff browser has been restarted after crash and UserManager
312 // finished restoring user sessions.
313 virtual bool UserSessionsRestored() const = 0;
314
315 // Returns true when the browser has crashed and restarted during the current
316 // user's session.
317 virtual bool HasBrowserRestarted() const = 0;
318
319 // Returns true if data stored or cached for the user with the given user id
320 // address outside that user's cryptohome (wallpaper, avatar, OAuth token
321 // status, display name, display email) is to be treated as ephemeral.
322 virtual bool IsUserNonCryptohomeDataEphemeral(
323 const std::string& user_id) const = 0;
324
325 // Method that allows to set |flow| for user identified by |user_id|.
326 // Flow should be set before login attempt.
327 // Takes ownership of the |flow|, |flow| will be deleted in case of login
328 // failure.
329 virtual void SetUserFlow(const std::string& user_id, UserFlow* flow) = 0;
330
331 // Return user flow for current user. Returns instance of DefaultUserFlow if
332 // no flow was defined for current user, or user is not logged in.
333 // Returned value should not be cached.
334 virtual UserFlow* GetCurrentUserFlow() const = 0;
335
336 // Return user flow for user identified by |user_id|. Returns instance of
337 // DefaultUserFlow if no flow was defined for user.
338 // Returned value should not be cached.
339 virtual UserFlow* GetUserFlow(const std::string& user_id) const = 0;
340
341 // Resets user flow for user identified by |user_id|.
342 virtual void ResetUserFlow(const std::string& user_id) = 0;
343
344 // Gets/sets chrome oauth client id and secret for kiosk app mode. The default
345 // values can be overridden with kiosk auth file.
346 virtual bool GetAppModeChromeClientOAuthInfo(
347 std::string* chrome_client_id,
348 std::string* chrome_client_secret) = 0;
349 virtual void SetAppModeChromeClientOAuthInfo(
350 const std::string& chrome_client_id,
351 const std::string& chrome_client_secret) = 0;
352
353 virtual void AddObserver(Observer* obs) = 0;
354 virtual void RemoveObserver(Observer* obs) = 0;
355
356 virtual void AddSessionStateObserver(UserSessionStateObserver* obs) = 0;
357 virtual void RemoveSessionStateObserver(UserSessionStateObserver* obs) = 0;
358
359 virtual void NotifyLocalStateChanged() = 0;
360
361 // Returns true if locally managed users allowed.
362 virtual bool AreLocallyManagedUsersAllowed() const = 0;
363
364 // Returns profile dir for the user identified by |user_id|.
365 virtual base::FilePath GetUserProfileDir(const std::string& user_id)
366 const = 0;
367
368 // Changes browser locale (selects best suitable locale from different
369 // user settings). Returns true if callback will be called.
370 virtual bool RespectLocalePreference(
371 Profile* profile,
372 const User* user,
373 scoped_ptr<locale_util::SwitchLanguageCallback> callback) const = 0;
374
375 private:
376 friend class ScopedUserManagerEnabler;
377
378 // Sets the singleton to the given |user_manager|, taking ownership. Returns
379 // the previous value of the singleton, passing ownership.
380 static UserManager* SetForTesting(UserManager* user_manager);
381 };
382
383 // Helper class for unit tests. Initializes the UserManager singleton to the
384 // given |user_manager| and tears it down again on destruction. If the singleton
385 // had already been initialized, its previous value is restored after tearing
386 // down |user_manager|.
387 class ScopedUserManagerEnabler {
388 public:
389 // Takes ownership of |user_manager|.
390 explicit ScopedUserManagerEnabler(UserManager* user_manager);
391 ~ScopedUserManagerEnabler();
392
393 private:
394 UserManager* previous_user_manager_;
395
396 DISALLOW_COPY_AND_ASSIGN(ScopedUserManagerEnabler);
397 };
398
399 // Helper class for unit tests. Initializes the UserManager singleton on
400 // construction and tears it down again on destruction.
401 class ScopedTestUserManager {
402 public:
403 ScopedTestUserManager();
404 ~ScopedTestUserManager();
405
406 private:
407 DISALLOW_COPY_AND_ASSIGN(ScopedTestUserManager);
408 };
409
410 } // namespace chromeos
411
412 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_image_sync_observer.cc ('k') | chrome/browser/chromeos/login/user_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698