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 <set> | |
8 #include <string> | 9 #include <string> |
10 #include <vector> | |
9 | 11 |
10 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
13 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
14 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "base/values.h" | |
15 #include "chrome/browser/api/sync/profile_sync_service_observer.h" | 18 #include "chrome/browser/api/sync/profile_sync_service_observer.h" |
16 #include "chrome/browser/chromeos/login/user.h" | 19 #include "chrome/browser/chromeos/login/user.h" |
17 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" | 20 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" |
18 #include "chrome/browser/chromeos/login/user_manager.h" | 21 #include "chrome/browser/chromeos/login/user_manager.h" |
19 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | 22 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
23 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
20 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 24 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
21 #include "content/public/browser/notification_observer.h" | 25 #include "content/public/browser/notification_observer.h" |
22 #include "content/public/browser/notification_registrar.h" | 26 #include "content/public/browser/notification_registrar.h" |
23 | 27 |
24 class FilePath; | 28 class FilePath; |
25 class PrefService; | 29 class PrefService; |
26 class ProfileSyncService; | 30 class ProfileSyncService; |
27 | 31 |
28 namespace chromeos { | 32 namespace chromeos { |
29 | 33 |
30 class RemoveUserDelegate; | 34 class RemoveUserDelegate; |
31 | 35 |
32 // Implementation of the UserManager. | 36 // Implementation of the UserManager. |
33 class UserManagerImpl : public UserManager, | 37 class UserManagerImpl : public UserManager, |
34 public ProfileSyncServiceObserver, | 38 public ProfileSyncServiceObserver, |
35 public content::NotificationObserver { | 39 public content::NotificationObserver { |
36 public: | 40 public: |
37 virtual ~UserManagerImpl(); | 41 virtual ~UserManagerImpl(); |
38 | 42 |
39 // UserManager implementation: | 43 // UserManager implementation: |
44 virtual void Shutdown() OVERRIDE; | |
40 virtual UserImageManager* GetUserImageManager() OVERRIDE; | 45 virtual UserImageManager* GetUserImageManager() OVERRIDE; |
41 virtual const UserList& GetUsers() const OVERRIDE; | 46 virtual const UserList& GetUsers() const OVERRIDE; |
42 virtual void UserLoggedIn(const std::string& email, | 47 virtual void UserLoggedIn(const std::string& email, |
43 bool browser_restart) OVERRIDE; | 48 bool browser_restart) OVERRIDE; |
44 virtual void RetailModeUserLoggedIn() OVERRIDE; | 49 virtual void RetailModeUserLoggedIn() OVERRIDE; |
45 virtual void GuestUserLoggedIn() OVERRIDE; | 50 virtual void GuestUserLoggedIn() OVERRIDE; |
46 virtual void EphemeralUserLoggedIn(const std::string& email) OVERRIDE; | 51 virtual void EphemeralUserLoggedIn(const std::string& email) OVERRIDE; |
47 virtual void SessionStarted() OVERRIDE; | 52 virtual void SessionStarted() OVERRIDE; |
48 virtual void RemoveUser(const std::string& email, | 53 virtual void RemoveUser(const std::string& email, |
49 RemoveUserDelegate* delegate) OVERRIDE; | 54 RemoveUserDelegate* delegate) OVERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... | |
61 const std::string& username) const OVERRIDE; | 66 const std::string& username) const OVERRIDE; |
62 virtual void SaveUserDisplayEmail(const std::string& username, | 67 virtual void SaveUserDisplayEmail(const std::string& username, |
63 const std::string& display_email) OVERRIDE; | 68 const std::string& display_email) OVERRIDE; |
64 virtual std::string GetUserDisplayEmail( | 69 virtual std::string GetUserDisplayEmail( |
65 const std::string& username) const OVERRIDE; | 70 const std::string& username) const OVERRIDE; |
66 virtual bool IsCurrentUserOwner() const OVERRIDE; | 71 virtual bool IsCurrentUserOwner() const OVERRIDE; |
67 virtual bool IsCurrentUserNew() const OVERRIDE; | 72 virtual bool IsCurrentUserNew() const OVERRIDE; |
68 virtual bool IsCurrentUserEphemeral() const OVERRIDE; | 73 virtual bool IsCurrentUserEphemeral() const OVERRIDE; |
69 virtual bool CanCurrentUserLock() const OVERRIDE; | 74 virtual bool CanCurrentUserLock() const OVERRIDE; |
70 virtual bool IsUserLoggedIn() const OVERRIDE; | 75 virtual bool IsUserLoggedIn() const OVERRIDE; |
76 virtual bool IsLoggedInAsRegularUser() const OVERRIDE; | |
71 virtual bool IsLoggedInAsDemoUser() const OVERRIDE; | 77 virtual bool IsLoggedInAsDemoUser() const OVERRIDE; |
72 virtual bool IsLoggedInAsPublicAccount() const OVERRIDE; | 78 virtual bool IsLoggedInAsPublicAccount() const OVERRIDE; |
73 virtual bool IsLoggedInAsGuest() const OVERRIDE; | 79 virtual bool IsLoggedInAsGuest() const OVERRIDE; |
74 virtual bool IsLoggedInAsStub() const OVERRIDE; | 80 virtual bool IsLoggedInAsStub() const OVERRIDE; |
75 virtual bool IsSessionStarted() const OVERRIDE; | 81 virtual bool IsSessionStarted() const OVERRIDE; |
76 virtual bool IsEphemeralUser(const std::string& email) const OVERRIDE; | 82 virtual bool IsEphemeralUser(const std::string& email) const OVERRIDE; |
77 virtual void AddObserver(UserManager::Observer* obs) OVERRIDE; | 83 virtual void AddObserver(UserManager::Observer* obs) OVERRIDE; |
78 virtual void RemoveObserver(UserManager::Observer* obs) OVERRIDE; | 84 virtual void RemoveObserver(UserManager::Observer* obs) OVERRIDE; |
79 virtual void NotifyLocalStateChanged() OVERRIDE; | 85 virtual void NotifyLocalStateChanged() OVERRIDE; |
80 | 86 |
81 // content::NotificationObserver implementation. | 87 // content::NotificationObserver implementation. |
82 virtual void Observe(int type, | 88 virtual void Observe(int type, |
83 const content::NotificationSource& source, | 89 const content::NotificationSource& source, |
84 const content::NotificationDetails& details) OVERRIDE; | 90 const content::NotificationDetails& details) OVERRIDE; |
85 | 91 |
86 // ProfileSyncServiceObserver implementation. | 92 // ProfileSyncServiceObserver implementation. |
87 virtual void OnStateChanged() OVERRIDE; | 93 virtual void OnStateChanged() OVERRIDE; |
88 | 94 |
89 private: | 95 private: |
90 friend class UserManagerImplWrapper; | 96 friend class UserManagerImplWrapper; |
91 friend class WallpaperManager; | 97 friend class WallpaperManager; |
92 friend class UserManagerTest; | 98 friend class UserManagerTest; |
93 | 99 |
94 UserManagerImpl(); | 100 UserManagerImpl(); |
95 | 101 |
102 // Helper function that copies users from |users_list| to |users_vector| and | |
103 // |users_set|. Duplicates and users already present in |existing_users| are | |
104 // skipped. The |logged_in_user| is also skipped and the return value | |
105 // indicates whether that user was found in |users_list|. | |
106 bool ParseUserList(const ListValue& users_list, | |
107 const std::set<std::string>& existing_users, | |
108 const std::string& logged_in_user, | |
109 std::vector<std::string>* users_vector, | |
110 std::set<std::string>* users_set) const; | |
111 | |
96 // Loads |users_| from Local State if the list has not been loaded yet. | 112 // Loads |users_| from Local State if the list has not been loaded yet. |
97 // Subsequent calls have no effect. Must be called on the UI thread. | 113 // Subsequent calls have no effect. Must be called on the UI thread. |
98 void EnsureUsersLoaded(); | 114 void EnsureUsersLoaded() const; |
Ivan Korotkov
2012/11/28 21:40:53
const here doesn't look right. In GetUsers() it's
bartfab (slow)
2012/11/29 14:18:09
This was requested by Julian in his review. I agre
Ivan Korotkov
2012/11/29 17:25:33
Yes, I still think it's better to leave it non-con
bartfab (slow)
2012/11/29 18:56:17
Done.
| |
99 | 115 |
100 // Retrieves trusted device policies and removes users from the persistent | 116 // Retrieves trusted device policies and removes users from the persistent |
101 // list if ephemeral users are enabled. Schedules a callback to itself if | 117 // list if ephemeral users are enabled. Schedules a callback to itself if |
102 // trusted device policies are not yet available. | 118 // trusted device policies are not yet available. |
103 void RetrieveTrustedDevicePolicies(); | 119 void RetrieveTrustedDevicePolicies(); |
104 | 120 |
105 // Returns true if trusted device policies have successfully been retrieved | 121 // Returns true if trusted device policies have successfully been retrieved |
106 // and ephemeral users are enabled. | 122 // and ephemeral users are enabled. |
107 bool AreEphemeralUsersEnabled() const; | 123 bool AreEphemeralUsersEnabled() const; |
108 | 124 |
109 // Returns the user with the given email address if found in the persistent | 125 // Returns the user with the given email address if found in the persistent |
110 // list. Returns |NULL| otherwise. | 126 // list. Returns |NULL| otherwise. |
111 const User* FindUserInList(const std::string& email) const; | 127 const User* FindUserInList(const std::string& email) const; |
112 | 128 |
113 // Notifies on new user session. | 129 // Notifies on new user session. |
114 void NotifyOnLogin(); | 130 void NotifyOnLogin(); |
115 | 131 |
116 // Reads user's oauth token status from local state preferences. | 132 // Reads user's oauth token status from local state preferences. |
117 User::OAuthTokenStatus LoadUserOAuthStatus(const std::string& username) const; | 133 User::OAuthTokenStatus LoadUserOAuthStatus(const std::string& username) const; |
118 | 134 |
119 void SetCurrentUserIsOwner(bool is_current_user_owner); | 135 void SetCurrentUserIsOwner(bool is_current_user_owner); |
120 | 136 |
121 // Updates current user ownership on UI thread. | 137 // Updates current user ownership on UI thread. |
122 void UpdateOwnership(DeviceSettingsService::OwnershipStatus status, | 138 void UpdateOwnership(DeviceSettingsService::OwnershipStatus status, |
123 bool is_owner); | 139 bool is_owner); |
124 | 140 |
125 // Triggers an asynchronous ownership check. | 141 // Triggers an asynchronous ownership check. |
126 void CheckOwnership(); | 142 void CheckOwnership(); |
127 | 143 |
128 // Removes the user from the persistent list only. Also removes the user's | 144 // Removes data stored or cached outside the user's cryptohome (wallpaper, |
129 // picture. | 145 // avatar, OAuth token status, display name, display email). |
130 void RemoveUserFromListInternal(const std::string& email); | 146 void RemoveNonCryptohomeData(const std::string& email); |
131 | 147 |
132 // List of all known users. User instances are owned by |this| and deleted | 148 // Removes a user from the user list. Returns the user if found or NULL |
133 // when users are removed by |RemoveUserFromListInternal|. | 149 // otherwise. Also removes the user from the persistent user list. |
150 User *RemoveUserFromListInternal(const std::string& email); | |
151 | |
152 // Replaces the list of device-local users with |local_users_list|. Ensures | |
153 // that data stored outside their cryptohomes is removed for any users who are | |
154 // no longer on the list. Returns |true| if the user list has changed. | |
155 bool UpdateLocalUsers(const base::ListValue& local_users_list); | |
Ivan Korotkov
2012/11/28 21:40:53
Please rename to indicate that pending removal is
bartfab (slow)
2012/11/29 14:18:09
Done.
| |
156 | |
157 // Interface to the signed settings store. | |
158 CrosSettings* cros_settings_; | |
159 | |
160 // True if users have been loaded from prefs already. Mutable so that | |
161 // |EnsureUsersLoaded| can lazily load the user list. | |
162 mutable bool users_loaded_; | |
163 | |
164 // List of all known users. User instances are owned by |this|. Regular users | |
165 // are removed by |RemoveUserFromList|, device-local users by | |
166 // |UpdateLocalUsers|. Mutable so that |EnsureUsersLoaded| can lazily load the | |
167 // user list. | |
134 mutable UserList users_; | 168 mutable UserList users_; |
135 | 169 |
136 // The logged-in user. NULL until a user has logged in, then points to one | 170 // The logged-in user. NULL until a user has logged in, then points to one |
137 // of the User instances in |users_|, the |guest_user_| instance or an | 171 // of the User instances in |users_|, the |guest_user_| instance or an |
138 // ephemeral user instance. | 172 // ephemeral user instance. |
139 User* logged_in_user_; | 173 User* logged_in_user_; |
140 | 174 |
141 // True if SessionStarted() has been called. | 175 // True if SessionStarted() has been called. |
142 bool session_started_; | 176 bool session_started_; |
143 | 177 |
(...skipping 25 matching lines...) Expand all Loading... | |
169 | 203 |
170 content::NotificationRegistrar registrar_; | 204 content::NotificationRegistrar registrar_; |
171 | 205 |
172 // Profile sync service which is observed to take actions after sync | 206 // Profile sync service which is observed to take actions after sync |
173 // errors appear. NOTE: there is no guarantee that it is the current sync | 207 // errors appear. NOTE: there is no guarantee that it is the current sync |
174 // service, so do NOT use it outside |OnStateChanged| method. | 208 // service, so do NOT use it outside |OnStateChanged| method. |
175 ProfileSyncService* observed_sync_service_; | 209 ProfileSyncService* observed_sync_service_; |
176 | 210 |
177 ObserverList<UserManager::Observer> observer_list_; | 211 ObserverList<UserManager::Observer> observer_list_; |
178 | 212 |
179 scoped_ptr<UserImageManagerImpl> user_image_manager_; | 213 // User avatar manager. Mutable so that |EnsureUsersLoaded| can request |
214 // avatars to be loaded when lazily loading the user list. | |
215 mutable scoped_ptr<UserImageManagerImpl> user_image_manager_; | |
180 | 216 |
181 DISALLOW_COPY_AND_ASSIGN(UserManagerImpl); | 217 DISALLOW_COPY_AND_ASSIGN(UserManagerImpl); |
182 }; | 218 }; |
183 | 219 |
184 } // namespace chromeos | 220 } // namespace chromeos |
185 | 221 |
186 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_IMPL_H_ | 222 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_IMPL_H_ |
OLD | NEW |