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

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: Update after review. Created 5 years, 1 month 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);
achuithb 2015/10/28 23:11:46 I think you can get rid of this temporary and inli
Alexander Alekseev 2015/10/29 02:00:41 Done.
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(
achuithb 2015/10/28 23:11:46 authenticated_account_id?
Alexander Alekseev 2015/10/29 02:00:41 Done.
439 AccountId::FromUserEmailGaiaId(canonicalized_email, gaia_id));
440
441 // If we don't have UserManager instance (i.e. we are in unit test),
442 // or a known user has authenticated, just log in.
438 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 443 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
439 if (user_manager && !user_manager->IsKnownUser(canonicalized_email)) { 444 if (!user_manager || user_manager->IsKnownUser(authenticated_id))
440 std::string old_canonical_email; 445 return authenticated_id;
441 if (user_manager->GetKnownUserCanonicalEmail(gaia_id, 446
442 &old_canonical_email)) { 447 // If [part of] user id has changed, update stored data and connect user
443 if (old_canonical_email != canonicalized_email) { 448 // to existing home directory.
444 LOG(WARNING) << "Existing user '" << old_canonical_email 449 AccountId old_account_id(EmptyAccountId());
445 << "' authenticated by alias '" << sanitized_email << "'."; 450 if (!user_manager->GetKnownUserAccountId(authenticated_id, &old_account_id)) {
achuithb 2015/10/28 23:11:46 Don't need {}
Alexander Alekseev 2015/10/29 02:00:41 Now it has multiline condition.
446 return old_canonical_email; 451 return authenticated_id;
447 }
448 }
449 } 452 }
450 // For compatibility reasons, sanitized email is used. 453
451 return sanitized_email; 454 if (old_account_id.GetUserEmail() != canonicalized_email) {
455 LOG(WARNING) << "Existing user '" << old_account_id.GetUserEmail()
achuithb 2015/10/28 23:11:46 Wonder if we should make this VLOG(1) instead
Alexander Alekseev 2015/10/29 02:00:42 This is only 1 log line per user login. Do you thi
456 << "' authenticated by alias '" << sanitized_email << "'.";
achuithb 2015/10/28 23:11:46 canonicalized_email?
Alexander Alekseev 2015/10/29 02:00:41 Done.
457 return old_account_id;
458 }
459
460 return authenticated_id;
achuithb 2015/10/28 23:11:46 This is a change of behavior right? Because now yo
Alexander Alekseev 2015/10/29 02:00:41 Yes! This is a first step to have AccountId assoc
452 } 461 }
453 462
454 void GaiaScreenHandler::HandleCompleteAuthentication( 463 void GaiaScreenHandler::HandleCompleteAuthentication(
455 const std::string& gaia_id, 464 const std::string& gaia_id,
456 const std::string& email, 465 const std::string& email,
457 const std::string& password, 466 const std::string& password,
458 const std::string& auth_code, 467 const std::string& auth_code,
459 bool using_saml, 468 bool using_saml,
460 const std::string& gaps_cookie) { 469 const std::string& gaps_cookie) {
461 if (!Delegate()) 470 if (!Delegate())
462 return; 471 return;
463 472
464 DCHECK(!email.empty()); 473 DCHECK(!email.empty());
465 DCHECK(!gaia_id.empty()); 474 DCHECK(!gaia_id.empty());
466 const std::string sanitized_email = gaia::SanitizeEmail(email); 475 const std::string sanitized_email = gaia::SanitizeEmail(email);
467 Delegate()->SetDisplayEmail(sanitized_email); 476 Delegate()->SetDisplayEmail(sanitized_email);
468 477
469 const std::string canonical_email = GetCanonicalEmail(email, gaia_id); 478 UserContext user_context(GetAccountId(email, gaia_id));
470 UserContext user_context(canonical_email);
471 user_context.SetGaiaID(gaia_id); 479 user_context.SetGaiaID(gaia_id);
472 user_context.SetKey(Key(password)); 480 user_context.SetKey(Key(password));
473 user_context.SetAuthCode(auth_code); 481 user_context.SetAuthCode(auth_code);
474 user_context.SetAuthFlow(using_saml 482 user_context.SetAuthFlow(using_saml
475 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML 483 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML
476 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); 484 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
477 user_context.SetGAPSCookie(gaps_cookie); 485 user_context.SetGAPSCookie(gaps_cookie);
478 Delegate()->CompleteLogin(user_context); 486 Delegate()->CompleteLogin(user_context);
479 } 487 }
480 488
(...skipping 12 matching lines...) Expand all
493 const std::string& typed_email, 501 const std::string& typed_email,
494 const std::string& password, 502 const std::string& password,
495 bool using_saml) { 503 bool using_saml) {
496 if (!is_enrolling_consumer_management_) { 504 if (!is_enrolling_consumer_management_) {
497 DoCompleteLogin(gaia_id, typed_email, password, using_saml); 505 DoCompleteLogin(gaia_id, typed_email, password, using_saml);
498 return; 506 return;
499 } 507 }
500 508
501 // Consumer management enrollment is in progress. 509 // Consumer management enrollment is in progress.
502 const std::string owner_email = 510 const std::string owner_email =
503 user_manager::UserManager::Get()->GetOwnerEmail(); 511 user_manager::UserManager::Get()->GetOwnerAccountId().GetUserEmail();
504 if (typed_email != owner_email) { 512 if (typed_email != owner_email) {
505 // Show Gaia sign-in screen again, since we only allow the owner to sign 513 // Show Gaia sign-in screen again, since we only allow the owner to sign
506 // in. 514 // in.
507 populated_email_ = owner_email; 515 populated_email_ = owner_email;
508 ShowGaiaAsync(is_enrolling_consumer_management_); 516 ShowGaiaAsync(is_enrolling_consumer_management_);
509 return; 517 return;
510 } 518 }
511 519
512 CHECK(consumer_management_); 520 CHECK(consumer_management_);
513 consumer_management_->SetOwner(owner_email, 521 consumer_management_->SetOwner(owner_email,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 if (!Delegate()) 589 if (!Delegate())
582 return; 590 return;
583 591
584 if (using_saml && !using_saml_api_) 592 if (using_saml && !using_saml_api_)
585 RecordSAMLScrapingVerificationResultInHistogram(true); 593 RecordSAMLScrapingVerificationResultInHistogram(true);
586 594
587 DCHECK(!typed_email.empty()); 595 DCHECK(!typed_email.empty());
588 DCHECK(!gaia_id.empty()); 596 DCHECK(!gaia_id.empty());
589 const std::string sanitized_email = gaia::SanitizeEmail(typed_email); 597 const std::string sanitized_email = gaia::SanitizeEmail(typed_email);
590 Delegate()->SetDisplayEmail(sanitized_email); 598 Delegate()->SetDisplayEmail(sanitized_email);
591 const std::string canonical_email = GetCanonicalEmail(typed_email, gaia_id); 599 UserContext user_context(GetAccountId(typed_email, gaia_id));
592 UserContext user_context(canonical_email);
593 user_context.SetGaiaID(gaia_id); 600 user_context.SetGaiaID(gaia_id);
594 user_context.SetKey(Key(password)); 601 user_context.SetKey(Key(password));
595 user_context.SetAuthFlow(using_saml 602 user_context.SetAuthFlow(using_saml
596 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML 603 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML
597 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); 604 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
598 Delegate()->CompleteLogin(user_context); 605 Delegate()->CompleteLogin(user_context);
599 606
600 if (test_expects_complete_login_) { 607 if (test_expects_complete_login_) {
601 VLOG(2) << "Complete test login for " << typed_email 608 VLOG(2) << "Complete test login for " << typed_email
602 << ", requested=" << test_user_; 609 << ", requested=" << test_user_;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 imm->SetState(gaia_ime_state); 748 imm->SetState(gaia_ime_state);
742 749
743 // Set Least Recently Used input method for the user. 750 // Set Least Recently Used input method for the user.
744 if (!populated_email_.empty()) { 751 if (!populated_email_.empty()) {
745 SigninScreenHandler::SetUserInputMethod(populated_email_, 752 SigninScreenHandler::SetUserInputMethod(populated_email_,
746 gaia_ime_state.get()); 753 gaia_ime_state.get());
747 } else { 754 } else {
748 std::vector<std::string> input_methods = 755 std::vector<std::string> input_methods =
749 imm->GetInputMethodUtil()->GetHardwareLoginInputMethodIds(); 756 imm->GetInputMethodUtil()->GetHardwareLoginInputMethodIds();
750 const std::string owner_im = SigninScreenHandler::GetUserLRUInputMethod( 757 const std::string owner_im = SigninScreenHandler::GetUserLRUInputMethod(
751 user_manager::UserManager::Get()->GetOwnerEmail()); 758 user_manager::UserManager::Get()->GetOwnerAccountId().GetUserEmail());
752 const std::string system_im = g_browser_process->local_state()->GetString( 759 const std::string system_im = g_browser_process->local_state()->GetString(
753 language_prefs::kPreferredKeyboardLayout); 760 language_prefs::kPreferredKeyboardLayout);
754 761
755 PushFrontIMIfNotExists(owner_im, &input_methods); 762 PushFrontIMIfNotExists(owner_im, &input_methods);
756 PushFrontIMIfNotExists(system_im, &input_methods); 763 PushFrontIMIfNotExists(system_im, &input_methods);
757 764
758 gaia_ime_state->EnableLoginLayouts( 765 gaia_ime_state->EnableLoginLayouts(
759 g_browser_process->GetApplicationLocale(), input_methods); 766 g_browser_process->GetApplicationLocale(), input_methods);
760 767
761 if (!system_im.empty()) { 768 if (!system_im.empty()) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 << ", silent_load: " << silent_load 836 << ", silent_load: " << silent_load
830 << ", offline: " << offline; 837 << ", offline: " << offline;
831 GaiaContext context; 838 GaiaContext context;
832 context.force_reload = force; 839 context.force_reload = force;
833 context.is_local = offline; 840 context.is_local = offline;
834 context.use_offline = offline; 841 context.use_offline = offline;
835 context.email = populated_email_; 842 context.email = populated_email_;
836 context.is_enrolling_consumer_management = is_enrolling_consumer_management_; 843 context.is_enrolling_consumer_management = is_enrolling_consumer_management_;
837 844
838 std::string gaia_id; 845 std::string gaia_id;
839 if (user_manager::UserManager::Get()->FindGaiaID(context.email, &gaia_id)) 846 if (user_manager::UserManager::Get()->FindGaiaID(
847 AccountId::FromUserEmail(context.email), &gaia_id))
840 context.gaia_id = gaia_id; 848 context.gaia_id = gaia_id;
841 849
842 if (Delegate()) { 850 if (Delegate()) {
843 context.show_users = Delegate()->IsShowUsers(); 851 context.show_users = Delegate()->IsShowUsers();
844 } 852 }
845 853
846 if (!context.email.empty()) { 854 if (!context.email.empty()) {
847 context.gaps_cookie = 855 context.gaps_cookie =
848 user_manager::UserManager::Get()->GetKnownUserGAPSCookie( 856 user_manager::UserManager::Get()->GetKnownUserGAPSCookie(
849 gaia::CanonicalizeEmail(context.email)); 857 AccountId::FromUserEmail(gaia::CanonicalizeEmail(context.email)));
850 } 858 }
851 859
852 populated_email_.clear(); 860 populated_email_.clear();
853 861
854 LoadGaia(context); 862 LoadGaia(context);
855 } 863 }
856 864
857 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) { 865 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) {
858 if (signin_screen_handler_) 866 if (signin_screen_handler_)
859 signin_screen_handler_->UpdateState(reason); 867 signin_screen_handler_->UpdateState(reason);
(...skipping 11 matching lines...) Expand all
871 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL || 879 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL ||
872 captive_portal_status_ == 880 captive_portal_status_ ==
873 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; 881 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE;
874 } 882 }
875 883
876 void GaiaScreenHandler::DisableRestrictiveProxyCheckForTest() { 884 void GaiaScreenHandler::DisableRestrictiveProxyCheckForTest() {
877 disable_restrictive_proxy_check_for_test_ = true; 885 disable_restrictive_proxy_check_for_test_ = true;
878 } 886 }
879 887
880 } // namespace chromeos 888 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698