Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: chrome/browser/chromeos/login/lock/screen_locker.cc

Issue 2859363003: cros: Initial structure for views-based lock. (Closed)
Patch Set: Address comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/login/lock/screen_locker.h" 5 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/login/views/lock_screen.h"
11 #include "ash/public/interfaces/constants.mojom.h"
12 #include "ash/public/interfaces/session_controller.mojom.h"
10 #include "ash/shell.h" 13 #include "ash/shell.h"
11 #include "ash/wm/window_state.h" 14 #include "ash/wm/window_state.h"
12 #include "ash/wm/window_state_aura.h" 15 #include "ash/wm/window_state_aura.h"
13 #include "ash/wm/window_util.h" 16 #include "ash/wm/window_util.h"
14 #include "ash/wm/wm_event.h" 17 #include "ash/wm/wm_event.h"
15 #include "base/bind.h" 18 #include "base/bind.h"
16 #include "base/command_line.h" 19 #include "base/command_line.h"
17 #include "base/lazy_instance.h" 20 #include "base/lazy_instance.h"
18 #include "base/location.h" 21 #include "base/location.h"
19 #include "base/macros.h" 22 #include "base/macros.h"
(...skipping 19 matching lines...) Expand all
39 #include "chrome/browser/signin/easy_unlock_service.h" 42 #include "chrome/browser/signin/easy_unlock_service.h"
40 #include "chrome/browser/signin/signin_manager_factory.h" 43 #include "chrome/browser/signin/signin_manager_factory.h"
41 #include "chrome/browser/ui/ash/ash_util.h" 44 #include "chrome/browser/ui/ash/ash_util.h"
42 #include "chrome/browser/ui/ash/session_controller_client.h" 45 #include "chrome/browser/ui/ash/session_controller_client.h"
43 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h" 46 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h"
44 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h" 47 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h"
45 #include "chrome/common/chrome_switches.h" 48 #include "chrome/common/chrome_switches.h"
46 #include "chrome/grit/browser_resources.h" 49 #include "chrome/grit/browser_resources.h"
47 #include "chrome/grit/generated_resources.h" 50 #include "chrome/grit/generated_resources.h"
48 #include "chromeos/audio/chromeos_sounds.h" 51 #include "chromeos/audio/chromeos_sounds.h"
52 #include "chromeos/chromeos_switches.h"
49 #include "chromeos/dbus/biod/constants.pb.h" 53 #include "chromeos/dbus/biod/constants.pb.h"
50 #include "chromeos/dbus/dbus_thread_manager.h" 54 #include "chromeos/dbus/dbus_thread_manager.h"
51 #include "chromeos/dbus/session_manager_client.h" 55 #include "chromeos/dbus/session_manager_client.h"
52 #include "chromeos/login/auth/authenticator.h" 56 #include "chromeos/login/auth/authenticator.h"
53 #include "chromeos/login/auth/extended_authenticator.h" 57 #include "chromeos/login/auth/extended_authenticator.h"
54 #include "chromeos/network/portal_detector/network_portal_detector.h" 58 #include "chromeos/network/portal_detector/network_portal_detector.h"
55 #include "components/session_manager/core/session_manager.h" 59 #include "components/session_manager/core/session_manager.h"
56 #include "components/signin/core/browser/signin_manager.h" 60 #include "components/signin/core/browser/signin_manager.h"
57 #include "components/user_manager/user_manager.h" 61 #include "components/user_manager/user_manager.h"
58 #include "components/user_manager/user_type.h" 62 #include "components/user_manager/user_type.h"
59 #include "content/public/browser/browser_thread.h" 63 #include "content/public/browser/browser_thread.h"
60 #include "content/public/browser/notification_service.h" 64 #include "content/public/browser/notification_service.h"
61 #include "content/public/browser/url_data_source.h" 65 #include "content/public/browser/url_data_source.h"
62 #include "content/public/browser/web_contents.h" 66 #include "content/public/browser/web_contents.h"
63 #include "content/public/browser/web_ui.h" 67 #include "content/public/browser/web_ui.h"
64 #include "content/public/common/service_manager_connection.h" 68 #include "content/public/common/service_manager_connection.h"
65 #include "media/audio/sounds/sounds_manager.h" 69 #include "media/audio/sounds/sounds_manager.h"
66 #include "services/device/public/interfaces/constants.mojom.h" 70 #include "services/device/public/interfaces/constants.mojom.h"
67 #include "services/service_manager/public/cpp/connector.h" 71 #include "services/service_manager/public/cpp/connector.h"
68 #include "ui/base/resource/resource_bundle.h" 72 #include "ui/base/resource/resource_bundle.h"
73 #include "ui/display/display.h"
74 #include "ui/display/screen.h"
69 #include "ui/gfx/image/image.h" 75 #include "ui/gfx/image/image.h"
70 #include "url/gurl.h" 76 #include "url/gurl.h"
71 77
72 using base::UserMetricsAction; 78 using base::UserMetricsAction;
73 using content::BrowserThread; 79 using content::BrowserThread;
74 80
75 namespace chromeos { 81 namespace chromeos {
76 82
77 namespace { 83 namespace {
78 84
79 // Timeout for unlock animation guard - some animations may be required to run 85 // Timeout for unlock animation guard - some animations may be required to run
80 // on successful authentication before unlocking, but we want to be sure that 86 // on successful authentication before unlocking, but we want to be sure that
81 // unlock happens even if animations are broken. 87 // unlock happens even if animations are broken.
82 const int kUnlockGuardTimeoutMs = 400; 88 const int kUnlockGuardTimeoutMs = 400;
83 89
90 // Returns true if we are using md-based login/lock.
91 bool IsUsingMdLogin() {
92 return base::CommandLine::ForCurrentProcess()->HasSwitch(
93 chromeos::switches::kShowMdLogin);
94 }
95
84 // Returns true if fingerprint authentication is available for one of the 96 // Returns true if fingerprint authentication is available for one of the
85 // |users|. 97 // |users|.
86 bool IsFingerprintAuthenticationAvailableForUsers( 98 bool IsFingerprintAuthenticationAvailableForUsers(
87 const user_manager::UserList& users) { 99 const user_manager::UserList& users) {
88 for (auto* user : users) { 100 for (auto* user : users) {
89 quick_unlock::QuickUnlockStorage* quick_unlock_storage = 101 quick_unlock::QuickUnlockStorage* quick_unlock_storage =
90 quick_unlock::QuickUnlockFactory::GetForUser(user); 102 quick_unlock::QuickUnlockFactory::GetForUser(user);
91 if (quick_unlock_storage && 103 if (quick_unlock_storage &&
92 quick_unlock_storage->IsFingerprintAuthenticationAvailable()) { 104 quick_unlock_storage->IsFingerprintAuthenticationAvailable()) {
93 return true; 105 return true;
(...skipping 10 matching lines...) Expand all
104 ScreenLockObserver() : session_started_(false) { 116 ScreenLockObserver() : session_started_(false) {
105 registrar_.Add(this, 117 registrar_.Add(this,
106 chrome::NOTIFICATION_SESSION_STARTED, 118 chrome::NOTIFICATION_SESSION_STARTED,
107 content::NotificationService::AllSources()); 119 content::NotificationService::AllSources());
108 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate(this); 120 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate(this);
109 } 121 }
110 122
111 ~ScreenLockObserver() override { 123 ~ScreenLockObserver() override {
112 if (DBusThreadManager::IsInitialized()) { 124 if (DBusThreadManager::IsInitialized()) {
113 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate( 125 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate(
114 NULL); 126 nullptr);
115 } 127 }
116 } 128 }
117 129
118 bool session_started() const { return session_started_; } 130 bool session_started() const { return session_started_; }
119 131
120 // SessionManagerClient::StubDelegate overrides: 132 // SessionManagerClient::StubDelegate overrides:
121 void LockScreenForStub() override { ScreenLocker::HandleLockScreenRequest(); } 133 void LockScreenForStub() override { ScreenLocker::HandleLockScreenRequest(); }
122 134
123 // NotificationObserver overrides: 135 // NotificationObserver overrides:
124 void Observe(int type, 136 void Observe(int type,
(...skipping 21 matching lines...) Expand all
146 ScreenLocker::HandleLockScreenRequest(); 158 ScreenLocker::HandleLockScreenRequest();
147 } 159 }
148 160
149 private: 161 private:
150 bool session_started_; 162 bool session_started_;
151 content::NotificationRegistrar registrar_; 163 content::NotificationRegistrar registrar_;
152 164
153 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); 165 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver);
154 }; 166 };
155 167
156 ScreenLockObserver* g_screen_lock_observer = NULL; 168 // Stubbed delegate that will eventually be replaced by mojo calls.
169 class StubDelegate : public ScreenLocker::Delegate {
170 public:
171 StubDelegate() = default;
172 ~StubDelegate() override = default;
173
174 // ScreenLocker::Delegate:
175 void SetPasswordInputEnabled(bool enabled) override { NOTIMPLEMENTED(); }
176 void ShowErrorMessage(int error_msg_id,
177 HelpAppLauncher::HelpTopic help_topic_id) override {
178 NOTIMPLEMENTED();
179 }
180 void ClearErrors() override { NOTIMPLEMENTED(); }
181 void AnimateAuthenticationSuccess() override { NOTIMPLEMENTED(); }
182 void OnLockWebUIReady() override { NOTIMPLEMENTED(); }
183 void OnLockBackgroundDisplayed() override { NOTIMPLEMENTED(); }
184 void OnHeaderBarVisible() override { NOTIMPLEMENTED(); }
185 void OnAshLockAnimationFinished() override { NOTIMPLEMENTED(); }
186 void SetFingerprintState(const AccountId& account_id,
187 ScreenLocker::FingerprintState state) override {
188 NOTIMPLEMENTED();
189 }
190 content::WebContents* GetWebContents() override { return nullptr; }
191
192 private:
193 DISALLOW_COPY_AND_ASSIGN(StubDelegate);
194 };
195
196 ScreenLockObserver* g_screen_lock_observer = nullptr;
157 197
158 } // namespace 198 } // namespace
159 199
160 // static 200 // static
161 ScreenLocker* ScreenLocker::screen_locker_ = NULL; 201 ScreenLocker* ScreenLocker::screen_locker_ = nullptr;
202
203 //////////////////////////////////////////////////////////////////////////////
204 // ScreenLocker::Delegate, public:
205
206 ScreenLocker::Delegate::Delegate() = default;
207
208 ScreenLocker::Delegate::~Delegate() = default;
162 209
163 ////////////////////////////////////////////////////////////////////////////// 210 //////////////////////////////////////////////////////////////////////////////
164 // ScreenLocker, public: 211 // ScreenLocker, public:
165 212
166 ScreenLocker::ScreenLocker(const user_manager::UserList& users) 213 ScreenLocker::ScreenLocker(const user_manager::UserList& users)
167 : users_(users), binding_(this), weak_factory_(this) { 214 : users_(users), binding_(this), weak_factory_(this) {
168 DCHECK(!screen_locker_); 215 DCHECK(!screen_locker_);
169 screen_locker_ = this; 216 screen_locker_ = this;
170 217
171 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 218 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
172 media::SoundsManager* manager = media::SoundsManager::Get(); 219 media::SoundsManager* manager = media::SoundsManager::Get();
173 manager->Initialize(SOUND_LOCK, 220 manager->Initialize(SOUND_LOCK,
174 bundle.GetRawDataResource(IDR_SOUND_LOCK_WAV)); 221 bundle.GetRawDataResource(IDR_SOUND_LOCK_WAV));
175 manager->Initialize(SOUND_UNLOCK, 222 manager->Initialize(SOUND_UNLOCK,
176 bundle.GetRawDataResource(IDR_SOUND_UNLOCK_WAV)); 223 bundle.GetRawDataResource(IDR_SOUND_UNLOCK_WAV));
177 service_manager::Connector* connector = 224 service_manager::Connector* connector =
178 content::ServiceManagerConnection::GetForProcess()->GetConnector(); 225 content::ServiceManagerConnection::GetForProcess()->GetConnector();
179 connector->BindInterface(device::mojom::kServiceName, &fp_service_); 226 connector->BindInterface(device::mojom::kServiceName, &fp_service_);
180 fp_service_->AddFingerprintObserver(binding_.CreateInterfacePtrAndBind()); 227 fp_service_->AddFingerprintObserver(binding_.CreateInterfacePtrAndBind());
181 } 228 }
182 229
183 void ScreenLocker::Init() { 230 void ScreenLocker::Init() {
184 input_method::InputMethodManager* imm = 231 input_method::InputMethodManager* imm =
185 input_method::InputMethodManager::Get(); 232 input_method::InputMethodManager::Get();
186 saved_ime_state_ = imm->GetActiveIMEState(); 233 saved_ime_state_ = imm->GetActiveIMEState();
187 imm->SetState(saved_ime_state_->Clone()); 234 imm->SetState(saved_ime_state_->Clone());
188 235
189 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); 236 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this);
190 extended_authenticator_ = ExtendedAuthenticator::Create(this); 237 extended_authenticator_ = ExtendedAuthenticator::Create(this);
191 web_ui_.reset(new WebUIScreenLocker(this)); 238 if (IsUsingMdLogin()) {
192 web_ui()->LockScreen(); 239 // Create delegate that will eventually call into the views-based lock
240 // screen via mojo.
241 delegate_ = new StubDelegate();
242 owns_delegate_ = true;
193 243
194 // Ownership of |icon_image_source| is passed. 244 // Create and display lock screen.
195 screenlock_icon_provider_.reset(new ScreenlockIconProvider); 245 // TODO(jdufualt): LockWindow should live in ash.
196 ScreenlockIconSource* screenlock_icon_source = 246 // TODO(jdufault): Calling ash::ShowLockScreenInWidget should be a mojo
197 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); 247 // call. We should only set the session state to locked after the mojo call
198 content::URLDataSource::Add(web_ui()->GetWebContents()->GetBrowserContext(), 248 // has completed.
199 screenlock_icon_source); 249 LockWindow* lock_window = new LockWindow();
250 lock_window->SetBounds(
251 display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
252 ash::ShowLockScreenInWidget(lock_window);
253 session_manager::SessionManager::Get()->SetSessionState(
254 session_manager::SessionState::LOCKED);
255 } else {
256 web_ui_.reset(new WebUIScreenLocker(this));
257 delegate_ = web_ui_.get();
258 owns_delegate_ = false;
259 web_ui_->LockScreen();
260
261 // Ownership of |icon_image_source| is passed.
262 screenlock_icon_provider_ = base::MakeUnique<ScreenlockIconProvider>();
263 ScreenlockIconSource* screenlock_icon_source =
264 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr());
265 content::URLDataSource::Add(web_ui_->web_contents()->GetBrowserContext(),
266 screenlock_icon_source);
267 }
200 268
201 // Start locking on ash side. 269 // Start locking on ash side.
202 SessionControllerClient::Get()->StartLock(base::Bind( 270 SessionControllerClient::Get()->StartLock(base::Bind(
203 &ScreenLocker::OnStartLockCallback, weak_factory_.GetWeakPtr())); 271 &ScreenLocker::OnStartLockCallback, weak_factory_.GetWeakPtr()));
204 } 272 }
205 273
206 void ScreenLocker::OnAuthFailure(const AuthFailure& error) { 274 void ScreenLocker::OnAuthFailure(const AuthFailure& error) {
207 base::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); 275 base::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure"));
208 if (authentication_start_time_.is_null()) { 276 if (authentication_start_time_.is_null()) {
209 LOG(ERROR) << "Start time is not set at authentication failure"; 277 LOG(ERROR) << "Start time is not set at authentication failure";
210 } else { 278 } else {
211 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; 279 base::TimeDelta delta = base::Time::Now() - authentication_start_time_;
212 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)"; 280 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)";
213 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); 281 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta);
214 } 282 }
215 283
216 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure", 284 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure",
217 unlock_attempt_type_, UnlockType::AUTH_COUNT); 285 unlock_attempt_type_, UnlockType::AUTH_COUNT);
218 286
219 EnableInput(); 287 EnableInput();
220 // Don't enable signout button here as we're showing 288 // Don't enable signout button here as we're showing
221 // MessageBubble. 289 // MessageBubble.
222 290
223 web_ui()->ShowErrorMessage(incorrect_passwords_count_++ 291 delegate_->ShowErrorMessage(incorrect_passwords_count_++
224 ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME 292 ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME
225 : IDS_LOGIN_ERROR_AUTHENTICATING, 293 : IDS_LOGIN_ERROR_AUTHENTICATING,
226 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); 294 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT);
227 295
228 if (auth_status_consumer_) 296 if (auth_status_consumer_)
229 auth_status_consumer_->OnAuthFailure(error); 297 auth_status_consumer_->OnAuthFailure(error);
230 } 298 }
231 299
232 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { 300 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) {
233 incorrect_passwords_count_ = 0; 301 incorrect_passwords_count_ = 0;
234 if (authentication_start_time_.is_null()) { 302 if (authentication_start_time_.is_null()) {
235 if (user_context.GetAccountId().is_valid()) 303 if (user_context.GetAccountId().is_valid())
236 LOG(ERROR) << "Start time is not set at authentication success"; 304 LOG(ERROR) << "Start time is not set at authentication success";
237 } else { 305 } else {
238 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; 306 base::TimeDelta delta = base::Time::Now() - authentication_start_time_;
239 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; 307 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)";
240 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationSuccessTime", delta); 308 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationSuccessTime", delta);
241 } 309 }
242 310
243 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationSuccess", 311 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationSuccess",
244 unlock_attempt_type_, UnlockType::AUTH_COUNT); 312 unlock_attempt_type_, UnlockType::AUTH_COUNT);
245 313
246 const user_manager::User* user = 314 const user_manager::User* user =
247 user_manager::UserManager::Get()->FindUser(user_context.GetAccountId()); 315 user_manager::UserManager::Get()->FindUser(user_context.GetAccountId());
248 if (user) { 316 if (user) {
249 if (!user->is_active()) { 317 if (!user->is_active()) {
250 saved_ime_state_ = NULL; 318 saved_ime_state_ = nullptr;
251 user_manager::UserManager::Get()->SwitchActiveUser( 319 user_manager::UserManager::Get()->SwitchActiveUser(
252 user_context.GetAccountId()); 320 user_context.GetAccountId());
253 } 321 }
254 322
255 // Reset the number of PIN attempts available to the user. We always do this 323 // Reset the number of PIN attempts available to the user. We always do this
256 // because: 324 // because:
257 // 1. If the user signed in with a PIN, that means they should be able to 325 // 1. If the user signed in with a PIN, that means they should be able to
258 // continue signing in with a PIN. 326 // continue signing in with a PIN.
259 // 2. If the user signed in with cryptohome keys, then the PIN timeout is 327 // 2. If the user signed in with cryptohome keys, then the PIN timeout is
260 // going to be reset as well, so it is safe to reset the unlock attempt 328 // going to be reset as well, so it is safe to reset the unlock attempt
(...skipping 12 matching lines...) Expand all
273 341
274 authentication_capture_.reset(new AuthenticationParametersCapture()); 342 authentication_capture_.reset(new AuthenticationParametersCapture());
275 authentication_capture_->user_context = user_context; 343 authentication_capture_->user_context = user_context;
276 344
277 // Add guard for case when something get broken in call chain to unlock 345 // Add guard for case when something get broken in call chain to unlock
278 // for sure. 346 // for sure.
279 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 347 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
280 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess, 348 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess,
281 weak_factory_.GetWeakPtr()), 349 weak_factory_.GetWeakPtr()),
282 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); 350 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs));
283 web_ui()->AnimateAuthenticationSuccess(); 351 delegate_->AnimateAuthenticationSuccess();
284 } 352 }
285 353
286 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) { 354 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) {
287 // The user has signed in using their password, so reset the PIN timeout. 355 // The user has signed in using their password, so reset the PIN timeout.
288 quick_unlock::QuickUnlockStorage* quick_unlock_storage = 356 quick_unlock::QuickUnlockStorage* quick_unlock_storage =
289 quick_unlock::QuickUnlockFactory::GetForAccountId( 357 quick_unlock::QuickUnlockFactory::GetForAccountId(
290 user_context.GetAccountId()); 358 user_context.GetAccountId());
291 if (quick_unlock_storage) 359 if (quick_unlock_storage)
292 quick_unlock_storage->MarkStrongAuth(); 360 quick_unlock_storage->MarkStrongAuth();
293 } 361 }
(...skipping 14 matching lines...) Expand all
308 376
309 VLOG(1) << "Hiding the lock screen."; 377 VLOG(1) << "Hiding the lock screen.";
310 chromeos::ScreenLocker::Hide(); 378 chromeos::ScreenLocker::Hide();
311 } 379 }
312 380
313 void ScreenLocker::Authenticate(const UserContext& user_context) { 381 void ScreenLocker::Authenticate(const UserContext& user_context) {
314 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId())) 382 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId()))
315 << "Invalid user trying to unlock."; 383 << "Invalid user trying to unlock.";
316 384
317 authentication_start_time_ = base::Time::Now(); 385 authentication_start_time_ = base::Time::Now();
318 web_ui()->SetInputEnabled(false); 386 delegate_->SetPasswordInputEnabled(false);
319 if (user_context.IsUsingPin()) 387 if (user_context.IsUsingPin())
320 unlock_attempt_type_ = AUTH_PIN; 388 unlock_attempt_type_ = AUTH_PIN;
321 389
322 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId()); 390 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId());
323 if (user) { 391 if (user) {
324 // Check to see if the user submitted a PIN and it is valid. 392 // Check to see if the user submitted a PIN and it is valid.
325 const std::string pin = user_context.GetKey()->GetSecret(); 393 const std::string pin = user_context.GetKey()->GetSecret();
326 394
327 // We only want to try authenticating the pin if it is a number, 395 // We only want to try authenticating the pin if it is a number,
328 // otherwise we will timeout PIN if the user enters their account password 396 // otherwise we will timeout PIN if the user enters their account password
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 return nullptr; 440 return nullptr;
373 } 441 }
374 442
375 void ScreenLocker::OnStartLockCallback(bool locked) { 443 void ScreenLocker::OnStartLockCallback(bool locked) {
376 // Happens in tests that exit with a pending lock. In real lock failure, 444 // Happens in tests that exit with a pending lock. In real lock failure,
377 // ash::LockStateController would cause the current user session to be 445 // ash::LockStateController would cause the current user session to be
378 // terminated. 446 // terminated.
379 if (!locked) 447 if (!locked)
380 return; 448 return;
381 449
382 web_ui()->OnAshLockAnimationFinished(); 450 delegate_->OnAshLockAnimationFinished();
383 451
384 AccessibilityManager::Get()->PlayEarcon( 452 AccessibilityManager::Get()->PlayEarcon(
385 chromeos::SOUND_LOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); 453 chromeos::SOUND_LOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
386 } 454 }
387 455
388 void ScreenLocker::ClearErrors() { 456 void ScreenLocker::ClearErrors() {
389 web_ui()->ClearErrors(); 457 delegate_->ClearErrors();
390 } 458 }
391 459
392 void ScreenLocker::Signout() { 460 void ScreenLocker::Signout() {
393 web_ui()->ClearErrors(); 461 delegate_->ClearErrors();
394 base::RecordAction(UserMetricsAction("ScreenLocker_Signout")); 462 base::RecordAction(UserMetricsAction("ScreenLocker_Signout"));
395 // We expect that this call will not wait for any user input. 463 // We expect that this call will not wait for any user input.
396 // If it changes at some point, we will need to force exit. 464 // If it changes at some point, we will need to force exit.
397 chrome::AttemptUserExit(); 465 chrome::AttemptUserExit();
398 466
399 // Don't hide yet the locker because the chrome screen may become visible 467 // Don't hide yet the locker because the chrome screen may become visible
400 // briefly. 468 // briefly.
401 } 469 }
402 470
403 void ScreenLocker::EnableInput() { 471 void ScreenLocker::EnableInput() {
404 web_ui()->SetInputEnabled(true); 472 delegate_->SetPasswordInputEnabled(true);
405 } 473 }
406 474
407 void ScreenLocker::ShowErrorMessage(int error_msg_id, 475 void ScreenLocker::ShowErrorMessage(int error_msg_id,
408 HelpAppLauncher::HelpTopic help_topic_id, 476 HelpAppLauncher::HelpTopic help_topic_id,
409 bool sign_out_only) { 477 bool sign_out_only) {
410 web_ui()->SetInputEnabled(!sign_out_only); 478 delegate_->SetPasswordInputEnabled(!sign_out_only);
411 web_ui()->ShowErrorMessage(error_msg_id, help_topic_id); 479 delegate_->ShowErrorMessage(error_msg_id, help_topic_id);
412 } 480 }
413 481
414 void ScreenLocker::SetLoginStatusConsumer( 482 void ScreenLocker::SetLoginStatusConsumer(
415 chromeos::AuthStatusConsumer* consumer) { 483 chromeos::AuthStatusConsumer* consumer) {
416 auth_status_consumer_ = consumer; 484 auth_status_consumer_ = consumer;
417 } 485 }
418 486
419 // static 487 // static
420 void ScreenLocker::InitClass() { 488 void ScreenLocker::InitClass() {
421 DCHECK(!g_screen_lock_observer); 489 DCHECK(!g_screen_lock_observer);
422 g_screen_lock_observer = new ScreenLockObserver; 490 g_screen_lock_observer = new ScreenLockObserver;
423 } 491 }
424 492
425 // static 493 // static
426 void ScreenLocker::ShutDownClass() { 494 void ScreenLocker::ShutDownClass() {
427 DCHECK(g_screen_lock_observer); 495 DCHECK(g_screen_lock_observer);
428 delete g_screen_lock_observer; 496 delete g_screen_lock_observer;
429 g_screen_lock_observer = NULL; 497 g_screen_lock_observer = nullptr;
430 } 498 }
431 499
432 // static 500 // static
433 void ScreenLocker::HandleLockScreenRequest() { 501 void ScreenLocker::HandleLockScreenRequest() {
434 VLOG(1) << "Received LockScreen request from session manager"; 502 VLOG(1) << "Received LockScreen request from session manager";
435 DCHECK(g_screen_lock_observer); 503 DCHECK(g_screen_lock_observer);
436 if (UserAddingScreen::Get()->IsRunning()) { 504 if (UserAddingScreen::Get()->IsRunning()) {
437 VLOG(1) << "Waiting for user adding screen to stop"; 505 VLOG(1) << "Waiting for user adding screen to stop";
438 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer); 506 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer);
439 UserAddingScreen::Get()->Cancel(); 507 UserAddingScreen::Get()->Cancel();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 573 }
506 574
507 DCHECK(screen_locker_); 575 DCHECK(screen_locker_);
508 SessionControllerClient::Get()->RunUnlockAnimation( 576 SessionControllerClient::Get()->RunUnlockAnimation(
509 base::Bind(&ScreenLocker::ScheduleDeletion)); 577 base::Bind(&ScreenLocker::ScheduleDeletion));
510 } 578 }
511 579
512 // static 580 // static
513 void ScreenLocker::ScheduleDeletion() { 581 void ScreenLocker::ScheduleDeletion() {
514 // Avoid possible multiple calls. 582 // Avoid possible multiple calls.
515 if (screen_locker_ == NULL) 583 if (screen_locker_ == nullptr)
516 return; 584 return;
517 VLOG(1) << "Deleting ScreenLocker " << screen_locker_; 585 VLOG(1) << "Deleting ScreenLocker " << screen_locker_;
518 586
519 AccessibilityManager::Get()->PlayEarcon( 587 AccessibilityManager::Get()->PlayEarcon(
520 SOUND_UNLOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); 588 SOUND_UNLOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
521 589
522 delete screen_locker_; 590 delete screen_locker_;
523 screen_locker_ = NULL; 591 screen_locker_ = nullptr;
524 } 592 }
525 593
526 //////////////////////////////////////////////////////////////////////////////// 594 ////////////////////////////////////////////////////////////////////////////////
527 // ScreenLocker, private: 595 // ScreenLocker, private:
528 596
529 ScreenLocker::~ScreenLocker() { 597 ScreenLocker::~ScreenLocker() {
530 VLOG(1) << "Destroying ScreenLocker " << this; 598 VLOG(1) << "Destroying ScreenLocker " << this;
531 DCHECK(base::MessageLoopForUI::IsCurrent()); 599 DCHECK(base::MessageLoopForUI::IsCurrent());
532 600
533 if (authenticator_.get()) 601 if (authenticator_.get())
534 authenticator_->SetConsumer(NULL); 602 authenticator_->SetConsumer(nullptr);
535 ClearErrors(); 603 ClearErrors();
536 604
537 screen_locker_ = NULL; 605 screen_locker_ = nullptr;
538 bool state = false; 606 bool state = false;
539 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; 607 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state;
540 content::NotificationService::current()->Notify( 608 content::NotificationService::current()->Notify(
541 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 609 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
542 content::Source<ScreenLocker>(this), 610 content::Source<ScreenLocker>(this),
543 content::Details<bool>(&state)); 611 content::Details<bool>(&state));
544 612
545 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method"; 613 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method";
546 DBusThreadManager::Get()->GetSessionManagerClient()-> 614 DBusThreadManager::Get()->GetSessionManagerClient()->
547 NotifyLockScreenDismissed(); 615 NotifyLockScreenDismissed();
548 616
549 session_manager::SessionManager::Get()->SetSessionState( 617 session_manager::SessionManager::Get()->SetSessionState(
550 session_manager::SessionState::ACTIVE); 618 session_manager::SessionState::ACTIVE);
551 619
552 if (saved_ime_state_.get()) { 620 if (saved_ime_state_.get()) {
553 input_method::InputMethodManager::Get()->SetState(saved_ime_state_); 621 input_method::InputMethodManager::Get()->SetState(saved_ime_state_);
554 } 622 }
623
624 if (owns_delegate_) {
625 owns_delegate_ = false;
626 delete delegate_;
627 delegate_ = nullptr;
628 }
555 } 629 }
556 630
557 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { 631 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) {
558 authenticator_ = authenticator; 632 authenticator_ = authenticator;
559 } 633 }
560 634
561 void ScreenLocker::ScreenLockReady() { 635 void ScreenLocker::ScreenLockReady() {
562 locked_ = true; 636 locked_ = true;
563 base::TimeDelta delta = base::Time::Now() - start_time_; 637 base::TimeDelta delta = base::Time::Now() - start_time_;
564 VLOG(1) << "ScreenLocker " << this << " is ready after " 638 VLOG(1) << "ScreenLocker " << this << " is ready after "
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 if (scan_result != biod::ScanResult::SCAN_RESULT_SUCCESS) { 683 if (scan_result != biod::ScanResult::SCAN_RESULT_SUCCESS) {
610 OnFingerprintAuthFailure(*active_user); 684 OnFingerprintAuthFailure(*active_user);
611 return; 685 return;
612 } 686 }
613 687
614 UserContext user_context(active_user->GetAccountId()); 688 UserContext user_context(active_user->GetAccountId());
615 if (!base::ContainsKey(matches, active_user->username_hash())) { 689 if (!base::ContainsKey(matches, active_user->username_hash())) {
616 OnFingerprintAuthFailure(*active_user); 690 OnFingerprintAuthFailure(*active_user);
617 return; 691 return;
618 } 692 }
619 web_ui()->SetFingerprintState(active_user->GetAccountId(), 693 delegate_->SetFingerprintState(active_user->GetAccountId(),
620 WebUIScreenLocker::FingerprintState::kSignin); 694 FingerprintState::kSignin);
621 OnAuthSuccess(user_context); 695 OnAuthSuccess(user_context);
622 } 696 }
623 697
624 void ScreenLocker::OnSessionFailed() { 698 void ScreenLocker::OnSessionFailed() {
625 LOG(ERROR) << "Fingerprint session failed."; 699 LOG(ERROR) << "Fingerprint session failed.";
626 } 700 }
627 701
628 void ScreenLocker::OnFingerprintAuthFailure(const user_manager::User& user) { 702 void ScreenLocker::OnFingerprintAuthFailure(const user_manager::User& user) {
629 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure", 703 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure",
630 unlock_attempt_type_, UnlockType::AUTH_COUNT); 704 unlock_attempt_type_, UnlockType::AUTH_COUNT);
631 705
632 web_ui()->SetFingerprintState(user.GetAccountId(), 706 delegate_->SetFingerprintState(user.GetAccountId(),
633 WebUIScreenLocker::FingerprintState::kFailed); 707 FingerprintState::kFailed);
634 708
635 quick_unlock::QuickUnlockStorage* quick_unlock_storage = 709 quick_unlock::QuickUnlockStorage* quick_unlock_storage =
636 quick_unlock::QuickUnlockFactory::GetForUser(&user); 710 quick_unlock::QuickUnlockFactory::GetForUser(&user);
637 if (quick_unlock_storage && 711 if (quick_unlock_storage &&
638 quick_unlock_storage->IsFingerprintAuthenticationAvailable()) { 712 quick_unlock_storage->IsFingerprintAuthenticationAvailable()) {
639 quick_unlock_storage->fingerprint_storage()->AddUnlockAttempt(); 713 quick_unlock_storage->fingerprint_storage()->AddUnlockAttempt();
640 if (quick_unlock_storage->fingerprint_storage()->ExceededUnlockAttempts()) { 714 if (quick_unlock_storage->fingerprint_storage()->ExceededUnlockAttempts()) {
641 web_ui()->SetFingerprintState( 715 delegate_->SetFingerprintState(user.GetAccountId(),
642 user.GetAccountId(), WebUIScreenLocker::FingerprintState::kRemoved); 716 FingerprintState::kRemoved);
643 web_ui()->ShowErrorMessage(IDS_LOGIN_ERROR_FINGERPRINT_MAX_ATTEMPT, 717 delegate_->ShowErrorMessage(IDS_LOGIN_ERROR_FINGERPRINT_MAX_ATTEMPT,
644 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); 718 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT);
645 } 719 }
646 } 720 }
647 721
648 if (auth_status_consumer_) { 722 if (auth_status_consumer_) {
649 AuthFailure failure(AuthFailure::UNLOCK_FAILED); 723 AuthFailure failure(AuthFailure::UNLOCK_FAILED);
650 auth_status_consumer_->OnAuthFailure(failure); 724 auth_status_consumer_->OnAuthFailure(failure);
651 } 725 }
652 } 726 }
653 727
654 } // namespace chromeos 728 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698