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_IMPL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_IMPL_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_IMPL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_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/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "chrome/browser/chromeos/login/login_utils.h" |
16 #include "chrome/browser/chromeos/login/user.h" | 17 #include "chrome/browser/chromeos/login/user.h" |
17 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" | 18 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" |
18 #include "chrome/browser/chromeos/login/user_manager.h" | 19 #include "chrome/browser/chromeos/login/user_manager.h" |
19 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | 20 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
20 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 21 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
21 #include "chrome/browser/chromeos/settings/cros_settings.h" | 22 #include "chrome/browser/chromeos/settings/cros_settings.h" |
22 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 23 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
23 #include "chrome/browser/sync/profile_sync_service_observer.h" | 24 #include "chrome/browser/sync/profile_sync_service_observer.h" |
24 #include "chromeos/dbus/session_manager_client.h" | 25 #include "chromeos/dbus/session_manager_client.h" |
25 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
26 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
27 | 28 |
28 class PrefService; | 29 class PrefService; |
29 class ProfileSyncService; | 30 class ProfileSyncService; |
30 | 31 |
31 namespace policy { | 32 namespace policy { |
32 struct DeviceLocalAccount; | 33 struct DeviceLocalAccount; |
33 } | 34 } |
34 | 35 |
35 namespace chromeos { | 36 namespace chromeos { |
36 | 37 |
37 class RemoveUserDelegate; | 38 class RemoveUserDelegate; |
38 class SessionLengthLimiter; | 39 class SessionLengthLimiter; |
39 | 40 |
40 // Implementation of the UserManager. | 41 // Implementation of the UserManager. |
41 class UserManagerImpl | 42 class UserManagerImpl |
42 : public UserManager, | 43 : public UserManager, |
| 44 public LoginUtils::Delegate, |
43 public ProfileSyncServiceObserver, | 45 public ProfileSyncServiceObserver, |
44 public content::NotificationObserver, | 46 public content::NotificationObserver, |
45 public policy::DeviceLocalAccountPolicyService::Observer { | 47 public policy::DeviceLocalAccountPolicyService::Observer { |
46 public: | 48 public: |
47 virtual ~UserManagerImpl(); | 49 virtual ~UserManagerImpl(); |
48 | 50 |
49 // UserManager implementation: | 51 // UserManager implementation: |
50 virtual void Shutdown() OVERRIDE; | 52 virtual void Shutdown() OVERRIDE; |
51 virtual UserImageManager* GetUserImageManager() OVERRIDE; | 53 virtual UserImageManager* GetUserImageManager() OVERRIDE; |
52 virtual const UserList& GetUsers() const OVERRIDE; | 54 virtual const UserList& GetUsers() const OVERRIDE; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 virtual bool CanCurrentUserLock() const OVERRIDE; | 88 virtual bool CanCurrentUserLock() const OVERRIDE; |
87 virtual bool IsUserLoggedIn() const OVERRIDE; | 89 virtual bool IsUserLoggedIn() const OVERRIDE; |
88 virtual bool IsLoggedInAsRegularUser() const OVERRIDE; | 90 virtual bool IsLoggedInAsRegularUser() const OVERRIDE; |
89 virtual bool IsLoggedInAsDemoUser() const OVERRIDE; | 91 virtual bool IsLoggedInAsDemoUser() const OVERRIDE; |
90 virtual bool IsLoggedInAsPublicAccount() const OVERRIDE; | 92 virtual bool IsLoggedInAsPublicAccount() const OVERRIDE; |
91 virtual bool IsLoggedInAsGuest() const OVERRIDE; | 93 virtual bool IsLoggedInAsGuest() const OVERRIDE; |
92 virtual bool IsLoggedInAsLocallyManagedUser() const OVERRIDE; | 94 virtual bool IsLoggedInAsLocallyManagedUser() const OVERRIDE; |
93 virtual bool IsLoggedInAsKioskApp() const OVERRIDE; | 95 virtual bool IsLoggedInAsKioskApp() const OVERRIDE; |
94 virtual bool IsLoggedInAsStub() const OVERRIDE; | 96 virtual bool IsLoggedInAsStub() const OVERRIDE; |
95 virtual bool IsSessionStarted() const OVERRIDE; | 97 virtual bool IsSessionStarted() const OVERRIDE; |
| 98 virtual bool UserSessionsRestored() const OVERRIDE; |
96 virtual MergeSessionState GetMergeSessionState() const OVERRIDE; | 99 virtual MergeSessionState GetMergeSessionState() const OVERRIDE; |
97 virtual void SetMergeSessionState(MergeSessionState status) OVERRIDE; | 100 virtual void SetMergeSessionState(MergeSessionState status) OVERRIDE; |
98 virtual bool HasBrowserRestarted() const OVERRIDE; | 101 virtual bool HasBrowserRestarted() const OVERRIDE; |
99 virtual bool IsUserNonCryptohomeDataEphemeral( | 102 virtual bool IsUserNonCryptohomeDataEphemeral( |
100 const std::string& email) const OVERRIDE; | 103 const std::string& email) const OVERRIDE; |
101 virtual void AddObserver(UserManager::Observer* obs) OVERRIDE; | 104 virtual void AddObserver(UserManager::Observer* obs) OVERRIDE; |
102 virtual void RemoveObserver(UserManager::Observer* obs) OVERRIDE; | 105 virtual void RemoveObserver(UserManager::Observer* obs) OVERRIDE; |
103 virtual void AddSessionStateObserver( | 106 virtual void AddSessionStateObserver( |
104 UserManager::UserSessionStateObserver* obs) OVERRIDE; | 107 UserManager::UserSessionStateObserver* obs) OVERRIDE; |
105 virtual void RemoveSessionStateObserver( | 108 virtual void RemoveSessionStateObserver( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 virtual void OnPolicyUpdated(const std::string& user_id) OVERRIDE; | 143 virtual void OnPolicyUpdated(const std::string& user_id) OVERRIDE; |
141 virtual void OnDeviceLocalAccountsChanged() OVERRIDE; | 144 virtual void OnDeviceLocalAccountsChanged() OVERRIDE; |
142 | 145 |
143 private: | 146 private: |
144 friend class UserManager; | 147 friend class UserManager; |
145 friend class WallpaperManager; | 148 friend class WallpaperManager; |
146 friend class UserManagerTest; | 149 friend class UserManagerTest; |
147 | 150 |
148 UserManagerImpl(); | 151 UserManagerImpl(); |
149 | 152 |
| 153 // LoginUtils::Delegate implementation: |
| 154 // Used when restoring user sessions after crash. |
| 155 virtual void OnProfilePrepared(Profile* profile) OVERRIDE; |
| 156 |
150 // Loads |users_| from Local State if the list has not been loaded yet. | 157 // Loads |users_| from Local State if the list has not been loaded yet. |
151 // Subsequent calls have no effect. Must be called on the UI thread. | 158 // Subsequent calls have no effect. Must be called on the UI thread. |
152 void EnsureUsersLoaded(); | 159 void EnsureUsersLoaded(); |
153 | 160 |
154 // Retrieves trusted device policies and removes users from the persistent | 161 // Retrieves trusted device policies and removes users from the persistent |
155 // list if ephemeral users are enabled. Schedules a callback to itself if | 162 // list if ephemeral users are enabled. Schedules a callback to itself if |
156 // trusted device policies are not yet available. | 163 // trusted device policies are not yet available. |
157 void RetrieveTrustedDevicePolicies(); | 164 void RetrieveTrustedDevicePolicies(); |
158 | 165 |
159 // Returns true if trusted device policies have successfully been retrieved | 166 // Returns true if trusted device policies have successfully been retrieved |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 254 |
248 // Notifies the UI about a change to the user list. | 255 // Notifies the UI about a change to the user list. |
249 void NotifyUserListChanged(); | 256 void NotifyUserListChanged(); |
250 | 257 |
251 // Notifies observers that merge session state had changed. | 258 // Notifies observers that merge session state had changed. |
252 void NotifyMergeSessionStateChanged(); | 259 void NotifyMergeSessionStateChanged(); |
253 | 260 |
254 // Notifies observers that active user_id hash has changed. | 261 // Notifies observers that active user_id hash has changed. |
255 void NotifyActiveUserHashChanged(const std::string& hash); | 262 void NotifyActiveUserHashChanged(const std::string& hash); |
256 | 263 |
| 264 // Notifies observers that user pending sessions restore has finished. |
| 265 void NotifyPendingUserSessionsRestoreFinished(); |
| 266 |
257 // Returns true if there is non-committed user creation transaction. | 267 // Returns true if there is non-committed user creation transaction. |
258 bool HasFailedLocallyManagedUserCreationTransaction(); | 268 bool HasFailedLocallyManagedUserCreationTransaction(); |
259 | 269 |
260 // Attempts to clean up data that could be left from failed user creation. | 270 // Attempts to clean up data that could be left from failed user creation. |
261 void RollbackLocallyManagedUserCreationTransaction(); | 271 void RollbackLocallyManagedUserCreationTransaction(); |
262 | 272 |
263 // Lazily creates default user flow. | 273 // Lazily creates default user flow. |
264 UserFlow* GetDefaultUserFlow() const; | 274 UserFlow* GetDefaultUserFlow() const; |
265 | 275 |
266 // Update the global LoginState. | 276 // Update the global LoginState. |
267 void UpdateLoginState(); | 277 void UpdateLoginState(); |
268 | 278 |
269 // Insert |user| at the front of the LRU user list.. | 279 // Insert |user| at the front of the LRU user list.. |
270 void SetLRUUser(User* user); | 280 void SetLRUUser(User* user); |
271 | 281 |
272 // Callback to process RetrieveActiveSessions() request results. | 282 // Callback to process RetrieveActiveSessions() request results. |
273 void OnRestoreActiveSessions( | 283 void OnRestoreActiveSessions( |
274 const SessionManagerClient::ActiveSessionsMap& sessions, | 284 const SessionManagerClient::ActiveSessionsMap& sessions, |
275 bool success); | 285 bool success); |
276 | 286 |
| 287 // Called by OnRestoreActiveSessions() when there're user sessions in |
| 288 // |pending_user_sessions_| that has to be restored one by one. |
| 289 // Also called after first user session from that list is restored and so on. |
| 290 // Process continues till |pending_user_sessions_| map is not empty. |
| 291 void RestorePendingUserSessions(); |
| 292 |
277 // Interface to the signed settings store. | 293 // Interface to the signed settings store. |
278 CrosSettings* cros_settings_; | 294 CrosSettings* cros_settings_; |
279 | 295 |
280 // Interface to device-local account definitions and associated policy. | 296 // Interface to device-local account definitions and associated policy. |
281 policy::DeviceLocalAccountPolicyService* device_local_account_policy_service_; | 297 policy::DeviceLocalAccountPolicyService* device_local_account_policy_service_; |
282 | 298 |
283 // True if users have been loaded from prefs already. | 299 // True if users have been loaded from prefs already. |
284 bool users_loaded_; | 300 bool users_loaded_; |
285 | 301 |
286 // List of all known users. User instances are owned by |this|. Regular users | 302 // List of all known users. User instances are owned by |this|. Regular users |
(...skipping 15 matching lines...) Expand all Loading... |
302 | 318 |
303 // The logged-in user that is currently active in current session. | 319 // The logged-in user that is currently active in current session. |
304 // NULL until a user has logged in, then points to one | 320 // NULL until a user has logged in, then points to one |
305 // of the User instances in |users_|, the |guest_user_| instance or an | 321 // of the User instances in |users_|, the |guest_user_| instance or an |
306 // ephemeral user instance. | 322 // ephemeral user instance. |
307 User* active_user_; | 323 User* active_user_; |
308 | 324 |
309 // True if SessionStarted() has been called. | 325 // True if SessionStarted() has been called. |
310 bool session_started_; | 326 bool session_started_; |
311 | 327 |
| 328 // True is user sessions has been restored after crash. |
| 329 // On a normal boot then login into user sessions this will be false. |
| 330 bool user_sessions_restored_; |
| 331 |
312 // Cached flag of whether currently logged-in user is owner or not. | 332 // Cached flag of whether currently logged-in user is owner or not. |
313 // May be accessed on different threads, requires locking. | 333 // May be accessed on different threads, requires locking. |
314 bool is_current_user_owner_; | 334 bool is_current_user_owner_; |
315 mutable base::Lock is_current_user_owner_lock_; | 335 mutable base::Lock is_current_user_owner_lock_; |
316 | 336 |
317 // Cached flag of whether the currently logged-in user existed before this | 337 // Cached flag of whether the currently logged-in user existed before this |
318 // login. | 338 // login. |
319 bool is_current_user_new_; | 339 bool is_current_user_new_; |
320 | 340 |
321 // Cached flag of whether the currently logged-in user is a regular user who | 341 // Cached flag of whether the currently logged-in user is a regular user who |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 scoped_ptr<SessionLengthLimiter> session_length_limiter_; | 381 scoped_ptr<SessionLengthLimiter> session_length_limiter_; |
362 | 382 |
363 typedef std::map<std::string, UserFlow*> FlowMap; | 383 typedef std::map<std::string, UserFlow*> FlowMap; |
364 | 384 |
365 // Lazy-initialized default flow. | 385 // Lazy-initialized default flow. |
366 mutable scoped_ptr<UserFlow> default_flow_; | 386 mutable scoped_ptr<UserFlow> default_flow_; |
367 | 387 |
368 // Specific flows by user e-mail. | 388 // Specific flows by user e-mail. |
369 FlowMap specific_flows_; | 389 FlowMap specific_flows_; |
370 | 390 |
| 391 // User sessions that have to be restored after browser crash. |
| 392 // [user_id] > [user_id_hash] |
| 393 SessionManagerClient::ActiveSessionsMap pending_user_sessions_; |
| 394 |
371 DISALLOW_COPY_AND_ASSIGN(UserManagerImpl); | 395 DISALLOW_COPY_AND_ASSIGN(UserManagerImpl); |
372 }; | 396 }; |
373 | 397 |
374 } // namespace chromeos | 398 } // namespace chromeos |
375 | 399 |
376 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_IMPL_H_ | 400 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_IMPL_H_ |
OLD | NEW |