OLD | NEW |
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/ui/lock_screen.h" | 10 #include "ash/login/ui/lock_screen.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 imm->SetState(saved_ime_state_->Clone()); | 237 imm->SetState(saved_ime_state_->Clone()); |
238 | 238 |
239 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); | 239 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); |
240 extended_authenticator_ = ExtendedAuthenticator::Create(this); | 240 extended_authenticator_ = ExtendedAuthenticator::Create(this); |
241 if (IsUsingMdLogin()) { | 241 if (IsUsingMdLogin()) { |
242 // Create delegate that calls into the views-based lock screen via mojo. | 242 // Create delegate that calls into the views-based lock screen via mojo. |
243 delegate_ = new MojoDelegate(); | 243 delegate_ = new MojoDelegate(); |
244 owns_delegate_ = true; | 244 owns_delegate_ = true; |
245 | 245 |
246 // Create and display lock screen. | 246 // Create and display lock screen. |
247 // TODO(jdufault): Calling ash::ShowLockScreenInWidget should be a mojo | 247 LockScreenClient::Get()->ShowLockScreen(base::BindOnce([](bool did_show) { |
248 // call. We should only set the session state to locked after the mojo call | 248 CHECK(did_show); |
249 // has completed. | |
250 if (ash::ShowLockScreen()) { | |
251 session_manager::SessionManager::Get()->SetSessionState( | 249 session_manager::SessionManager::Get()->SetSessionState( |
252 session_manager::SessionState::LOCKED); | 250 session_manager::SessionState::LOCKED); |
253 } | 251 })); |
254 } else { | 252 } else { |
255 web_ui_.reset(new WebUIScreenLocker(this)); | 253 web_ui_.reset(new WebUIScreenLocker(this)); |
256 delegate_ = web_ui_.get(); | 254 delegate_ = web_ui_.get(); |
257 owns_delegate_ = false; | 255 owns_delegate_ = false; |
258 web_ui_->LockScreen(); | 256 web_ui_->LockScreen(); |
259 | 257 |
260 // Ownership of |icon_image_source| is passed. | 258 // Ownership of |icon_image_source| is passed. |
261 screenlock_icon_provider_ = base::MakeUnique<ScreenlockIconProvider>(); | 259 screenlock_icon_provider_ = base::MakeUnique<ScreenlockIconProvider>(); |
262 ScreenlockIconSource* screenlock_icon_source = | 260 ScreenlockIconSource* screenlock_icon_source = |
263 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); | 261 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); |
(...skipping 23 matching lines...) Expand all Loading... |
287 // Don't enable signout button here as we're showing | 285 // Don't enable signout button here as we're showing |
288 // MessageBubble. | 286 // MessageBubble. |
289 | 287 |
290 delegate_->ShowErrorMessage(incorrect_passwords_count_++ | 288 delegate_->ShowErrorMessage(incorrect_passwords_count_++ |
291 ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME | 289 ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME |
292 : IDS_LOGIN_ERROR_AUTHENTICATING, | 290 : IDS_LOGIN_ERROR_AUTHENTICATING, |
293 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); | 291 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); |
294 | 292 |
295 if (auth_status_consumer_) | 293 if (auth_status_consumer_) |
296 auth_status_consumer_->OnAuthFailure(error); | 294 auth_status_consumer_->OnAuthFailure(error); |
| 295 |
| 296 if (on_auth_complete_) |
| 297 std::move(on_auth_complete_).Run(false); |
297 } | 298 } |
298 | 299 |
299 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { | 300 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { |
300 incorrect_passwords_count_ = 0; | 301 incorrect_passwords_count_ = 0; |
301 if (authentication_start_time_.is_null()) { | 302 if (authentication_start_time_.is_null()) { |
302 if (user_context.GetAccountId().is_valid()) | 303 if (user_context.GetAccountId().is_valid()) |
303 LOG(ERROR) << "Start time is not set at authentication success"; | 304 LOG(ERROR) << "Start time is not set at authentication success"; |
304 } else { | 305 } else { |
305 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; | 306 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; |
306 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; | 307 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 authentication_capture_.reset(new AuthenticationParametersCapture()); | 342 authentication_capture_.reset(new AuthenticationParametersCapture()); |
342 authentication_capture_->user_context = user_context; | 343 authentication_capture_->user_context = user_context; |
343 | 344 |
344 // 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 |
345 // for sure. | 346 // for sure. |
346 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 347 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
347 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess, | 348 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess, |
348 weak_factory_.GetWeakPtr()), | 349 weak_factory_.GetWeakPtr()), |
349 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); | 350 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); |
350 delegate_->AnimateAuthenticationSuccess(); | 351 delegate_->AnimateAuthenticationSuccess(); |
| 352 |
| 353 if (on_auth_complete_) |
| 354 std::move(on_auth_complete_).Run(true); |
351 } | 355 } |
352 | 356 |
353 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) { | 357 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) { |
354 // The user has signed in using their password, so reset the PIN timeout. | 358 // The user has signed in using their password, so reset the PIN timeout. |
355 quick_unlock::QuickUnlockStorage* quick_unlock_storage = | 359 quick_unlock::QuickUnlockStorage* quick_unlock_storage = |
356 quick_unlock::QuickUnlockFactory::GetForAccountId( | 360 quick_unlock::QuickUnlockFactory::GetForAccountId( |
357 user_context.GetAccountId()); | 361 user_context.GetAccountId()); |
358 if (quick_unlock_storage) | 362 if (quick_unlock_storage) |
359 quick_unlock_storage->MarkStrongAuth(); | 363 quick_unlock_storage->MarkStrongAuth(); |
360 } | 364 } |
361 | 365 |
362 void ScreenLocker::UnlockOnLoginSuccess() { | 366 void ScreenLocker::UnlockOnLoginSuccess() { |
363 DCHECK(base::MessageLoopForUI::IsCurrent()); | 367 DCHECK(base::MessageLoopForUI::IsCurrent()); |
364 if (!authentication_capture_.get()) { | 368 if (!authentication_capture_.get()) { |
365 LOG(WARNING) << "Call to UnlockOnLoginSuccess without previous " << | 369 LOG(WARNING) << "Call to UnlockOnLoginSuccess without previous " << |
366 "authentication success."; | 370 "authentication success."; |
367 return; | 371 return; |
368 } | 372 } |
369 | 373 |
370 if (auth_status_consumer_) { | 374 if (auth_status_consumer_) { |
371 auth_status_consumer_->OnAuthSuccess(authentication_capture_->user_context); | 375 auth_status_consumer_->OnAuthSuccess(authentication_capture_->user_context); |
372 } | 376 } |
373 authentication_capture_.reset(); | 377 authentication_capture_.reset(); |
374 weak_factory_.InvalidateWeakPtrs(); | 378 weak_factory_.InvalidateWeakPtrs(); |
375 | 379 |
376 VLOG(1) << "Hiding the lock screen."; | 380 VLOG(1) << "Hiding the lock screen."; |
377 chromeos::ScreenLocker::Hide(); | 381 chromeos::ScreenLocker::Hide(); |
378 } | 382 } |
379 | 383 |
380 void ScreenLocker::Authenticate(const UserContext& user_context) { | 384 void ScreenLocker::Authenticate(const UserContext& user_context, |
| 385 AuthenticateCallback callback) { |
381 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId())) | 386 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId())) |
382 << "Invalid user trying to unlock."; | 387 << "Invalid user trying to unlock."; |
383 | 388 |
| 389 DCHECK(!on_auth_complete_); |
| 390 on_auth_complete_ = std::move(callback); |
| 391 |
384 authentication_start_time_ = base::Time::Now(); | 392 authentication_start_time_ = base::Time::Now(); |
385 delegate_->SetPasswordInputEnabled(false); | 393 delegate_->SetPasswordInputEnabled(false); |
386 if (user_context.IsUsingPin()) | 394 if (user_context.IsUsingPin()) |
387 unlock_attempt_type_ = AUTH_PIN; | 395 unlock_attempt_type_ = AUTH_PIN; |
388 | 396 |
389 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId()); | 397 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId()); |
390 if (user) { | 398 if (user) { |
391 // Check to see if the user submitted a PIN and it is valid. | 399 // Check to see if the user submitted a PIN and it is valid. |
392 const std::string pin = user_context.GetKey()->GetSecret(); | 400 const std::string pin = user_context.GetKey()->GetSecret(); |
393 | 401 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 } | 726 } |
719 } | 727 } |
720 | 728 |
721 if (auth_status_consumer_) { | 729 if (auth_status_consumer_) { |
722 AuthFailure failure(AuthFailure::UNLOCK_FAILED); | 730 AuthFailure failure(AuthFailure::UNLOCK_FAILED); |
723 auth_status_consumer_->OnAuthFailure(failure); | 731 auth_status_consumer_->OnAuthFailure(failure); |
724 } | 732 } |
725 } | 733 } |
726 | 734 |
727 } // namespace chromeos | 735 } // namespace chromeos |
OLD | NEW |