ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / users / chrome_user_manager_impl.h
blob3e1ec1bdab24dfd19faef7c059bc0b67e77b323f
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/user_flow.h"
21 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h"
22 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
23 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller_delegate.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"
32 class PrefRegistrySimple;
33 class PrefService;
34 class ProfileSyncService;
36 namespace policy {
37 struct DeviceLocalAccount;
40 namespace user_manager {
41 class RemoveUserDelegate;
44 namespace chromeos {
46 class MultiProfileUserController;
47 class SupervisedUserManagerImpl;
48 class SessionLengthLimiter;
50 // Chrome specific implementation of the UserManager.
51 class ChromeUserManagerImpl
52 : public ChromeUserManager,
53 public content::NotificationObserver,
54 public policy::CloudExternalDataPolicyObserver::Delegate,
55 public policy::DeviceLocalAccountPolicyService::Observer,
56 public MultiProfileUserControllerDelegate {
57 public:
58 ~ChromeUserManagerImpl() override;
60 // Creates ChromeUserManagerImpl instance.
61 static scoped_ptr<ChromeUserManager> CreateChromeUserManager();
63 // Registers user manager preferences.
64 static void RegisterPrefs(PrefRegistrySimple* registry);
66 // UserManagerInterface implementation:
67 MultiProfileUserController* GetMultiProfileUserController() override;
68 UserImageManager* GetUserImageManager(const std::string& user_id) override;
69 SupervisedUserManager* GetSupervisedUserManager() override;
70 UserFlow* GetCurrentUserFlow() const override;
71 UserFlow* GetUserFlow(const std::string& user_id) const override;
72 void SetUserFlow(const std::string& user_id, UserFlow* flow) override;
73 void ResetUserFlow(const std::string& user_id) override;
75 // UserManager implementation:
76 void Shutdown() override;
77 user_manager::UserList GetUsersAllowedForMultiProfile() const override;
78 user_manager::UserList GetUsersAllowedForSupervisedUsersCreation()
79 const override;
80 user_manager::UserList GetUnlockUsers() const override;
81 void SessionStarted() override;
82 void SaveUserOAuthStatus(
83 const std::string& user_id,
84 user_manager::User::OAuthTokenStatus oauth_token_status) override;
85 void SaveUserDisplayName(const std::string& user_id,
86 const base::string16& display_name) override;
87 bool CanCurrentUserLock() const override;
88 bool IsUserNonCryptohomeDataEphemeral(
89 const std::string& user_id) const override;
90 bool AreSupervisedUsersAllowed() const override;
92 // content::NotificationObserver implementation.
93 void Observe(int type,
94 const content::NotificationSource& source,
95 const content::NotificationDetails& details) override;
97 // policy::CloudExternalDataPolicyObserver::Delegate:
98 void OnExternalDataSet(const std::string& policy,
99 const std::string& user_id) override;
100 void OnExternalDataCleared(const std::string& policy,
101 const std::string& user_id) override;
102 void OnExternalDataFetched(const std::string& policy,
103 const std::string& user_id,
104 scoped_ptr<std::string> data) override;
106 // policy::DeviceLocalAccountPolicyService::Observer implementation.
107 void OnPolicyUpdated(const std::string& user_id) override;
108 void OnDeviceLocalAccountsChanged() override;
110 void StopPolicyObserverForTesting();
112 protected:
113 // UserManagerBase implementation:
114 bool AreEphemeralUsersEnabled() const override;
115 const std::string& GetApplicationLocale() const override;
116 PrefService* GetLocalState() const override;
117 void HandleUserOAuthTokenStatusChange(
118 const std::string& user_id,
119 user_manager::User::OAuthTokenStatus status) const override;
120 bool IsEnterpriseManaged() const override;
121 void LoadPublicAccounts(std::set<std::string>* users_set) override;
122 void NotifyOnLogin() override;
123 void NotifyUserAddedToSession(const user_manager::User* added_user,
124 bool user_switch_pending) override;
125 void PerformPreUserListLoadingActions() override;
126 void PerformPostUserListLoadingActions() override;
127 void PerformPostUserLoggedInActions(bool browser_restart) override;
128 void RemoveNonCryptohomeData(const std::string& user_id) override;
129 void RemoveUserInternal(const std::string& user_email,
130 user_manager::RemoveUserDelegate* delegate) override;
131 bool IsDemoApp(const std::string& user_id) const override;
132 bool IsKioskApp(const std::string& user_id) const override;
133 bool IsPublicAccountMarkedForRemoval(
134 const std::string& user_id) const override;
135 void DemoAccountLoggedIn() override;
136 void GuestUserLoggedIn() override;
137 void KioskAppLoggedIn(const std::string& app_id) override;
138 void PublicAccountUserLoggedIn(user_manager::User* user) override;
139 void RegularUserLoggedIn(const std::string& user_id) override;
140 void RegularUserLoggedInAsEphemeral(const std::string& user_id) override;
141 void SupervisedUserLoggedIn(const std::string& user_id) override;
143 private:
144 friend class SupervisedUserManagerImpl;
145 friend class UserManagerTest;
146 friend class WallpaperManager;
147 friend class WallpaperManagerTest;
149 typedef base::hash_map<std::string, linked_ptr<UserImageManager> >
150 UserImageManagerMap;
152 ChromeUserManagerImpl();
154 // Retrieves trusted device policies and removes users from the persistent
155 // list if ephemeral users are enabled. Schedules a callback to itself if
156 // trusted device policies are not yet available.
157 void RetrieveTrustedDevicePolicies();
159 // Updates current user ownership on UI thread.
160 void UpdateOwnership();
162 // If data for a public account is marked as pending removal and the user is
163 // no longer logged into that account, removes the data.
164 void CleanUpPublicAccountNonCryptohomeDataPendingRemoval();
166 // Removes data belonging to public accounts that are no longer found on the
167 // user list. If the user is currently logged into one of these accounts, the
168 // data for that account is not removed immediately but marked as pending
169 // removal after logout.
170 void CleanUpPublicAccountNonCryptohomeData(
171 const std::vector<std::string>& old_public_accounts);
173 // Replaces the list of public accounts with those found in
174 // |device_local_accounts|. Ensures that data belonging to accounts no longer
175 // on the list is removed. Returns |true| if the list has changed.
176 // Public accounts are defined by policy. This method is called whenever an
177 // updated list of public accounts is received from policy.
178 bool UpdateAndCleanUpPublicAccounts(
179 const std::vector<policy::DeviceLocalAccount>& device_local_accounts);
181 // Updates the display name for public account |username| from policy settings
182 // associated with that username.
183 void UpdatePublicAccountDisplayName(const std::string& user_id);
185 // Notifies the UI about a change to the user list.
186 void NotifyUserListChanged();
188 // Lazily creates default user flow.
189 UserFlow* GetDefaultUserFlow() const;
191 // MultiProfileUserControllerDelegate implementation:
192 void OnUserNotAllowed(const std::string& user_email) override;
194 // Update the number of users.
195 void UpdateNumberOfUsers();
197 // Starts (or stops) automatic timezone refresh on geolocation,
198 // depending on user preferences.
199 void UpdateUserTimeZoneRefresher(Profile* profile);
201 // Interface to the signed settings store.
202 CrosSettings* cros_settings_;
204 // Interface to device-local account definitions and associated policy.
205 policy::DeviceLocalAccountPolicyService* device_local_account_policy_service_;
207 content::NotificationRegistrar registrar_;
209 // User avatar managers.
210 UserImageManagerMap user_image_managers_;
212 // Supervised user manager.
213 scoped_ptr<SupervisedUserManagerImpl> supervised_user_manager_;
215 // Session length limiter.
216 scoped_ptr<SessionLengthLimiter> session_length_limiter_;
218 typedef std::map<std::string, UserFlow*> FlowMap;
220 // Lazy-initialized default flow.
221 mutable scoped_ptr<UserFlow> default_flow_;
223 // Specific flows by user e-mail. Keys should be canonicalized before
224 // access.
225 FlowMap specific_flows_;
227 scoped_ptr<CrosSettings::ObserverSubscription> local_accounts_subscription_;
229 scoped_ptr<MultiProfileUserController> multi_profile_user_controller_;
231 // Observer for the policy that can be used to manage user images.
232 scoped_ptr<policy::CloudExternalDataPolicyObserver> avatar_policy_observer_;
234 // Observer for the policy that can be used to manage wallpapers.
235 scoped_ptr<policy::CloudExternalDataPolicyObserver>
236 wallpaper_policy_observer_;
238 base::WeakPtrFactory<ChromeUserManagerImpl> weak_factory_;
240 DISALLOW_COPY_AND_ASSIGN(ChromeUserManagerImpl);
243 } // namespace chromeos
245 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_IMPL_H_