| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREEN_LOCKER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREEN_LOCKER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 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 "chrome/browser/signin/screenlock_bridge.h" | |
| 22 #include "ui/base/accelerators/accelerator.h" | |
| 23 | |
| 24 namespace content { | |
| 25 class WebUI; | |
| 26 } | |
| 27 | |
| 28 namespace gfx { | |
| 29 class Image; | |
| 30 } | |
| 31 | |
| 32 namespace chromeos { | |
| 33 | |
| 34 class Authenticator; | |
| 35 class ExtendedAuthenticator; | |
| 36 class LoginFailure; | |
| 37 class ScreenlockIconProvider; | |
| 38 | |
| 39 namespace test { | |
| 40 class ScreenLockerTester; | |
| 41 class ScreenLockerViewsTester; | |
| 42 class WebUIScreenLockerTester; | |
| 43 } // namespace test | |
| 44 | |
| 45 // ScreenLocker creates a ScreenLockerDelegate which will display the lock UI. | |
| 46 // As well, it takes care of authenticating the user and managing a global | |
| 47 // instance of itself which will be deleted when the system is unlocked. | |
| 48 class ScreenLocker : public LoginStatusConsumer, | |
| 49 public ScreenlockBridge::LockHandler { | |
| 50 public: | |
| 51 explicit ScreenLocker(const UserList& users); | |
| 52 | |
| 53 // Returns the default instance if it has been created. | |
| 54 static ScreenLocker* default_screen_locker() { | |
| 55 return screen_locker_; | |
| 56 } | |
| 57 | |
| 58 bool locked() const { return locked_; } | |
| 59 | |
| 60 // Initialize and show the screen locker. | |
| 61 void Init(); | |
| 62 | |
| 63 // LoginStatusConsumer: | |
| 64 virtual void OnLoginFailure(const chromeos::LoginFailure& error) OVERRIDE; | |
| 65 virtual void OnLoginSuccess(const UserContext& user_context) OVERRIDE; | |
| 66 | |
| 67 // Does actual unlocking once authentication is successful and all blocking | |
| 68 // animations are done. | |
| 69 void UnlockOnLoginSuccess(); | |
| 70 | |
| 71 // Authenticates the user with given |user_context|. | |
| 72 void Authenticate(const UserContext& user_context); | |
| 73 | |
| 74 // Close message bubble to clear error messages. | |
| 75 void ClearErrors(); | |
| 76 | |
| 77 // Exit the chrome, which will sign out the current session. | |
| 78 void Signout(); | |
| 79 | |
| 80 // ScreenlockBridge::LockHandler: | |
| 81 virtual void ShowBannerMessage(const std::string& message) OVERRIDE; | |
| 82 virtual void ShowUserPodButton(const std::string& username, | |
| 83 const gfx::Image& icon, | |
| 84 const base::Closure& click_callback) OVERRIDE; | |
| 85 virtual void HideUserPodButton(const std::string& username) OVERRIDE; | |
| 86 virtual void EnableInput() OVERRIDE; | |
| 87 virtual void SetAuthType(const std::string& username, | |
| 88 ScreenlockBridge::LockHandler::AuthType auth_type, | |
| 89 const std::string& initial_value) OVERRIDE; | |
| 90 virtual ScreenlockBridge::LockHandler::AuthType GetAuthType( | |
| 91 const std::string& username) const OVERRIDE; | |
| 92 virtual void Unlock(const std::string& user_email) OVERRIDE; | |
| 93 | |
| 94 // Disables all UI needed and shows error bubble with |message|. | |
| 95 // If |sign_out_only| is true then all other input except "Sign Out" | |
| 96 // button is blocked. | |
| 97 void ShowErrorMessage(int error_msg_id, | |
| 98 HelpAppLauncher::HelpTopic help_topic_id, | |
| 99 bool sign_out_only); | |
| 100 | |
| 101 // Returns the screen locker's delegate. | |
| 102 ScreenLockerDelegate* delegate() const { return delegate_.get(); } | |
| 103 | |
| 104 // Returns the users to authenticate. | |
| 105 const UserList& users() const { return users_; } | |
| 106 | |
| 107 // Allow a LoginStatusConsumer to listen for | |
| 108 // the same login events that ScreenLocker does. | |
| 109 void SetLoginStatusConsumer(chromeos::LoginStatusConsumer* consumer); | |
| 110 | |
| 111 // Returns WebUI associated with screen locker implementation or NULL if | |
| 112 // there isn't one. | |
| 113 content::WebUI* GetAssociatedWebUI(); | |
| 114 | |
| 115 // Initialize or uninitialize the ScreenLocker class. It listens to | |
| 116 // NOTIFICATION_SESSION_STARTED so that the screen locker accepts lock | |
| 117 // requests only after a user has logged in. | |
| 118 static void InitClass(); | |
| 119 static void ShutDownClass(); | |
| 120 | |
| 121 // Handles a request from the session manager to lock the screen. | |
| 122 static void HandleLockScreenRequest(); | |
| 123 | |
| 124 // Show the screen locker. | |
| 125 static void Show(); | |
| 126 | |
| 127 // Hide the screen locker. | |
| 128 static void Hide(); | |
| 129 | |
| 130 // Returns the tester | |
| 131 static test::ScreenLockerTester* GetTester(); | |
| 132 | |
| 133 private: | |
| 134 friend class base::DeleteHelper<ScreenLocker>; | |
| 135 friend class test::ScreenLockerTester; | |
| 136 friend class test::ScreenLockerViewsTester; | |
| 137 friend class test::WebUIScreenLockerTester; | |
| 138 friend class ScreenLockerDelegate; | |
| 139 | |
| 140 struct AuthenticationParametersCapture { | |
| 141 UserContext user_context; | |
| 142 }; | |
| 143 | |
| 144 virtual ~ScreenLocker(); | |
| 145 | |
| 146 // Sets the authenticator. | |
| 147 void SetAuthenticator(Authenticator* authenticator); | |
| 148 | |
| 149 // Called when the screen lock is ready. | |
| 150 void ScreenLockReady(); | |
| 151 | |
| 152 // Called when screen locker is safe to delete. | |
| 153 static void ScheduleDeletion(); | |
| 154 | |
| 155 // Returns true if |username| is found among logged in users. | |
| 156 bool IsUserLoggedIn(const std::string& username); | |
| 157 | |
| 158 // Looks up user in unlock user list. | |
| 159 const User* FindUnlockUser(const std::string& user_id); | |
| 160 | |
| 161 // ScreenLockerDelegate instance in use. | |
| 162 scoped_ptr<ScreenLockerDelegate> delegate_; | |
| 163 | |
| 164 // Users that can unlock the device. | |
| 165 UserList users_; | |
| 166 | |
| 167 // Used to authenticate the user to unlock. | |
| 168 scoped_refptr<Authenticator> authenticator_; | |
| 169 | |
| 170 // Used to authenticate the user to unlock supervised users. | |
| 171 scoped_refptr<ExtendedAuthenticator> extended_authenticator_; | |
| 172 | |
| 173 // True if the screen is locked, or false otherwise. This changes | |
| 174 // from false to true, but will never change from true to | |
| 175 // false. Instead, ScreenLocker object gets deleted when unlocked. | |
| 176 bool locked_; | |
| 177 | |
| 178 // Reference to the single instance of the screen locker object. | |
| 179 // This is used to make sure there is only one screen locker instance. | |
| 180 static ScreenLocker* screen_locker_; | |
| 181 | |
| 182 // The time when the screen locker object is created. | |
| 183 base::Time start_time_; | |
| 184 // The time when the authentication is started. | |
| 185 base::Time authentication_start_time_; | |
| 186 | |
| 187 // Delegate to forward all login status events to. | |
| 188 // Tests can use this to receive login status events. | |
| 189 LoginStatusConsumer* login_status_consumer_; | |
| 190 | |
| 191 // Number of bad login attempts in a row. | |
| 192 int incorrect_passwords_count_; | |
| 193 | |
| 194 // Copy of parameters passed to last call of OnLoginSuccess for usage in | |
| 195 // UnlockOnLoginSuccess(). | |
| 196 scoped_ptr<AuthenticationParametersCapture> authentication_capture_; | |
| 197 | |
| 198 // Provider for button icon set by the screenlockPrivate API. | |
| 199 scoped_ptr<ScreenlockIconProvider> screenlock_icon_provider_; | |
| 200 | |
| 201 base::WeakPtrFactory<ScreenLocker> weak_factory_; | |
| 202 | |
| 203 DISALLOW_COPY_AND_ASSIGN(ScreenLocker); | |
| 204 }; | |
| 205 | |
| 206 } // namespace chromeos | |
| 207 | |
| 208 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREEN_LOCKER_H_ | |
| OLD | NEW |