[email protected] | 83d82d4 | 2014-05-16 02:04:42 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | bab1bceb | 2010-02-02 18:25:05 | [diff] [blame] | 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] | 83d82d4 | 2014-05-16 02:04:42 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_H_ |
[email protected] | bab1bceb | 2010-02-02 18:25:05 | [diff] [blame] | 7 | |
| 8 | #include <string> |
[email protected] | bab1bceb | 2010-02-02 18:25:05 | [diff] [blame] | 9 | |
[email protected] | fcb10a48 | 2013-11-13 20:08:43 | [diff] [blame] | 10 | #include "chrome/browser/chromeos/base/locale_util.h" |
[email protected] | 1a2a6d5 | 2013-02-22 19:20:53 | [diff] [blame] | 11 | #include "chrome/browser/chromeos/login/user_flow.h" |
[email protected] | 83d82d4 | 2014-05-16 02:04:42 | [diff] [blame] | 12 | #include "chrome/browser/chromeos/login/users/user.h" |
[email protected] | bab1bceb | 2010-02-02 18:25:05 | [diff] [blame] | 13 | |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 14 | class PrefRegistrySimple; |
[email protected] | c2a7e68 | 2011-03-16 13:03:18 | [diff] [blame] | 15 | |
[email protected] | 8f0d8ecd1 | 2010-04-20 11:51:30 | [diff] [blame] | 16 | namespace chromeos { |
[email protected] | 39db0670 | 2011-11-10 16:31:24 | [diff] [blame] | 17 | |
[email protected] | 2c857e6 | 2014-02-06 11:49:07 | [diff] [blame] | 18 | class MultiProfileUserController; |
[email protected] | 773a814 | 2011-03-02 16:44:11 | [diff] [blame] | 19 | class RemoveUserDelegate; |
[email protected] | c4e418f | 2012-10-15 15:53:45 | [diff] [blame] | 20 | class UserImageManager; |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 21 | class SupervisedUserManager; |
[email protected] | 8f0d8ecd1 | 2010-04-20 11:51:30 | [diff] [blame] | 22 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 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 { |
[email protected] | bab1bceb | 2010-02-02 18:25:05 | [diff] [blame] | 26 | public: |
[email protected] | 61a9fb3 | 2011-08-03 21:00:51 | [diff] [blame] | 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: |
[email protected] | 64f784cc | 2013-02-16 02:14:21 | [diff] [blame] | 31 | // Called when the local state preferences is changed. |
[email protected] | f8622a4 | 2013-06-07 14:12:36 | [diff] [blame] | 32 | virtual void LocalStateChanged(UserManager* user_manager); |
[email protected] | 61a9fb3 | 2011-08-03 21:00:51 | [diff] [blame] | 33 | |
| 34 | protected: |
[email protected] | 7cad6b0d | 2013-04-25 20:29:32 | [diff] [blame] | 35 | virtual ~Observer(); |
| 36 | }; |
| 37 | |
[email protected] | cfad875 | 2013-06-04 16:58:34 | [diff] [blame] | 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. |
[email protected] | 7cad6b0d | 2013-04-25 20:29:32 | [diff] [blame] | 41 | class UserSessionStateObserver { |
| 42 | public: |
[email protected] | cfad875 | 2013-06-04 16:58:34 | [diff] [blame] | 43 | // Called when active user has changed. |
| 44 | virtual void ActiveUserChanged(const User* active_user); |
| 45 | |
[email protected] | ad87c67 | 2013-10-09 21:01:36 | [diff] [blame] | 46 | // Called when another user got added to the existing session. |
| 47 | virtual void UserAddedToSession(const User* added_user); |
| 48 | |
[email protected] | 7cad6b0d | 2013-04-25 20:29:32 | [diff] [blame] | 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. |
[email protected] | cfad875 | 2013-06-04 16:58:34 | [diff] [blame] | 51 | virtual void ActiveUserHashChanged(const std::string& hash); |
[email protected] | 7cad6b0d | 2013-04-25 20:29:32 | [diff] [blame] | 52 | |
[email protected] | 2622feb8 | 2013-05-28 20:41:38 | [diff] [blame] | 53 | // Called when UserManager finishes restoring user sessions after crash. |
[email protected] | cfad875 | 2013-06-04 16:58:34 | [diff] [blame] | 54 | virtual void PendingUserSessionsRestoreFinished(); |
[email protected] | 2622feb8 | 2013-05-28 20:41:38 | [diff] [blame] | 55 | |
[email protected] | 7cad6b0d | 2013-04-25 20:29:32 | [diff] [blame] | 56 | protected: |
| 57 | virtual ~UserSessionStateObserver(); |
[email protected] | 61a9fb3 | 2011-08-03 21:00:51 | [diff] [blame] | 58 | }; |
| 59 | |
[email protected] | 6dd7682 | 2013-11-26 12:04:11 | [diff] [blame] | 60 | // Data retrieved from user account. |
| 61 | class UserAccountData { |
| 62 | public: |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 63 | UserAccountData(const base::string16& display_name, |
| 64 | const base::string16& given_name, |
[email protected] | 6dd7682 | 2013-11-26 12:04:11 | [diff] [blame] | 65 | const std::string& locale); |
| 66 | ~UserAccountData(); |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 67 | const base::string16& display_name() const { return display_name_; } |
| 68 | const base::string16& given_name() const { return given_name_; } |
[email protected] | 6dd7682 | 2013-11-26 12:04:11 | [diff] [blame] | 69 | const std::string& locale() const { return locale_; } |
| 70 | |
| 71 | private: |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 72 | const base::string16 display_name_; |
| 73 | const base::string16 given_name_; |
[email protected] | 6dd7682 | 2013-11-26 12:04:11 | [diff] [blame] | 74 | const std::string locale_; |
| 75 | |
| 76 | DISALLOW_COPY_AND_ASSIGN(UserAccountData); |
| 77 | }; |
| 78 | |
[email protected] | 89dbb177 | 2012-07-17 13:47:25 | [diff] [blame] | 79 | // Username for stub login when not running on ChromeOS. |
| 80 | static const char kStubUser[]; |
| 81 | |
[email protected] | 688a922 | 2014-02-07 08:34:27 | [diff] [blame] | 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 | |
[email protected] | 68e3169 | 2013-05-20 13:08:27 | [diff] [blame] | 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 | |
[email protected] | a2774c38 | 2013-01-16 14:35:38 | [diff] [blame] | 93 | // Domain that is used for all locally managed users. |
| 94 | static const char kLocallyManagedUserDomain[]; |
| 95 | |
[email protected] | 68e3169 | 2013-05-20 13:08:27 | [diff] [blame] | 96 | // The retail mode user has a magic, domainless e-mail address. |
| 97 | static const char kRetailModeUserName[]; |
| 98 | |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 99 | // Creates the singleton instance. This method is not thread-safe and must be |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 100 | // called from the main UI thread. |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 101 | static void Initialize(); |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 102 | |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 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(); |
[email protected] | 79bac42 | 2013-04-22 15:44:26 | [diff] [blame] | 121 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 122 | // Registers user manager preferences. |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 123 | static void RegisterPrefs(PrefRegistrySimple* registry); |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 124 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 125 | virtual ~UserManager(); |
| 126 | |
[email protected] | 2c857e6 | 2014-02-06 11:49:07 | [diff] [blame] | 127 | virtual MultiProfileUserController* GetMultiProfileUserController() = 0; |
[email protected] | 2812658 | 2013-12-24 18:36:55 | [diff] [blame] | 128 | virtual UserImageManager* GetUserImageManager(const std::string& user_id) = 0; |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 129 | virtual SupervisedUserManager* GetSupervisedUserManager() = 0; |
[email protected] | c4e418f | 2012-10-15 15:53:45 | [diff] [blame] | 130 | |
[email protected] | 8e85e946 | 2012-03-13 11:23:23 | [diff] [blame] | 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. |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 133 | virtual const UserList& GetUsers() const = 0; |
| 134 | |
[email protected] | d1756c5 | 2014-06-17 08:07:17 | [diff] [blame] | 135 | // Returns list of users admitted for logging in into multi-profile session. |
[email protected] | 9319f08 | 2014-06-20 00:35:44 | [diff] [blame^] | 136 | // Users that have a policy that prevents them from being added to the |
| 137 | // multi-profile session will still be part of this list as long as they |
| 138 | // are regular users (i.e. not a public session/supervised etc.). |
| 139 | // Returns an empty list in case when primary user is not a regular one or |
| 140 | // has a policy that prohibids it to be part of multi-profile session. |
[email protected] | 0488716 | 2013-05-29 23:01:51 | [diff] [blame] | 141 | virtual UserList GetUsersAdmittedForMultiProfile() const = 0; |
| 142 | |
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 143 | // Returns a list of users who are currently logged in. |
| 144 | virtual const UserList& GetLoggedInUsers() const = 0; |
| 145 | |
[email protected] | c8d19f8 | 2013-05-18 09:09:41 | [diff] [blame] | 146 | // Returns a list of users who are currently logged in in the LRU order - |
| 147 | // so the active user is the first one in the list. If there is no user logged |
| 148 | // in, the current user will be returned. |
| 149 | virtual const UserList& GetLRULoggedInUsers() = 0; |
| 150 | |
[email protected] | 8f48483 | 2013-09-18 02:52:56 | [diff] [blame] | 151 | // Returns a list of users who can unlock the device. |
[email protected] | 402fcdd | 2014-01-24 12:51:52 | [diff] [blame] | 152 | // This list is based on policy and whether user is able to do unlock. |
| 153 | // Policy: |
| 154 | // * If user has primary-only policy then it is the only user in unlock users. |
| 155 | // * Otherwise all users with unrestricted policy are added to this list. |
| 156 | // All users that are unable to perform unlock are excluded from this list. |
[email protected] | 8f48483 | 2013-09-18 02:52:56 | [diff] [blame] | 157 | virtual UserList GetUnlockUsers() const = 0; |
| 158 | |
[email protected] | 204c19c | 2013-09-01 23:27:46 | [diff] [blame] | 159 | // Returns the email of the owner user. Returns an empty string if there is |
| 160 | // no owner for the device. |
| 161 | virtual const std::string& GetOwnerEmail() = 0; |
| 162 | |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 163 | // Indicates that a user with the given |user_id| has just logged in. The |
[email protected] | 8e85e946 | 2012-03-13 11:23:23 | [diff] [blame] | 164 | // persistent list is updated accordingly if the user is not ephemeral. |
[email protected] | 503fc5b | 2012-06-14 17:52:12 | [diff] [blame] | 165 | // |browser_restart| is true when reloading Chrome after crash to distinguish |
| 166 | // from normal sign in flow. |
[email protected] | 4042959 | 2013-03-29 17:52:33 | [diff] [blame] | 167 | // |username_hash| is used to identify homedir mount point. |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 168 | virtual void UserLoggedIn(const std::string& user_id, |
[email protected] | 4042959 | 2013-03-29 17:52:33 | [diff] [blame] | 169 | const std::string& username_hash, |
| 170 | bool browser_restart) = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 171 | |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 172 | // Switches to active user identified by |user_id|. User has to be logged in. |
| 173 | virtual void SwitchActiveUser(const std::string& user_id) = 0; |
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 174 | |
[email protected] | d4f22f2 | 2012-05-05 00:44:55 | [diff] [blame] | 175 | // Called when browser session is started i.e. after |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 176 | // browser_creator.LaunchBrowser(...) was called after user sign in. |
[email protected] | d4f22f2 | 2012-05-05 00:44:55 | [diff] [blame] | 177 | // When user is at the image screen IsUserLoggedIn() will return true |
[email protected] | 5311469 | 2013-09-13 22:07:18 | [diff] [blame] | 178 | // but IsSessionStarted() will return false. During the kiosk splash screen, |
| 179 | // we perform additional initialization after the user is logged in but |
| 180 | // before the session has been started. |
[email protected] | d4f22f2 | 2012-05-05 00:44:55 | [diff] [blame] | 181 | // Fires NOTIFICATION_SESSION_STARTED. |
| 182 | virtual void SessionStarted() = 0; |
| 183 | |
[email protected] | 0fbe5d6 | 2013-05-23 16:10:16 | [diff] [blame] | 184 | // Usually is called when Chrome is restarted after a crash and there's an |
| 185 | // active session. First user (one that is passed with --login-user) Chrome |
| 186 | // session has been already restored at this point. This method asks session |
| 187 | // manager for all active user sessions, marks them as logged in |
| 188 | // and notifies observers. |
| 189 | virtual void RestoreActiveSessions() = 0; |
| 190 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 191 | // Removes the user from the device. Note, it will verify that the given user |
| 192 | // isn't the owner, so calling this method for the owner will take no effect. |
| 193 | // Note, |delegate| can be NULL. |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 194 | virtual void RemoveUser(const std::string& user_id, |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 195 | RemoveUserDelegate* delegate) = 0; |
| 196 | |
| 197 | // Removes the user from the persistent list only. Also removes the user's |
| 198 | // picture. |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 199 | virtual void RemoveUserFromList(const std::string& user_id) = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 200 | |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 201 | // Returns true if a user with the given user id is found in the persistent |
| 202 | // list or currently logged in as ephemeral. |
| 203 | virtual bool IsKnownUser(const std::string& user_id) const = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 204 | |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 205 | // Returns the user with the given user id if found in the persistent |
[email protected] | 8e85e946 | 2012-03-13 11:23:23 | [diff] [blame] | 206 | // list or currently logged in as ephemeral. Returns |NULL| otherwise. |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 207 | virtual const User* FindUser(const std::string& user_id) const = 0; |
[email protected] | 0a5da5b | 2013-10-01 13:48:37 | [diff] [blame] | 208 | |
[email protected] | 25206cc | 2013-11-18 07:47:18 | [diff] [blame] | 209 | // Returns the user with the given user id if found in the persistent |
| 210 | // list or currently logged in as ephemeral. Returns |NULL| otherwise. |
| 211 | // Same as FindUser but returns non-const pointer to User object. |
| 212 | virtual User* FindUserAndModify(const std::string& user_id) = 0; |
| 213 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 214 | // Returns the logged-in user. |
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 215 | // TODO(nkostylev): Deprecate this call, move clients to GetActiveUser(). |
| 216 | // http://crbug.com/230852 |
[email protected] | c4e418f | 2012-10-15 15:53:45 | [diff] [blame] | 217 | virtual const User* GetLoggedInUser() const = 0; |
| 218 | virtual User* GetLoggedInUser() = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 219 | |
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 220 | // Returns the logged-in user that is currently active within this session. |
| 221 | // There could be multiple users logged in at the the same but for now |
| 222 | // we support only one of them being active. |
| 223 | virtual const User* GetActiveUser() const = 0; |
| 224 | virtual User* GetActiveUser() = 0; |
| 225 | |
[email protected] | 8f48483 | 2013-09-18 02:52:56 | [diff] [blame] | 226 | // Returns the primary user of the current session. It is recorded for the |
| 227 | // first signed-in user and does not change thereafter. |
| 228 | virtual const User* GetPrimaryUser() const = 0; |
| 229 | |
[email protected] | adcef6b | 2013-10-10 09:18:09 | [diff] [blame] | 230 | // Returns NULL if User is not created. |
| 231 | virtual User* GetUserByProfile(Profile* profile) const = 0; |
| 232 | |
[email protected] | 1681952 | 2013-12-16 14:08:26 | [diff] [blame] | 233 | /// Returns NULL if profile for user is not found or is not fully loaded. |
[email protected] | fe70877 | 2013-11-20 04:53:05 | [diff] [blame] | 234 | virtual Profile* GetProfileByUser(const User* user) const = 0; |
| 235 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 236 | // Saves user's oauth token status in local state preferences. |
| 237 | virtual void SaveUserOAuthStatus( |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 238 | const std::string& user_id, |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 239 | User::OAuthTokenStatus oauth_token_status) = 0; |
| 240 | |
[email protected] | f727a35 | 2014-01-25 22:52:46 | [diff] [blame] | 241 | // Saves a flag indicating whether online authentication against GAIA should |
| 242 | // be enforced during the user's next sign-in. |
| 243 | virtual void SaveForceOnlineSignin(const std::string& user_id, |
| 244 | bool force_online_signin) = 0; |
| 245 | |
[email protected] | 7aa538b | 2012-06-06 00:27:38 | [diff] [blame] | 246 | // Saves user's displayed name in local state preferences. |
| 247 | // Ignored If there is no such user. |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 248 | virtual void SaveUserDisplayName(const std::string& user_id, |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 249 | const base::string16& display_name) = 0; |
[email protected] | 7aa538b | 2012-06-06 00:27:38 | [diff] [blame] | 250 | |
[email protected] | c2b68c8 | 2013-09-24 02:49:39 | [diff] [blame] | 251 | // Updates data upon User Account download. |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 252 | virtual void UpdateUserAccountData(const std::string& user_id, |
[email protected] | 6dd7682 | 2013-11-26 12:04:11 | [diff] [blame] | 253 | const UserAccountData& account_data) = 0; |
[email protected] | c2b68c8 | 2013-09-24 02:49:39 | [diff] [blame] | 254 | |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 255 | // Returns the display name for user |user_id| if it is known (was |
[email protected] | 7aa538b | 2012-06-06 00:27:38 | [diff] [blame] | 256 | // previously set by a |SaveUserDisplayName| call). |
| 257 | // Otherwise, returns an empty string. |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 258 | virtual base::string16 GetUserDisplayName( |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 259 | const std::string& user_id) const = 0; |
[email protected] | 7aa538b | 2012-06-06 00:27:38 | [diff] [blame] | 260 | |
[email protected] | 2f5b483 | 2012-05-15 21:41:37 | [diff] [blame] | 261 | // Saves user's displayed (non-canonical) email in local state preferences. |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 262 | // Ignored If there is no such user. |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 263 | virtual void SaveUserDisplayEmail(const std::string& user_id, |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 264 | const std::string& display_email) = 0; |
| 265 | |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 266 | // Returns the display email for user |user_id| if it is known (was |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 267 | // previously set by a |SaveUserDisplayEmail| call). |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 268 | // Otherwise, returns |user_id| itself. |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 269 | virtual std::string GetUserDisplayEmail( |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 270 | const std::string& user_id) const = 0; |
[email protected] | 6c3bdc2 | 2013-07-08 18:12:44 | [diff] [blame] | 271 | |
[email protected] | a43c12e | 2012-03-06 21:57:10 | [diff] [blame] | 272 | // Returns true if current user is an owner. |
| 273 | virtual bool IsCurrentUserOwner() const = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 274 | |
[email protected] | a43c12e | 2012-03-06 21:57:10 | [diff] [blame] | 275 | // Returns true if current user is not existing one (hasn't signed in before). |
| 276 | virtual bool IsCurrentUserNew() const = 0; |
| 277 | |
[email protected] | bdee404 | 2012-12-07 07:36:30 | [diff] [blame] | 278 | // Returns true if data stored or cached for the current user outside that |
| 279 | // user's cryptohome (wallpaper, avatar, OAuth token status, display name, |
| 280 | // display email) is ephemeral. |
| 281 | virtual bool IsCurrentUserNonCryptohomeDataEphemeral() const = 0; |
[email protected] | 8e85e946 | 2012-03-13 11:23:23 | [diff] [blame] | 282 | |
[email protected] | 9154587 | 2012-11-21 13:58:27 | [diff] [blame] | 283 | // Returns true if the current user's session can be locked (i.e. the user has |
| 284 | // a password with which to unlock the session). |
| 285 | virtual bool CanCurrentUserLock() const = 0; |
| 286 | |
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 287 | // Returns true if at least one user has signed in. |
[email protected] | a43c12e | 2012-03-06 21:57:10 | [diff] [blame] | 288 | virtual bool IsUserLoggedIn() const = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 289 | |
[email protected] | 364aaef | 2012-12-04 12:18:13 | [diff] [blame] | 290 | // Returns true if we're logged in as a regular user. |
| 291 | virtual bool IsLoggedInAsRegularUser() const = 0; |
| 292 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 293 | // Returns true if we're logged in as a demo user. |
| 294 | virtual bool IsLoggedInAsDemoUser() const = 0; |
| 295 | |
[email protected] | 4b9b7369 | 2012-11-01 06:35:55 | [diff] [blame] | 296 | // Returns true if we're logged in as a public account. |
| 297 | virtual bool IsLoggedInAsPublicAccount() const = 0; |
| 298 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 299 | // Returns true if we're logged in as a Guest. |
| 300 | virtual bool IsLoggedInAsGuest() const = 0; |
| 301 | |
[email protected] | a2774c38 | 2013-01-16 14:35:38 | [diff] [blame] | 302 | // Returns true if we're logged in as a locally managed user. |
| 303 | virtual bool IsLoggedInAsLocallyManagedUser() const = 0; |
| 304 | |
[email protected] | 974bab5 | 2013-03-19 09:28:24 | [diff] [blame] | 305 | // Returns true if we're logged in as a kiosk app. |
| 306 | virtual bool IsLoggedInAsKioskApp() const = 0; |
| 307 | |
[email protected] | d4f22f2 | 2012-05-05 00:44:55 | [diff] [blame] | 308 | // Returns true if we're logged in as the stub user used for testing on Linux. |
[email protected] | 93cc27b | 2012-03-21 12:44:32 | [diff] [blame] | 309 | virtual bool IsLoggedInAsStub() const = 0; |
| 310 | |
[email protected] | d4f22f2 | 2012-05-05 00:44:55 | [diff] [blame] | 311 | // Returns true if we're logged in and browser has been started i.e. |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 312 | // browser_creator.LaunchBrowser(...) was called after sign in |
[email protected] | d4f22f2 | 2012-05-05 00:44:55 | [diff] [blame] | 313 | // or restart after crash. |
| 314 | virtual bool IsSessionStarted() const = 0; |
| 315 | |
[email protected] | 2622feb8 | 2013-05-28 20:41:38 | [diff] [blame] | 316 | // Returns true iff browser has been restarted after crash and UserManager |
| 317 | // finished restoring user sessions. |
| 318 | virtual bool UserSessionsRestored() const = 0; |
| 319 | |
[email protected] | cf50d18 | 2012-12-15 08:37:07 | [diff] [blame] | 320 | // Returns true when the browser has crashed and restarted during the current |
| 321 | // user's session. |
| 322 | virtual bool HasBrowserRestarted() const = 0; |
| 323 | |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 324 | // Returns true if data stored or cached for the user with the given user id |
[email protected] | bdee404 | 2012-12-07 07:36:30 | [diff] [blame] | 325 | // address outside that user's cryptohome (wallpaper, avatar, OAuth token |
| 326 | // status, display name, display email) is to be treated as ephemeral. |
| 327 | virtual bool IsUserNonCryptohomeDataEphemeral( |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 328 | const std::string& user_id) const = 0; |
[email protected] | 9b4976f | 2012-08-29 17:58:40 | [diff] [blame] | 329 | |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 330 | // Method that allows to set |flow| for user identified by |user_id|. |
[email protected] | 1a2a6d5 | 2013-02-22 19:20:53 | [diff] [blame] | 331 | // Flow should be set before login attempt. |
| 332 | // Takes ownership of the |flow|, |flow| will be deleted in case of login |
| 333 | // failure. |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 334 | virtual void SetUserFlow(const std::string& user_id, UserFlow* flow) = 0; |
[email protected] | 1a2a6d5 | 2013-02-22 19:20:53 | [diff] [blame] | 335 | |
| 336 | // Return user flow for current user. Returns instance of DefaultUserFlow if |
| 337 | // no flow was defined for current user, or user is not logged in. |
| 338 | // Returned value should not be cached. |
| 339 | virtual UserFlow* GetCurrentUserFlow() const = 0; |
| 340 | |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 341 | // Return user flow for user identified by |user_id|. Returns instance of |
[email protected] | 1a2a6d5 | 2013-02-22 19:20:53 | [diff] [blame] | 342 | // DefaultUserFlow if no flow was defined for user. |
| 343 | // Returned value should not be cached. |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 344 | virtual UserFlow* GetUserFlow(const std::string& user_id) const = 0; |
[email protected] | 1a2a6d5 | 2013-02-22 19:20:53 | [diff] [blame] | 345 | |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 346 | // Resets user flow for user identified by |user_id|. |
| 347 | virtual void ResetUserFlow(const std::string& user_id) = 0; |
[email protected] | 1a2a6d5 | 2013-02-22 19:20:53 | [diff] [blame] | 348 | |
[email protected] | e282cc6 | 2013-03-30 17:39:43 | [diff] [blame] | 349 | // Gets/sets chrome oauth client id and secret for kiosk app mode. The default |
[email protected] | 4442624 | 2013-09-13 22:35:34 | [diff] [blame] | 350 | // values can be overridden with kiosk auth file. |
[email protected] | e282cc6 | 2013-03-30 17:39:43 | [diff] [blame] | 351 | virtual bool GetAppModeChromeClientOAuthInfo( |
| 352 | std::string* chrome_client_id, |
| 353 | std::string* chrome_client_secret) = 0; |
| 354 | virtual void SetAppModeChromeClientOAuthInfo( |
| 355 | const std::string& chrome_client_id, |
| 356 | const std::string& chrome_client_secret) = 0; |
| 357 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 358 | virtual void AddObserver(Observer* obs) = 0; |
| 359 | virtual void RemoveObserver(Observer* obs) = 0; |
| 360 | |
[email protected] | 7cad6b0d | 2013-04-25 20:29:32 | [diff] [blame] | 361 | virtual void AddSessionStateObserver(UserSessionStateObserver* obs) = 0; |
| 362 | virtual void RemoveSessionStateObserver(UserSessionStateObserver* obs) = 0; |
| 363 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 364 | virtual void NotifyLocalStateChanged() = 0; |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 365 | |
[email protected] | 59c61c81 | 2013-06-22 00:38:14 | [diff] [blame] | 366 | // Returns true if locally managed users allowed. |
| 367 | virtual bool AreLocallyManagedUsersAllowed() const = 0; |
| 368 | |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 369 | // Returns profile dir for the user identified by |user_id|. |
| 370 | virtual base::FilePath GetUserProfileDir(const std::string& user_id) |
| 371 | const = 0; |
[email protected] | 4442624 | 2013-09-13 22:35:34 | [diff] [blame] | 372 | |
[email protected] | 0b7fc20 | 2013-10-10 23:24:53 | [diff] [blame] | 373 | // Changes browser locale (selects best suitable locale from different |
[email protected] | fcb10a48 | 2013-11-13 20:08:43 | [diff] [blame] | 374 | // user settings). Returns true if callback will be called. |
| 375 | virtual bool RespectLocalePreference( |
| 376 | Profile* profile, |
| 377 | const User* user, |
| 378 | scoped_ptr<locale_util::SwitchLanguageCallback> callback) const = 0; |
[email protected] | 0b7fc20 | 2013-10-10 23:24:53 | [diff] [blame] | 379 | |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 380 | private: |
| 381 | friend class ScopedUserManagerEnabler; |
| 382 | |
| 383 | // Sets the singleton to the given |user_manager|, taking ownership. Returns |
| 384 | // the previous value of the singleton, passing ownership. |
| 385 | static UserManager* SetForTesting(UserManager* user_manager); |
| 386 | }; |
| 387 | |
[email protected] | 1cfc9a1f | 2013-06-13 20:15:30 | [diff] [blame] | 388 | // Helper class for unit tests. Initializes the UserManager singleton to the |
| 389 | // given |user_manager| and tears it down again on destruction. If the singleton |
| 390 | // had already been initialized, its previous value is restored after tearing |
| 391 | // down |user_manager|. |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 392 | class ScopedUserManagerEnabler { |
| 393 | public: |
| 394 | // Takes ownership of |user_manager|. |
| 395 | explicit ScopedUserManagerEnabler(UserManager* user_manager); |
| 396 | ~ScopedUserManagerEnabler(); |
| 397 | |
| 398 | private: |
| 399 | UserManager* previous_user_manager_; |
| 400 | |
| 401 | DISALLOW_COPY_AND_ASSIGN(ScopedUserManagerEnabler); |
| 402 | }; |
| 403 | |
[email protected] | 1cfc9a1f | 2013-06-13 20:15:30 | [diff] [blame] | 404 | // Helper class for unit tests. Initializes the UserManager singleton on |
| 405 | // construction and tears it down again on destruction. |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 406 | class ScopedTestUserManager { |
| 407 | public: |
| 408 | ScopedTestUserManager(); |
| 409 | ~ScopedTestUserManager(); |
| 410 | |
| 411 | private: |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 412 | DISALLOW_COPY_AND_ASSIGN(ScopedTestUserManager); |
[email protected] | bab1bceb | 2010-02-02 18:25:05 | [diff] [blame] | 413 | }; |
| 414 | |
| 415 | } // namespace chromeos |
| 416 | |
[email protected] | 83d82d4 | 2014-05-16 02:04:42 | [diff] [blame] | 417 | #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_H_ |