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

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

Issue 1165323004: We should use UserID object to identify users instead of username. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 bool using_saml) { 497 bool using_saml) {
498 if (!Delegate()) 498 if (!Delegate())
499 return; 499 return;
500 500
501 RecordGAIAFlowTypeHistogram(); 501 RecordGAIAFlowTypeHistogram();
502 502
503 DCHECK(!email.empty()); 503 DCHECK(!email.empty());
504 DCHECK(!gaia_id.empty()); 504 DCHECK(!gaia_id.empty());
505 const std::string sanitized_email = gaia::SanitizeEmail(email); 505 const std::string sanitized_email = gaia::SanitizeEmail(email);
506 Delegate()->SetDisplayEmail(sanitized_email); 506 Delegate()->SetDisplayEmail(sanitized_email);
507 UserContext user_context(sanitized_email); 507
508 user_context.SetGaiaID(gaia_id); 508 user_manager::UserID user_id(user_manager::UserID::FromUserEmail(sanitized_ema il));
509 user_id.SetGaiaId(gaia_id);
510 UserContext user_context(user_id);
509 user_context.SetKey(Key(password)); 511 user_context.SetKey(Key(password));
510 user_context.SetAuthCode(auth_code); 512 user_context.SetAuthCode(auth_code);
511 user_context.SetAuthFlow(using_saml 513 user_context.SetAuthFlow(using_saml
512 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML 514 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML
513 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); 515 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
514 Delegate()->CompleteLogin(user_context); 516 Delegate()->CompleteLogin(user_context);
515 } 517 }
516 518
517 void GaiaScreenHandler::HandleCompleteAuthenticationAuthCodeOnly( 519 void GaiaScreenHandler::HandleCompleteAuthenticationAuthCodeOnly(
518 const std::string& auth_code) { 520 const std::string& auth_code) {
(...skipping 11 matching lines...) Expand all
530 void GaiaScreenHandler::HandleCompleteLogin(const std::string& gaia_id, 532 void GaiaScreenHandler::HandleCompleteLogin(const std::string& gaia_id,
531 const std::string& typed_email, 533 const std::string& typed_email,
532 const std::string& password, 534 const std::string& password,
533 bool using_saml) { 535 bool using_saml) {
534 if (!is_enrolling_consumer_management_) { 536 if (!is_enrolling_consumer_management_) {
535 DoCompleteLogin(gaia_id, typed_email, password, using_saml); 537 DoCompleteLogin(gaia_id, typed_email, password, using_saml);
536 return; 538 return;
537 } 539 }
538 540
539 // Consumer management enrollment is in progress. 541 // Consumer management enrollment is in progress.
540 const std::string owner_email = 542 const user_manager::UserID owner_id =
541 user_manager::UserManager::Get()->GetOwnerEmail(); 543 user_manager::UserManager::Get()->GetOwnerID();
542 if (typed_email != owner_email) { 544 if (user_manager::UserID::FromUserEmail(typed_email) != owner_id) {
543 // Show Gaia sign-in screen again, since we only allow the owner to sign 545 // Show Gaia sign-in screen again, since we only allow the owner to sign
544 // in. 546 // in.
545 populated_email_ = owner_email; 547 populated_email_ = owner_id.GetUserEmail();
546 ShowGaiaAsync(is_enrolling_consumer_management_); 548 ShowGaiaAsync(is_enrolling_consumer_management_);
547 return; 549 return;
548 } 550 }
549 551
550 CHECK(consumer_management_); 552 CHECK(consumer_management_);
551 consumer_management_->SetOwner(owner_email, 553 consumer_management_->SetOwner(owner_id,
552 base::Bind(&GaiaScreenHandler::OnSetOwnerDone, 554 base::Bind(&GaiaScreenHandler::OnSetOwnerDone,
553 weak_factory_.GetWeakPtr(), 555 weak_factory_.GetWeakPtr(),
554 gaia_id, 556 gaia_id,
555 typed_email, 557 typed_email,
556 password, 558 password,
557 using_saml)); 559 using_saml));
558 } 560 }
559 561
560 void GaiaScreenHandler::HandleUsingSAMLAPI() { 562 void GaiaScreenHandler::HandleUsingSAMLAPI() {
561 SetSAMLPrincipalsAPIUsed(true); 563 SetSAMLPrincipalsAPIUsed(true);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 return; 659 return;
658 660
659 if (using_saml && !using_saml_api_) 661 if (using_saml && !using_saml_api_)
660 RecordSAMLScrapingVerificationResultInHistogram(true); 662 RecordSAMLScrapingVerificationResultInHistogram(true);
661 RecordGAIAFlowTypeHistogram(); 663 RecordGAIAFlowTypeHistogram();
662 664
663 DCHECK(!typed_email.empty()); 665 DCHECK(!typed_email.empty());
664 DCHECK(!gaia_id.empty()); 666 DCHECK(!gaia_id.empty());
665 const std::string sanitized_email = gaia::SanitizeEmail(typed_email); 667 const std::string sanitized_email = gaia::SanitizeEmail(typed_email);
666 Delegate()->SetDisplayEmail(sanitized_email); 668 Delegate()->SetDisplayEmail(sanitized_email);
667 UserContext user_context(sanitized_email); 669
668 user_context.SetGaiaID(gaia_id); 670 user_manager::UserID user_id(user_manager::UserID::FromUserEmail(sanitized_ema il));
671 user_id.SetGaiaId(gaia_id);
672 UserContext user_context(user_id);
669 user_context.SetKey(Key(password)); 673 user_context.SetKey(Key(password));
670 user_context.SetAuthFlow(using_saml 674 user_context.SetAuthFlow(using_saml
671 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML 675 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML
672 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); 676 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
673 Delegate()->CompleteLogin(user_context); 677 Delegate()->CompleteLogin(user_context);
674 678
675 if (test_expects_complete_login_) { 679 if (test_expects_complete_login_) {
676 VLOG(2) << "Complete test login for " << typed_email 680 VLOG(2) << "Complete test login for " << typed_email
677 << ", requested=" << test_user_; 681 << ", requested=" << test_user_;
678 682
679 test_expects_complete_login_ = false; 683 test_expects_complete_login_ = false;
680 test_user_.clear(); 684 test_user_.clear();
681 test_pass_.clear(); 685 test_pass_.clear();
682 } 686 }
683 } 687 }
684 688
685 void GaiaScreenHandler::PopulateEmail(const std::string& user_id) { 689 void GaiaScreenHandler::PopulateEmail(const std::string& user_id) {
686 populated_email_ = user_id; 690 populated_email_ = user_id;
687 } 691 }
688 692
689 void GaiaScreenHandler::PasswordChangedFor(const std::string& user_id) { 693 void GaiaScreenHandler::PasswordChangedFor(const user_manager::UserID& user_id) {
690 password_changed_for_.insert(user_id); 694 password_changed_for_.insert(user_id);
691 } 695 }
692 696
693 void GaiaScreenHandler::StartClearingDnsCache() { 697 void GaiaScreenHandler::StartClearingDnsCache() {
694 if (dns_clear_task_running_ || !g_browser_process->io_thread()) 698 if (dns_clear_task_running_ || !g_browser_process->io_thread())
695 return; 699 return;
696 700
697 dns_cleared_ = false; 701 dns_cleared_ = false;
698 BrowserThread::PostTaskAndReply( 702 BrowserThread::PostTaskAndReply(
699 BrowserThread::IO, 703 BrowserThread::IO,
(...skipping 21 matching lines...) Expand all
721 weak_factory_.GetWeakPtr(), on_clear_callback)); 725 weak_factory_.GetWeakPtr(), on_clear_callback));
722 } 726 }
723 727
724 void GaiaScreenHandler::OnCookiesCleared( 728 void GaiaScreenHandler::OnCookiesCleared(
725 const base::Closure& on_clear_callback) { 729 const base::Closure& on_clear_callback) {
726 DCHECK_CURRENTLY_ON(BrowserThread::UI); 730 DCHECK_CURRENTLY_ON(BrowserThread::UI);
727 cookies_cleared_ = true; 731 cookies_cleared_ = true;
728 on_clear_callback.Run(); 732 on_clear_callback.Run();
729 } 733 }
730 734
731 void GaiaScreenHandler::ShowSigninScreenForCreds(const std::string& username, 735 void GaiaScreenHandler::ShowSigninScreenForCreds(const user_manager::UserID& use r_id,
732 const std::string& password) { 736 const std::string& password) {
733 VLOG(2) << "ShowSigninScreenForCreds for user " << username 737 VLOG(2) << "ShowSigninScreenForCreds for user " << user_id.GetUserEmail()
734 << ", frame_state=" << frame_state(); 738 << ", frame_state=" << frame_state();
735 739
736 test_user_ = username; 740 test_user_ = user_id.GetUserEmail();
737 test_pass_ = password; 741 test_pass_ = password;
738 test_expects_complete_login_ = true; 742 test_expects_complete_login_ = true;
739 743
740 // Submit login form for test if gaia is ready. If gaia is loading, login 744 // Submit login form for test if gaia is ready. If gaia is loading, login
741 // will be attempted in HandleLoginWebuiReady after gaia is ready. Otherwise, 745 // will be attempted in HandleLoginWebuiReady after gaia is ready. Otherwise,
742 // reload gaia then follow the loading case. 746 // reload gaia then follow the loading case.
743 if (frame_state() == GaiaScreenHandler::FRAME_STATE_LOADED) { 747 if (frame_state() == GaiaScreenHandler::FRAME_STATE_LOADED) {
744 SubmitLoginFormForTest(); 748 SubmitLoginFormForTest();
745 } else if (frame_state() != GaiaScreenHandler::FRAME_STATE_LOADING) { 749 } else if (frame_state() != GaiaScreenHandler::FRAME_STATE_LOADING) {
746 DCHECK(signin_screen_handler_); 750 DCHECK(signin_screen_handler_);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 std::string active_network_path = network_state_informer_->network_path(); 822 std::string active_network_path = network_state_informer_->network_path();
819 if (gaia_silent_load_ && 823 if (gaia_silent_load_ &&
820 (network_state_informer_->state() != NetworkStateInformer::ONLINE || 824 (network_state_informer_->state() != NetworkStateInformer::ONLINE ||
821 gaia_silent_load_network_ != active_network_path)) { 825 gaia_silent_load_network_ != active_network_path)) {
822 // Network has changed. Force Gaia reload. 826 // Network has changed. Force Gaia reload.
823 gaia_silent_load_ = false; 827 gaia_silent_load_ = false;
824 // Gaia page will be realoded, so focus isn't stolen anymore. 828 // Gaia page will be realoded, so focus isn't stolen anymore.
825 focus_stolen_ = false; 829 focus_stolen_ = false;
826 } 830 }
827 831
828 // Note that LoadAuthExtension clears |populated_email_|. 832 const user_manager::UserID populated_user_id = user_manager::UserID::FromUserE mail(populated_email_);
829 if (populated_email_.empty()) 833
834 // Note that LoadAuthExtension clears |populated_user_id|.
835 if (populated_user_id.empty())
830 Delegate()->LoadSigninWallpaper(); 836 Delegate()->LoadSigninWallpaper();
831 else 837 else
832 Delegate()->LoadWallpaper(populated_email_); 838 Delegate()->LoadWallpaper(populated_user_id);
833 839
834 input_method::InputMethodManager* imm = 840 input_method::InputMethodManager* imm =
835 input_method::InputMethodManager::Get(); 841 input_method::InputMethodManager::Get();
836 842
837 scoped_refptr<input_method::InputMethodManager::State> gaia_ime_state = 843 scoped_refptr<input_method::InputMethodManager::State> gaia_ime_state =
838 imm->GetActiveIMEState()->Clone(); 844 imm->GetActiveIMEState()->Clone();
839 imm->SetState(gaia_ime_state); 845 imm->SetState(gaia_ime_state);
840 846
841 // Set Least Recently Used input method for the user. 847 // Set Least Recently Used input method for the user.
842 if (!populated_email_.empty()) { 848 if (!populated_user_id.empty()) {
843 SigninScreenHandler::SetUserInputMethod(populated_email_, 849 SigninScreenHandler::SetUserInputMethod(populated_user_id,
844 gaia_ime_state.get()); 850 gaia_ime_state.get());
845 } else { 851 } else {
846 std::vector<std::string> input_methods = 852 std::vector<std::string> input_methods =
847 imm->GetInputMethodUtil()->GetHardwareLoginInputMethodIds(); 853 imm->GetInputMethodUtil()->GetHardwareLoginInputMethodIds();
848 const std::string owner_im = SigninScreenHandler::GetUserLRUInputMethod( 854 const std::string owner_im = SigninScreenHandler::GetUserLRUInputMethod(
849 user_manager::UserManager::Get()->GetOwnerEmail()); 855 user_manager::UserManager::Get()->GetOwnerID());
850 const std::string system_im = g_browser_process->local_state()->GetString( 856 const std::string system_im = g_browser_process->local_state()->GetString(
851 language_prefs::kPreferredKeyboardLayout); 857 language_prefs::kPreferredKeyboardLayout);
852 858
853 PushFrontIMIfNotExists(owner_im, &input_methods); 859 PushFrontIMIfNotExists(owner_im, &input_methods);
854 PushFrontIMIfNotExists(system_im, &input_methods); 860 PushFrontIMIfNotExists(system_im, &input_methods);
855 861
856 gaia_ime_state->EnableLoginLayouts( 862 gaia_ime_state->EnableLoginLayouts(
857 g_browser_process->GetApplicationLocale(), input_methods); 863 g_browser_process->GetApplicationLocale(), input_methods);
858 864
859 if (!system_im.empty()) { 865 if (!system_im.empty()) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 params.SetBoolean("enterpriseManaged", 913 params.SetBoolean("enterpriseManaged",
908 g_browser_process->platform_part() 914 g_browser_process->platform_part()
909 ->browser_policy_connector_chromeos() 915 ->browser_policy_connector_chromeos()
910 ->IsEnterpriseManaged()); 916 ->IsEnterpriseManaged());
911 CallJS("showWhitelistCheckFailedError", true, params); 917 CallJS("showWhitelistCheckFailedError", true, params);
912 } 918 }
913 919
914 void GaiaScreenHandler::LoadAuthExtension(bool force, 920 void GaiaScreenHandler::LoadAuthExtension(bool force,
915 bool silent_load, 921 bool silent_load,
916 bool offline) { 922 bool offline) {
923 const user_manager::UserID populated_user_id = user_manager::UserID::FromUserE mail(populated_email_);
924
917 GaiaContext context; 925 GaiaContext context;
918 context.force_reload = force; 926 context.force_reload = force;
919 context.is_local = offline; 927 context.is_local = offline;
920 context.password_changed = !populated_email_.empty() && 928 context.password_changed = !populated_user_id.empty() &&
921 password_changed_for_.count(populated_email_); 929 password_changed_for_.count(populated_user_id);
922 context.use_offline = offline; 930 context.use_offline = offline;
923 context.email = populated_email_; 931 context.email = populated_user_id.GetUserEmail();
924 context.is_enrolling_consumer_management = is_enrolling_consumer_management_; 932 context.is_enrolling_consumer_management = is_enrolling_consumer_management_;
925 933
926 std::string gaia_id; 934 std::string gaia_id;
927 if (user_manager::UserManager::Get()->FindGaiaID(context.email, &gaia_id)) 935 if (user_manager::UserManager::Get()->FindGaiaID(populated_user_id, &gaia_id))
928 context.gaia_id = gaia_id; 936 context.gaia_id = gaia_id;
929 937
930 if (Delegate()) { 938 if (Delegate()) {
931 context.show_users = Delegate()->IsShowUsers(); 939 context.show_users = Delegate()->IsShowUsers();
932 context.has_users = !Delegate()->GetUsers().empty(); 940 context.has_users = !Delegate()->GetUsers().empty();
933 } 941 }
934 942
935 populated_email_.clear(); 943 populated_email_.clear();
936 944
937 LoadGaia(context); 945 LoadGaia(context);
938 } 946 }
939 947
940 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) { 948 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) {
941 if (signin_screen_handler_) 949 if (signin_screen_handler_)
942 signin_screen_handler_->UpdateState(reason); 950 signin_screen_handler_->UpdateState(reason);
943 } 951 }
944 952
945 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() { 953 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() {
946 DCHECK(signin_screen_handler_); 954 DCHECK(signin_screen_handler_);
947 return signin_screen_handler_->delegate_; 955 return signin_screen_handler_->delegate_;
948 } 956 }
949 957
950 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) { 958 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) {
951 signin_screen_handler_ = handler; 959 signin_screen_handler_ = handler;
952 } 960 }
953 961
954 } // namespace chromeos 962 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698