Added affiliation IDs, that in future will be used to determine user affiliation...
[chromium-blink-merge.git] / chrome / browser / chromeos / login / users / chrome_user_manager_impl.h
blobf23dee7340f790171d10d9a1a8372629f8667262
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;
119 // ChromeUserManager implementation:
120 void SetUserAffiliation(
121 const std::string& user_email,
122 const AffiliationIDSet& user_affiliation_ids) override;
124 protected:
125 const std::string& GetApplicationLocale() const override;
126 PrefService* GetLocalState() const override;
127 void HandleUserOAuthTokenStatusChange(
128 const std::string& user_id,
129 user_manager::User::OAuthTokenStatus status) const override;
130 bool IsEnterpriseManaged() const override;
131 void LoadPublicAccounts(std::set<std::string>* users_set) override;
132 void NotifyOnLogin() override;
133 void NotifyUserAddedToSession(const user_manager::User* added_user,
134 bool user_switch_pending) override;
135 void PerformPreUserListLoadingActions() override;
136 void PerformPostUserListLoadingActions() override;
137 void PerformPostUserLoggedInActions(bool browser_restart) override;
138 void RemoveNonCryptohomeData(const std::string& user_id) override;
139 void RemoveUserInternal(const std::string& user_email,
140 user_manager::RemoveUserDelegate* delegate) override;
141 bool IsDemoApp(const std::string& user_id) const override;
142 bool IsKioskApp(const std::string& user_id) const override;
143 bool IsPublicAccountMarkedForRemoval(
144 const std::string& user_id) const override;
145 void DemoAccountLoggedIn() override;
146 void GuestUserLoggedIn() override;
147 void KioskAppLoggedIn(const std::string& app_id) override;
148 void PublicAccountUserLoggedIn(user_manager::User* user) override;
149 void RegularUserLoggedIn(const std::string& user_id) override;
150 void RegularUserLoggedInAsEphemeral(const std::string& user_id) override;
151 void SupervisedUserLoggedIn(const std::string& user_id) override;
152 bool HasPendingBootstrap(const std::string& user_id) const override;
154 private:
155 friend class SupervisedUserManagerImpl;
156 friend class UserManagerTest;
157 friend class WallpaperManager;
158 friend class WallpaperManagerTest;
160 typedef base::hash_map<std::string, linked_ptr<UserImageManager> >
161 UserImageManagerMap;
163 ChromeUserManagerImpl();
165 // Retrieves trusted device policies and removes users from the persistent
166 // list if ephemeral users are enabled. Schedules a callback to itself if
167 // trusted device policies are not yet available.
168 void RetrieveTrustedDevicePolicies();
170 // Updates current user ownership on UI thread.
171 void UpdateOwnership();
173 // If data for a public account is marked as pending removal and the user is
174 // no longer logged into that account, removes the data.
175 void CleanUpPublicAccountNonCryptohomeDataPendingRemoval();
177 // Removes data belonging to public accounts that are no longer found on the
178 // user list. If the user is currently logged into one of these accounts, the
179 // data for that account is not removed immediately but marked as pending
180 // removal after logout.
181 void CleanUpPublicAccountNonCryptohomeData(
182 const std::vector<std::string>& old_public_accounts);
184 // Replaces the list of public accounts with those found in
185 // |device_local_accounts|. Ensures that data belonging to accounts no longer
186 // on the list is removed. Returns |true| if the list has changed.
187 // Public accounts are defined by policy. This method is called whenever an
188 // updated list of public accounts is received from policy.
189 bool UpdateAndCleanUpPublicAccounts(
190 const std::vector<policy::DeviceLocalAccount>& device_local_accounts);
192 // Updates the display name for public account |username| from policy settings
193 // associated with that username.
194 void UpdatePublicAccountDisplayName(const std::string& user_id);
196 // Notifies the UI about a change to the user list.
197 void NotifyUserListChanged();
199 // Lazily creates default user flow.
200 UserFlow* GetDefaultUserFlow() const;
202 // MultiProfileUserControllerDelegate implementation:
203 void OnUserNotAllowed(const std::string& user_email) override;
205 // BootstrapManager::Delegate implementation:
206 void RemovePendingBootstrapUser(const std::string& user_id) override;
208 // Update the number of users.
209 void UpdateNumberOfUsers();
211 // Starts (or stops) automatic timezone refresh on geolocation,
212 // depending on user preferences.
213 void UpdateUserTimeZoneRefresher(Profile* profile);
215 // Interface to the signed settings store.
216 CrosSettings* cros_settings_;
218 // Interface to device-local account definitions and associated policy.
219 policy::DeviceLocalAccountPolicyService* device_local_account_policy_service_;
221 content::NotificationRegistrar registrar_;
223 // User avatar managers.
224 UserImageManagerMap user_image_managers_;
226 // Supervised user manager.
227 scoped_ptr<SupervisedUserManagerImpl> supervised_user_manager_;
229 // Session length limiter.
230 scoped_ptr<SessionLengthLimiter> session_length_limiter_;
232 typedef std::map<std::string, UserFlow*> FlowMap;
234 // Lazy-initialized default flow.
235 mutable scoped_ptr<UserFlow> default_flow_;
237 // Specific flows by user e-mail. Keys should be canonicalized before
238 // access.
239 FlowMap specific_flows_;
241 scoped_ptr<CrosSettings::ObserverSubscription> local_accounts_subscription_;
243 scoped_ptr<MultiProfileUserController> multi_profile_user_controller_;
245 // Observer for the policy that can be used to manage user images.
246 scoped_ptr<policy::CloudExternalDataPolicyObserver> avatar_policy_observer_;
248 // Observer for the policy that can be used to manage wallpapers.
249 scoped_ptr<policy::CloudExternalDataPolicyObserver>
250 wallpaper_policy_observer_;
252 scoped_ptr<BootstrapManager> bootstrap_manager_;
254 base::WeakPtrFactory<ChromeUserManagerImpl> weak_factory_;
256 DISALLOW_COPY_AND_ASSIGN(ChromeUserManagerImpl);
259 } // namespace chromeos
261 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_IMPL_H_