OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_USERS_USER_MANAGER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_IMPL_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_IMPL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "chrome/browser/chromeos/login/login_utils.h" | |
20 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h" | 19 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h" |
21 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller_dele
gate.h" | 20 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller_dele
gate.h" |
22 #include "chrome/browser/chromeos/login/users/user.h" | 21 #include "chrome/browser/chromeos/login/users/user.h" |
23 #include "chrome/browser/chromeos/login/users/user_manager.h" | 22 #include "chrome/browser/chromeos/login/users/user_manager.h" |
24 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 23 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
25 #include "chrome/browser/chromeos/policy/cloud_external_data_policy_observer.h" | 24 #include "chrome/browser/chromeos/policy/cloud_external_data_policy_observer.h" |
26 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 25 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
27 #include "chrome/browser/chromeos/settings/cros_settings.h" | 26 #include "chrome/browser/chromeos/settings/cros_settings.h" |
28 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 27 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
29 #include "chromeos/dbus/session_manager_client.h" | |
30 #include "content/public/browser/notification_observer.h" | 28 #include "content/public/browser/notification_observer.h" |
31 #include "content/public/browser/notification_registrar.h" | 29 #include "content/public/browser/notification_registrar.h" |
32 | 30 |
33 class PrefService; | 31 class PrefService; |
34 class ProfileSyncService; | 32 class ProfileSyncService; |
35 | 33 |
36 namespace policy { | 34 namespace policy { |
37 struct DeviceLocalAccount; | 35 struct DeviceLocalAccount; |
38 } | 36 } |
39 | 37 |
40 namespace chromeos { | 38 namespace chromeos { |
41 | 39 |
42 class MultiProfileUserController; | 40 class MultiProfileUserController; |
43 class RemoveUserDelegate; | 41 class RemoveUserDelegate; |
44 class SupervisedUserManagerImpl; | 42 class SupervisedUserManagerImpl; |
45 class SessionLengthLimiter; | 43 class SessionLengthLimiter; |
46 | 44 |
47 // Implementation of the UserManager. | 45 // Implementation of the UserManager. |
48 class UserManagerImpl | 46 class UserManagerImpl |
49 : public UserManager, | 47 : public UserManager, |
50 public LoginUtils::Delegate, | |
51 public content::NotificationObserver, | 48 public content::NotificationObserver, |
52 public policy::CloudExternalDataPolicyObserver::Delegate, | 49 public policy::CloudExternalDataPolicyObserver::Delegate, |
53 public policy::DeviceLocalAccountPolicyService::Observer, | 50 public policy::DeviceLocalAccountPolicyService::Observer, |
54 public MultiProfileUserControllerDelegate { | 51 public MultiProfileUserControllerDelegate { |
55 public: | 52 public: |
56 virtual ~UserManagerImpl(); | 53 virtual ~UserManagerImpl(); |
57 | 54 |
58 // UserManager implementation: | 55 // UserManager implementation: |
59 virtual void Shutdown() OVERRIDE; | 56 virtual void Shutdown() OVERRIDE; |
60 virtual MultiProfileUserController* GetMultiProfileUserController() OVERRIDE; | 57 virtual MultiProfileUserController* GetMultiProfileUserController() OVERRIDE; |
61 virtual UserImageManager* GetUserImageManager( | 58 virtual UserImageManager* GetUserImageManager( |
62 const std::string& user_id) OVERRIDE; | 59 const std::string& user_id) OVERRIDE; |
63 virtual SupervisedUserManager* GetSupervisedUserManager() OVERRIDE; | 60 virtual SupervisedUserManager* GetSupervisedUserManager() OVERRIDE; |
64 virtual const UserList& GetUsers() const OVERRIDE; | 61 virtual const UserList& GetUsers() const OVERRIDE; |
65 virtual UserList GetUsersAdmittedForMultiProfile() const OVERRIDE; | 62 virtual UserList GetUsersAdmittedForMultiProfile() const OVERRIDE; |
66 virtual const UserList& GetLoggedInUsers() const OVERRIDE; | 63 virtual const UserList& GetLoggedInUsers() const OVERRIDE; |
67 virtual const UserList& GetLRULoggedInUsers() OVERRIDE; | 64 virtual const UserList& GetLRULoggedInUsers() OVERRIDE; |
68 virtual UserList GetUnlockUsers() const OVERRIDE; | 65 virtual UserList GetUnlockUsers() const OVERRIDE; |
69 virtual const std::string& GetOwnerEmail() OVERRIDE; | 66 virtual const std::string& GetOwnerEmail() OVERRIDE; |
70 virtual void UserLoggedIn(const std::string& user_id, | 67 virtual void UserLoggedIn(const std::string& user_id, |
71 const std::string& user_id_hash, | 68 const std::string& user_id_hash, |
72 bool browser_restart) OVERRIDE; | 69 bool browser_restart) OVERRIDE; |
73 virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE; | 70 virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE; |
74 virtual void RestoreActiveSessions() OVERRIDE; | |
75 virtual void SessionStarted() OVERRIDE; | 71 virtual void SessionStarted() OVERRIDE; |
76 virtual void RemoveUser(const std::string& user_id, | 72 virtual void RemoveUser(const std::string& user_id, |
77 RemoveUserDelegate* delegate) OVERRIDE; | 73 RemoveUserDelegate* delegate) OVERRIDE; |
78 virtual void RemoveUserFromList(const std::string& user_id) OVERRIDE; | 74 virtual void RemoveUserFromList(const std::string& user_id) OVERRIDE; |
79 virtual bool IsKnownUser(const std::string& user_id) const OVERRIDE; | 75 virtual bool IsKnownUser(const std::string& user_id) const OVERRIDE; |
80 virtual const User* FindUser(const std::string& user_id) const OVERRIDE; | 76 virtual const User* FindUser(const std::string& user_id) const OVERRIDE; |
81 virtual User* FindUserAndModify(const std::string& user_id) OVERRIDE; | 77 virtual User* FindUserAndModify(const std::string& user_id) OVERRIDE; |
82 virtual const User* GetLoggedInUser() const OVERRIDE; | 78 virtual const User* GetLoggedInUser() const OVERRIDE; |
83 virtual User* GetLoggedInUser() OVERRIDE; | 79 virtual User* GetLoggedInUser() OVERRIDE; |
84 virtual const User* GetActiveUser() const OVERRIDE; | 80 virtual const User* GetActiveUser() const OVERRIDE; |
(...skipping 21 matching lines...) Expand all Loading... |
106 virtual bool CanCurrentUserLock() const OVERRIDE; | 102 virtual bool CanCurrentUserLock() const OVERRIDE; |
107 virtual bool IsUserLoggedIn() const OVERRIDE; | 103 virtual bool IsUserLoggedIn() const OVERRIDE; |
108 virtual bool IsLoggedInAsRegularUser() const OVERRIDE; | 104 virtual bool IsLoggedInAsRegularUser() const OVERRIDE; |
109 virtual bool IsLoggedInAsDemoUser() const OVERRIDE; | 105 virtual bool IsLoggedInAsDemoUser() const OVERRIDE; |
110 virtual bool IsLoggedInAsPublicAccount() const OVERRIDE; | 106 virtual bool IsLoggedInAsPublicAccount() const OVERRIDE; |
111 virtual bool IsLoggedInAsGuest() const OVERRIDE; | 107 virtual bool IsLoggedInAsGuest() const OVERRIDE; |
112 virtual bool IsLoggedInAsLocallyManagedUser() const OVERRIDE; | 108 virtual bool IsLoggedInAsLocallyManagedUser() const OVERRIDE; |
113 virtual bool IsLoggedInAsKioskApp() const OVERRIDE; | 109 virtual bool IsLoggedInAsKioskApp() const OVERRIDE; |
114 virtual bool IsLoggedInAsStub() const OVERRIDE; | 110 virtual bool IsLoggedInAsStub() const OVERRIDE; |
115 virtual bool IsSessionStarted() const OVERRIDE; | 111 virtual bool IsSessionStarted() const OVERRIDE; |
116 virtual bool UserSessionsRestored() const OVERRIDE; | |
117 virtual bool IsUserNonCryptohomeDataEphemeral( | 112 virtual bool IsUserNonCryptohomeDataEphemeral( |
118 const std::string& user_id) const OVERRIDE; | 113 const std::string& user_id) const OVERRIDE; |
119 virtual void AddObserver(UserManager::Observer* obs) OVERRIDE; | 114 virtual void AddObserver(UserManager::Observer* obs) OVERRIDE; |
120 virtual void RemoveObserver(UserManager::Observer* obs) OVERRIDE; | 115 virtual void RemoveObserver(UserManager::Observer* obs) OVERRIDE; |
121 virtual void AddSessionStateObserver( | 116 virtual void AddSessionStateObserver( |
122 UserManager::UserSessionStateObserver* obs) OVERRIDE; | 117 UserManager::UserSessionStateObserver* obs) OVERRIDE; |
123 virtual void RemoveSessionStateObserver( | 118 virtual void RemoveSessionStateObserver( |
124 UserManager::UserSessionStateObserver* obs) OVERRIDE; | 119 UserManager::UserSessionStateObserver* obs) OVERRIDE; |
125 virtual void NotifyLocalStateChanged() OVERRIDE; | 120 virtual void NotifyLocalStateChanged() OVERRIDE; |
126 | 121 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // Stages of loading user list from preferences. Some methods can have | 158 // Stages of loading user list from preferences. Some methods can have |
164 // different behavior depending on stage. | 159 // different behavior depending on stage. |
165 enum UserLoadStage { | 160 enum UserLoadStage { |
166 STAGE_NOT_LOADED = 0, | 161 STAGE_NOT_LOADED = 0, |
167 STAGE_LOADING, | 162 STAGE_LOADING, |
168 STAGE_LOADED | 163 STAGE_LOADED |
169 }; | 164 }; |
170 | 165 |
171 UserManagerImpl(); | 166 UserManagerImpl(); |
172 | 167 |
173 // LoginUtils::Delegate implementation: | |
174 // Used when restoring user sessions after crash. | |
175 virtual void OnProfilePrepared(Profile* profile) OVERRIDE; | |
176 | |
177 // Loads |users_| from Local State if the list has not been loaded yet. | 168 // Loads |users_| from Local State if the list has not been loaded yet. |
178 // Subsequent calls have no effect. Must be called on the UI thread. | 169 // Subsequent calls have no effect. Must be called on the UI thread. |
179 void EnsureUsersLoaded(); | 170 void EnsureUsersLoaded(); |
180 | 171 |
181 // Retrieves trusted device policies and removes users from the persistent | 172 // Retrieves trusted device policies and removes users from the persistent |
182 // list if ephemeral users are enabled. Schedules a callback to itself if | 173 // list if ephemeral users are enabled. Schedules a callback to itself if |
183 // trusted device policies are not yet available. | 174 // trusted device policies are not yet available. |
184 void RetrieveTrustedDevicePolicies(); | 175 void RetrieveTrustedDevicePolicies(); |
185 | 176 |
186 // Returns true if trusted device policies have successfully been retrieved | 177 // Returns true if trusted device policies have successfully been retrieved |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 | 273 |
283 // Notifies observers that active user has changed. | 274 // Notifies observers that active user has changed. |
284 void NotifyActiveUserChanged(const User* active_user); | 275 void NotifyActiveUserChanged(const User* active_user); |
285 | 276 |
286 // Notifies observers that another user was added to the session. | 277 // Notifies observers that another user was added to the session. |
287 void NotifyUserAddedToSession(const User* added_user); | 278 void NotifyUserAddedToSession(const User* added_user); |
288 | 279 |
289 // Notifies observers that active user_id hash has changed. | 280 // Notifies observers that active user_id hash has changed. |
290 void NotifyActiveUserHashChanged(const std::string& hash); | 281 void NotifyActiveUserHashChanged(const std::string& hash); |
291 | 282 |
292 // Notifies observers that user pending sessions restore has finished. | |
293 void NotifyPendingUserSessionsRestoreFinished(); | |
294 | |
295 // Lazily creates default user flow. | 283 // Lazily creates default user flow. |
296 UserFlow* GetDefaultUserFlow() const; | 284 UserFlow* GetDefaultUserFlow() const; |
297 | 285 |
298 // Update the global LoginState. | 286 // Update the global LoginState. |
299 void UpdateLoginState(); | 287 void UpdateLoginState(); |
300 | 288 |
301 // Insert |user| at the front of the LRU user list. | 289 // Insert |user| at the front of the LRU user list. |
302 void SetLRUUser(User* user); | 290 void SetLRUUser(User* user); |
303 | 291 |
304 // Adds |user| to users list, and adds it to front of LRU list. It is assumed | 292 // Adds |user| to users list, and adds it to front of LRU list. It is assumed |
305 // that there is no user with same id. | 293 // that there is no user with same id. |
306 void AddUserRecord(User* user); | 294 void AddUserRecord(User* user); |
307 | 295 |
308 // Callback to process RetrieveActiveSessions() request results. | |
309 void OnRestoreActiveSessions( | |
310 const SessionManagerClient::ActiveSessionsMap& sessions, | |
311 bool success); | |
312 | |
313 // Called by OnRestoreActiveSessions() when there're user sessions in | |
314 // |pending_user_sessions_| that has to be restored one by one. | |
315 // Also called after first user session from that list is restored and so on. | |
316 // Process continues till |pending_user_sessions_| map is not empty. | |
317 void RestorePendingUserSessions(); | |
318 | |
319 // Sends metrics in response to a regular user logging in. | 296 // Sends metrics in response to a regular user logging in. |
320 void SendRegularUserLoginMetrics(const std::string& user_id); | 297 void SendRegularUserLoginMetrics(const std::string& user_id); |
321 | 298 |
322 // Implementation for RemoveUser method. This is an asynchronous part of the | 299 // Implementation for RemoveUser method. This is an asynchronous part of the |
323 // method, that verifies that owner will not get deleted, and calls | 300 // method, that verifies that owner will not get deleted, and calls |
324 // |RemoveNonOwnerUserInternal|. | 301 // |RemoveNonOwnerUserInternal|. |
325 void RemoveUserInternal(const std::string& user_email, | 302 void RemoveUserInternal(const std::string& user_email, |
326 RemoveUserDelegate* delegate); | 303 RemoveUserDelegate* delegate); |
327 | 304 |
328 // Implementation for RemoveUser method. It is synchronous. It is called from | 305 // Implementation for RemoveUser method. It is synchronous. It is called from |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 // ephemeral user instance. | 357 // ephemeral user instance. |
381 User* active_user_; | 358 User* active_user_; |
382 | 359 |
383 // The primary user of the current session. It is recorded for the first | 360 // The primary user of the current session. It is recorded for the first |
384 // signed-in user and does not change thereafter. | 361 // signed-in user and does not change thereafter. |
385 User* primary_user_; | 362 User* primary_user_; |
386 | 363 |
387 // True if SessionStarted() has been called. | 364 // True if SessionStarted() has been called. |
388 bool session_started_; | 365 bool session_started_; |
389 | 366 |
390 // True is user sessions has been restored after crash. | |
391 // On a normal boot then login into user sessions this will be false. | |
392 bool user_sessions_restored_; | |
393 | |
394 // Cached flag of whether currently logged-in user is owner or not. | 367 // Cached flag of whether currently logged-in user is owner or not. |
395 // May be accessed on different threads, requires locking. | 368 // May be accessed on different threads, requires locking. |
396 bool is_current_user_owner_; | 369 bool is_current_user_owner_; |
397 mutable base::Lock is_current_user_owner_lock_; | 370 mutable base::Lock is_current_user_owner_lock_; |
398 | 371 |
399 // Cached flag of whether the currently logged-in user existed before this | 372 // Cached flag of whether the currently logged-in user existed before this |
400 // login. | 373 // login. |
401 bool is_current_user_new_; | 374 bool is_current_user_new_; |
402 | 375 |
403 // Cached flag of whether the currently logged-in user is a regular user who | 376 // Cached flag of whether the currently logged-in user is a regular user who |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 | 408 |
436 typedef std::map<std::string, UserFlow*> FlowMap; | 409 typedef std::map<std::string, UserFlow*> FlowMap; |
437 | 410 |
438 // Lazy-initialized default flow. | 411 // Lazy-initialized default flow. |
439 mutable scoped_ptr<UserFlow> default_flow_; | 412 mutable scoped_ptr<UserFlow> default_flow_; |
440 | 413 |
441 // Specific flows by user e-mail. Keys should be canonicalized before | 414 // Specific flows by user e-mail. Keys should be canonicalized before |
442 // access. | 415 // access. |
443 FlowMap specific_flows_; | 416 FlowMap specific_flows_; |
444 | 417 |
445 // User sessions that have to be restored after browser crash. | |
446 // [user_id] > [user_id_hash] | |
447 SessionManagerClient::ActiveSessionsMap pending_user_sessions_; | |
448 | |
449 // Time at which this object was created. | 418 // Time at which this object was created. |
450 base::TimeTicks manager_creation_time_; | 419 base::TimeTicks manager_creation_time_; |
451 | 420 |
452 scoped_ptr<CrosSettings::ObserverSubscription> | 421 scoped_ptr<CrosSettings::ObserverSubscription> |
453 local_accounts_subscription_; | 422 local_accounts_subscription_; |
454 | 423 |
455 scoped_ptr<MultiProfileUserController> multi_profile_user_controller_; | 424 scoped_ptr<MultiProfileUserController> multi_profile_user_controller_; |
456 | 425 |
457 // Observer for the policy that can be used to manage user images. | 426 // Observer for the policy that can be used to manage user images. |
458 scoped_ptr<policy::CloudExternalDataPolicyObserver> avatar_policy_observer_; | 427 scoped_ptr<policy::CloudExternalDataPolicyObserver> avatar_policy_observer_; |
459 | 428 |
460 // Observer for the policy that can be used to manage wallpapers. | 429 // Observer for the policy that can be used to manage wallpapers. |
461 scoped_ptr<policy::CloudExternalDataPolicyObserver> | 430 scoped_ptr<policy::CloudExternalDataPolicyObserver> |
462 wallpaper_policy_observer_; | 431 wallpaper_policy_observer_; |
463 | 432 |
464 // ID of the user just added to the session that needs to be activated | 433 // ID of the user just added to the session that needs to be activated |
465 // as soon as user's profile is loaded. | 434 // as soon as user's profile is loaded. |
466 std::string pending_user_switch_; | 435 std::string pending_user_switch_; |
467 | 436 |
468 DISALLOW_COPY_AND_ASSIGN(UserManagerImpl); | 437 DISALLOW_COPY_AND_ASSIGN(UserManagerImpl); |
469 }; | 438 }; |
470 | 439 |
471 } // namespace chromeos | 440 } // namespace chromeos |
472 | 441 |
473 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_IMPL_H_ | 442 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_IMPL_H_ |
OLD | NEW |