[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] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 5 | #ifndef COMPONENTS_USER_MANAGER_USER_MANAGER_H_ |
| 6 | #define COMPONENTS_USER_MANAGER_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 | |
alemate | 33433e2 | 2016-01-13 14:50:30 | [diff] [blame] | 10 | #include "base/callback_forward.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 11 | #include "base/macros.h" |
alemate | 33433e2 | 2016-01-13 14:50:30 | [diff] [blame] | 12 | #include "base/strings/string16.h" |
[email protected] | 2fda997 | 2014-07-23 14:51:59 | [diff] [blame] | 13 | #include "components/user_manager/user.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 14 | #include "components/user_manager/user_manager_export.h" |
merkulova | b82b713 | 2014-11-17 11:06:50 | [diff] [blame] | 15 | #include "components/user_manager/user_type.h" |
[email protected] | c2a7e68 | 2011-03-16 13:03:18 | [diff] [blame] | 16 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 17 | class AccountId; |
alemate | 8730a2f | 2015-12-19 07:13:09 | [diff] [blame] | 18 | class PrefService; |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 19 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 20 | namespace user_manager { |
| 21 | |
Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 22 | class ScopedUserManager; |
[email protected] | 773a814 | 2011-03-02 16:44:11 | [diff] [blame] | 23 | class RemoveUserDelegate; |
[email protected] | 8f0d8ecd1 | 2010-04-20 11:51:30 | [diff] [blame] | 24 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 25 | // Interface for UserManagerBase - that provides base implementation for |
| 26 | // Chrome OS user management. Typical features: |
| 27 | // * Get list of all know users (who have logged into this Chrome OS device) |
| 28 | // * Keep track for logged in/LRU users, active user in multi-user session. |
| 29 | // * Find/modify users, store user meta-data such as display name/email. |
| 30 | class USER_MANAGER_EXPORT UserManager { |
[email protected] | bab1bceb | 2010-02-02 18:25:05 | [diff] [blame] | 31 | public: |
[email protected] | 61a9fb3 | 2011-08-03 21:00:51 | [diff] [blame] | 32 | // Interface that observers of UserManager must implement in order |
| 33 | // to receive notification when local state preferences is changed |
| 34 | class Observer { |
| 35 | public: |
[email protected] | 64f784cc | 2013-02-16 02:14:21 | [diff] [blame] | 36 | // Called when the local state preferences is changed. |
[email protected] | f8622a4 | 2013-06-07 14:12:36 | [diff] [blame] | 37 | virtual void LocalStateChanged(UserManager* user_manager); |
[email protected] | 61a9fb3 | 2011-08-03 21:00:51 | [diff] [blame] | 38 | |
xiyuan | 66e4177 | 2016-12-13 21:57:58 | [diff] [blame] | 39 | // Called when the image of the given user is changed. |
| 40 | virtual void OnUserImageChanged(const User& user); |
| 41 | |
| 42 | // Called when the profile image download for the given user fails or |
| 43 | // user has the default profile image or no porfile image at all. |
| 44 | virtual void OnUserProfileImageUpdateFailed(const User& user); |
| 45 | |
| 46 | // Called when the profile image for the given user is downloaded. |
| 47 | // |profile_image| contains the downloaded profile image. |
| 48 | virtual void OnUserProfileImageUpdated(const User& user, |
| 49 | const gfx::ImageSkia& profile_image); |
| 50 | |
Daria Yakovleva | ea3ce4b | 2017-10-11 19:51:59 | [diff] [blame] | 51 | // Called when any of the device cros settings which are responsible for |
| 52 | // user sign in are changed. |
| 53 | virtual void OnUsersSignInConstraintsChanged(); |
| 54 | |
[email protected] | 61a9fb3 | 2011-08-03 21:00:51 | [diff] [blame] | 55 | protected: |
[email protected] | 7cad6b0d | 2013-04-25 20:29:32 | [diff] [blame] | 56 | virtual ~Observer(); |
| 57 | }; |
| 58 | |
xiyuan | 5d8d3ba | 2017-03-01 21:34:40 | [diff] [blame] | 59 | // TODO(xiyuan): Refactor and move this observer out of UserManager. |
[email protected] | cfad875 | 2013-06-04 16:58:34 | [diff] [blame] | 60 | // Observer interface that defines methods used to notify on user session / |
| 61 | // active user state changes. Default implementation is empty. |
[email protected] | 7cad6b0d | 2013-04-25 20:29:32 | [diff] [blame] | 62 | class UserSessionStateObserver { |
| 63 | public: |
[email protected] | cfad875 | 2013-06-04 16:58:34 | [diff] [blame] | 64 | // Called when active user has changed. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 65 | virtual void ActiveUserChanged(const User* active_user); |
[email protected] | cfad875 | 2013-06-04 16:58:34 | [diff] [blame] | 66 | |
[email protected] | ad87c67 | 2013-10-09 21:01:36 | [diff] [blame] | 67 | // Called when another user got added to the existing session. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 68 | virtual void UserAddedToSession(const User* added_user); |
[email protected] | ad87c67 | 2013-10-09 21:01:36 | [diff] [blame] | 69 | |
[email protected] | 7cad6b0d | 2013-04-25 20:29:32 | [diff] [blame] | 70 | // Called right before notifying on user change so that those who rely |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 71 | // on account_id hash would be accessing up-to-date value. |
[email protected] | cfad875 | 2013-06-04 16:58:34 | [diff] [blame] | 72 | virtual void ActiveUserHashChanged(const std::string& hash); |
[email protected] | 7cad6b0d | 2013-04-25 20:29:32 | [diff] [blame] | 73 | |
| 74 | protected: |
| 75 | virtual ~UserSessionStateObserver(); |
[email protected] | 61a9fb3 | 2011-08-03 21:00:51 | [diff] [blame] | 76 | }; |
| 77 | |
[email protected] | 6dd7682 | 2013-11-26 12:04:11 | [diff] [blame] | 78 | // Data retrieved from user account. |
| 79 | class UserAccountData { |
| 80 | public: |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 81 | UserAccountData(const base::string16& display_name, |
| 82 | const base::string16& given_name, |
[email protected] | 6dd7682 | 2013-11-26 12:04:11 | [diff] [blame] | 83 | const std::string& locale); |
| 84 | ~UserAccountData(); |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 85 | const base::string16& display_name() const { return display_name_; } |
| 86 | const base::string16& given_name() const { return given_name_; } |
[email protected] | 6dd7682 | 2013-11-26 12:04:11 | [diff] [blame] | 87 | const std::string& locale() const { return locale_; } |
| 88 | |
| 89 | private: |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 90 | const base::string16 display_name_; |
| 91 | const base::string16 given_name_; |
[email protected] | 6dd7682 | 2013-11-26 12:04:11 | [diff] [blame] | 92 | const std::string locale_; |
| 93 | |
| 94 | DISALLOW_COPY_AND_ASSIGN(UserAccountData); |
| 95 | }; |
| 96 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 97 | // Initializes UserManager instance to this. Normally should be called right |
| 98 | // after creation so that user_manager::UserManager::Get() doesn't fail. |
| 99 | // Tests could call this method if they are replacing existing UserManager |
| 100 | // instance with their own test instance. |
alemate | 33433e2 | 2016-01-13 14:50:30 | [diff] [blame] | 101 | virtual void Initialize(); |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 102 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 103 | // Checks whether the UserManager instance has been created already. |
| 104 | // This method is not thread-safe and must be called from the main UI thread. |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 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 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 113 | // Sets UserManager instance to NULL. Always call Shutdown() first. |
| 114 | // This method is not thread-safe and must be called from the main UI thread. |
| 115 | void Destroy(); |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 116 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 117 | // Returns UserManager instance or will crash if it is |NULL| (has either not |
| 118 | // been created yet or is already destroyed). This method is not thread-safe |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 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 | virtual ~UserManager(); |
| 123 | |
[email protected] | 8e85e946 | 2012-03-13 11:23:23 | [diff] [blame] | 124 | // Returns a list of users who have logged into this device previously. This |
| 125 | // is sorted by last login date with the most recent user at the beginning. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 126 | virtual const UserList& GetUsers() const = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 127 | |
rsorokin | c21feee5 | 2014-09-30 10:53:16 | [diff] [blame] | 128 | // Returns list of users allowed for logging in into multi-profile session. |
[email protected] | 9319f08 | 2014-06-20 00:35:44 | [diff] [blame] | 129 | // Users that have a policy that prevents them from being added to the |
| 130 | // multi-profile session will still be part of this list as long as they |
| 131 | // are regular users (i.e. not a public session/supervised etc.). |
| 132 | // Returns an empty list in case when primary user is not a regular one or |
merkulova | b82b713 | 2014-11-17 11:06:50 | [diff] [blame] | 133 | // has a policy that prohibits it to be part of multi-profile session. |
rsorokin | c21feee5 | 2014-09-30 10:53:16 | [diff] [blame] | 134 | virtual UserList GetUsersAllowedForMultiProfile() const = 0; |
[email protected] | 0488716 | 2013-05-29 23:01:51 | [diff] [blame] | 135 | |
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 136 | // Returns a list of users who are currently logged in. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 137 | virtual const UserList& GetLoggedInUsers() const = 0; |
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 138 | |
[email protected] | c8d19f8 | 2013-05-18 09:09:41 | [diff] [blame] | 139 | // Returns a list of users who are currently logged in in the LRU order - |
| 140 | // so the active user is the first one in the list. If there is no user logged |
| 141 | // in, the current user will be returned. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 142 | virtual const UserList& GetLRULoggedInUsers() const = 0; |
[email protected] | c8d19f8 | 2013-05-18 09:09:41 | [diff] [blame] | 143 | |
[email protected] | 8f48483 | 2013-09-18 02:52:56 | [diff] [blame] | 144 | // Returns a list of users who can unlock the device. |
[email protected] | 402fcdd | 2014-01-24 12:51:52 | [diff] [blame] | 145 | // This list is based on policy and whether user is able to do unlock. |
| 146 | // Policy: |
| 147 | // * If user has primary-only policy then it is the only user in unlock users. |
| 148 | // * Otherwise all users with unrestricted policy are added to this list. |
| 149 | // All users that are unable to perform unlock are excluded from this list. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 150 | virtual UserList GetUnlockUsers() const = 0; |
[email protected] | 8f48483 | 2013-09-18 02:52:56 | [diff] [blame] | 151 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 152 | // Returns account Id of the owner user. Returns an empty Id if there is |
[email protected] | 204c19c | 2013-09-01 23:27:46 | [diff] [blame] | 153 | // no owner for the device. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 154 | virtual const AccountId& GetOwnerAccountId() const = 0; |
[email protected] | 204c19c | 2013-09-01 23:27:46 | [diff] [blame] | 155 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 156 | // Indicates that a user with the given |account_id| has just logged in. The |
[email protected] | 8e85e946 | 2012-03-13 11:23:23 | [diff] [blame] | 157 | // persistent list is updated accordingly if the user is not ephemeral. |
[email protected] | 503fc5b | 2012-06-14 17:52:12 | [diff] [blame] | 158 | // |browser_restart| is true when reloading Chrome after crash to distinguish |
| 159 | // from normal sign in flow. |
[email protected] | 4042959 | 2013-03-29 17:52:33 | [diff] [blame] | 160 | // |username_hash| is used to identify homedir mount point. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 161 | virtual void UserLoggedIn(const AccountId& account_id, |
[email protected] | 4042959 | 2013-03-29 17:52:33 | [diff] [blame] | 162 | const std::string& username_hash, |
Alexander Alekseev | 2a5efd6 | 2017-12-06 07:27:28 | [diff] [blame] | 163 | bool browser_restart, |
| 164 | bool is_child) = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 165 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 166 | // Switches to active user identified by |account_id|. User has to be logged |
| 167 | // in. |
| 168 | virtual void SwitchActiveUser(const AccountId& account_id) = 0; |
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 169 | |
nkostylev | 5df7e99 | 2014-09-26 09:03:47 | [diff] [blame] | 170 | // Switches to the last active user (called after crash happens and session |
| 171 | // restore has completed). |
| 172 | virtual void SwitchToLastActiveUser() = 0; |
| 173 | |
xiyuan | 834f3bc | 2016-10-26 19:40:53 | [diff] [blame] | 174 | // Invoked by session manager to inform session start. |
| 175 | virtual void OnSessionStarted() = 0; |
[email protected] | d4f22f2 | 2012-05-05 00:44:55 | [diff] [blame] | 176 | |
atwilson | d5a7eabf | 2017-03-09 13:18:39 | [diff] [blame] | 177 | // Invoked once profile initialization has been completed. This allows various |
| 178 | // subsystems (for example, policy framework) to skip an expensive online |
| 179 | // initialization process, and also allows the signin screen to force an |
| 180 | // online signin if it knows that profile initialization has not yet |
| 181 | // completed. |user| is the User associated with the profile that has |
| 182 | // completed initialization. |
| 183 | virtual void OnProfileInitialized(User* user) = 0; |
| 184 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 185 | // Removes the user from the device. Note, it will verify that the given user |
| 186 | // isn't the owner, so calling this method for the owner will take no effect. |
| 187 | // Note, |delegate| can be NULL. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 188 | virtual void RemoveUser(const AccountId& account_id, |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 189 | RemoveUserDelegate* delegate) = 0; |
| 190 | |
| 191 | // Removes the user from the persistent list only. Also removes the user's |
| 192 | // picture. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 193 | virtual void RemoveUserFromList(const AccountId& account_id) = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 194 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 195 | // Returns true if a user with the given account id is found in the persistent |
[email protected] | 202f014 | 2013-10-18 12:12:48 | [diff] [blame] | 196 | // list or currently logged in as ephemeral. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 197 | virtual bool IsKnownUser(const AccountId& account_id) const = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 198 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 199 | // Returns the user with the given account id if found in the persistent |
[email protected] | 8e85e946 | 2012-03-13 11:23:23 | [diff] [blame] | 200 | // list or currently logged in as ephemeral. Returns |NULL| otherwise. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 201 | virtual const User* FindUser(const AccountId& account_id) const = 0; |
[email protected] | 0a5da5b | 2013-10-01 13:48:37 | [diff] [blame] | 202 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 203 | // Returns the user with the given account id if found in the persistent |
[email protected] | 25206cc | 2013-11-18 07:47:18 | [diff] [blame] | 204 | // list or currently logged in as ephemeral. Returns |NULL| otherwise. |
| 205 | // Same as FindUser but returns non-const pointer to User object. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 206 | virtual User* FindUserAndModify(const AccountId& account_id) = 0; |
[email protected] | 25206cc | 2013-11-18 07:47:18 | [diff] [blame] | 207 | |
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 208 | // Returns the logged-in user that is currently active within this session. |
| 209 | // There could be multiple users logged in at the the same but for now |
| 210 | // we support only one of them being active. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 211 | virtual const User* GetActiveUser() const = 0; |
| 212 | virtual User* GetActiveUser() = 0; |
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 213 | |
[email protected] | 8f48483 | 2013-09-18 02:52:56 | [diff] [blame] | 214 | // Returns the primary user of the current session. It is recorded for the |
| 215 | // first signed-in user and does not change thereafter. |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 216 | virtual const User* GetPrimaryUser() const = 0; |
[email protected] | 8f48483 | 2013-09-18 02:52:56 | [diff] [blame] | 217 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 218 | // Saves user's oauth token status in local state preferences. |
| 219 | virtual void SaveUserOAuthStatus( |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 220 | const AccountId& account_id, |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 221 | User::OAuthTokenStatus oauth_token_status) = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 222 | |
[email protected] | f727a35 | 2014-01-25 22:52:46 | [diff] [blame] | 223 | // Saves a flag indicating whether online authentication against GAIA should |
| 224 | // be enforced during the user's next sign-in. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 225 | virtual void SaveForceOnlineSignin(const AccountId& account_id, |
[email protected] | f727a35 | 2014-01-25 22:52:46 | [diff] [blame] | 226 | bool force_online_signin) = 0; |
| 227 | |
[email protected] | 7aa538b | 2012-06-06 00:27:38 | [diff] [blame] | 228 | // Saves user's displayed name in local state preferences. |
| 229 | // Ignored If there is no such user. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 230 | virtual void SaveUserDisplayName(const AccountId& account_id, |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 231 | const base::string16& display_name) = 0; |
[email protected] | 7aa538b | 2012-06-06 00:27:38 | [diff] [blame] | 232 | |
[email protected] | c2b68c8 | 2013-09-24 02:49:39 | [diff] [blame] | 233 | // Updates data upon User Account download. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 234 | virtual void UpdateUserAccountData(const AccountId& account_id, |
[email protected] | 6dd7682 | 2013-11-26 12:04:11 | [diff] [blame] | 235 | const UserAccountData& account_data) = 0; |
[email protected] | c2b68c8 | 2013-09-24 02:49:39 | [diff] [blame] | 236 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 237 | // Returns the display name for user |account_id| if it is known (was |
[email protected] | 7aa538b | 2012-06-06 00:27:38 | [diff] [blame] | 238 | // previously set by a |SaveUserDisplayName| call). |
| 239 | // Otherwise, returns an empty string. |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 240 | virtual base::string16 GetUserDisplayName( |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 241 | const AccountId& account_id) const = 0; |
[email protected] | 7aa538b | 2012-06-06 00:27:38 | [diff] [blame] | 242 | |
[email protected] | 2f5b483 | 2012-05-15 21:41:37 | [diff] [blame] | 243 | // Saves user's displayed (non-canonical) email in local state preferences. |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 244 | // Ignored If there is no such user. |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 245 | virtual void SaveUserDisplayEmail(const AccountId& account_id, |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 246 | const std::string& display_email) = 0; |
| 247 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 248 | // Returns the display email for user |account_id| if it is known (was |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 249 | // previously set by a |SaveUserDisplayEmail| call). |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 250 | // Otherwise, returns |account_id| itself. |
| 251 | virtual std::string GetUserDisplayEmail( |
| 252 | const AccountId& account_id) const = 0; |
[email protected] | 6c3bdc2 | 2013-07-08 18:12:44 | [diff] [blame] | 253 | |
Alexander Alekseev | 2a5efd6 | 2017-12-06 07:27:28 | [diff] [blame] | 254 | // Saves user's type for |user| into local state preferences. |
| 255 | virtual void SaveUserType(const User* user) = 0; |
merkulova | b82b713 | 2014-11-17 11:06:50 | [diff] [blame] | 256 | |
[email protected] | a43c12e | 2012-03-06 21:57:10 | [diff] [blame] | 257 | // Returns true if current user is an owner. |
| 258 | virtual bool IsCurrentUserOwner() const = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 259 | |
[email protected] | a43c12e | 2012-03-06 21:57:10 | [diff] [blame] | 260 | // Returns true if current user is not existing one (hasn't signed in before). |
| 261 | virtual bool IsCurrentUserNew() const = 0; |
| 262 | |
[email protected] | bdee404 | 2012-12-07 07:36:30 | [diff] [blame] | 263 | // Returns true if data stored or cached for the current user outside that |
| 264 | // user's cryptohome (wallpaper, avatar, OAuth token status, display name, |
| 265 | // display email) is ephemeral. |
| 266 | virtual bool IsCurrentUserNonCryptohomeDataEphemeral() const = 0; |
[email protected] | 8e85e946 | 2012-03-13 11:23:23 | [diff] [blame] | 267 | |
rsorokin | 79e9344 | 2016-04-29 07:54:12 | [diff] [blame] | 268 | // Returns true if data stored or cached for the current user inside that |
| 269 | // user's cryptohome is ephemeral. |
| 270 | virtual bool IsCurrentUserCryptohomeDataEphemeral() const = 0; |
| 271 | |
[email protected] | 9154587 | 2012-11-21 13:58:27 | [diff] [blame] | 272 | // Returns true if the current user's session can be locked (i.e. the user has |
| 273 | // a password with which to unlock the session). |
| 274 | virtual bool CanCurrentUserLock() const = 0; |
| 275 | |
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 276 | // Returns true if at least one user has signed in. |
[email protected] | a43c12e | 2012-03-06 21:57:10 | [diff] [blame] | 277 | virtual bool IsUserLoggedIn() const = 0; |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 278 | |
merkulova | c3ae44d | 2014-11-17 09:35:07 | [diff] [blame] | 279 | // Returns true if we're logged in as a user with gaia account. |
| 280 | virtual bool IsLoggedInAsUserWithGaiaAccount() const = 0; |
| 281 | |
merkulova | 6d6cb08a | 2014-12-11 09:40:02 | [diff] [blame] | 282 | // Returns true if we're logged in as a child user. |
| 283 | virtual bool IsLoggedInAsChildUser() const = 0; |
[email protected] | 364aaef | 2012-12-04 12:18:13 | [diff] [blame] | 284 | |
[email protected] | 4b9b7369 | 2012-11-01 06:35:55 | [diff] [blame] | 285 | // Returns true if we're logged in as a public account. |
| 286 | virtual bool IsLoggedInAsPublicAccount() const = 0; |
| 287 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 288 | // Returns true if we're logged in as a Guest. |
| 289 | virtual bool IsLoggedInAsGuest() const = 0; |
| 290 | |
merkulova | 6d6cb08a | 2014-12-11 09:40:02 | [diff] [blame] | 291 | // Returns true if we're logged in as a legacy supervised user. |
[email protected] | 933cc2e2 | 2014-07-18 13:26:57 | [diff] [blame] | 292 | virtual bool IsLoggedInAsSupervisedUser() const = 0; |
[email protected] | a2774c38 | 2013-01-16 14:35:38 | [diff] [blame] | 293 | |
[email protected] | 974bab5 | 2013-03-19 09:28:24 | [diff] [blame] | 294 | // Returns true if we're logged in as a kiosk app. |
| 295 | virtual bool IsLoggedInAsKioskApp() const = 0; |
| 296 | |
peletskyi | 53c440d | 2016-10-25 15:09:55 | [diff] [blame] | 297 | // Returns true if we're logged in as a ARC kiosk app. |
| 298 | virtual bool IsLoggedInAsArcKioskApp() const = 0; |
| 299 | |
[email protected] | d4f22f2 | 2012-05-05 00:44:55 | [diff] [blame] | 300 | // 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] | 301 | virtual bool IsLoggedInAsStub() const = 0; |
| 302 | |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 303 | // Returns true if data stored or cached for the user with the given |
| 304 | // |account_id| |
[email protected] | bdee404 | 2012-12-07 07:36:30 | [diff] [blame] | 305 | // address outside that user's cryptohome (wallpaper, avatar, OAuth token |
| 306 | // status, display name, display email) is to be treated as ephemeral. |
| 307 | virtual bool IsUserNonCryptohomeDataEphemeral( |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 308 | const AccountId& account_id) const = 0; |
[email protected] | 9b4976f | 2012-08-29 17:58:40 | [diff] [blame] | 309 | |
rsorokin | 79e9344 | 2016-04-29 07:54:12 | [diff] [blame] | 310 | virtual bool IsUserCryptohomeDataEphemeral( |
| 311 | const AccountId& account_id) const = 0; |
| 312 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 313 | virtual void AddObserver(Observer* obs) = 0; |
| 314 | virtual void RemoveObserver(Observer* obs) = 0; |
| 315 | |
[email protected] | 7cad6b0d | 2013-04-25 20:29:32 | [diff] [blame] | 316 | virtual void AddSessionStateObserver(UserSessionStateObserver* obs) = 0; |
| 317 | virtual void RemoveSessionStateObserver(UserSessionStateObserver* obs) = 0; |
| 318 | |
[email protected] | eddc251a | 2012-03-06 15:44:14 | [diff] [blame] | 319 | virtual void NotifyLocalStateChanged() = 0; |
xiyuan | 66e4177 | 2016-12-13 21:57:58 | [diff] [blame] | 320 | virtual void NotifyUserImageChanged(const User& user) = 0; |
| 321 | virtual void NotifyUserProfileImageUpdateFailed(const User& user) = 0; |
| 322 | virtual void NotifyUserProfileImageUpdated( |
| 323 | const User& user, |
| 324 | const gfx::ImageSkia& profile_image) = 0; |
Daria Yakovleva | ea3ce4b | 2017-10-11 19:51:59 | [diff] [blame] | 325 | virtual void NotifyUsersSignInConstraintsChanged() = 0; |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 326 | |
Pavol Marko | a9808a6 | 2017-08-31 16:22:37 | [diff] [blame] | 327 | // Resets this profile to be regarded as if it has never been initialized |
| 328 | // before. Used on profile wipe. |
| 329 | virtual void ResetProfileEverInitialized(const AccountId& account_id) = 0; |
merkulova | 57466b9 | 2014-10-09 10:55:12 | [diff] [blame] | 330 | |
[email protected] | 933cc2e2 | 2014-07-18 13:26:57 | [diff] [blame] | 331 | // Returns true if supervised users allowed. |
| 332 | virtual bool AreSupervisedUsersAllowed() const = 0; |
[email protected] | 59c61c81 | 2013-06-22 00:38:14 | [diff] [blame] | 333 | |
Daria Yakovleva | ea3ce4b | 2017-10-11 19:51:59 | [diff] [blame] | 334 | // Returns true if guest user is allowed. |
| 335 | virtual bool IsGuestSessionAllowed() const = 0; |
| 336 | |
| 337 | // Returns true if the |user|, which has a GAIA account is allowed according |
| 338 | // to device settings and policies. |
| 339 | // Accept only users who has gaia account. |
| 340 | virtual bool IsGaiaUserAllowed(const User& user) const = 0; |
| 341 | |
| 342 | // Returns true if |user| is allowed depending on device policies. |
| 343 | // Accepted user types: USER_TYPE_REGULAR, USER_TYPE_GUEST, |
| 344 | // USER_TYPE_SUPERVISED, USER_TYPE_CHILD. |
| 345 | virtual bool IsUserAllowed(const User& user) const = 0; |
| 346 | |
alemate | 8730a2f | 2015-12-19 07:13:09 | [diff] [blame] | 347 | // Returns "Local State" PrefService instance. |
| 348 | virtual PrefService* GetLocalState() const = 0; |
nkostylev | eb9ce0de5 | 2015-05-07 22:23:24 | [diff] [blame] | 349 | |
alemate | 33433e2 | 2016-01-13 14:50:30 | [diff] [blame] | 350 | // Checks for platform-specific known users matching given |user_email| and |
| 351 | // |gaia_id|. If data matches a known account, fills |out_account_id| with |
| 352 | // account id and returns true. |
| 353 | virtual bool GetPlatformKnownUserId(const std::string& user_email, |
| 354 | const std::string& gaia_id, |
| 355 | AccountId* out_account_id) const = 0; |
| 356 | |
| 357 | // Returns account id of the Guest user. |
| 358 | virtual const AccountId& GetGuestAccountId() const = 0; |
| 359 | |
| 360 | // Returns true if this is first exec after boot. |
| 361 | virtual bool IsFirstExecAfterBoot() const = 0; |
| 362 | |
| 363 | // Actually removes cryptohome. |
| 364 | virtual void AsyncRemoveCryptohome(const AccountId& account_id) const = 0; |
| 365 | |
| 366 | // Returns true if |account_id| is Guest user. |
| 367 | virtual bool IsGuestAccountId(const AccountId& account_id) const = 0; |
| 368 | |
| 369 | // Returns true if |account_id| is Stub user. |
| 370 | virtual bool IsStubAccountId(const AccountId& account_id) const = 0; |
| 371 | |
| 372 | // Returns true if |account_id| is supervised. |
| 373 | virtual bool IsSupervisedAccountId(const AccountId& account_id) const = 0; |
| 374 | |
Alexander Alekseev | 2a5efd6 | 2017-12-06 07:27:28 | [diff] [blame] | 375 | virtual bool IsDeviceLocalAccountMarkedForRemoval( |
| 376 | const AccountId& account_id) const = 0; |
| 377 | |
alemate | 33433e2 | 2016-01-13 14:50:30 | [diff] [blame] | 378 | // Returns true when the browser has crashed and restarted during the current |
| 379 | // user's session. |
| 380 | virtual bool HasBrowserRestarted() const = 0; |
| 381 | |
alemate | 9e6d710 | 2016-01-13 16:04:48 | [diff] [blame] | 382 | // Returns image from resources bundle. |
| 383 | virtual const gfx::ImageSkia& GetResourceImagekiaNamed(int id) const = 0; |
| 384 | |
| 385 | // Returns string from resources bundle. |
| 386 | virtual base::string16 GetResourceStringUTF16(int string_id) const = 0; |
| 387 | |
alemate | 33433e2 | 2016-01-13 14:50:30 | [diff] [blame] | 388 | // Schedules CheckAndResolveLocale using given task runner and |
| 389 | // |on_resolved_callback| as reply callback. |
| 390 | virtual void ScheduleResolveLocale( |
| 391 | const std::string& locale, |
Claudio DeSouza | 591a997 | 2018-02-21 17:27:16 | [diff] [blame] | 392 | base::OnceClosure on_resolved_callback, |
alemate | 33433e2 | 2016-01-13 14:50:30 | [diff] [blame] | 393 | std::string* out_resolved_locale) const = 0; |
| 394 | |
alemate | 9e6d710 | 2016-01-13 16:04:48 | [diff] [blame] | 395 | // Returns true if |image_index| is a valid default user image index. |
| 396 | virtual bool IsValidDefaultUserImageId(int image_index) const = 0; |
| 397 | |
Alexander Alekseev | 2a5efd6 | 2017-12-06 07:27:28 | [diff] [blame] | 398 | UserType CalculateUserType(const AccountId& account_id, |
| 399 | const User* user, |
| 400 | bool browser_restart, |
| 401 | bool is_child) const; |
| 402 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 403 | protected: |
| 404 | // Sets UserManager instance. |
| 405 | static void SetInstance(UserManager* user_manager); |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 406 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 407 | // Pointer to the existing UserManager instance (if any). |
| 408 | // Usually is set by calling Initialize(), reset by calling Destroy(). |
| 409 | // Not owned since specific implementation of UserManager should decide on its |
| 410 | // own appropriate owner. For src/chrome implementation such place is |
| 411 | // g_browser_process->platform_part(). |
| 412 | static UserManager* instance; |
| 413 | |
| 414 | private: |
Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 415 | friend class ScopedUserManager; |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 416 | |
| 417 | // Same as Get() but doesn't won't crash is current instance is NULL. |
| 418 | static UserManager* GetForTesting(); |
| 419 | |
| 420 | // Sets UserManager instance to the given |user_manager|. |
| 421 | // Returns the previous value of the instance. |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 422 | static UserManager* SetForTesting(UserManager* user_manager); |
| 423 | }; |
| 424 | |
xiyuan | 5d8d3ba | 2017-03-01 21:34:40 | [diff] [blame] | 425 | // TODO(xiyuan): Move this along with UserSessionStateObserver |
| 426 | class USER_MANAGER_EXPORT ScopedUserSessionStateObserver { |
| 427 | public: |
| 428 | explicit ScopedUserSessionStateObserver( |
| 429 | UserManager::UserSessionStateObserver* observer); |
| 430 | ~ScopedUserSessionStateObserver(); |
| 431 | |
| 432 | private: |
| 433 | UserManager::UserSessionStateObserver* const observer_; |
| 434 | |
| 435 | DISALLOW_COPY_AND_ASSIGN(ScopedUserSessionStateObserver); |
| 436 | }; |
| 437 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 438 | } // namespace user_manager |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 439 | |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 440 | #endif // COMPONENTS_USER_MANAGER_USER_MANAGER_H_ |