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

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

Issue 9405035: Implement ephemeral users (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Comments addressed. Created 8 years, 9 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
OLDNEW
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
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
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 {
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
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
193 // Reads user's oauth token status from local state preferences. 219 // Reads user's oauth token status from local state preferences.
194 User::OAuthTokenStatus LoadUserOAuthStatus(const std::string& username) const; 220 User::OAuthTokenStatus LoadUserOAuthStatus(const std::string& username) const;
195 221
196 // Sets one of the default images for the specified user and saves this 222 // Sets one of the default images for the specified user and saves this
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 // ProfileDownloaderDelegate implementation. 269 // ProfileDownloaderDelegate implementation.
244 virtual int GetDesiredImageSideLength() const OVERRIDE; 270 virtual int GetDesiredImageSideLength() const OVERRIDE;
245 virtual Profile* GetBrowserProfile() OVERRIDE; 271 virtual Profile* GetBrowserProfile() OVERRIDE;
246 virtual std::string GetCachedPictureURL() const OVERRIDE; 272 virtual std::string GetCachedPictureURL() const OVERRIDE;
247 virtual void OnDownloadComplete(ProfileDownloader* downloader, 273 virtual void OnDownloadComplete(ProfileDownloader* downloader,
248 bool success) OVERRIDE; 274 bool success) OVERRIDE;
249 275
250 // Creates a new User instance. 276 // Creates a new User instance.
251 User* CreateUser(const std::string& email) const; 277 User* CreateUser(const std::string& email) const;
252 278
279 // Removes all users except the owner from the device and sends
280 // NOTIFICATION_SYSTEM_SETTING_CHANGED.
281 void RemoveAllExceptOwnerFromList();
282
253 // Loads user image from its file. 283 // Loads user image from its file.
254 scoped_refptr<UserImageLoader> image_loader_; 284 scoped_refptr<UserImageLoader> image_loader_;
255 285
256 // List of all known users. User instances are owned by |this| and deleted 286 // List of all known users. User instances are owned by |this| and deleted
257 // when a user is removed with |RemoveUser|. 287 // when users are removed with |RemoveUser| or |RemoveAllExceptOwnerFromList|.
258 mutable UserList users_; 288 mutable UserList users_;
259 289
260 // Map of users' display names used to determine which users have unique 290 // Map of users' display names used to determine which users have unique
261 // display names. 291 // display names.
262 mutable base::hash_map<std::string, size_t> display_name_count_; 292 mutable base::hash_map<std::string, size_t> display_name_count_;
263 293
264 // User instance used to represent the demo user. 294 // User instance used to represent the demo user.
265 User demo_user_; 295 User demo_user_;
266 296
267 // User instance used to represent the off-the-record (guest) user. 297 // User instance used to represent the off-the-record (guest) user.
268 User guest_user_; 298 User guest_user_;
269 299
270 // A stub User instance for test paths (running without a logged-in user). 300 // A stub User instance for test paths (running without a logged-in user).
271 User stub_user_; 301 User stub_user_;
272 302
273 // The logged-in user. NULL until a user has logged in, then points to one 303 // 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. 304 // of the User instances in |users_|, the |guest_user_| instance or an
275 // In test paths without login points to the |stub_user_| instance. 305 // ephemeral user instance. In test paths without login points to the
306 // |stub_user_| instance.
276 User* logged_in_user_; 307 User* logged_in_user_;
277 308
278 // Cached flag of whether currently logged-in user is owner or not. 309 // Cached flag of whether currently logged-in user is owner or not.
279 // May be accessed on different threads, requires locking. 310 // May be accessed on different threads, requires locking.
280 bool current_user_is_owner_; 311 bool current_user_is_owner_;
281 mutable base::Lock current_user_is_owner_lock_; 312 mutable base::Lock current_user_is_owner_lock_;
282 313
283 // Cached flag of whether the currently logged-in user existed before this 314 // Cached flag of whether the currently logged-in user existed before this
284 // login. 315 // login.
285 bool current_user_is_new_; 316 bool current_user_is_new_;
286 317
318 // Cached flag of whether the currently logged-in user is ephemeral.
Nikita (slow) 2012/03/02 12:51:42 Please expand this comment on what "currently logg
use bartfab instead 2012/03/05 18:07:32 Done.
319 bool current_user_is_ephemeral_;
320
287 // Cached flag of whether any user is logged in at the moment. 321 // Cached flag of whether any user is logged in at the moment.
288 bool user_is_logged_in_; 322 bool user_is_logged_in_;
289 323
324 // Pointer to cached flag indicating whether ephemeral users are enabled.
325 // |NULL| if the value has not been read from trusted device policy yet.
326 scoped_ptr<bool> ephemeral_users_enabled_;
Ivan Korotkov 2012/03/01 20:16:30 I'm not sure if you really need the exact value fr
use bartfab instead 2012/03/05 18:07:32 I changed it so that ephemeral_users_enabled_ is a
327
328 // Pointer to cached name of device owner. |NULL| if the value has not been
329 // read from trusted device policy.
330 scoped_ptr<std::string> owner_;
Ivan Korotkov 2012/03/01 20:16:30 Please, rename this to owner_email_ as owner_ sugg
use bartfab instead 2012/03/05 18:07:32 Done.
331
290 content::NotificationRegistrar registrar_; 332 content::NotificationRegistrar registrar_;
291 333
292 // Profile sync service which is observed to take actions after sync 334 // 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 335 // errors appear. NOTE: there is no guarantee that it is the current sync
294 // service, so do NOT use it outside |OnStateChanged| method. 336 // service, so do NOT use it outside |OnStateChanged| method.
295 ProfileSyncService* observed_sync_service_; 337 ProfileSyncService* observed_sync_service_;
296 338
297 friend struct base::DefaultLazyInstanceTraits<UserManager>; 339 friend struct base::DefaultLazyInstanceTraits<UserManager>;
298 340
299 ObserverList<Observer> observer_list_; 341 ObserverList<Observer> observer_list_;
(...skipping 17 matching lines...) Expand all
317 359
318 // Data URL for |downloaded_profile_image_|. 360 // Data URL for |downloaded_profile_image_|.
319 std::string downloaded_profile_image_data_url_; 361 std::string downloaded_profile_image_data_url_;
320 362
321 DISALLOW_COPY_AND_ASSIGN(UserManager); 363 DISALLOW_COPY_AND_ASSIGN(UserManager);
322 }; 364 };
323 365
324 } // namespace chromeos 366 } // namespace chromeos
325 367
326 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ 368 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698