Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / chromeos / login / users / chrome_user_manager_impl.h
blobdbbf3f5be30ab16c2635959a4b7e2b4824029867
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_IMPL_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/containers/hash_tables.h"
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/easy_unlock/bootstrap_manager.h"
21 #include "chrome/browser/chromeos/login/user_flow.h"
22 #include "chrome/browser/chromeos/login/users/affiliation.h"
23 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h"
24 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
25 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller_delegate.h"
26 #include "chrome/browser/chromeos/policy/cloud_external_data_policy_observer.h"
27 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
28 #include "chrome/browser/chromeos/settings/cros_settings.h"
29 #include "chrome/browser/chromeos/settings/device_settings_service.h"
30 #include "components/user_manager/user.h"
31 #include "content/public/browser/notification_observer.h"
32 #include "content/public/browser/notification_registrar.h"
34 class PrefRegistrySimple;
35 class PrefService;
36 class ProfileSyncService;
38 namespace policy {
39 struct DeviceLocalAccount;
42 namespace user_manager {
43 class RemoveUserDelegate;
46 namespace chromeos {
48 class MultiProfileUserController;
49 class SupervisedUserManagerImpl;
50 class SessionLengthLimiter;
52 // Chrome specific implementation of the UserManager.
53 class ChromeUserManagerImpl
54 : public ChromeUserManager,
55 public content::NotificationObserver,
56 public policy::CloudExternalDataPolicyObserver::Delegate,
57 public policy::DeviceLocalAccountPolicyService::Observer,
58 public MultiProfileUserControllerDelegate,
59 public BootstrapManager::Delegate {
60 public:
61 ~ChromeUserManagerImpl() override;
63 // Creates ChromeUserManagerImpl instance.
64 static scoped_ptr<ChromeUserManager> CreateChromeUserManager();
66 // Registers user manager preferences.
67 static void RegisterPrefs(PrefRegistrySimple* registry);
69 // UserManagerInterface implementation:
70 BootstrapManager* GetBootstrapManager() override;
71 MultiProfileUserController* GetMultiProfileUserController() override;
72 UserImageManager* GetUserImageManager(const std::string& user_id) override;
73 SupervisedUserManager* GetSupervisedUserManager() override;
74 UserFlow* GetCurrentUserFlow() const override;
75 UserFlow* GetUserFlow(const std::string& user_id) const override;
76 void SetUserFlow(const std::string& user_id, UserFlow* flow) override;
77 void ResetUserFlow(const std::string& user_id) override;
79 // UserManager implementation:
80 void Shutdown() override;
81 user_manager::UserList GetUsersAllowedForMultiProfile() const override;
82 user_manager::UserList GetUsersAllowedForSupervisedUsersCreation()
83 const override;
84 user_manager::UserList GetUnlockUsers() const override;
85 void SessionStarted() override;
86 void SaveUserOAuthStatus(
87 const std::string& user_id,
88 user_manager::User::OAuthTokenStatus oauth_token_status) override;
89 void SaveUserDisplayName(const std::string& user_id,
90 const base::string16& display_name) override;
91 bool CanCurrentUserLock() const override;
92 bool IsUserNonCryptohomeDataEphemeral(
93 const std::string& user_id) const override;
94 bool AreSupervisedUsersAllowed() const override;
96 // content::NotificationObserver implementation.
97 void Observe(int type,
98 const content::NotificationSource& source,
99 const content::NotificationDetails& details) override;
101 // policy::CloudExternalDataPolicyObserver::Delegate:
102 void OnExternalDataSet(const std::string& policy,
103 const std::string& user_id) override;
104 void OnExternalDataCleared(const std::string& policy,
105 const std::string& user_id) override;
106 void OnExternalDataFetched(const std::string& policy,
107 const std::string& user_id,
108 scoped_ptr<std::string> data) override;
110 // policy::DeviceLocalAccountPolicyService::Observer implementation.
111 void OnPolicyUpdated(const std::string& user_id) override;
112 void OnDeviceLocalAccountsChanged() override;
114 void StopPolicyObserverForTesting();
116 // UserManagerBase implementation:
117 bool AreEphemeralUsersEnabled() const override;
118 void OnUserRemoved(const std::string& user_id) override;
120 // ChromeUserManager implementation:
121 bool ShouldReportUser(const std::string& user_id) const override;
122 void SetUserAffiliation(
123 const std::string& user_email,
124 const AffiliationIDSet& user_affiliation_ids) override;
126 protected:
127 const std::string& GetApplicationLocale() const override;
128 PrefService* GetLocalState() const override;
129 void HandleUserOAuthTokenStatusChange(
130 const std::string& user_id,
131 user_manager::User::OAuthTokenStatus status) const override;
132 bool IsEnterpriseManaged() const override;
133 void LoadPublicAccounts(std::set<std::string>* users_set) override;
134 void NotifyOnLogin() override;
135 void NotifyUserAddedToSession(const user_manager::User* added_user,
136 bool user_switch_pending) override;
137 void PerformPreUserListLoadingActions() override;
138 void PerformPostUserListLoadingActions() override;
139 void PerformPostUserLoggedInActions(bool browser_restart) override;
140 void RemoveNonCryptohomeData(const std::string& user_id) override;
141 void RemoveUserInternal(const std::string& user_email,
142 user_manager::RemoveUserDelegate* delegate) override;
143 bool IsDemoApp(const std::string& user_id) const override;
144 bool IsKioskApp(const std::string& user_id) const override;
145 bool IsPublicAccountMarkedForRemoval(
146 const std::string& user_id) const override;
147 void DemoAccountLoggedIn() override;
148 void GuestUserLoggedIn() override;
149 void KioskAppLoggedIn(const std::string& app_id) override;
150 void PublicAccountUserLoggedIn(user_manager::User* user) override;
151 void RegularUserLoggedIn(const std::string& user_id) override;
152 void RegularUserLoggedInAsEphemeral(const std::string& user_id) override;
153 void SupervisedUserLoggedIn(const std::string& user_id) override;
154 bool HasPendingBootstrap(const std::string& user_id) const override;
156 private:
157 friend class SupervisedUserManagerImpl;
158 friend class UserManagerTest;
159 friend class WallpaperManager;
160 friend class WallpaperManagerTest;
162 typedef base::hash_map<std::string, linked_ptr<UserImageManager> >
163 UserImageManagerMap;
165 ChromeUserManagerImpl();
167 // Retrieves trusted device policies and removes users from the persistent
168 // list if ephemeral users are enabled. Schedules a callback to itself if
169 // trusted device policies are not yet available.
170 void RetrieveTrustedDevicePolicies();
172 // Updates current user ownership on UI thread.
173 void UpdateOwnership();
175 // If data for a public account is marked as pending removal and the user is
176 // no longer logged into that account, removes the data.
177 void CleanUpPublicAccountNonCryptohomeDataPendingRemoval();
179 // Removes data belonging to public accounts that are no longer found on the
180 // user list. If the user is currently logged into one of these accounts, the
181 // data for that account is not removed immediately but marked as pending
182 // removal after logout.
183 void CleanUpPublicAccountNonCryptohomeData(
184 const std::vector<std::string>& old_public_accounts);
186 // Replaces the list of public accounts with those found in
187 // |device_local_accounts|. Ensures that data belonging to accounts no longer
188 // on the list is removed. Returns |true| if the list has changed.
189 // Public accounts are defined by policy. This method is called whenever an
190 // updated list of public accounts is received from policy.
191 bool UpdateAndCleanUpPublicAccounts(
192 const std::vector<policy::DeviceLocalAccount>& device_local_accounts);
194 // Updates the display name for public account |username| from policy settings
195 // associated with that username.
196 void UpdatePublicAccountDisplayName(const std::string& user_id);
198 // Notifies the UI about a change to the user list.
199 void NotifyUserListChanged();
201 // Lazily creates default user flow.
202 UserFlow* GetDefaultUserFlow() const;
204 // MultiProfileUserControllerDelegate implementation:
205 void OnUserNotAllowed(const std::string& user_email) override;
207 // BootstrapManager::Delegate implementation:
208 void RemovePendingBootstrapUser(const std::string& user_id) override;
210 // Update the number of users.
211 void UpdateNumberOfUsers();
213 // Starts (or stops) automatic timezone refresh on geolocation,
214 // depending on user preferences.
215 void UpdateUserTimeZoneRefresher(Profile* profile);
217 // Adds user to the list of the users who should be reported.
218 void AddReportingUser(const std::string& user_id);
220 // Removes user from the list of the users who should be reported.
221 void RemoveReportingUser(const std::string& user_id);
223 // Interface to the signed settings store.
224 CrosSettings* cros_settings_;
226 // Interface to device-local account definitions and associated policy.
227 policy::DeviceLocalAccountPolicyService* device_local_account_policy_service_;
229 content::NotificationRegistrar registrar_;
231 // User avatar managers.
232 UserImageManagerMap user_image_managers_;
234 // Supervised user manager.
235 scoped_ptr<SupervisedUserManagerImpl> supervised_user_manager_;
237 // Session length limiter.
238 scoped_ptr<SessionLengthLimiter> session_length_limiter_;
240 typedef std::map<std::string, UserFlow*> FlowMap;
242 // Lazy-initialized default flow.
243 mutable scoped_ptr<UserFlow> default_flow_;
245 // Specific flows by user e-mail. Keys should be canonicalized before
246 // access.
247 FlowMap specific_flows_;
249 scoped_ptr<CrosSettings::ObserverSubscription> local_accounts_subscription_;
251 scoped_ptr<MultiProfileUserController> multi_profile_user_controller_;
253 // Observer for the policy that can be used to manage user images.
254 scoped_ptr<policy::CloudExternalDataPolicyObserver> avatar_policy_observer_;
256 // Observer for the policy that can be used to manage wallpapers.
257 scoped_ptr<policy::CloudExternalDataPolicyObserver>
258 wallpaper_policy_observer_;
260 scoped_ptr<BootstrapManager> bootstrap_manager_;
262 base::WeakPtrFactory<ChromeUserManagerImpl> weak_factory_;
264 DISALLOW_COPY_AND_ASSIGN(ChromeUserManagerImpl);
267 } // namespace chromeos
269 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_IMPL_H_