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 "chrome/browser/profiles/profile_metrics.h"
15#include "chrome/browser/signin/screenlock_bridge.h"
16#include "chrome/browser/ui/host_desktop.h"
17#include "content/public/browser/web_ui_message_handler.h"
18#include "google_apis/gaia/gaia_auth_consumer.h"
19
20class GaiaAuthFetcher;
21
22namespace base {
23class DictionaryValue;
24class FilePath;
25class ListValue;
26}
27
28class UserManagerScreenHandler : public content::WebUIMessageHandler,
29                                 public ScreenlockBridge::LockHandler,
30                                 public GaiaAuthConsumer {
31 public:
32  UserManagerScreenHandler();
33  virtual ~UserManagerScreenHandler();
34
35  // WebUIMessageHandler implementation.
36  virtual void RegisterMessages() OVERRIDE;
37
38  void GetLocalizedValues(base::DictionaryValue* localized_strings);
39
40  // ScreenlockBridge::LockHandler implementation.
41  virtual void ShowBannerMessage(const std::string& message) OVERRIDE;
42  virtual void ShowUserPodCustomIcon(const std::string& user_email,
43                                     const gfx::Image& icon) OVERRIDE;
44  virtual void HideUserPodCustomIcon(const std::string& user_email) OVERRIDE;
45  virtual void EnableInput() OVERRIDE;
46  virtual void SetAuthType(const std::string& user_email,
47                           ScreenlockBridge::LockHandler::AuthType auth_type,
48                           const std::string& auth_value) OVERRIDE;
49  virtual ScreenlockBridge::LockHandler::AuthType GetAuthType(
50      const std::string& user_email) const OVERRIDE;
51  virtual void Unlock(const std::string& user_email) OVERRIDE;
52
53 private:
54  // An observer for any changes to Profiles in the ProfileInfoCache so that
55  // all the visible user manager screens can be updated.
56  class ProfileUpdateObserver;
57
58  void HandleInitialize(const base::ListValue* args);
59  void HandleAddUser(const base::ListValue* args);
60  void HandleAuthenticatedLaunchUser(const base::ListValue* args);
61  void HandleLaunchGuest(const base::ListValue* args);
62  void HandleLaunchUser(const base::ListValue* args);
63  void HandleRemoveUser(const base::ListValue* args);
64  void HandleAttemptUnlock(const base::ListValue* args);
65
66  // Handle GAIA auth results.
67  virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE;
68  virtual void OnClientLoginFailure(const GoogleServiceAuthError& error)
69      OVERRIDE;
70
71  // Sends user list to account chooser.
72  void SendUserList();
73
74  // Pass success/failure information back to the web page.
75  void ReportAuthenticationResult(bool success,
76                                  ProfileMetrics::ProfileAuth metric);
77
78  // Observes the ProfileInfoCache and gets notified when a profile has been
79  // modified, so that the displayed user pods can be updated.
80  scoped_ptr<ProfileUpdateObserver> profileInfoCacheObserver_;
81
82  // The host desktop type this user manager belongs to.
83  chrome::HostDesktopType desktop_type_;
84
85  // Authenticator used when local-auth fails.
86  scoped_ptr<GaiaAuthFetcher> client_login_;
87
88  // The index of the profile currently being authenticated.
89  size_t authenticating_profile_index_;
90
91  // Login password, held during on-line auth for saving later if correct.
92  std::string password_attempt_;
93
94  typedef std::map<std::string, ScreenlockBridge::LockHandler::AuthType>
95      UserAuthTypeMap;
96  UserAuthTypeMap user_auth_type_map_;
97
98  DISALLOW_COPY_AND_ASSIGN(UserManagerScreenHandler);
99};
100
101#endif  // CHROME_BROWSER_UI_WEBUI_SIGNIN_USER_MANAGER_SCREEN_HANDLER_H_
102