| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/webui/signin/user_manager_screen_handler.h" | 5 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 email_address_ = email_address; | 446 email_address_ = email_address; |
| 447 password_attempt_ = password; | 447 password_attempt_ = password; |
| 448 | 448 |
| 449 // This could be a mis-typed password or typing a new password while we | 449 // This could be a mis-typed password or typing a new password while we |
| 450 // still have a hash of the old one. The new way of checking a password | 450 // still have a hash of the old one. The new way of checking a password |
| 451 // change makes use of a token so we do that... if it's available. | 451 // change makes use of a token so we do that... if it's available. |
| 452 if (!oauth_client_) { | 452 if (!oauth_client_) { |
| 453 oauth_client_.reset(new gaia::GaiaOAuthClient( | 453 oauth_client_.reset(new gaia::GaiaOAuthClient( |
| 454 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext())); | 454 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext())); |
| 455 } | 455 } |
| 456 |
| 456 std::string token = info_cache.GetPasswordChangeDetectionTokenAtIndex( | 457 std::string token = info_cache.GetPasswordChangeDetectionTokenAtIndex( |
| 457 profile_index); | 458 authenticating_profile_index_); |
| 458 if (!token.empty()) { | 459 if (!token.empty()) { |
| 459 oauth_client_->GetTokenHandleInfo(token, kMaxOAuthRetries, this); | 460 oauth_client_->GetTokenHandleInfo(token, kMaxOAuthRetries, this); |
| 460 return; | 461 return; |
| 461 } | 462 } |
| 462 | 463 |
| 463 // In order to support the upgrade case where we have a local hash but no | 464 // In order to support the upgrade case where we have a local hash but no |
| 464 // password token, we fall back on (deprecated) ClientLogin. This will | 465 // password token, the user perform a full online reauth. |
| 465 // have to be removed in future versions as the service gets turned down | 466 UserManager::ShowReauthDialog(web_ui()->GetWebContents()->GetBrowserContext(), |
| 466 // but by then we'll have seamlessly updated the majority of users. | 467 base::UTF16ToUTF8(email_address_), authenticating_profile_index_); |
| 467 client_login_.reset(new GaiaAuthFetcher( | |
| 468 this, | |
| 469 GaiaConstants::kChromeSource, | |
| 470 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext())); | |
| 471 | |
| 472 client_login_->StartClientLogin( | |
| 473 base::UTF16ToUTF8(email_address), | |
| 474 password, | |
| 475 GaiaConstants::kSyncService, | |
| 476 std::string(), | |
| 477 std::string(), | |
| 478 GaiaAuthFetcher::HostedAccountsAllowed); | |
| 479 } | 468 } |
| 480 | 469 |
| 481 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { | 470 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { |
| 482 DCHECK(args); | 471 DCHECK(args); |
| 483 const base::Value* profile_path_value; | 472 const base::Value* profile_path_value; |
| 484 if (!args->Get(0, &profile_path_value)) { | 473 if (!args->Get(0, &profile_path_value)) { |
| 485 NOTREACHED(); | 474 NOTREACHED(); |
| 486 return; | 475 return; |
| 487 } | 476 } |
| 488 | 477 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 } | 561 } |
| 573 | 562 |
| 574 void UserManagerScreenHandler::OnGetTokenInfoResponse( | 563 void UserManagerScreenHandler::OnGetTokenInfoResponse( |
| 575 scoped_ptr<base::DictionaryValue> token_info) { | 564 scoped_ptr<base::DictionaryValue> token_info) { |
| 576 // Password is unchanged so user just mistyped it. Ask again. | 565 // Password is unchanged so user just mistyped it. Ask again. |
| 577 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); | 566 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); |
| 578 } | 567 } |
| 579 | 568 |
| 580 void UserManagerScreenHandler::OnOAuthError() { | 569 void UserManagerScreenHandler::OnOAuthError() { |
| 581 // Password has changed. Go through online signin flow. | 570 // Password has changed. Go through online signin flow. |
| 582 // ... if we had it. Until then, use deprecated ClientLogin to validate | |
| 583 // the password. This will have to be changed soon. (TODO: bcwhite) | |
| 584 oauth_client_.reset(); | |
| 585 client_login_.reset(new GaiaAuthFetcher( | |
| 586 this, | |
| 587 GaiaConstants::kChromeSource, | |
| 588 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext())); | |
| 589 | |
| 590 DCHECK(!email_address_.empty()); | 571 DCHECK(!email_address_.empty()); |
| 591 DCHECK(!password_attempt_.empty()); | 572 DCHECK_NE(std::string::npos, authenticating_profile_index_); |
| 592 client_login_->StartClientLogin( | 573 oauth_client_.reset(); |
| 593 base::UTF16ToUTF8(email_address_), | 574 UserManager::ShowReauthDialog(web_ui()->GetWebContents()->GetBrowserContext(), |
| 594 password_attempt_, | 575 base::UTF16ToUTF8(email_address_), authenticating_profile_index_); |
| 595 GaiaConstants::kSyncService, | |
| 596 std::string(), | |
| 597 std::string(), | |
| 598 GaiaAuthFetcher::HostedAccountsAllowed); | |
| 599 } | 576 } |
| 600 | 577 |
| 601 void UserManagerScreenHandler::OnNetworkError(int response_code) { | 578 void UserManagerScreenHandler::OnNetworkError(int response_code) { |
| 602 // Inconclusive but can't do real signin without being online anyway. | 579 // Inconclusive but can't do real signin without being online anyway. |
| 603 oauth_client_.reset(); | 580 oauth_client_.reset(); |
| 604 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED_OFFLINE); | 581 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED_OFFLINE); |
| 605 } | 582 } |
| 606 | 583 |
| 607 void UserManagerScreenHandler::OnClientLoginSuccess( | |
| 608 const ClientLoginResult& result) { | |
| 609 oauth_client_.reset(); | |
| 610 LocalAuth::SetLocalAuthCredentials(authenticating_profile_index_, | |
| 611 password_attempt_); | |
| 612 ReportAuthenticationResult(true, ProfileMetrics::AUTH_ONLINE); | |
| 613 } | |
| 614 | |
| 615 void UserManagerScreenHandler::OnClientLoginFailure( | |
| 616 const GoogleServiceAuthError& error) { | |
| 617 const GoogleServiceAuthError::State state = error.state(); | |
| 618 // Some "error" results mean the password was correct but some other action | |
| 619 // should be taken. For our purposes, we only care that the password was | |
| 620 // correct so count those as a success. | |
| 621 bool success = (state == GoogleServiceAuthError::NONE || | |
| 622 state == GoogleServiceAuthError::CAPTCHA_REQUIRED || | |
| 623 state == GoogleServiceAuthError::TWO_FACTOR || | |
| 624 state == GoogleServiceAuthError::ACCOUNT_DELETED || | |
| 625 state == GoogleServiceAuthError::ACCOUNT_DISABLED || | |
| 626 state == GoogleServiceAuthError::WEB_LOGIN_REQUIRED); | |
| 627 | |
| 628 // If the password was correct, the user must have changed it since the | |
| 629 // profile was locked. Save the password to streamline future unlocks. | |
| 630 if (success) { | |
| 631 DCHECK(!password_attempt_.empty()); | |
| 632 LocalAuth::SetLocalAuthCredentials(authenticating_profile_index_, | |
| 633 password_attempt_); | |
| 634 } | |
| 635 | |
| 636 bool offline = error.IsTransientError(); | |
| 637 ProfileMetrics::ProfileAuth failure_metric = | |
| 638 offline ? ProfileMetrics::AUTH_FAILED_OFFLINE : | |
| 639 ProfileMetrics::AUTH_FAILED; | |
| 640 ReportAuthenticationResult( | |
| 641 success, success ? ProfileMetrics::AUTH_ONLINE : failure_metric); | |
| 642 } | |
| 643 | |
| 644 void UserManagerScreenHandler::RegisterMessages() { | 584 void UserManagerScreenHandler::RegisterMessages() { |
| 645 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize, | 585 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize, |
| 646 base::Bind(&UserManagerScreenHandler::HandleInitialize, | 586 base::Bind(&UserManagerScreenHandler::HandleInitialize, |
| 647 base::Unretained(this))); | 587 base::Unretained(this))); |
| 648 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser, | 588 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser, |
| 649 base::Bind(&UserManagerScreenHandler::HandleAddUser, | 589 base::Bind(&UserManagerScreenHandler::HandleAddUser, |
| 650 base::Unretained(this))); | 590 base::Unretained(this))); |
| 651 web_ui()->RegisterMessageCallback(kJsApiUserManagerAuthLaunchUser, | 591 web_ui()->RegisterMessageCallback(kJsApiUserManagerAuthLaunchUser, |
| 652 base::Bind(&UserManagerScreenHandler::HandleAuthenticatedLaunchUser, | 592 base::Bind(&UserManagerScreenHandler::HandleAuthenticatedLaunchUser, |
| 653 base::Unretained(this))); | 593 base::Unretained(this))); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 Profile* profile, Profile::CreateStatus profile_create_status) { | 856 Profile* profile, Profile::CreateStatus profile_create_status) { |
| 917 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); | 857 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
| 918 if (browser && browser->window()) { | 858 if (browser && browser->window()) { |
| 919 OnBrowserWindowReady(browser); | 859 OnBrowserWindowReady(browser); |
| 920 } else { | 860 } else { |
| 921 registrar_.Add(this, | 861 registrar_.Add(this, |
| 922 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 862 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 923 content::NotificationService::AllSources()); | 863 content::NotificationService::AllSources()); |
| 924 } | 864 } |
| 925 } | 865 } |
| OLD | NEW |