1// Copyright 2013 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_UI_WEBUI_SIGNIN_USER_MANAGER_SCREEN_HANDLER_H_
6#define CHROME_BROWSER_UI_WEBUI_SIGNIN_USER_MANAGER_SCREEN_HANDLER_H_
7
8#include <map>
9#include <string>
10
11#include "base/callback.h"
12#include "base/compiler_specific.h"
13#include "base/memory/scoped_ptr.h"
14#include "base/memory/weak_ptr.h"
15#include "chrome/browser/profiles/profile.h"
16#include "chrome/browser/profiles/profile_metrics.h"
17#include "chrome/browser/signin/screenlock_bridge.h"
18#include "chrome/browser/ui/host_desktop.h"
19#include "content/public/browser/notification_observer.h"
20#include "content/public/browser/notification_registrar.h"
21#include "content/public/browser/web_ui_message_handler.h"
22#include "google_apis/gaia/gaia_auth_consumer.h"
23
24class GaiaAuthFetcher;
25
26namespace base {
27class DictionaryValue;
28class FilePath;
29class ListValue;
30}
31
32class UserManagerScreenHandler : public content::WebUIMessageHandler,
33                                 public ScreenlockBridge::LockHandler,
34                                 public GaiaAuthConsumer,
35                                 public content::NotificationObserver {
36 public:
37  UserManagerScreenHandler();
38  virtual ~UserManagerScreenHandler();
39
40  // WebUIMessageHandler implementation.
41  virtual void RegisterMessages() OVERRIDE;
42
43  void GetLocalizedValues(base::DictionaryValue* localized_strings);
44
45  // content::NotificationObserver implementation:
46  virtual void Observe(int type,
47                       const content::NotificationSource& source,
48                       const content::NotificationDetails& details) OVERRIDE;
49
50  // ScreenlockBridge::LockHandler implementation.
51  virtual void ShowBannerMessage(const base::string16& message) OVERRIDE;
52  virtual void ShowUserPodCustomIcon(
53      const std::string& user_email,
54      const ScreenlockBridge::UserPodCustomIconOptions& icon_options) OVERRIDE;
55  virtual void HideUserPodCustomIcon(const std::string& user_email) OVERRIDE;
56  virtual void EnableInput() OVERRIDE;
57  virtual void SetAuthType(const std::string& user_email,
58                           ScreenlockBridge::LockHandler::AuthType auth_type,
59                           const base::string16& auth_value) OVERRIDE;
60  virtual ScreenlockBridge::LockHandler::AuthType GetAuthType(
61      const std::string& user_email) const OVERRIDE;
62  virtual void Unlock(const std::string& user_email) OVERRIDE;
63  virtual void AttemptEasySignin(const std::string& user_email,
64                                 const std::string& secret,
65                                 const std::string& key_label) OVERRIDE;
66
67 private:
68  // An observer for any changes to Profiles in the ProfileInfoCache so that
69  // all the visible user manager screens can be updated.
70  class ProfileUpdateObserver;
71
72  void HandleInitialize(const base::ListValue* args);
73  void HandleAddUser(const base::ListValue* args);
74  void HandleAuthenticatedLaunchUser(const base::ListValue* args);
75  void HandleLaunchGuest(const base::ListValue* args);
76  void HandleLaunchUser(const base::ListValue* args);
77  void HandleRemoveUser(const base::ListValue* args);
78  void HandleAttemptUnlock(const base::ListValue* args);
79  void HandleHardlockUserPod(const base::ListValue* args);
80
81  // Handle GAIA auth results.
82  virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE;
83  virtual void OnClientLoginFailure(const GoogleServiceAuthError& error)
84      OVERRIDE;
85
86  // Handle when Notified of a NOTIFICATION_BROWSER_WINDOW_READY event.
87  void OnBrowserWindowReady(Browser* browser);
88
89  // Sends user list to account chooser.
90  void SendUserList();
91
92  // Pass success/failure information back to the web page.
93  void ReportAuthenticationResult(bool success,
94                                  ProfileMetrics::ProfileAuth metric);
95
96  // Perform cleanup once the profile and browser are open.
97  void OnSwitchToProfileComplete(Profile* profile,
98                                 Profile::CreateStatus profile_create_status);
99
100  // Observes the ProfileInfoCache and gets notified when a profile has been
101  // modified, so that the displayed user pods can be updated.
102  scoped_ptr<ProfileUpdateObserver> profileInfoCacheObserver_;
103
104  // The host desktop type this user manager belongs to.
105  chrome::HostDesktopType desktop_type_;
106
107  // Authenticator used when local-auth fails.
108  scoped_ptr<GaiaAuthFetcher> client_login_;
109
110  // The index of the profile currently being authenticated.
111  size_t authenticating_profile_index_;
112
113  // Login password, held during on-line auth for saving later if correct.
114  std::string password_attempt_;
115
116  // URL hash, used to key post-profile actions if present.
117  std::string url_hash_;
118
119  typedef std::map<std::string, ScreenlockBridge::LockHandler::AuthType>
120      UserAuthTypeMap;
121  UserAuthTypeMap user_auth_type_map_;
122
123  base::WeakPtrFactory<UserManagerScreenHandler> weak_ptr_factory_;
124
125  content::NotificationRegistrar registrar_;
126
127  DISALLOW_COPY_AND_ASSIGN(UserManagerScreenHandler);
128};
129
130#endif  // CHROME_BROWSER_UI_WEBUI_SIGNIN_USER_MANAGER_SCREEN_HANDLER_H_
131