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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_USER_MANAGER_SCREEN_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_USER_MANAGER_SCREEN_HANDLER_H_
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"
24 class GaiaAuthFetcher
;
27 class DictionaryValue
;
32 class UserManagerScreenHandler
: public content::WebUIMessageHandler
,
33 public ScreenlockBridge::LockHandler
,
34 public GaiaAuthConsumer
,
35 public content::NotificationObserver
{
37 UserManagerScreenHandler();
38 ~UserManagerScreenHandler() override
;
40 // WebUIMessageHandler implementation.
41 void RegisterMessages() override
;
43 void GetLocalizedValues(base::DictionaryValue
* localized_strings
);
45 // content::NotificationObserver implementation:
46 void Observe(int type
,
47 const content::NotificationSource
& source
,
48 const content::NotificationDetails
& details
) override
;
50 // ScreenlockBridge::LockHandler implementation.
51 void ShowBannerMessage(const base::string16
& message
) override
;
52 void ShowUserPodCustomIcon(
53 const std::string
& user_email
,
54 const ScreenlockBridge::UserPodCustomIconOptions
& icon_options
) override
;
55 void HideUserPodCustomIcon(const std::string
& user_email
) override
;
56 void EnableInput() override
;
57 void SetAuthType(const std::string
& user_email
,
58 ScreenlockBridge::LockHandler::AuthType auth_type
,
59 const base::string16
& auth_value
) override
;
60 AuthType
GetAuthType(const std::string
& user_email
) const override
;
61 ScreenType
GetScreenType() const override
;
62 void Unlock(const std::string
& user_email
) override
;
63 void AttemptEasySignin(const std::string
& user_email
,
64 const std::string
& secret
,
65 const std::string
& key_label
) override
;
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
;
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
);
81 // Handle GAIA auth results.
82 void OnClientLoginSuccess(const ClientLoginResult
& result
) override
;
83 void OnClientLoginFailure(const GoogleServiceAuthError
& error
) override
;
85 // Handle when Notified of a NOTIFICATION_BROWSER_WINDOW_READY event.
86 void OnBrowserWindowReady(Browser
* browser
);
88 // Sends user list to account chooser.
91 // Pass success/failure information back to the web page.
92 void ReportAuthenticationResult(bool success
,
93 ProfileMetrics::ProfileAuth metric
);
95 // Perform cleanup once the profile and browser are open.
96 void OnSwitchToProfileComplete(Profile
* profile
,
97 Profile::CreateStatus profile_create_status
);
99 // Observes the ProfileInfoCache and gets notified when a profile has been
100 // modified, so that the displayed user pods can be updated.
101 scoped_ptr
<ProfileUpdateObserver
> profileInfoCacheObserver_
;
103 // The host desktop type this user manager belongs to.
104 chrome::HostDesktopType desktop_type_
;
106 // Authenticator used when local-auth fails.
107 scoped_ptr
<GaiaAuthFetcher
> client_login_
;
109 // The index of the profile currently being authenticated.
110 size_t authenticating_profile_index_
;
112 // Login password, held during on-line auth for saving later if correct.
113 std::string password_attempt_
;
115 // URL hash, used to key post-profile actions if present.
116 std::string url_hash_
;
118 typedef std::map
<std::string
, ScreenlockBridge::LockHandler::AuthType
>
120 UserAuthTypeMap user_auth_type_map_
;
122 content::NotificationRegistrar registrar_
;
124 base::WeakPtrFactory
<UserManagerScreenHandler
> weak_ptr_factory_
;
126 DISALLOW_COPY_AND_ASSIGN(UserManagerScreenHandler
);
129 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_USER_MANAGER_SCREEN_HANDLER_H_