Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 public ProfileSyncServiceObserver, | 41 public ProfileSyncServiceObserver, |
| 42 public content::NotificationObserver { | 42 public content::NotificationObserver { |
| 43 public: | 43 public: |
| 44 // Returns a shared instance of a UserManager. Not thread-safe, should only be | 44 // Returns a shared instance of a UserManager. Not thread-safe, should only be |
| 45 // called from the main UI thread. | 45 // called from the main UI thread. |
| 46 static UserManager* Get(); | 46 static UserManager* Get(); |
| 47 | 47 |
| 48 // Registers user manager preferences. | 48 // Registers user manager preferences. |
| 49 static void RegisterPrefs(PrefService* local_state); | 49 static void RegisterPrefs(PrefService* local_state); |
| 50 | 50 |
| 51 // Returns a list of the users who have logged into this device previously. | 51 // Returns a list of users who have logged into this device previously. This |
| 52 // It is sorted in order of recency, with most recent at the beginning. | 52 // is sorted by last login date with the most recent user at the beginning. |
| 53 const UserList& GetUsers() const; | 53 const UserList& GetUsers() const; |
| 54 | 54 |
| 55 // Indicates that a user with the given email has just logged in. | 55 // Indicates that a user with the given email has just logged in. The |
| 56 // The persistent list will be updated accordingly. | 56 // persistent list is updated accordingly if the user is not ephemeral. |
| 57 void UserLoggedIn(const std::string& email); | 57 void UserLoggedIn(const std::string& email); |
| 58 | 58 |
| 59 // Indicates that user just logged on as the demo user. | 59 // Indicates that user just logged on as the demo user. |
| 60 void DemoUserLoggedIn(); | 60 void DemoUserLoggedIn(); |
| 61 | 61 |
| 62 // Indicates that user just started incognito session. | 62 // Indicates that user just started incognito session. |
| 63 void GuestUserLoggedIn(); | 63 void GuestUserLoggedIn(); |
| 64 | 64 |
| 65 // Removes the user from the device. Note, it will verify that the given user | 65 // Removes the user from the device. Note, it will verify that the given user |
| 66 // isn't the owner, so calling this method for the owner will take no effect. | 66 // isn't the owner, so calling this method for the owner will take no effect. |
| 67 // Note, |delegate| can be NULL. | 67 // Note, |delegate| can be NULL. |
| 68 void RemoveUser(const std::string& email, | 68 void RemoveUser(const std::string& email, |
| 69 RemoveUserDelegate* delegate); | 69 RemoveUserDelegate* delegate); |
| 70 | 70 |
| 71 // Removes the user from the persistent list only. Also removes the user's | 71 // Removes the user from the persistent list only. Also removes the user's |
| 72 // picture. | 72 // picture. |
| 73 void RemoveUserFromList(const std::string& email); | 73 void RemoveUserFromList(const std::string& email); |
| 74 | 74 |
| 75 // Returns true if given user has logged into the device before. | 75 // Returns true if a user with the given email address is found in the |
| 76 // persistent list or currently logged in as ephemeral. | |
| 76 virtual bool IsKnownUser(const std::string& email) const; | 77 virtual bool IsKnownUser(const std::string& email) const; |
| 77 | 78 |
| 78 // Returns a user with given email or |NULL| if no such user exists. | 79 // Returns the user with the given email address if found in the persistent |
| 80 // list or currently logged in as ephemeral. Returns |NULL| otherwise. | |
| 79 const User* FindUser(const std::string& email) const; | 81 const User* FindUser(const std::string& email) const; |
| 80 | 82 |
| 81 // Returns the logged-in user. | 83 // Returns the logged-in user. |
| 82 const User& logged_in_user() const { return *logged_in_user_; } | 84 const User& logged_in_user() const { return *logged_in_user_; } |
| 83 User& logged_in_user() { return *logged_in_user_; } | 85 User& logged_in_user() { return *logged_in_user_; } |
| 84 | 86 |
| 85 // Returns true if given display name is unique. | 87 // Returns true if given display name is unique. |
| 86 bool IsDisplayNameUnique(const std::string& display_name) const; | 88 bool IsDisplayNameUnique(const std::string& display_name) const; |
| 87 | 89 |
| 88 // Saves user's oauth token status in local state preferences. | 90 // Saves user's oauth token status in local state preferences. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 | 137 |
| 136 // Accessor for current_user_is_owner_ | 138 // Accessor for current_user_is_owner_ |
| 137 virtual bool current_user_is_owner() const; | 139 virtual bool current_user_is_owner() const; |
| 138 virtual void set_current_user_is_owner(bool current_user_is_owner); | 140 virtual void set_current_user_is_owner(bool current_user_is_owner); |
| 139 | 141 |
| 140 // Accessor for current_user_is_new_. | 142 // Accessor for current_user_is_new_. |
| 141 bool current_user_is_new() const { | 143 bool current_user_is_new() const { |
| 142 return current_user_is_new_; | 144 return current_user_is_new_; |
| 143 } | 145 } |
| 144 | 146 |
| 147 // Accessor for current_user_is_ephemeral_. | |
| 148 bool current_user_is_ephemeral() const { | |
|
Nikita (slow)
2012/03/07 10:03:04
needs merge:
Rename to IsCurrentUserEphemeral().
use bartfab instead
2012/03/07 11:10:08
After addressing your other comments, the method i
| |
| 149 return current_user_is_ephemeral_; | |
| 150 } | |
| 151 | |
| 145 bool user_is_logged_in() const { return user_is_logged_in_; } | 152 bool user_is_logged_in() const { return user_is_logged_in_; } |
| 146 | 153 |
| 147 // Returns true if we're logged in as a demo user. | 154 // Returns true if we're logged in as a demo user. |
| 148 bool IsLoggedInAsDemoUser() const; | 155 bool IsLoggedInAsDemoUser() const; |
| 149 | 156 |
| 150 // Returns true if we're logged in as a Guest. | 157 // Returns true if we're logged in as a Guest. |
| 151 bool IsLoggedInAsGuest() const; | 158 bool IsLoggedInAsGuest() const; |
| 152 | 159 |
| 153 // Interface that observers of UserManager must implement in order | 160 // Interface that observers of UserManager must implement in order |
| 154 // to receive notification when local state preferences is changed | 161 // to receive notification when local state preferences is changed |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 173 } | 180 } |
| 174 | 181 |
| 175 protected: | 182 protected: |
| 176 UserManager(); | 183 UserManager(); |
| 177 virtual ~UserManager(); | 184 virtual ~UserManager(); |
| 178 | 185 |
| 179 // Returns image filepath for the given user. | 186 // Returns image filepath for the given user. |
| 180 FilePath GetImagePathForUser(const std::string& username); | 187 FilePath GetImagePathForUser(const std::string& username); |
| 181 | 188 |
| 182 private: | 189 private: |
| 190 friend class UserManagerTest; | |
| 191 | |
| 183 // Loads |users_| from Local State if the list has not been loaded yet. | 192 // Loads |users_| from Local State if the list has not been loaded yet. |
| 184 // Subsequent calls have no effect. Must be called on the UI thread. | 193 // Subsequent calls have no effect. Must be called on the UI thread. |
| 185 void EnsureUsersLoaded(); | 194 void EnsureUsersLoaded(); |
| 186 | 195 |
| 196 // Retrieves trusted device policies and removes users from the persistent | |
| 197 // list if ephemeral users are enabled. Schedules a callback to itself if | |
| 198 // trusted device policies are not yet available. | |
| 199 void RetrieveTrustedDevicePolicies(); | |
| 200 | |
| 201 // Returns true if trusted device policies have successfully been retrieved | |
| 202 // and ephemeral users are enabled. | |
| 203 bool AreEphemeralUsersEnabled() const; | |
| 204 | |
| 205 // Returns true if the user with the given email address is to be treated as | |
| 206 // ephemeral. | |
| 207 bool IsEphemeralUser(const std::string& email) const; | |
| 208 | |
| 209 // Returns the user with the given email address if found in the persistent | |
| 210 // list. Returns |NULL| otherwise. | |
| 211 const User* FindUserInList(const std::string& email) const; | |
| 212 | |
| 187 // Makes stub user the current logged-in user (for test paths). | 213 // Makes stub user the current logged-in user (for test paths). |
| 188 void StubUserLoggedIn(); | 214 void StubUserLoggedIn(); |
| 189 | 215 |
| 190 // Notifies on new user session. | 216 // Notifies on new user session. |
| 191 void NotifyOnLogin(); | 217 void NotifyOnLogin(); |
| 192 | 218 |
| 219 // Resets internal state to the initial values before user login. | |
| 220 void LogoutForTest(); | |
| 221 | |
| 193 // Reads user's oauth token status from local state preferences. | 222 // Reads user's oauth token status from local state preferences. |
| 194 User::OAuthTokenStatus LoadUserOAuthStatus(const std::string& username) const; | 223 User::OAuthTokenStatus LoadUserOAuthStatus(const std::string& username) const; |
| 195 | 224 |
| 196 // Sets one of the default images for the specified user and saves this | 225 // Sets one of the default images for the specified user and saves this |
| 197 // setting in local state. | 226 // setting in local state. |
| 198 // Does not send LOGIN_USER_IMAGE_CHANGED notification. | 227 // Does not send LOGIN_USER_IMAGE_CHANGED notification. |
| 199 void SetInitialUserImage(const std::string& username); | 228 void SetInitialUserImage(const std::string& username); |
| 200 | 229 |
| 201 // Sets image for user |username| and sends LOGIN_USER_IMAGE_CHANGED | 230 // Sets image for user |username| and sends LOGIN_USER_IMAGE_CHANGED |
| 202 // notification unless this is a new user and image is set for the first time. | 231 // notification unless this is a new user and image is set for the first time. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 // ProfileDownloaderDelegate implementation. | 272 // ProfileDownloaderDelegate implementation. |
| 244 virtual int GetDesiredImageSideLength() const OVERRIDE; | 273 virtual int GetDesiredImageSideLength() const OVERRIDE; |
| 245 virtual Profile* GetBrowserProfile() OVERRIDE; | 274 virtual Profile* GetBrowserProfile() OVERRIDE; |
| 246 virtual std::string GetCachedPictureURL() const OVERRIDE; | 275 virtual std::string GetCachedPictureURL() const OVERRIDE; |
| 247 virtual void OnDownloadComplete(ProfileDownloader* downloader, | 276 virtual void OnDownloadComplete(ProfileDownloader* downloader, |
| 248 bool success) OVERRIDE; | 277 bool success) OVERRIDE; |
| 249 | 278 |
| 250 // Creates a new User instance. | 279 // Creates a new User instance. |
| 251 User* CreateUser(const std::string& email) const; | 280 User* CreateUser(const std::string& email) const; |
| 252 | 281 |
| 282 // Removes the user from the persistent list only. Also removes the user's | |
| 283 // picture. | |
| 284 void RemoveUserFromListInternal(const std::string& email); | |
| 285 | |
| 253 // Loads user image from its file. | 286 // Loads user image from its file. |
| 254 scoped_refptr<UserImageLoader> image_loader_; | 287 scoped_refptr<UserImageLoader> image_loader_; |
| 255 | 288 |
| 256 // List of all known users. User instances are owned by |this| and deleted | 289 // List of all known users. User instances are owned by |this| and deleted |
| 257 // when a user is removed with |RemoveUser|. | 290 // when users are removed by |RemoveUserFromListInternal|. |
| 258 mutable UserList users_; | 291 mutable UserList users_; |
| 259 | 292 |
| 260 // Map of users' display names used to determine which users have unique | 293 // Map of users' display names used to determine which users have unique |
| 261 // display names. | 294 // display names. |
| 262 mutable base::hash_map<std::string, size_t> display_name_count_; | 295 mutable base::hash_map<std::string, size_t> display_name_count_; |
| 263 | 296 |
| 264 // User instance used to represent the demo user. | 297 // User instance used to represent the demo user. |
| 265 User demo_user_; | 298 User demo_user_; |
| 266 | 299 |
| 267 // User instance used to represent the off-the-record (guest) user. | 300 // User instance used to represent the off-the-record (guest) user. |
| 268 User guest_user_; | 301 User guest_user_; |
| 269 | 302 |
| 270 // A stub User instance for test paths (running without a logged-in user). | 303 // A stub User instance for test paths (running without a logged-in user). |
| 271 User stub_user_; | 304 User stub_user_; |
| 272 | 305 |
| 273 // The logged-in user. NULL until a user has logged in, then points to one | 306 // The logged-in user. NULL until a user has logged in, then points to one |
| 274 // of the User instances in |users_| or to the |guest_user_| instance. | 307 // of the User instances in |users_|, the |guest_user_| instance or an |
| 275 // In test paths without login points to the |stub_user_| instance. | 308 // ephemeral user instance. In test paths without login points to the |
| 309 // |stub_user_| instance. | |
| 276 User* logged_in_user_; | 310 User* logged_in_user_; |
| 277 | 311 |
| 278 // Cached flag of whether currently logged-in user is owner or not. | 312 // Cached flag of whether currently logged-in user is owner or not. |
| 279 // May be accessed on different threads, requires locking. | 313 // May be accessed on different threads, requires locking. |
| 280 bool current_user_is_owner_; | 314 bool current_user_is_owner_; |
| 281 mutable base::Lock current_user_is_owner_lock_; | 315 mutable base::Lock current_user_is_owner_lock_; |
| 282 | 316 |
| 283 // Cached flag of whether the currently logged-in user existed before this | 317 // Cached flag of whether the currently logged-in user existed before this |
| 284 // login. | 318 // login. |
| 285 bool current_user_is_new_; | 319 bool current_user_is_new_; |
| 286 | 320 |
| 321 // Cached flag of whether the currently logged-in user is ephemeral. Storage | |
| 322 // of persistent information is avoided for such users by not adding them to | |
| 323 // the user list in local state, not downloading their custom user images and | |
| 324 // mounting their cryptohomes using tmpfs. | |
| 325 bool current_user_is_ephemeral_; | |
|
Nikita (slow)
2012/03/07 10:03:04
nit: Should follow naming that other members in Us
use bartfab instead
2012/03/07 11:10:08
Done.
| |
| 326 | |
| 287 // Cached flag of whether any user is logged in at the moment. | 327 // Cached flag of whether any user is logged in at the moment. |
| 288 bool user_is_logged_in_; | 328 bool user_is_logged_in_; |
| 289 | 329 |
| 330 // Cached flag indicating whether ephemeral users are enabled. Defaults to | |
| 331 // |false| if the value has not been read from trusted device policy yet. | |
| 332 bool ephemeral_users_enabled_; | |
| 333 | |
| 334 // Cached name of device owner. Defaults to empty string if the value has not | |
| 335 // been read from trusted device policy yet. | |
| 336 std::string owner_email_; | |
|
Nikita (slow)
2012/03/07 10:03:04
We already have cached versions of trusted setting
use bartfab instead
2012/03/07 11:10:08
Before accessing cached trusted settings, GetTrust
| |
| 337 | |
| 290 content::NotificationRegistrar registrar_; | 338 content::NotificationRegistrar registrar_; |
| 291 | 339 |
| 292 // Profile sync service which is observed to take actions after sync | 340 // Profile sync service which is observed to take actions after sync |
| 293 // errors appear. NOTE: there is no guarantee that it is the current sync | 341 // errors appear. NOTE: there is no guarantee that it is the current sync |
| 294 // service, so do NOT use it outside |OnStateChanged| method. | 342 // service, so do NOT use it outside |OnStateChanged| method. |
| 295 ProfileSyncService* observed_sync_service_; | 343 ProfileSyncService* observed_sync_service_; |
| 296 | 344 |
| 297 friend struct base::DefaultLazyInstanceTraits<UserManager>; | 345 friend struct base::DefaultLazyInstanceTraits<UserManager>; |
| 298 | 346 |
| 299 ObserverList<Observer> observer_list_; | 347 ObserverList<Observer> observer_list_; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 317 | 365 |
| 318 // Data URL for |downloaded_profile_image_|. | 366 // Data URL for |downloaded_profile_image_|. |
| 319 std::string downloaded_profile_image_data_url_; | 367 std::string downloaded_profile_image_data_url_; |
| 320 | 368 |
| 321 DISALLOW_COPY_AND_ASSIGN(UserManager); | 369 DISALLOW_COPY_AND_ASSIGN(UserManager); |
| 322 }; | 370 }; |
| 323 | 371 |
| 324 } // namespace chromeos | 372 } // namespace chromeos |
| 325 | 373 |
| 326 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ | 374 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ |
| OLD | NEW |