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 virtual ~UserManagerScreenHandler();
40 // WebUIMessageHandler implementation.
41 virtual void RegisterMessages() override
;
43 void GetLocalizedValues(base::DictionaryValue
* localized_strings
);
45 // content::NotificationObserver implementation:
46 virtual void Observe(int type
,
47 const content::NotificationSource
& source
,
48 const content::NotificationDetails
& details
) override
;
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
;
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 virtual void OnClientLoginSuccess(const ClientLoginResult
& result
) override
;
83 virtual void OnClientLoginFailure(const GoogleServiceAuthError
& error
)
86 // Handle when Notified of a NOTIFICATION_BROWSER_WINDOW_READY event.
87 void OnBrowserWindowReady(Browser
* browser
);
89 // Sends user list to account chooser.
92 // Pass success/failure information back to the web page.
93 void ReportAuthenticationResult(bool success
,
94 ProfileMetrics::ProfileAuth metric
);
96 // Perform cleanup once the profile and browser are open.
97 void OnSwitchToProfileComplete(Profile
* profile
,
98 Profile::CreateStatus profile_create_status
);
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_
;
104 // The host desktop type this user manager belongs to.
105 chrome::HostDesktopType desktop_type_
;
107 // Authenticator used when local-auth fails.
108 scoped_ptr
<GaiaAuthFetcher
> client_login_
;
110 // The index of the profile currently being authenticated.
111 size_t authenticating_profile_index_
;
113 // Login password, held during on-line auth for saving later if correct.
114 std::string password_attempt_
;
116 // URL hash, used to key post-profile actions if present.
117 std::string url_hash_
;
119 typedef std::map
<std::string
, ScreenlockBridge::LockHandler::AuthType
>
121 UserAuthTypeMap user_auth_type_map_
;
123 base::WeakPtrFactory
<UserManagerScreenHandler
> weak_ptr_factory_
;
125 content::NotificationRegistrar registrar_
;
127 DISALLOW_COPY_AND_ASSIGN(UserManagerScreenHandler
);
130 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_USER_MANAGER_SCREEN_HANDLER_H_