| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/existing_user_controller.h" | 5 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 } | 212 } |
| 213 | 213 |
| 214 void ExistingUserController::DoAutoEnrollment() { | 214 void ExistingUserController::DoAutoEnrollment() { |
| 215 do_auto_enrollment_ = true; | 215 do_auto_enrollment_ = true; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void ExistingUserController::ResumeLogin() { | 218 void ExistingUserController::ResumeLogin() { |
| 219 // This means the user signed-in, then auto-enrollment used his credentials | 219 // This means the user signed-in, then auto-enrollment used his credentials |
| 220 // to enroll and succeeded. | 220 // to enroll and succeeded. |
| 221 resume_login_callback_.Run(); | 221 resume_login_callback_.Run(); |
| 222 resume_login_callback_.Reset(); |
| 222 } | 223 } |
| 223 | 224 |
| 224 void ExistingUserController::PrepareKioskAppLaunch() { | 225 void ExistingUserController::PrepareKioskAppLaunch() { |
| 225 // Disable login UI while waiting for the kiosk app launch. There is no | 226 // Disable login UI while waiting for the kiosk app launch. There is no |
| 226 // balanced UI enable call because this very login screen will not be | 227 // balanced UI enable call because this very login screen will not be |
| 227 // accessed again. If app is launched, it will be destroyed. If app fails to | 228 // accessed again. If app is launched, it will be destroyed. If app fails to |
| 228 // launch, chrome is restarted to go back to a new login screen. | 229 // launch, chrome is restarted to go back to a new login screen. |
| 229 login_display_->SetUIEnabled(false); | 230 login_display_->SetUIEnabled(false); |
| 230 } | 231 } |
| 231 | 232 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 delegate = login_performer_delegate_.get(); | 351 delegate = login_performer_delegate_.get(); |
| 351 // Only one instance of LoginPerformer should exist at a time. | 352 // Only one instance of LoginPerformer should exist at a time. |
| 352 login_performer_.reset(NULL); | 353 login_performer_.reset(NULL); |
| 353 login_performer_.reset(new LoginPerformer(delegate)); | 354 login_performer_.reset(new LoginPerformer(delegate)); |
| 354 is_login_in_progress_ = true; | 355 is_login_in_progress_ = true; |
| 355 login_performer_-> | 356 login_performer_-> |
| 356 CreateLocallyManagedUser(display_name, password); | 357 CreateLocallyManagedUser(display_name, password); |
| 357 // TODO(nkostylev): A11y message. | 358 // TODO(nkostylev): A11y message. |
| 358 } | 359 } |
| 359 | 360 |
| 360 void ExistingUserController::CompleteLogin(const std::string& username, | 361 void ExistingUserController::CompleteLogin(const UserCredentials& credentials) { |
| 361 const std::string& password) { | |
| 362 if (!host_) { | 362 if (!host_) { |
| 363 // Complete login event was generated already from UI. Ignore notification. | 363 // Complete login event was generated already from UI. Ignore notification. |
| 364 return; | 364 return; |
| 365 } | 365 } |
| 366 | 366 |
| 367 // Stop the auto-login timer when attempting login. | 367 // Stop the auto-login timer when attempting login. |
| 368 StopPublicSessionAutoLoginTimer(); | 368 StopPublicSessionAutoLoginTimer(); |
| 369 | 369 |
| 370 // Disable UI while loading user profile. | 370 // Disable UI while loading user profile. |
| 371 login_display_->SetUIEnabled(false); | 371 login_display_->SetUIEnabled(false); |
| 372 | 372 |
| 373 if (!time_init_.is_null()) { | 373 if (!time_init_.is_null()) { |
| 374 base::TimeDelta delta = base::Time::Now() - time_init_; | 374 base::TimeDelta delta = base::Time::Now() - time_init_; |
| 375 UMA_HISTOGRAM_MEDIUM_TIMES("Login.PromptToCompleteLoginTime", delta); | 375 UMA_HISTOGRAM_MEDIUM_TIMES("Login.PromptToCompleteLoginTime", delta); |
| 376 time_init_ = base::Time(); // Reset to null. | 376 time_init_ = base::Time(); // Reset to null. |
| 377 } | 377 } |
| 378 | 378 |
| 379 host_->OnCompleteLogin(); | 379 host_->OnCompleteLogin(); |
| 380 | 380 |
| 381 // Do an ownership check now to avoid auto-enrolling if the device has | 381 // Do an ownership check now to avoid auto-enrolling if the device has |
| 382 // already been owned. | 382 // already been owned. |
| 383 DeviceSettingsService::Get()->GetOwnershipStatusAsync( | 383 DeviceSettingsService::Get()->GetOwnershipStatusAsync( |
| 384 base::Bind(&ExistingUserController::CompleteLoginInternal, | 384 base::Bind(&ExistingUserController::CompleteLoginInternal, |
| 385 weak_factory_.GetWeakPtr(), | 385 weak_factory_.GetWeakPtr(), |
| 386 username, password)); | 386 credentials)); |
| 387 } | 387 } |
| 388 | 388 |
| 389 void ExistingUserController::CompleteLoginInternal( | 389 void ExistingUserController::CompleteLoginInternal( |
| 390 const std::string& username, | 390 const UserCredentials& credentials, |
| 391 const std::string& password, | |
| 392 DeviceSettingsService::OwnershipStatus ownership_status, | 391 DeviceSettingsService::OwnershipStatus ownership_status, |
| 393 bool is_owner) { | 392 bool is_owner) { |
| 394 // Auto-enrollment must have made a decision by now. It's too late to enroll | 393 // Auto-enrollment must have made a decision by now. It's too late to enroll |
| 395 // if the protocol isn't done at this point. | 394 // if the protocol isn't done at this point. |
| 396 if (do_auto_enrollment_ && | 395 if (do_auto_enrollment_ && |
| 397 ownership_status == DeviceSettingsService::OWNERSHIP_NONE) { | 396 ownership_status == DeviceSettingsService::OWNERSHIP_NONE) { |
| 398 VLOG(1) << "Forcing auto-enrollment before completing login"; | 397 VLOG(1) << "Forcing auto-enrollment before completing login"; |
| 399 // The only way to get out of the enrollment screen from now on is to either | 398 // The only way to get out of the enrollment screen from now on is to either |
| 400 // complete enrollment, or opt-out of it. So this controller shouldn't force | 399 // complete enrollment, or opt-out of it. So this controller shouldn't force |
| 401 // enrollment again if it is reused for another sign-in. | 400 // enrollment again if it is reused for another sign-in. |
| 402 do_auto_enrollment_ = false; | 401 do_auto_enrollment_ = false; |
| 403 auto_enrollment_username_ = username; | 402 auto_enrollment_username_ = credentials.username; |
| 404 resume_login_callback_ = base::Bind( | 403 resume_login_callback_ = base::Bind( |
| 405 &ExistingUserController::PerformLogin, | 404 &ExistingUserController::PerformLogin, |
| 406 weak_factory_.GetWeakPtr(), | 405 weak_factory_.GetWeakPtr(), |
| 407 username, password, LoginPerformer::AUTH_MODE_EXTENSION); | 406 credentials, LoginPerformer::AUTH_MODE_EXTENSION); |
| 408 ShowEnrollmentScreen(true, username); | 407 ShowEnrollmentScreen(true, credentials.username); |
| 409 // Enable UI for the enrollment screen. SetUIEnabled(true) will post a | 408 // Enable UI for the enrollment screen. SetUIEnabled(true) will post a |
| 410 // request to show the sign-in screen again when invoked at the sign-in | 409 // request to show the sign-in screen again when invoked at the sign-in |
| 411 // screen; invoke SetUIEnabled() after navigating to the enrollment screen. | 410 // screen; invoke SetUIEnabled() after navigating to the enrollment screen. |
| 412 login_display_->SetUIEnabled(true); | 411 login_display_->SetUIEnabled(true); |
| 413 } else { | 412 } else { |
| 414 PerformLogin(username, password, LoginPerformer::AUTH_MODE_EXTENSION); | 413 PerformLogin(credentials, LoginPerformer::AUTH_MODE_EXTENSION); |
| 415 } | 414 } |
| 416 } | 415 } |
| 417 | 416 |
| 418 string16 ExistingUserController::GetConnectedNetworkName() { | 417 string16 ExistingUserController::GetConnectedNetworkName() { |
| 419 return GetCurrentNetworkName(); | 418 return GetCurrentNetworkName(); |
| 420 } | 419 } |
| 421 | 420 |
| 422 void ExistingUserController::Login(const std::string& username, | 421 void ExistingUserController::Login(const UserCredentials& credentials) { |
| 423 const std::string& password) { | 422 if ((credentials.username.empty() || credentials.password.empty()) && |
| 424 if (username.empty() || password.empty()) | 423 credentials.auth_code.empty()) |
| 425 return; | 424 return; |
| 426 | 425 |
| 427 // Stop the auto-login timer when attempting login. | 426 // Stop the auto-login timer when attempting login. |
| 428 StopPublicSessionAutoLoginTimer(); | 427 StopPublicSessionAutoLoginTimer(); |
| 429 | 428 |
| 430 // Disable clicking on other windows. | 429 // Disable clicking on other windows. |
| 431 login_display_->SetUIEnabled(false); | 430 login_display_->SetUIEnabled(false); |
| 432 | 431 |
| 433 BootTimesLoader::Get()->RecordLoginAttempted(); | 432 BootTimesLoader::Get()->RecordLoginAttempted(); |
| 434 | 433 |
| 435 if (last_login_attempt_username_ != username) { | 434 if (last_login_attempt_username_ != credentials.username) { |
| 436 last_login_attempt_username_ = username; | 435 last_login_attempt_username_ = credentials.username; |
| 437 num_login_attempts_ = 0; | 436 num_login_attempts_ = 0; |
| 438 // Also reset state variables, which are used to determine password change. | 437 // Also reset state variables, which are used to determine password change. |
| 439 offline_failed_ = false; | 438 offline_failed_ = false; |
| 440 online_succeeded_for_.clear(); | 439 online_succeeded_for_.clear(); |
| 441 } | 440 } |
| 442 num_login_attempts_++; | 441 num_login_attempts_++; |
| 443 PerformLogin(username, password, LoginPerformer::AUTH_MODE_INTERNAL); | 442 PerformLogin(credentials, LoginPerformer::AUTH_MODE_INTERNAL); |
| 444 } | 443 } |
| 445 | 444 |
| 446 void ExistingUserController::PerformLogin( | 445 void ExistingUserController::PerformLogin( |
| 447 std::string username, | 446 const UserCredentials& credentials, |
| 448 std::string password, | |
| 449 LoginPerformer::AuthorizationMode auth_mode) { | 447 LoginPerformer::AuthorizationMode auth_mode) { |
| 450 // Disable UI while loading user profile. | 448 // Disable UI while loading user profile. |
| 451 login_display_->SetUIEnabled(false); | 449 login_display_->SetUIEnabled(false); |
| 452 resume_login_callback_.Reset(); | |
| 453 | 450 |
| 454 // Use the same LoginPerformer for subsequent login as it has state | 451 // Use the same LoginPerformer for subsequent login as it has state |
| 455 // such as Authenticator instance. | 452 // such as Authenticator instance. |
| 456 if (!login_performer_.get() || num_login_attempts_ <= 1) { | 453 if (!login_performer_.get() || num_login_attempts_ <= 1) { |
| 457 LoginPerformer::Delegate* delegate = this; | 454 LoginPerformer::Delegate* delegate = this; |
| 458 if (login_performer_delegate_.get()) | 455 if (login_performer_delegate_.get()) |
| 459 delegate = login_performer_delegate_.get(); | 456 delegate = login_performer_delegate_.get(); |
| 460 // Only one instance of LoginPerformer should exist at a time. | 457 // Only one instance of LoginPerformer should exist at a time. |
| 461 login_performer_.reset(NULL); | 458 login_performer_.reset(NULL); |
| 462 login_performer_.reset(new LoginPerformer(delegate)); | 459 login_performer_.reset(new LoginPerformer(delegate)); |
| 463 } | 460 } |
| 464 | 461 |
| 465 is_login_in_progress_ = true; | 462 is_login_in_progress_ = true; |
| 466 if (gaia::ExtractDomainName(username) == | 463 if (gaia::ExtractDomainName(credentials.username) == |
| 467 UserManager::kLocallyManagedUserDomain) { | 464 UserManager::kLocallyManagedUserDomain) { |
| 468 login_performer_->LoginAsLocallyManagedUser(username, password); | 465 login_performer_->LoginAsLocallyManagedUser( |
| 466 UserCredentials(credentials.username, |
| 467 credentials.password, |
| 468 std::string())); // auth_code |
| 469 } else { | 469 } else { |
| 470 login_performer_->PerformLogin(username, password, auth_mode); | 470 login_performer_->PerformLogin(credentials, auth_mode); |
| 471 } | 471 } |
| 472 accessibility::MaybeSpeak( | 472 accessibility::MaybeSpeak( |
| 473 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNING_IN)); | 473 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNING_IN)); |
| 474 } | 474 } |
| 475 | 475 |
| 476 void ExistingUserController::LoginAsRetailModeUser() { | 476 void ExistingUserController::LoginAsRetailModeUser() { |
| 477 // Stop the auto-login timer when attempting login. | 477 // Stop the auto-login timer when attempting login. |
| 478 StopPublicSessionAutoLoginTimer(); | 478 StopPublicSessionAutoLoginTimer(); |
| 479 | 479 |
| 480 // Disable clicking on other windows. | 480 // Disable clicking on other windows. |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 UserManager::Get()->ResetUserFlow(last_login_attempt_username_); | 747 UserManager::Get()->ResetUserFlow(last_login_attempt_username_); |
| 748 | 748 |
| 749 if (login_status_consumer_) | 749 if (login_status_consumer_) |
| 750 login_status_consumer_->OnLoginFailure(failure); | 750 login_status_consumer_->OnLoginFailure(failure); |
| 751 | 751 |
| 752 // Clear the recorded displayed email so it won't affect any future attempts. | 752 // Clear the recorded displayed email so it won't affect any future attempts. |
| 753 display_email_.clear(); | 753 display_email_.clear(); |
| 754 } | 754 } |
| 755 | 755 |
| 756 void ExistingUserController::OnLoginSuccess( | 756 void ExistingUserController::OnLoginSuccess( |
| 757 const std::string& username, | 757 const UserCredentials& credentials, |
| 758 const std::string& password, | |
| 759 bool pending_requests, | 758 bool pending_requests, |
| 760 bool using_oauth) { | 759 bool using_oauth) { |
| 761 is_login_in_progress_ = false; | 760 is_login_in_progress_ = false; |
| 762 offline_failed_ = false; | 761 offline_failed_ = false; |
| 763 | 762 |
| 764 StopPublicSessionAutoLoginTimer(); | 763 StopPublicSessionAutoLoginTimer(); |
| 765 | 764 |
| 766 bool has_cookies = | 765 bool has_cookies = |
| 767 login_performer_->auth_mode() == LoginPerformer::AUTH_MODE_EXTENSION; | 766 login_performer_->auth_mode() == LoginPerformer::AUTH_MODE_EXTENSION && |
| 767 credentials.auth_code.empty(); |
| 768 | 768 |
| 769 // Login performer will be gone so cache this value to use | 769 // Login performer will be gone so cache this value to use |
| 770 // once profile is loaded. | 770 // once profile is loaded. |
| 771 password_changed_ = login_performer_->password_changed(); | 771 password_changed_ = login_performer_->password_changed(); |
| 772 | 772 |
| 773 // LoginPerformer instance will delete itself once online auth result is OK. | 773 // LoginPerformer instance will delete itself once online auth result is OK. |
| 774 // In case of failure it'll bring up ScreenLock and ask for | 774 // In case of failure it'll bring up ScreenLock and ask for |
| 775 // correct password/display error message. | 775 // correct password/display error message. |
| 776 // Even in case when following online,offline protocol and returning | 776 // Even in case when following online,offline protocol and returning |
| 777 // requests_pending = false, let LoginPerformer delete itself. | 777 // requests_pending = false, let LoginPerformer delete itself. |
| 778 login_performer_->set_delegate(NULL); | 778 login_performer_->set_delegate(NULL); |
| 779 ignore_result(login_performer_.release()); | 779 ignore_result(login_performer_.release()); |
| 780 | 780 |
| 781 // Will call OnProfilePrepared() in the end. | 781 // Will call OnProfilePrepared() in the end. |
| 782 LoginUtils::Get()->PrepareProfile(username, | 782 LoginUtils::Get()->PrepareProfile(credentials, |
| 783 display_email_, | 783 display_email_, |
| 784 password, | |
| 785 using_oauth, | 784 using_oauth, |
| 786 has_cookies, | 785 has_cookies, |
| 787 this); | 786 this); |
| 788 | 787 |
| 789 display_email_.clear(); | 788 display_email_.clear(); |
| 790 | 789 |
| 791 // Notify LoginDisplay to allow it provide visual feedback to user. | 790 // Notify LoginDisplay to allow it provide visual feedback to user. |
| 792 login_display_->OnLoginSuccess(username); | 791 login_display_->OnLoginSuccess(credentials.username); |
| 793 } | 792 } |
| 794 | 793 |
| 795 void ExistingUserController::OnProfilePrepared(Profile* profile) { | 794 void ExistingUserController::OnProfilePrepared(Profile* profile) { |
| 796 OptionallyShowReleaseNotes(profile); | 795 OptionallyShowReleaseNotes(profile); |
| 797 | 796 |
| 798 // Reenable clicking on other windows and status area. | 797 // Reenable clicking on other windows and status area. |
| 799 login_display_->SetUIEnabled(true); | 798 login_display_->SetUIEnabled(true); |
| 800 | 799 |
| 801 if (UserManager::Get()->IsCurrentUserNew() && | 800 if (UserManager::Get()->IsCurrentUserNew() && |
| 802 !UserManager::Get()->GetCurrentUserFlow()->ShouldSkipPostLoginScreens() && | 801 !UserManager::Get()->GetCurrentUserFlow()->ShouldSkipPostLoginScreens() && |
| (...skipping 15 matching lines...) Expand all Loading... |
| 818 #ifndef NDEBUG | 817 #ifndef NDEBUG |
| 819 } | 818 } |
| 820 #endif | 819 #endif |
| 821 } else { | 820 } else { |
| 822 LoginUtils::Get()->DoBrowserLaunch(profile, host_); | 821 LoginUtils::Get()->DoBrowserLaunch(profile, host_); |
| 823 host_ = NULL; | 822 host_ = NULL; |
| 824 } | 823 } |
| 825 // Inform |login_status_consumer_| about successful login. Set most | 824 // Inform |login_status_consumer_| about successful login. Set most |
| 826 // parameters to empty since they're not needed. | 825 // parameters to empty since they're not needed. |
| 827 if (login_status_consumer_) | 826 if (login_status_consumer_) |
| 828 login_status_consumer_->OnLoginSuccess("", "", false, false); | 827 login_status_consumer_->OnLoginSuccess(UserCredentials(), |
| 828 false, // pending_requests |
| 829 false); // using_oauth |
| 829 login_display_->OnFadeOut(); | 830 login_display_->OnFadeOut(); |
| 830 } | 831 } |
| 831 | 832 |
| 832 void ExistingUserController::OnOffTheRecordLoginSuccess() { | 833 void ExistingUserController::OnOffTheRecordLoginSuccess() { |
| 833 is_login_in_progress_ = false; | 834 is_login_in_progress_ = false; |
| 834 offline_failed_ = false; | 835 offline_failed_ = false; |
| 835 if (WizardController::IsDeviceRegistered()) { | 836 if (WizardController::IsDeviceRegistered()) { |
| 836 LoginUtils::Get()->CompleteOffTheRecordLogin(guest_mode_url_); | 837 LoginUtils::Get()->CompleteOffTheRecordLogin(guest_mode_url_); |
| 837 } else { | 838 } else { |
| 838 // Postpone CompleteOffTheRecordLogin until registration completion. | 839 // Postpone CompleteOffTheRecordLogin until registration completion. |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 // changed. | 1129 // changed. |
| 1129 UserManager::Get()->SaveUserOAuthStatus( | 1130 UserManager::Get()->SaveUserOAuthStatus( |
| 1130 username, | 1131 username, |
| 1131 User::OAUTH2_TOKEN_STATUS_INVALID); | 1132 User::OAUTH2_TOKEN_STATUS_INVALID); |
| 1132 | 1133 |
| 1133 login_display_->SetUIEnabled(true); | 1134 login_display_->SetUIEnabled(true); |
| 1134 login_display_->ShowGaiaPasswordChanged(username); | 1135 login_display_->ShowGaiaPasswordChanged(username); |
| 1135 } | 1136 } |
| 1136 | 1137 |
| 1137 } // namespace chromeos | 1138 } // namespace chromeos |
| OLD | NEW |