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