1 // Copyright (c) 2012 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_CHROMEOS_LOGIN_SCREEN_LOCKER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREEN_LOCKER_H_
10 #include "base/callback_forward.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/sequenced_task_runner_helpers.h"
15 #include "base/time/time.h"
16 #include "chrome/browser/chromeos/login/help_app_launcher.h"
17 #include "chrome/browser/chromeos/login/login_display.h"
18 #include "chrome/browser/chromeos/login/login_status_consumer.h"
19 #include "chrome/browser/chromeos/login/screen_locker_delegate.h"
20 #include "chrome/browser/chromeos/login/user.h"
21 #include "ui/base/accelerators/accelerator.h"
34 class ExtendedAuthenticator
;
36 class ScreenlockIconProvider
;
39 class ScreenLockerTester
;
40 class ScreenLockerViewsTester
;
41 class WebUIScreenLockerTester
;
44 // ScreenLocker creates a ScreenLockerDelegate which will display the lock UI.
45 // As well, it takes care of authenticating the user and managing a global
46 // instance of itself which will be deleted when the system is unlocked.
47 class ScreenLocker
: public LoginStatusConsumer
{
49 explicit ScreenLocker(const UserList
& users
);
51 // Returns the default instance if it has been created.
52 static ScreenLocker
* default_screen_locker() {
53 return screen_locker_
;
56 bool locked() const { return locked_
; }
58 // Initialize and show the screen locker.
61 // LoginStatusConsumer implements:
62 virtual void OnLoginFailure(const chromeos::LoginFailure
& error
) OVERRIDE
;
63 virtual void OnLoginSuccess(const UserContext
& user_context
) OVERRIDE
;
65 // Does actual unlocking once authentication is successful and all blocking
66 // animations are done.
67 void UnlockOnLoginSuccess();
69 // Authenticates the user with given |user_context|.
70 void Authenticate(const UserContext
& user_context
);
72 // Close message bubble to clear error messages.
75 // (Re)enable input field.
78 // Exit the chrome, which will sign out the current session.
81 // Displays |message| in a banner on the lock screen.
82 void ShowBannerMessage(const std::string
& message
);
84 // Shows a button inside the user pod on the lock screen with an icon.
85 void ShowUserPodButton(const std::string
& username
,
86 const gfx::Image
& icon
,
87 const base::Closure
& click_callback
);
89 // Hides the user pod button for a user.
90 void HideUserPodButton(const std::string
& username
);
92 // Set the authentication type to be used on the lock screen.
93 void SetAuthType(const std::string
& username
,
94 LoginDisplay::AuthType auth_type
,
95 const std::string
& initial_value
);
97 // Returns the authentication type used for |username|.
98 LoginDisplay::AuthType
GetAuthType(const std::string
& username
) const;
100 // Disables all UI needed and shows error bubble with |message|.
101 // If |sign_out_only| is true then all other input except "Sign Out"
102 // button is blocked.
103 void ShowErrorMessage(int error_msg_id
,
104 HelpAppLauncher::HelpTopic help_topic_id
,
107 // Returns the screen locker's delegate.
108 ScreenLockerDelegate
* delegate() const { return delegate_
.get(); }
110 // Returns the users to authenticate.
111 const UserList
& users() const { return users_
; }
113 // Allow a LoginStatusConsumer to listen for
114 // the same login events that ScreenLocker does.
115 void SetLoginStatusConsumer(chromeos::LoginStatusConsumer
* consumer
);
117 // Returns WebUI associated with screen locker implementation or NULL if
119 content::WebUI
* GetAssociatedWebUI();
121 // Initialize or uninitialize the ScreenLocker class. It listens to
122 // NOTIFICATION_SESSION_STARTED so that the screen locker accepts lock
123 // requests only after a user has logged in.
124 static void InitClass();
125 static void ShutDownClass();
127 // Handles a request from the session manager to lock the screen.
128 static void HandleLockScreenRequest();
130 // Show the screen locker.
133 // Hide the screen locker.
136 // Returns the tester
137 static test::ScreenLockerTester
* GetTester();
140 friend class base::DeleteHelper
<ScreenLocker
>;
141 friend class test::ScreenLockerTester
;
142 friend class test::ScreenLockerViewsTester
;
143 friend class test::WebUIScreenLockerTester
;
144 friend class ScreenLockerDelegate
;
146 struct AuthenticationParametersCapture
{
147 UserContext user_context
;
150 virtual ~ScreenLocker();
152 // Sets the authenticator.
153 void SetAuthenticator(Authenticator
* authenticator
);
155 // Called when the screen lock is ready.
156 void ScreenLockReady();
158 // Called when screen locker is safe to delete.
159 static void ScheduleDeletion();
161 // Returns true if |username| is found among logged in users.
162 bool IsUserLoggedIn(const std::string
& username
);
164 // Looks up user in unlock user list.
165 const User
* FindUnlockUser(const std::string
& user_id
);
167 // ScreenLockerDelegate instance in use.
168 scoped_ptr
<ScreenLockerDelegate
> delegate_
;
170 // Users that can unlock the device.
173 // Used to authenticate the user to unlock.
174 scoped_refptr
<Authenticator
> authenticator_
;
176 // Used to authenticate the user to unlock supervised users.
177 scoped_refptr
<ExtendedAuthenticator
> extended_authenticator_
;
179 // True if the screen is locked, or false otherwise. This changes
180 // from false to true, but will never change from true to
181 // false. Instead, ScreenLocker object gets deleted when unlocked.
184 // Reference to the single instance of the screen locker object.
185 // This is used to make sure there is only one screen locker instance.
186 static ScreenLocker
* screen_locker_
;
188 // The time when the screen locker object is created.
189 base::Time start_time_
;
190 // The time when the authentication is started.
191 base::Time authentication_start_time_
;
193 // Delegate to forward all login status events to.
194 // Tests can use this to receive login status events.
195 LoginStatusConsumer
* login_status_consumer_
;
197 // Number of bad login attempts in a row.
198 int incorrect_passwords_count_
;
200 // Copy of parameters passed to last call of OnLoginSuccess for usage in
201 // UnlockOnLoginSuccess().
202 scoped_ptr
<AuthenticationParametersCapture
> authentication_capture_
;
204 // Provider for button icon set by the screenlockPrivate API.
205 scoped_ptr
<ScreenlockIconProvider
> screenlock_icon_provider_
;
207 base::WeakPtrFactory
<ScreenLocker
> weak_factory_
;
209 DISALLOW_COPY_AND_ASSIGN(ScreenLocker
);
212 } // namespace chromeos
214 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREEN_LOCKER_H_