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_CHROME_USER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include "base/basictypes.h" |
9 #include <string> | 9 #include "components/user_manager/user_manager_base.h" |
10 #include <vector> | |
11 | 10 |
12 #include "base/basictypes.h" | 11 namespace base { |
13 #include "base/containers/hash_tables.h" | 12 class TaskRunner; |
14 #include "base/memory/linked_ptr.h" | |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/memory/weak_ptr.h" | |
17 #include "base/observer_list.h" | |
18 #include "base/synchronization/lock.h" | |
19 #include "base/time/time.h" | |
20 #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" | |
22 #include "chrome/browser/chromeos/login/users/user_manager_base.h" | |
23 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | |
24 #include "chrome/browser/chromeos/policy/cloud_external_data_policy_observer.h" | |
25 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | |
26 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
27 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
28 #include "components/user_manager/user.h" | |
29 #include "content/public/browser/notification_observer.h" | |
30 #include "content/public/browser/notification_registrar.h" | |
31 | |
32 class PrefService; | |
33 class ProfileSyncService; | |
34 | |
35 namespace policy { | |
36 struct DeviceLocalAccount; | |
37 } | 13 } |
38 | 14 |
39 namespace chromeos { | 15 namespace chromeos { |
40 | 16 |
41 class MultiProfileUserController; | 17 class MultiProfileUserController; |
42 class RemoveUserDelegate; | 18 class SupervisedUserManager; |
43 class SupervisedUserManagerImpl; | 19 class UserFlow; |
44 class SessionLengthLimiter; | 20 class UserImageManager; |
45 | 21 |
46 // Chrome specific implementation of the UserManager. | 22 // Chrome specific interface of the UserManager. |
47 class ChromeUserManager | 23 class ChromeUserManager : public user_manager::UserManagerBase { |
48 : public UserManagerBase, | |
49 public content::NotificationObserver, | |
50 public policy::CloudExternalDataPolicyObserver::Delegate, | |
51 public policy::DeviceLocalAccountPolicyService::Observer, | |
52 public MultiProfileUserControllerDelegate { | |
53 public: | 24 public: |
| 25 ChromeUserManager(scoped_refptr<base::TaskRunner> task_runner, |
| 26 scoped_refptr<base::TaskRunner> blocking_task_runner); |
54 virtual ~ChromeUserManager(); | 27 virtual ~ChromeUserManager(); |
55 | 28 |
56 // UserManager implementation: | 29 // Returns current ChromeUserManager or NULL if instance hasn't been |
57 virtual void Shutdown() OVERRIDE; | 30 // yet initialized. |
58 virtual MultiProfileUserController* GetMultiProfileUserController() OVERRIDE; | 31 static ChromeUserManager* Get(); |
59 virtual UserImageManager* GetUserImageManager( | |
60 const std::string& user_id) OVERRIDE; | |
61 virtual SupervisedUserManager* GetSupervisedUserManager() OVERRIDE; | |
62 virtual user_manager::UserList GetUsersAdmittedForMultiProfile() | |
63 const OVERRIDE; | |
64 virtual user_manager::UserList GetUnlockUsers() const OVERRIDE; | |
65 virtual void SessionStarted() OVERRIDE; | |
66 virtual void SaveUserOAuthStatus( | |
67 const std::string& user_id, | |
68 user_manager::User::OAuthTokenStatus oauth_token_status) OVERRIDE; | |
69 virtual void SaveUserDisplayName(const std::string& user_id, | |
70 const base::string16& display_name) OVERRIDE; | |
71 virtual bool CanCurrentUserLock() const OVERRIDE; | |
72 virtual bool IsUserNonCryptohomeDataEphemeral( | |
73 const std::string& user_id) const OVERRIDE; | |
74 | 32 |
75 virtual UserFlow* GetCurrentUserFlow() const OVERRIDE; | 33 virtual MultiProfileUserController* GetMultiProfileUserController() = 0; |
76 virtual UserFlow* GetUserFlow(const std::string& user_id) const OVERRIDE; | 34 virtual UserImageManager* GetUserImageManager(const std::string& user_id) = 0; |
77 virtual void SetUserFlow(const std::string& user_id, UserFlow* flow) OVERRIDE; | 35 virtual SupervisedUserManager* GetSupervisedUserManager() = 0; |
78 virtual void ResetUserFlow(const std::string& user_id) OVERRIDE; | |
79 virtual bool AreSupervisedUsersAllowed() const OVERRIDE; | |
80 | 36 |
81 // content::NotificationObserver implementation. | 37 // Method that allows to set |flow| for user identified by |user_id|. |
82 virtual void Observe(int type, | 38 // Flow should be set before login attempt. |
83 const content::NotificationSource& source, | 39 // Takes ownership of the |flow|, |flow| will be deleted in case of login |
84 const content::NotificationDetails& details) OVERRIDE; | 40 // failure. |
| 41 virtual void SetUserFlow(const std::string& user_id, UserFlow* flow) = 0; |
85 | 42 |
86 // policy::CloudExternalDataPolicyObserver::Delegate: | 43 // Return user flow for current user. Returns instance of DefaultUserFlow if |
87 virtual void OnExternalDataSet(const std::string& policy, | 44 // no flow was defined for current user, or user is not logged in. |
88 const std::string& user_id) OVERRIDE; | 45 // Returned value should not be cached. |
89 virtual void OnExternalDataCleared(const std::string& policy, | 46 virtual UserFlow* GetCurrentUserFlow() const = 0; |
90 const std::string& user_id) OVERRIDE; | |
91 virtual void OnExternalDataFetched(const std::string& policy, | |
92 const std::string& user_id, | |
93 scoped_ptr<std::string> data) OVERRIDE; | |
94 | 47 |
95 // policy::DeviceLocalAccountPolicyService::Observer implementation. | 48 // Return user flow for user identified by |user_id|. Returns instance of |
96 virtual void OnPolicyUpdated(const std::string& user_id) OVERRIDE; | 49 // DefaultUserFlow if no flow was defined for user. |
97 virtual void OnDeviceLocalAccountsChanged() OVERRIDE; | 50 // Returned value should not be cached. |
| 51 virtual UserFlow* GetUserFlow(const std::string& user_id) const = 0; |
98 | 52 |
99 void StopPolicyObserverForTesting(); | 53 // Resets user flow for user identified by |user_id|. |
100 | 54 virtual void ResetUserFlow(const std::string& user_id) = 0; |
101 protected: | |
102 // UserManagerBase implementation: | |
103 virtual bool AreEphemeralUsersEnabled() const OVERRIDE; | |
104 virtual const std::string& GetApplicationLocale() const OVERRIDE; | |
105 virtual PrefService* GetLocalState() const OVERRIDE; | |
106 virtual bool IsEnterpriseManaged() const OVERRIDE; | |
107 virtual void LoadPublicAccounts(std::set<std::string>* users_set) OVERRIDE; | |
108 virtual void NotifyOnLogin() OVERRIDE; | |
109 virtual void NotifyUserAddedToSession(const user_manager::User* added_user, | |
110 bool user_switch_pending) OVERRIDE; | |
111 virtual void PerformPreUserListLoadingActions() OVERRIDE; | |
112 virtual void PerformPostUserListLoadingActions() OVERRIDE; | |
113 virtual void PerformPostUserLoggedInActions(bool browser_restart) OVERRIDE; | |
114 virtual void RemoveNonCryptohomeData(const std::string& user_id) OVERRIDE; | |
115 virtual void RemoveUserInternal(const std::string& user_email, | |
116 RemoveUserDelegate* delegate) OVERRIDE; | |
117 virtual bool IsDemoApp(const std::string& user_id) const OVERRIDE; | |
118 virtual bool IsKioskApp(const std::string& user_id) const OVERRIDE; | |
119 virtual bool IsPublicAccountMarkedForRemoval( | |
120 const std::string& user_id) const OVERRIDE; | |
121 virtual void DemoAccountLoggedIn() OVERRIDE; | |
122 virtual void GuestUserLoggedIn() OVERRIDE; | |
123 virtual void KioskAppLoggedIn(const std::string& app_id) OVERRIDE; | |
124 virtual void PublicAccountUserLoggedIn(user_manager::User* user) OVERRIDE; | |
125 virtual void RegularUserLoggedIn(const std::string& user_id) OVERRIDE; | |
126 virtual void RegularUserLoggedInAsEphemeral( | |
127 const std::string& user_id) OVERRIDE; | |
128 virtual void RetailModeUserLoggedIn() OVERRIDE; | |
129 virtual void SupervisedUserLoggedIn(const std::string& user_id) OVERRIDE; | |
130 | |
131 private: | |
132 friend class SupervisedUserManagerImpl; | |
133 friend class UserManager; | |
134 friend class UserManagerTest; | |
135 friend class WallpaperManager; | |
136 friend class WallpaperManagerTest; | |
137 | |
138 typedef base::hash_map<std::string, linked_ptr<UserImageManager> > | |
139 UserImageManagerMap; | |
140 | |
141 ChromeUserManager(); | |
142 | |
143 // Retrieves trusted device policies and removes users from the persistent | |
144 // list if ephemeral users are enabled. Schedules a callback to itself if | |
145 // trusted device policies are not yet available. | |
146 void RetrieveTrustedDevicePolicies(); | |
147 | |
148 // Updates current user ownership on UI thread. | |
149 void UpdateOwnership(); | |
150 | |
151 // If data for a public account is marked as pending removal and the user is | |
152 // no longer logged into that account, removes the data. | |
153 void CleanUpPublicAccountNonCryptohomeDataPendingRemoval(); | |
154 | |
155 // Removes data belonging to public accounts that are no longer found on the | |
156 // user list. If the user is currently logged into one of these accounts, the | |
157 // data for that account is not removed immediately but marked as pending | |
158 // removal after logout. | |
159 void CleanUpPublicAccountNonCryptohomeData( | |
160 const std::vector<std::string>& old_public_accounts); | |
161 | |
162 // Replaces the list of public accounts with those found in | |
163 // |device_local_accounts|. Ensures that data belonging to accounts no longer | |
164 // on the list is removed. Returns |true| if the list has changed. | |
165 // Public accounts are defined by policy. This method is called whenever an | |
166 // updated list of public accounts is received from policy. | |
167 bool UpdateAndCleanUpPublicAccounts( | |
168 const std::vector<policy::DeviceLocalAccount>& device_local_accounts); | |
169 | |
170 // Updates the display name for public account |username| from policy settings | |
171 // associated with that username. | |
172 void UpdatePublicAccountDisplayName(const std::string& user_id); | |
173 | |
174 // Notifies the UI about a change to the user list. | |
175 void NotifyUserListChanged(); | |
176 | |
177 // Lazily creates default user flow. | |
178 UserFlow* GetDefaultUserFlow() const; | |
179 | |
180 // MultiProfileUserControllerDelegate implementation: | |
181 virtual void OnUserNotAllowed(const std::string& user_email) OVERRIDE; | |
182 | |
183 // Update the number of users. | |
184 void UpdateNumberOfUsers(); | |
185 | |
186 // Interface to the signed settings store. | |
187 CrosSettings* cros_settings_; | |
188 | |
189 // Interface to device-local account definitions and associated policy. | |
190 policy::DeviceLocalAccountPolicyService* device_local_account_policy_service_; | |
191 | |
192 content::NotificationRegistrar registrar_; | |
193 | |
194 // User avatar managers. | |
195 UserImageManagerMap user_image_managers_; | |
196 | |
197 // Supervised user manager. | |
198 scoped_ptr<SupervisedUserManagerImpl> supervised_user_manager_; | |
199 | |
200 // Session length limiter. | |
201 scoped_ptr<SessionLengthLimiter> session_length_limiter_; | |
202 | |
203 typedef std::map<std::string, UserFlow*> FlowMap; | |
204 | |
205 // Lazy-initialized default flow. | |
206 mutable scoped_ptr<UserFlow> default_flow_; | |
207 | |
208 // Specific flows by user e-mail. Keys should be canonicalized before | |
209 // access. | |
210 FlowMap specific_flows_; | |
211 | |
212 scoped_ptr<CrosSettings::ObserverSubscription> local_accounts_subscription_; | |
213 | |
214 scoped_ptr<MultiProfileUserController> multi_profile_user_controller_; | |
215 | |
216 // Observer for the policy that can be used to manage user images. | |
217 scoped_ptr<policy::CloudExternalDataPolicyObserver> avatar_policy_observer_; | |
218 | |
219 // Observer for the policy that can be used to manage wallpapers. | |
220 scoped_ptr<policy::CloudExternalDataPolicyObserver> | |
221 wallpaper_policy_observer_; | |
222 | |
223 base::WeakPtrFactory<ChromeUserManager> weak_factory_; | |
224 | 55 |
225 DISALLOW_COPY_AND_ASSIGN(ChromeUserManager); | 56 DISALLOW_COPY_AND_ASSIGN(ChromeUserManager); |
226 }; | 57 }; |
227 | 58 |
228 } // namespace chromeos | 59 } // namespace chromeos |
229 | 60 |
230 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_H_ | 61 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_H_ |
OLD | NEW |