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

Side by Side Diff: chrome/browser/chromeos/login/existing_user_controller.cc

Issue 12704002: Support for auth code based authentication flow for both app and web UI driven flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 delegate = login_performer_delegate_.get(); 351 delegate = login_performer_delegate_.get();
352 // Only one instance of LoginPerformer should exist at a time. 352 // Only one instance of LoginPerformer should exist at a time.
353 login_performer_.reset(NULL); 353 login_performer_.reset(NULL);
354 login_performer_.reset(new LoginPerformer(delegate)); 354 login_performer_.reset(new LoginPerformer(delegate));
355 is_login_in_progress_ = true; 355 is_login_in_progress_ = true;
356 login_performer_-> 356 login_performer_->
357 CreateLocallyManagedUser(display_name, password); 357 CreateLocallyManagedUser(display_name, password);
358 // TODO(nkostylev): A11y message. 358 // TODO(nkostylev): A11y message.
359 } 359 }
360 360
361 void ExistingUserController::CompleteLogin(const std::string& username, 361 void ExistingUserController::CompleteLogin(const UserCredentials& credentials) {
362 const std::string& password) {
363 if (!host_) { 362 if (!host_) {
364 // Complete login event was generated already from UI. Ignore notification. 363 // Complete login event was generated already from UI. Ignore notification.
365 return; 364 return;
366 } 365 }
367 366
368 // Stop the auto-login timer when attempting login. 367 // Stop the auto-login timer when attempting login.
369 StopPublicSessionAutoLoginTimer(); 368 StopPublicSessionAutoLoginTimer();
370 369
371 // Disable UI while loading user profile. 370 // Disable UI while loading user profile.
372 login_display_->SetUIEnabled(false); 371 login_display_->SetUIEnabled(false);
373 372
374 if (!time_init_.is_null()) { 373 if (!time_init_.is_null()) {
375 base::TimeDelta delta = base::Time::Now() - time_init_; 374 base::TimeDelta delta = base::Time::Now() - time_init_;
376 UMA_HISTOGRAM_MEDIUM_TIMES("Login.PromptToCompleteLoginTime", delta); 375 UMA_HISTOGRAM_MEDIUM_TIMES("Login.PromptToCompleteLoginTime", delta);
377 time_init_ = base::Time(); // Reset to null. 376 time_init_ = base::Time(); // Reset to null.
378 } 377 }
379 378
380 host_->OnCompleteLogin(); 379 host_->OnCompleteLogin();
381 380
382 // 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
383 // already been owned. 382 // already been owned.
384 DeviceSettingsService::Get()->GetOwnershipStatusAsync( 383 DeviceSettingsService::Get()->GetOwnershipStatusAsync(
385 base::Bind(&ExistingUserController::CompleteLoginInternal, 384 base::Bind(&ExistingUserController::CompleteLoginInternal,
386 weak_factory_.GetWeakPtr(), 385 weak_factory_.GetWeakPtr(),
387 username, password)); 386 credentials));
388 } 387 }
389 388
390 void ExistingUserController::CompleteLoginInternal( 389 void ExistingUserController::CompleteLoginInternal(
391 const std::string& username, 390 const UserCredentials& credentials,
392 const std::string& password,
393 DeviceSettingsService::OwnershipStatus ownership_status, 391 DeviceSettingsService::OwnershipStatus ownership_status,
394 bool is_owner) { 392 bool is_owner) {
395 // 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
396 // if the protocol isn't done at this point. 394 // if the protocol isn't done at this point.
397 if (do_auto_enrollment_ && 395 if (do_auto_enrollment_ &&
398 ownership_status == DeviceSettingsService::OWNERSHIP_NONE) { 396 ownership_status == DeviceSettingsService::OWNERSHIP_NONE) {
399 VLOG(1) << "Forcing auto-enrollment before completing login"; 397 VLOG(1) << "Forcing auto-enrollment before completing login";
400 // 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
401 // 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
402 // enrollment again if it is reused for another sign-in. 400 // enrollment again if it is reused for another sign-in.
403 do_auto_enrollment_ = false; 401 do_auto_enrollment_ = false;
404 auto_enrollment_username_ = username; 402 auto_enrollment_username_ = credentials.username;
405 resume_login_callback_ = base::Bind( 403 resume_login_callback_ = base::Bind(
406 &ExistingUserController::PerformLogin, 404 &ExistingUserController::PerformLogin,
407 weak_factory_.GetWeakPtr(), 405 weak_factory_.GetWeakPtr(),
408 username, password, LoginPerformer::AUTH_MODE_EXTENSION); 406 credentials, LoginPerformer::AUTH_MODE_EXTENSION);
409 ShowEnrollmentScreen(true, username); 407 ShowEnrollmentScreen(true, credentials.username);
410 // Enable UI for the enrollment screen. SetUIEnabled(true) will post a 408 // Enable UI for the enrollment screen. SetUIEnabled(true) will post a
411 // 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
412 // screen; invoke SetUIEnabled() after navigating to the enrollment screen. 410 // screen; invoke SetUIEnabled() after navigating to the enrollment screen.
413 login_display_->SetUIEnabled(true); 411 login_display_->SetUIEnabled(true);
414 } else { 412 } else {
415 PerformLogin(username, password, LoginPerformer::AUTH_MODE_EXTENSION); 413 PerformLogin(credentials, LoginPerformer::AUTH_MODE_EXTENSION);
416 } 414 }
417 } 415 }
418 416
419 string16 ExistingUserController::GetConnectedNetworkName() { 417 string16 ExistingUserController::GetConnectedNetworkName() {
420 return GetCurrentNetworkName(); 418 return GetCurrentNetworkName();
421 } 419 }
422 420
423 void ExistingUserController::Login(const std::string& username, 421 void ExistingUserController::Login(const UserCredentials& credentials) {
424 const std::string& password) { 422 if ((credentials.username.empty() || credentials.password.empty()) &&
425 if (username.empty() || password.empty()) 423 credentials.auth_code.empty())
Nikita (slow) 2013/03/21 22:17:32 Is auth code really required for a regular user lo
zel 2013/03/22 05:03:15 nope, you either need to have username+pwd or auth
426 return; 424 return;
427 425
428 // Stop the auto-login timer when attempting login. 426 // Stop the auto-login timer when attempting login.
429 StopPublicSessionAutoLoginTimer(); 427 StopPublicSessionAutoLoginTimer();
430 428
431 // Disable clicking on other windows. 429 // Disable clicking on other windows.
432 login_display_->SetUIEnabled(false); 430 login_display_->SetUIEnabled(false);
433 431
434 BootTimesLoader::Get()->RecordLoginAttempted(); 432 BootTimesLoader::Get()->RecordLoginAttempted();
435 433
436 if (last_login_attempt_username_ != username) { 434 if (last_login_attempt_username_ != credentials.username) {
437 last_login_attempt_username_ = username; 435 last_login_attempt_username_ = credentials.username;
438 num_login_attempts_ = 0; 436 num_login_attempts_ = 0;
439 // Also reset state variables, which are used to determine password change. 437 // Also reset state variables, which are used to determine password change.
440 offline_failed_ = false; 438 offline_failed_ = false;
441 online_succeeded_for_.clear(); 439 online_succeeded_for_.clear();
442 } 440 }
443 num_login_attempts_++; 441 num_login_attempts_++;
444 PerformLogin(username, password, LoginPerformer::AUTH_MODE_INTERNAL); 442 PerformLogin(credentials, LoginPerformer::AUTH_MODE_INTERNAL);
445 } 443 }
446 444
447 void ExistingUserController::PerformLogin( 445 void ExistingUserController::PerformLogin(
448 std::string username, 446 const UserCredentials& credentials,
449 std::string password,
450 LoginPerformer::AuthorizationMode auth_mode) { 447 LoginPerformer::AuthorizationMode auth_mode) {
451 // Disable UI while loading user profile. 448 // Disable UI while loading user profile.
452 login_display_->SetUIEnabled(false); 449 login_display_->SetUIEnabled(false);
453 resume_login_callback_.Reset(); 450 resume_login_callback_.Reset();
454 451
455 // Use the same LoginPerformer for subsequent login as it has state 452 // Use the same LoginPerformer for subsequent login as it has state
456 // such as Authenticator instance. 453 // such as Authenticator instance.
457 if (!login_performer_.get() || num_login_attempts_ <= 1) { 454 if (!login_performer_.get() || num_login_attempts_ <= 1) {
458 LoginPerformer::Delegate* delegate = this; 455 LoginPerformer::Delegate* delegate = this;
459 if (login_performer_delegate_.get()) 456 if (login_performer_delegate_.get())
460 delegate = login_performer_delegate_.get(); 457 delegate = login_performer_delegate_.get();
461 // Only one instance of LoginPerformer should exist at a time. 458 // Only one instance of LoginPerformer should exist at a time.
462 login_performer_.reset(NULL); 459 login_performer_.reset(NULL);
463 login_performer_.reset(new LoginPerformer(delegate)); 460 login_performer_.reset(new LoginPerformer(delegate));
464 } 461 }
465 462
466 is_login_in_progress_ = true; 463 is_login_in_progress_ = true;
467 if (gaia::ExtractDomainName(username) == 464 if (gaia::ExtractDomainName(credentials.username) ==
468 UserManager::kLocallyManagedUserDomain) { 465 UserManager::kLocallyManagedUserDomain) {
469 login_performer_->LoginAsLocallyManagedUser(username, password); 466 login_performer_->LoginAsLocallyManagedUser(
467 UserCredentials(credentials.username,
468 credentials.password,
469 std::string())); // auth_code
470 } else { 470 } else {
471 login_performer_->PerformLogin(username, password, auth_mode); 471 login_performer_->PerformLogin(credentials, auth_mode);
472 } 472 }
473 accessibility::MaybeSpeak( 473 accessibility::MaybeSpeak(
474 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNING_IN)); 474 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNING_IN));
475 } 475 }
476 476
477 void ExistingUserController::LoginAsRetailModeUser() { 477 void ExistingUserController::LoginAsRetailModeUser() {
478 // Stop the auto-login timer when attempting login. 478 // Stop the auto-login timer when attempting login.
479 StopPublicSessionAutoLoginTimer(); 479 StopPublicSessionAutoLoginTimer();
480 480
481 // Disable clicking on other windows. 481 // Disable clicking on other windows.
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 UserManager::Get()->ResetUserFlow(last_login_attempt_username_); 743 UserManager::Get()->ResetUserFlow(last_login_attempt_username_);
744 744
745 if (login_status_consumer_) 745 if (login_status_consumer_)
746 login_status_consumer_->OnLoginFailure(failure); 746 login_status_consumer_->OnLoginFailure(failure);
747 747
748 // Clear the recorded displayed email so it won't affect any future attempts. 748 // Clear the recorded displayed email so it won't affect any future attempts.
749 display_email_.clear(); 749 display_email_.clear();
750 } 750 }
751 751
752 void ExistingUserController::OnLoginSuccess( 752 void ExistingUserController::OnLoginSuccess(
753 const std::string& username, 753 const UserCredentials& credentials,
754 const std::string& password,
755 bool pending_requests, 754 bool pending_requests,
756 bool using_oauth) { 755 bool using_oauth) {
757 is_login_in_progress_ = false; 756 is_login_in_progress_ = false;
758 offline_failed_ = false; 757 offline_failed_ = false;
759 758
760 StopPublicSessionAutoLoginTimer(); 759 StopPublicSessionAutoLoginTimer();
761 760
762 bool has_cookies = 761 bool has_cookies =
763 login_performer_->auth_mode() == LoginPerformer::AUTH_MODE_EXTENSION; 762 login_performer_->auth_mode() == LoginPerformer::AUTH_MODE_EXTENSION &&
763 credentials.auth_code.empty();
764 764
765 // Login performer will be gone so cache this value to use 765 // Login performer will be gone so cache this value to use
766 // once profile is loaded. 766 // once profile is loaded.
767 password_changed_ = login_performer_->password_changed(); 767 password_changed_ = login_performer_->password_changed();
768 768
769 // LoginPerformer instance will delete itself once online auth result is OK. 769 // LoginPerformer instance will delete itself once online auth result is OK.
770 // In case of failure it'll bring up ScreenLock and ask for 770 // In case of failure it'll bring up ScreenLock and ask for
771 // correct password/display error message. 771 // correct password/display error message.
772 // Even in case when following online,offline protocol and returning 772 // Even in case when following online,offline protocol and returning
773 // requests_pending = false, let LoginPerformer delete itself. 773 // requests_pending = false, let LoginPerformer delete itself.
774 login_performer_->set_delegate(NULL); 774 login_performer_->set_delegate(NULL);
775 ignore_result(login_performer_.release()); 775 ignore_result(login_performer_.release());
776 776
777 // Will call OnProfilePrepared() in the end. 777 // Will call OnProfilePrepared() in the end.
778 LoginUtils::Get()->PrepareProfile(username, 778 LoginUtils::Get()->PrepareProfile(credentials,
779 display_email_, 779 display_email_,
780 password,
781 using_oauth, 780 using_oauth,
782 has_cookies, 781 has_cookies,
783 this); 782 this);
784 783
785 display_email_.clear(); 784 display_email_.clear();
786 785
787 // Notify LoginDisplay to allow it provide visual feedback to user. 786 // Notify LoginDisplay to allow it provide visual feedback to user.
788 login_display_->OnLoginSuccess(username); 787 login_display_->OnLoginSuccess(credentials.username);
789 } 788 }
790 789
791 void ExistingUserController::OnProfilePrepared(Profile* profile) { 790 void ExistingUserController::OnProfilePrepared(Profile* profile) {
792 OptionallyShowReleaseNotes(profile); 791 OptionallyShowReleaseNotes(profile);
793 792
794 // Reenable clicking on other windows and status area. 793 // Reenable clicking on other windows and status area.
795 login_display_->SetUIEnabled(true); 794 login_display_->SetUIEnabled(true);
796 795
797 if (UserManager::Get()->IsCurrentUserNew() && 796 if (UserManager::Get()->IsCurrentUserNew() &&
798 !UserManager::Get()->GetCurrentUserFlow()->ShouldSkipPostLoginScreens() && 797 !UserManager::Get()->GetCurrentUserFlow()->ShouldSkipPostLoginScreens() &&
(...skipping 15 matching lines...) Expand all
814 #ifndef NDEBUG 813 #ifndef NDEBUG
815 } 814 }
816 #endif 815 #endif
817 } else { 816 } else {
818 LoginUtils::Get()->DoBrowserLaunch(profile, host_); 817 LoginUtils::Get()->DoBrowserLaunch(profile, host_);
819 host_ = NULL; 818 host_ = NULL;
820 } 819 }
821 // Inform |login_status_consumer_| about successful login. Set most 820 // Inform |login_status_consumer_| about successful login. Set most
822 // parameters to empty since they're not needed. 821 // parameters to empty since they're not needed.
823 if (login_status_consumer_) 822 if (login_status_consumer_)
824 login_status_consumer_->OnLoginSuccess("", "", false, false); 823 login_status_consumer_->OnLoginSuccess(UserCredentials(),
824 false, // pending_requests
825 false); // using_oauth
825 login_display_->OnFadeOut(); 826 login_display_->OnFadeOut();
826 } 827 }
827 828
828 void ExistingUserController::OnOffTheRecordLoginSuccess() { 829 void ExistingUserController::OnOffTheRecordLoginSuccess() {
829 is_login_in_progress_ = false; 830 is_login_in_progress_ = false;
830 offline_failed_ = false; 831 offline_failed_ = false;
831 if (WizardController::IsDeviceRegistered()) { 832 if (WizardController::IsDeviceRegistered()) {
832 LoginUtils::Get()->CompleteOffTheRecordLogin(guest_mode_url_); 833 LoginUtils::Get()->CompleteOffTheRecordLogin(guest_mode_url_);
833 } else { 834 } else {
834 // Postpone CompleteOffTheRecordLogin until registration completion. 835 // Postpone CompleteOffTheRecordLogin until registration completion.
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 // changed. 1120 // changed.
1120 UserManager::Get()->SaveUserOAuthStatus( 1121 UserManager::Get()->SaveUserOAuthStatus(
1121 username, 1122 username,
1122 User::OAUTH2_TOKEN_STATUS_INVALID); 1123 User::OAUTH2_TOKEN_STATUS_INVALID);
1123 1124
1124 login_display_->SetUIEnabled(true); 1125 login_display_->SetUIEnabled(true);
1125 login_display_->ShowGaiaPasswordChanged(username); 1126 login_display_->ShowGaiaPasswordChanged(username);
1126 } 1127 }
1127 1128
1128 } // namespace chromeos 1129 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698