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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 208 |
209 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); | 209 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); |
210 extended_authenticator_ = ExtendedAuthenticator::Create(this); | 210 extended_authenticator_ = ExtendedAuthenticator::Create(this); |
211 if (IsUsingMdLogin()) { | 211 if (IsUsingMdLogin()) { |
212 // Create delegate that calls into the views-based lock screen via mojo. | 212 // Create delegate that calls into the views-based lock screen via mojo. |
213 views_screen_locker_ = base::MakeUnique<ViewsScreenLocker>(this); | 213 views_screen_locker_ = base::MakeUnique<ViewsScreenLocker>(this); |
214 delegate_ = views_screen_locker_.get(); | 214 delegate_ = views_screen_locker_.get(); |
215 views_screen_locker_->Init(); | 215 views_screen_locker_->Init(); |
216 | 216 |
217 // Create and display lock screen. | 217 // Create and display lock screen. |
218 // TODO(jdufault): Calling ash::ShowLockScreenInWidget should be a mojo | 218 LockScreenClient::Get()->ShowLockScreen(base::BindOnce( |
219 // call. We should only set the session state to locked after the mojo call | 219 [](ViewsScreenLocker* screen_locker, bool did_show) { |
220 // has completed. | 220 CHECK(did_show); |
221 if (ash::ShowLockScreen()) | 221 screen_locker->OnLockScreenReady(); |
222 views_screen_locker_->OnLockScreenReady(); | 222 }, |
| 223 views_screen_locker_.get())); |
223 } else { | 224 } else { |
224 web_ui_.reset(new WebUIScreenLocker(this)); | 225 web_ui_.reset(new WebUIScreenLocker(this)); |
225 delegate_ = web_ui_.get(); | 226 delegate_ = web_ui_.get(); |
226 web_ui_->LockScreen(); | 227 web_ui_->LockScreen(); |
227 | 228 |
228 // Ownership of |icon_image_source| is passed. | 229 // Ownership of |icon_image_source| is passed. |
229 screenlock_icon_provider_ = base::MakeUnique<ScreenlockIconProvider>(); | 230 screenlock_icon_provider_ = base::MakeUnique<ScreenlockIconProvider>(); |
230 ScreenlockIconSource* screenlock_icon_source = | 231 ScreenlockIconSource* screenlock_icon_source = |
231 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); | 232 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); |
232 content::URLDataSource::Add(web_ui_->web_contents()->GetBrowserContext(), | 233 content::URLDataSource::Add(web_ui_->web_contents()->GetBrowserContext(), |
(...skipping 22 matching lines...) Expand all Loading... |
255 // Don't enable signout button here as we're showing | 256 // Don't enable signout button here as we're showing |
256 // MessageBubble. | 257 // MessageBubble. |
257 | 258 |
258 delegate_->ShowErrorMessage(incorrect_passwords_count_++ | 259 delegate_->ShowErrorMessage(incorrect_passwords_count_++ |
259 ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME | 260 ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME |
260 : IDS_LOGIN_ERROR_AUTHENTICATING, | 261 : IDS_LOGIN_ERROR_AUTHENTICATING, |
261 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); | 262 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); |
262 | 263 |
263 if (auth_status_consumer_) | 264 if (auth_status_consumer_) |
264 auth_status_consumer_->OnAuthFailure(error); | 265 auth_status_consumer_->OnAuthFailure(error); |
| 266 |
| 267 if (on_auth_complete_) |
| 268 std::move(on_auth_complete_).Run(false); |
265 } | 269 } |
266 | 270 |
267 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { | 271 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { |
268 incorrect_passwords_count_ = 0; | 272 incorrect_passwords_count_ = 0; |
269 if (authentication_start_time_.is_null()) { | 273 if (authentication_start_time_.is_null()) { |
270 if (user_context.GetAccountId().is_valid()) | 274 if (user_context.GetAccountId().is_valid()) |
271 LOG(ERROR) << "Start time is not set at authentication success"; | 275 LOG(ERROR) << "Start time is not set at authentication success"; |
272 } else { | 276 } else { |
273 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; | 277 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; |
274 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; | 278 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 authentication_capture_.reset(new AuthenticationParametersCapture()); | 313 authentication_capture_.reset(new AuthenticationParametersCapture()); |
310 authentication_capture_->user_context = user_context; | 314 authentication_capture_->user_context = user_context; |
311 | 315 |
312 // Add guard for case when something get broken in call chain to unlock | 316 // Add guard for case when something get broken in call chain to unlock |
313 // for sure. | 317 // for sure. |
314 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 318 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
315 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess, | 319 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess, |
316 weak_factory_.GetWeakPtr()), | 320 weak_factory_.GetWeakPtr()), |
317 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); | 321 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); |
318 delegate_->AnimateAuthenticationSuccess(); | 322 delegate_->AnimateAuthenticationSuccess(); |
| 323 |
| 324 if (on_auth_complete_) |
| 325 std::move(on_auth_complete_).Run(true); |
319 } | 326 } |
320 | 327 |
321 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) { | 328 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) { |
322 // The user has signed in using their password, so reset the PIN timeout. | 329 // The user has signed in using their password, so reset the PIN timeout. |
323 quick_unlock::QuickUnlockStorage* quick_unlock_storage = | 330 quick_unlock::QuickUnlockStorage* quick_unlock_storage = |
324 quick_unlock::QuickUnlockFactory::GetForAccountId( | 331 quick_unlock::QuickUnlockFactory::GetForAccountId( |
325 user_context.GetAccountId()); | 332 user_context.GetAccountId()); |
326 if (quick_unlock_storage) | 333 if (quick_unlock_storage) |
327 quick_unlock_storage->MarkStrongAuth(); | 334 quick_unlock_storage->MarkStrongAuth(); |
328 } | 335 } |
329 | 336 |
330 void ScreenLocker::UnlockOnLoginSuccess() { | 337 void ScreenLocker::UnlockOnLoginSuccess() { |
331 DCHECK(base::MessageLoopForUI::IsCurrent()); | 338 DCHECK(base::MessageLoopForUI::IsCurrent()); |
332 if (!authentication_capture_.get()) { | 339 if (!authentication_capture_.get()) { |
333 LOG(WARNING) << "Call to UnlockOnLoginSuccess without previous " << | 340 LOG(WARNING) << "Call to UnlockOnLoginSuccess without previous " << |
334 "authentication success."; | 341 "authentication success."; |
335 return; | 342 return; |
336 } | 343 } |
337 | 344 |
338 if (auth_status_consumer_) { | 345 if (auth_status_consumer_) { |
339 auth_status_consumer_->OnAuthSuccess(authentication_capture_->user_context); | 346 auth_status_consumer_->OnAuthSuccess(authentication_capture_->user_context); |
340 } | 347 } |
341 authentication_capture_.reset(); | 348 authentication_capture_.reset(); |
342 weak_factory_.InvalidateWeakPtrs(); | 349 weak_factory_.InvalidateWeakPtrs(); |
343 | 350 |
344 VLOG(1) << "Hiding the lock screen."; | 351 VLOG(1) << "Hiding the lock screen."; |
345 chromeos::ScreenLocker::Hide(); | 352 chromeos::ScreenLocker::Hide(); |
346 } | 353 } |
347 | 354 |
348 void ScreenLocker::Authenticate(const UserContext& user_context) { | 355 void ScreenLocker::Authenticate(const UserContext& user_context, |
| 356 AuthenticateCallback callback) { |
349 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId())) | 357 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId())) |
350 << "Invalid user trying to unlock."; | 358 << "Invalid user trying to unlock."; |
351 | 359 |
| 360 DCHECK(!on_auth_complete_); |
| 361 on_auth_complete_ = std::move(callback); |
| 362 |
352 authentication_start_time_ = base::Time::Now(); | 363 authentication_start_time_ = base::Time::Now(); |
353 delegate_->SetPasswordInputEnabled(false); | 364 delegate_->SetPasswordInputEnabled(false); |
354 if (user_context.IsUsingPin()) | 365 if (user_context.IsUsingPin()) |
355 unlock_attempt_type_ = AUTH_PIN; | 366 unlock_attempt_type_ = AUTH_PIN; |
356 | 367 |
357 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId()); | 368 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId()); |
358 if (user) { | 369 if (user) { |
359 // Check to see if the user submitted a PIN and it is valid. | 370 // Check to see if the user submitted a PIN and it is valid. |
360 const std::string pin = user_context.GetKey()->GetSecret(); | 371 const std::string pin = user_context.GetKey()->GetSecret(); |
361 | 372 |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 } | 691 } |
681 } | 692 } |
682 | 693 |
683 if (auth_status_consumer_) { | 694 if (auth_status_consumer_) { |
684 AuthFailure failure(AuthFailure::UNLOCK_FAILED); | 695 AuthFailure failure(AuthFailure::UNLOCK_FAILED); |
685 auth_status_consumer_->OnAuthFailure(failure); | 696 auth_status_consumer_->OnAuthFailure(failure); |
686 } | 697 } |
687 } | 698 } |
688 | 699 |
689 } // namespace chromeos | 700 } // namespace chromeos |
OLD | NEW |