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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.cc

Issue 1412813003: This CL replaces user_manager::UserID with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@468875--Chrome-OS-handles-deletion-of-Gmail-account-poorly--Create-AccountID-structure-part2--user_names
Patch Set: Rebased. Created 5 years, 2 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
OLDNEW
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/chromeos/login/gaia_screen_handler.h" 5 #include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h"
6 6
7 #include "ash/system/chromeos/devicetype_utils.h" 7 #include "ash/system/chromeos/devicetype_utils.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 else 421 else
422 frame_error_ = net::ERR_INTERNET_DISCONNECTED; 422 frame_error_ = net::ERR_INTERNET_DISCONNECTED;
423 423
424 LOG(ERROR) << "Gaia webview error: " << error_reason_str; 424 LOG(ERROR) << "Gaia webview error: " << error_reason_str;
425 NetworkError::ErrorReason error_reason = 425 NetworkError::ErrorReason error_reason =
426 NetworkError::ERROR_REASON_FRAME_ERROR; 426 NetworkError::ERROR_REASON_FRAME_ERROR;
427 frame_state_ = FRAME_STATE_ERROR; 427 frame_state_ = FRAME_STATE_ERROR;
428 UpdateState(error_reason); 428 UpdateState(error_reason);
429 } 429 }
430 430
431 std::string GaiaScreenHandler::GetCanonicalEmail( 431 AccountId GaiaScreenHandler::GetAccountId(
432 const std::string& authenticated_email, 432 const std::string& authenticated_email,
433 const std::string& gaia_id) const { 433 const std::string& gaia_id) const {
434 const std::string sanitized_email = gaia::SanitizeEmail(authenticated_email); 434 const std::string sanitized_email = gaia::SanitizeEmail(authenticated_email);
435 435
436 const std::string canonicalized_email = 436 const std::string canonicalized_email =
437 gaia::CanonicalizeEmail(sanitized_email); 437 gaia::CanonicalizeEmail(sanitized_email);
438 const AccountId authenticated_id(
439 AccountId::FromUserEmailGaiaId(canonicalized_email, gaia_id));
440
438 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 441 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
439 if (user_manager && !user_manager->IsKnownUser(canonicalized_email)) { 442 if (user_manager && !user_manager->IsKnownUser(authenticated_id)) {
stevenjb 2015/10/22 17:52:36 nit: invert and early exit
Alexander Alekseev 2015/10/23 09:11:23 Done.
440 std::string old_canonical_email; 443 AccountId old_account_id(EmptyAccountId());
stevenjb 2015/10/22 17:52:36 It looks like this ship has sailed, but it is a bi
Alexander Alekseev 2015/10/23 09:11:23 The reason for this is to make EmptyAccountId() lo
441 if (user_manager->GetKnownUserCanonicalEmail(gaia_id, 444 if (user_manager->GetKnownUserAccountId(authenticated_id,
442 &old_canonical_email)) { 445 &old_account_id)) {
stevenjb 2015/10/22 17:52:36 nit: invert and early exit (same below, maybe comb
Alexander Alekseev 2015/10/23 09:11:23 Done.
443 if (old_canonical_email != canonicalized_email) { 446 if (old_account_id.GetUserEmail() != canonicalized_email) {
444 LOG(WARNING) << "Existing user '" << old_canonical_email 447 LOG(WARNING) << "Existing user '" << old_account_id.GetUserEmail()
445 << "' authenticated by alias '" << sanitized_email << "'."; 448 << "' authenticated by alias '" << sanitized_email << "'.";
446 return old_canonical_email; 449 return old_account_id;
447 } 450 }
448 } 451 }
449 } 452 }
450 // For compatibility reasons, sanitized email is used. 453 return authenticated_id;
451 return sanitized_email;
452 } 454 }
453 455
454 void GaiaScreenHandler::HandleCompleteAuthentication( 456 void GaiaScreenHandler::HandleCompleteAuthentication(
455 const std::string& gaia_id, 457 const std::string& gaia_id,
456 const std::string& email, 458 const std::string& email,
457 const std::string& password, 459 const std::string& password,
458 const std::string& auth_code, 460 const std::string& auth_code,
459 bool using_saml, 461 bool using_saml,
460 const std::string& gaps_cookie) { 462 const std::string& gaps_cookie) {
461 if (!Delegate()) 463 if (!Delegate())
462 return; 464 return;
463 465
464 DCHECK(!email.empty()); 466 DCHECK(!email.empty());
465 DCHECK(!gaia_id.empty()); 467 DCHECK(!gaia_id.empty());
466 const std::string sanitized_email = gaia::SanitizeEmail(email); 468 const std::string sanitized_email = gaia::SanitizeEmail(email);
467 Delegate()->SetDisplayEmail(sanitized_email); 469 Delegate()->SetDisplayEmail(sanitized_email);
468 470
469 const std::string canonical_email = GetCanonicalEmail(email, gaia_id); 471 const AccountId account_id(GetAccountId(email, gaia_id));
470 UserContext user_context(canonical_email); 472 UserContext user_context(account_id);
achuithb 2015/10/23 00:08:51 Just inline invocation to GetAccountId(email, gaia
Alexander Alekseev 2015/10/23 09:11:23 Done.
471 user_context.SetGaiaID(gaia_id); 473 user_context.SetGaiaID(gaia_id);
472 user_context.SetKey(Key(password)); 474 user_context.SetKey(Key(password));
473 user_context.SetAuthCode(auth_code); 475 user_context.SetAuthCode(auth_code);
474 user_context.SetAuthFlow(using_saml 476 user_context.SetAuthFlow(using_saml
475 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML 477 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML
476 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); 478 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
477 user_context.SetGAPSCookie(gaps_cookie); 479 user_context.SetGAPSCookie(gaps_cookie);
478 Delegate()->CompleteLogin(user_context); 480 Delegate()->CompleteLogin(user_context);
479 } 481 }
480 482
(...skipping 12 matching lines...) Expand all
493 const std::string& typed_email, 495 const std::string& typed_email,
494 const std::string& password, 496 const std::string& password,
495 bool using_saml) { 497 bool using_saml) {
496 if (!is_enrolling_consumer_management_) { 498 if (!is_enrolling_consumer_management_) {
497 DoCompleteLogin(gaia_id, typed_email, password, using_saml); 499 DoCompleteLogin(gaia_id, typed_email, password, using_saml);
498 return; 500 return;
499 } 501 }
500 502
501 // Consumer management enrollment is in progress. 503 // Consumer management enrollment is in progress.
502 const std::string owner_email = 504 const std::string owner_email =
503 user_manager::UserManager::Get()->GetOwnerEmail(); 505 user_manager::UserManager::Get()->GetOwnerId().GetUserEmail();
504 if (typed_email != owner_email) { 506 if (typed_email != owner_email) {
505 // Show Gaia sign-in screen again, since we only allow the owner to sign 507 // Show Gaia sign-in screen again, since we only allow the owner to sign
506 // in. 508 // in.
507 populated_email_ = owner_email; 509 populated_email_ = owner_email;
508 ShowGaiaAsync(is_enrolling_consumer_management_); 510 ShowGaiaAsync(is_enrolling_consumer_management_);
509 return; 511 return;
510 } 512 }
511 513
512 CHECK(consumer_management_); 514 CHECK(consumer_management_);
513 consumer_management_->SetOwner(owner_email, 515 consumer_management_->SetOwner(owner_email,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 if (!Delegate()) 583 if (!Delegate())
582 return; 584 return;
583 585
584 if (using_saml && !using_saml_api_) 586 if (using_saml && !using_saml_api_)
585 RecordSAMLScrapingVerificationResultInHistogram(true); 587 RecordSAMLScrapingVerificationResultInHistogram(true);
586 588
587 DCHECK(!typed_email.empty()); 589 DCHECK(!typed_email.empty());
588 DCHECK(!gaia_id.empty()); 590 DCHECK(!gaia_id.empty());
589 const std::string sanitized_email = gaia::SanitizeEmail(typed_email); 591 const std::string sanitized_email = gaia::SanitizeEmail(typed_email);
590 Delegate()->SetDisplayEmail(sanitized_email); 592 Delegate()->SetDisplayEmail(sanitized_email);
591 const std::string canonical_email = GetCanonicalEmail(typed_email, gaia_id); 593 const AccountId account_id(GetAccountId(typed_email, gaia_id));
592 UserContext user_context(canonical_email); 594 UserContext user_context(account_id);
achuithb 2015/10/23 00:08:51 inline GetAccountId
Alexander Alekseev 2015/10/23 09:11:23 Done.
593 user_context.SetGaiaID(gaia_id); 595 user_context.SetGaiaID(gaia_id);
594 user_context.SetKey(Key(password)); 596 user_context.SetKey(Key(password));
595 user_context.SetAuthFlow(using_saml 597 user_context.SetAuthFlow(using_saml
596 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML 598 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML
597 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); 599 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
598 Delegate()->CompleteLogin(user_context); 600 Delegate()->CompleteLogin(user_context);
599 601
600 if (test_expects_complete_login_) { 602 if (test_expects_complete_login_) {
601 VLOG(2) << "Complete test login for " << typed_email 603 VLOG(2) << "Complete test login for " << typed_email
602 << ", requested=" << test_user_; 604 << ", requested=" << test_user_;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 imm->SetState(gaia_ime_state); 743 imm->SetState(gaia_ime_state);
742 744
743 // Set Least Recently Used input method for the user. 745 // Set Least Recently Used input method for the user.
744 if (!populated_email_.empty()) { 746 if (!populated_email_.empty()) {
745 SigninScreenHandler::SetUserInputMethod(populated_email_, 747 SigninScreenHandler::SetUserInputMethod(populated_email_,
746 gaia_ime_state.get()); 748 gaia_ime_state.get());
747 } else { 749 } else {
748 std::vector<std::string> input_methods = 750 std::vector<std::string> input_methods =
749 imm->GetInputMethodUtil()->GetHardwareLoginInputMethodIds(); 751 imm->GetInputMethodUtil()->GetHardwareLoginInputMethodIds();
750 const std::string owner_im = SigninScreenHandler::GetUserLRUInputMethod( 752 const std::string owner_im = SigninScreenHandler::GetUserLRUInputMethod(
751 user_manager::UserManager::Get()->GetOwnerEmail()); 753 user_manager::UserManager::Get()->GetOwnerId().GetUserEmail());
752 const std::string system_im = g_browser_process->local_state()->GetString( 754 const std::string system_im = g_browser_process->local_state()->GetString(
753 language_prefs::kPreferredKeyboardLayout); 755 language_prefs::kPreferredKeyboardLayout);
754 756
755 PushFrontIMIfNotExists(owner_im, &input_methods); 757 PushFrontIMIfNotExists(owner_im, &input_methods);
756 PushFrontIMIfNotExists(system_im, &input_methods); 758 PushFrontIMIfNotExists(system_im, &input_methods);
757 759
758 gaia_ime_state->EnableLoginLayouts( 760 gaia_ime_state->EnableLoginLayouts(
759 g_browser_process->GetApplicationLocale(), input_methods); 761 g_browser_process->GetApplicationLocale(), input_methods);
760 762
761 if (!system_im.empty()) { 763 if (!system_im.empty()) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 << ", silent_load: " << silent_load 831 << ", silent_load: " << silent_load
830 << ", offline: " << offline; 832 << ", offline: " << offline;
831 GaiaContext context; 833 GaiaContext context;
832 context.force_reload = force; 834 context.force_reload = force;
833 context.is_local = offline; 835 context.is_local = offline;
834 context.use_offline = offline; 836 context.use_offline = offline;
835 context.email = populated_email_; 837 context.email = populated_email_;
836 context.is_enrolling_consumer_management = is_enrolling_consumer_management_; 838 context.is_enrolling_consumer_management = is_enrolling_consumer_management_;
837 839
838 std::string gaia_id; 840 std::string gaia_id;
839 if (user_manager::UserManager::Get()->FindGaiaID(context.email, &gaia_id)) 841 if (user_manager::UserManager::Get()->FindGaiaID(
842 AccountId::FromUserEmail(context.email), &gaia_id))
840 context.gaia_id = gaia_id; 843 context.gaia_id = gaia_id;
841 844
842 if (Delegate()) { 845 if (Delegate()) {
843 context.show_users = Delegate()->IsShowUsers(); 846 context.show_users = Delegate()->IsShowUsers();
844 } 847 }
845 848
846 if (!context.email.empty()) { 849 if (!context.email.empty()) {
847 context.gaps_cookie = 850 context.gaps_cookie =
848 user_manager::UserManager::Get()->GetKnownUserGAPSCookie( 851 user_manager::UserManager::Get()->GetKnownUserGAPSCookie(
849 gaia::CanonicalizeEmail(context.email)); 852 AccountId::FromUserEmail(gaia::CanonicalizeEmail(context.email)));
850 } 853 }
851 854
852 populated_email_.clear(); 855 populated_email_.clear();
853 856
854 LoadGaia(context); 857 LoadGaia(context);
855 } 858 }
856 859
857 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) { 860 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) {
858 if (signin_screen_handler_) 861 if (signin_screen_handler_)
859 signin_screen_handler_->UpdateState(reason); 862 signin_screen_handler_->UpdateState(reason);
(...skipping 11 matching lines...) Expand all
871 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL || 874 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL ||
872 captive_portal_status_ == 875 captive_portal_status_ ==
873 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; 876 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE;
874 } 877 }
875 878
876 void GaiaScreenHandler::DisableRestrictiveProxyCheckForTest() { 879 void GaiaScreenHandler::DisableRestrictiveProxyCheckForTest() {
877 disable_restrictive_proxy_check_for_test_ = true; 880 disable_restrictive_proxy_check_for_test_ = true;
878 } 881 }
879 882
880 } // namespace chromeos 883 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698