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

Side by Side Diff: chrome/browser/ui/webui/sync_setup_handler.cc

Issue 12077030: Allow signin to continue even if sync is disabled by policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows sync integration test failure Created 7 years, 10 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/ui/webui/sync_setup_handler.h" 5 #include "chrome/browser/ui/webui/sync_setup_handler.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 bool AreUserNamesEqual(const string16& user1, const string16& user2) { 181 bool AreUserNamesEqual(const string16& user1, const string16& user2) {
182 return NormalizeUserName(user1) == NormalizeUserName(user2); 182 return NormalizeUserName(user1) == NormalizeUserName(user2);
183 } 183 }
184 184
185 bool IsKeystoreEncryptionEnabled() { 185 bool IsKeystoreEncryptionEnabled() {
186 return CommandLine::ForCurrentProcess()->HasSwitch( 186 return CommandLine::ForCurrentProcess()->HasSwitch(
187 switches::kSyncKeystoreEncryption); 187 switches::kSyncKeystoreEncryption);
188 } 188 }
189 189
190 void BringTabToFront(WebContents* web_contents) { 190 void BringTabToFront(WebContents* web_contents) {
191 DCHECK(web_contents);
191 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 192 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
192 if (browser) { 193 if (browser) {
193 TabStripModel* tab_strip_model = browser->tab_strip_model(); 194 TabStripModel* tab_strip_model = browser->tab_strip_model();
194 if (tab_strip_model) { 195 if (tab_strip_model) {
195 int index = tab_strip_model->GetIndexOfWebContents(web_contents); 196 int index = tab_strip_model->GetIndexOfWebContents(web_contents);
196 if (index != TabStripModel::kNoTab) 197 if (index != TabStripModel::kNoTab)
197 tab_strip_model->ActivateTabAt(index, false); 198 tab_strip_model->ActivateTabAt(index, false);
198 } 199 }
199 } 200 }
200 } 201 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 { "fullEncryptionOption", IDS_SYNC_FULL_ENCRYPTION_DATA }, 379 { "fullEncryptionOption", IDS_SYNC_FULL_ENCRYPTION_DATA },
379 }; 380 };
380 381
381 RegisterStrings(localized_strings, resources, arraysize(resources)); 382 RegisterStrings(localized_strings, resources, arraysize(resources));
382 RegisterTitle(localized_strings, "syncSetupOverlay", IDS_SYNC_SETUP_TITLE); 383 RegisterTitle(localized_strings, "syncSetupOverlay", IDS_SYNC_SETUP_TITLE);
383 } 384 }
384 385
385 void SyncSetupHandler::DisplayConfigureSync(bool show_advanced, 386 void SyncSetupHandler::DisplayConfigureSync(bool show_advanced,
386 bool passphrase_failed) { 387 bool passphrase_failed) {
387 ProfileSyncService* service = GetSyncService(); 388 ProfileSyncService* service = GetSyncService();
389 DCHECK(service);
388 if (!service->sync_initialized()) { 390 if (!service->sync_initialized()) {
389 // When user tries to setup sync while the sync backend is not initialized, 391 // When user tries to setup sync while the sync backend is not initialized,
390 // kick the sync backend and wait for it to be ready and show spinner until 392 // kick the sync backend and wait for it to be ready and show spinner until
391 // the backend gets ready. 393 // the backend gets ready.
392 retry_on_signin_failure_ = false; 394 retry_on_signin_failure_ = false;
393 395
394 service->UnsuppressAndStart(); 396 service->UnsuppressAndStart();
395 DisplaySpinner(); 397 DisplaySpinner();
396 398
397 // To listen to the token available notifications, start SigninTracker. 399 // To listen to the token available notifications, start SigninTracker.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 void SyncSetupHandler::ConfigureSyncDone() { 513 void SyncSetupHandler::ConfigureSyncDone() {
512 StringValue page("done"); 514 StringValue page("done");
513 web_ui()->CallJavascriptFunction( 515 web_ui()->CallJavascriptFunction(
514 "SyncSetupOverlay.showSyncSetupPage", page); 516 "SyncSetupOverlay.showSyncSetupPage", page);
515 517
516 // Suppress the sync promo once the user signs into sync. This way the user 518 // Suppress the sync promo once the user signs into sync. This way the user
517 // doesn't see the sync promo even if they sign out of sync later on. 519 // doesn't see the sync promo even if they sign out of sync later on.
518 SyncPromoUI::SetUserSkippedSyncPromo(GetProfile()); 520 SyncPromoUI::SetUserSkippedSyncPromo(GetProfile());
519 521
520 ProfileSyncService* service = GetSyncService(); 522 ProfileSyncService* service = GetSyncService();
523 DCHECK(service);
521 if (!service->HasSyncSetupCompleted()) { 524 if (!service->HasSyncSetupCompleted()) {
522 // This is the first time configuring sync, so log it. 525 // This is the first time configuring sync, so log it.
523 FilePath profile_file_path = GetProfile()->GetPath(); 526 FilePath profile_file_path = GetProfile()->GetPath();
524 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); 527 ProfileMetrics::LogProfileSyncSignIn(profile_file_path);
525 528
526 // We're done configuring, so notify ProfileSyncService that it is OK to 529 // We're done configuring, so notify ProfileSyncService that it is OK to
527 // start syncing. 530 // start syncing.
528 service->SetSyncSetupCompleted(); 531 service->SetSyncSetupCompleted();
529 } 532 }
530 } 533 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 args.SetString("errorMessage", local_error_message); 673 args.SetString("errorMessage", local_error_message);
671 if (fatal_error) 674 if (fatal_error)
672 args.SetBoolean("fatalError", true); 675 args.SetBoolean("fatalError", true);
673 args.SetString("captchaUrl", captcha); 676 args.SetString("captchaUrl", captcha);
674 StringValue page("login"); 677 StringValue page("login");
675 web_ui()->CallJavascriptFunction( 678 web_ui()->CallJavascriptFunction(
676 "SyncSetupOverlay.showSyncSetupPage", page, args); 679 "SyncSetupOverlay.showSyncSetupPage", page, args);
677 } 680 }
678 681
679 bool SyncSetupHandler::PrepareSyncSetup() { 682 bool SyncSetupHandler::PrepareSyncSetup() {
680 ProfileSyncService* service = GetSyncService();
681 if (!service) {
682 // If there's no sync service, the user tried to manually invoke a syncSetup
683 // URL, but sync features are disabled. We need to close the overlay for
684 // this (rare) case.
685 DLOG(WARNING) << "Closing sync UI because sync is disabled";
686 CloseOverlay();
687 return false;
688 }
689 683
690 // If the wizard is already visible, just focus that one. 684 // If the wizard is already visible, just focus that one.
691 if (FocusExistingWizardIfPresent()) { 685 if (FocusExistingWizardIfPresent()) {
692 if (!IsActiveLogin()) 686 if (!IsActiveLogin())
693 CloseOverlay(); 687 CloseOverlay();
694 return false; 688 return false;
695 } 689 }
696 690
697 // Notify services that login UI is now active. 691 // Notify services that login UI is now active.
698 GetLoginUIService()->SetLoginUI(this); 692 GetLoginUIService()->SetLoginUI(this);
699 service->SetSetupInProgress(true); 693
694 ProfileSyncService* service = GetSyncService();
695 if (service)
696 service->SetSetupInProgress(true);
700 697
701 return true; 698 return true;
702 } 699 }
703 700
704 void SyncSetupHandler::DisplaySpinner() { 701 void SyncSetupHandler::DisplaySpinner() {
705 configuring_sync_ = true; 702 configuring_sync_ = true;
706 StringValue page("spinner"); 703 StringValue page("spinner");
707 DictionaryValue args; 704 DictionaryValue args;
708 705
709 const int kTimeoutSec = 30; 706 const int kTimeoutSec = 30;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 // If we're just being called to provide an ASP, then pass it to the 812 // If we're just being called to provide an ASP, then pass it to the
816 // SigninManager and wait for the next step. 813 // SigninManager and wait for the next step.
817 if (!access_code.empty()) { 814 if (!access_code.empty()) {
818 signin->ProvideSecondFactorAccessCode(access_code); 815 signin->ProvideSecondFactorAccessCode(access_code);
819 return; 816 return;
820 } 817 }
821 818
822 // The user has submitted credentials, which indicates they don't want to 819 // The user has submitted credentials, which indicates they don't want to
823 // suppress start up anymore. We do this before starting the signin process, 820 // suppress start up anymore. We do this before starting the signin process,
824 // so the ProfileSyncService knows to listen to the cached password. 821 // so the ProfileSyncService knows to listen to the cached password.
825 GetSyncService()->UnsuppressAndStart(); 822 ProfileSyncService* service = GetSyncService();
823 if (service)
824 service->UnsuppressAndStart();
826 825
827 // Kick off a sign-in through the signin manager. 826 // Kick off a sign-in through the signin manager.
828 signin->StartSignIn(username, password, current_error.captcha().token, 827 signin->StartSignIn(username, password, current_error.captcha().token,
829 solution); 828 solution);
830 } 829 }
831 830
832 void SyncSetupHandler::GaiaCredentialsValid() { 831 void SyncSetupHandler::GaiaCredentialsValid() {
833 DCHECK(IsActiveLogin()); 832 DCHECK(IsActiveLogin());
834 833
835 // Gaia credentials are valid - update the UI. 834 // Gaia credentials are valid - update the UI.
(...skipping 10 matching lines...) Expand all
846 // since there is no way to show the user an error message. 845 // since there is no way to show the user an error message.
847 if (SyncPromoUI::UseWebBasedSigninFlow()) { 846 if (SyncPromoUI::UseWebBasedSigninFlow()) {
848 CloseSyncSetup(); 847 CloseSyncSetup();
849 } else if (retry_on_signin_failure_) { 848 } else if (retry_on_signin_failure_) {
850 // Got a failed signin - this is either just a typical auth error, or a 849 // Got a failed signin - this is either just a typical auth error, or a
851 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). 850 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors).
852 // On ChromeOS, this condition can happen when auth token is invalid and 851 // On ChromeOS, this condition can happen when auth token is invalid and
853 // cannot start sync backend. 852 // cannot start sync backend.
854 // If using web-based sign in flow, don't show the gaia sign in page again 853 // If using web-based sign in flow, don't show the gaia sign in page again
855 // since there is no way to show the user an error message. 854 // since there is no way to show the user an error message.
856 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); 855 ProfileSyncService* service = GetSyncService();
856 DisplayGaiaLogin(service && service->HasUnrecoverableError());
857 } else { 857 } else {
858 // TODO(peria): Show error dialog for prompting sign in and out on 858 // TODO(peria): Show error dialog for prompting sign in and out on
859 // Chrome OS. http://crbug.com/128692 859 // Chrome OS. http://crbug.com/128692
860 CloseOverlay(); 860 CloseOverlay();
861 } 861 }
862 } 862 }
863 863
864 Profile* SyncSetupHandler::GetProfile() const { 864 Profile* SyncSetupHandler::GetProfile() const {
865 return Profile::FromWebUI(web_ui()); 865 return Profile::FromWebUI(web_ui());
866 } 866 }
867 867
868 ProfileSyncService* SyncSetupHandler::GetSyncService() const { 868 ProfileSyncService* SyncSetupHandler::GetSyncService() const {
869 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); 869 Profile* profile = GetProfile();
870 return profile->IsSyncAccessible() ?
871 ProfileSyncServiceFactory::GetForProfile(GetProfile()) : NULL;
870 } 872 }
871 873
872 void SyncSetupHandler::SigninSuccess() { 874 void SyncSetupHandler::SigninSuccess() {
873 DCHECK(GetSyncService()->sync_initialized()); 875 ProfileSyncService* service = GetSyncService();
876 DCHECK(!service || service->sync_initialized());
874 // Stop a timer to handle timeout in waiting for checking network connection. 877 // Stop a timer to handle timeout in waiting for checking network connection.
875 backend_start_timer_.reset(); 878 backend_start_timer_.reset();
876 879
877 // If we have signed in while sync is already setup, it must be due to some 880 // If we have signed in while sync is already setup, it must be due to some
878 // kind of re-authentication flow. In that case, just close the signin dialog 881 // kind of re-authentication flow. In that case, just close the signin dialog
879 // rather than forcing the user to go through sync configuration. 882 // rather than forcing the user to go through sync configuration.
880 if (GetSyncService()->HasSyncSetupCompleted()) 883 if (!service || service->HasSyncSetupCompleted())
881 DisplayGaiaSuccessAndClose(); 884 DisplayGaiaSuccessAndClose();
882 else 885 else
883 DisplayConfigureSync(false, false); 886 DisplayConfigureSync(false, false);
884 } 887 }
885 888
886 void SyncSetupHandler::HandleConfigure(const ListValue* args) { 889 void SyncSetupHandler::HandleConfigure(const ListValue* args) {
887 std::string json; 890 std::string json;
888 if (!args->GetString(0, &json)) { 891 if (!args->GetString(0, &json)) {
889 NOTREACHED() << "Could not read JSON argument"; 892 NOTREACHED() << "Could not read JSON argument";
890 return; 893 return;
(...skipping 10 matching lines...) Expand all
901 NOTREACHED(); 904 NOTREACHED();
902 return; 905 return;
903 } 906 }
904 907
905 // Start configuring the ProfileSyncService using the configuration passed 908 // Start configuring the ProfileSyncService using the configuration passed
906 // to us from the JS layer. 909 // to us from the JS layer.
907 ProfileSyncService* service = GetSyncService(); 910 ProfileSyncService* service = GetSyncService();
908 911
909 // If the sync engine has shutdown for some reason, just close the sync 912 // If the sync engine has shutdown for some reason, just close the sync
910 // dialog. 913 // dialog.
911 if (!service->sync_initialized()) { 914 if (!service || !service->sync_initialized()) {
912 CloseOverlay(); 915 CloseOverlay();
913 return; 916 return;
914 } 917 }
915 918
916 // Note: Data encryption will not occur until configuration is complete 919 // Note: Data encryption will not occur until configuration is complete
917 // (when the PSS receives its CONFIGURE_DONE notification from the sync 920 // (when the PSS receives its CONFIGURE_DONE notification from the sync
918 // backend), so the user still has a chance to cancel out of the operation 921 // backend), so the user still has a chance to cancel out of the operation
919 // if (for example) some kind of passphrase error is encountered. 922 // if (for example) some kind of passphrase error is encountered.
920 if (configuration.encrypt_all) 923 if (configuration.encrypt_all)
921 service->EnableEncryptEverything(); 924 service->EnableEncryptEverything();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 1010
1008 // Bring up the existing wizard, or just display it on this page. 1011 // Bring up the existing wizard, or just display it on this page.
1009 if (!FocusExistingWizardIfPresent()) 1012 if (!FocusExistingWizardIfPresent())
1010 OpenSyncSetup(false); 1013 OpenSyncSetup(false);
1011 } 1014 }
1012 1015
1013 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { 1016 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) {
1014 OpenSyncSetup(false); 1017 OpenSyncSetup(false);
1015 } 1018 }
1016 1019
1020 // TODO(atwilson): Remove chrome-os-only API in favor of routing everything
1021 // through ShowSetupUI.
1017 void SyncSetupHandler::HandleShowSetupUIWithoutLogin(const ListValue* args) { 1022 void SyncSetupHandler::HandleShowSetupUIWithoutLogin(const ListValue* args) {
1018 OpenConfigureSync(); 1023 OpenConfigureSync();
1019 } 1024 }
1020 1025
1021 void SyncSetupHandler::HandleDoSignOutOnAuthError(const ListValue* args) { 1026 void SyncSetupHandler::HandleDoSignOutOnAuthError(const ListValue* args) {
1022 DLOG(INFO) << "Signing out the user to fix a sync error."; 1027 DLOG(INFO) << "Signing out the user to fix a sync error.";
1023 browser::AttemptUserExit(); 1028 browser::AttemptUserExit();
1024 } 1029 }
1025 1030
1026 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) { 1031 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) {
1027 ProfileSyncService* service = GetSyncService(); 1032 ProfileSyncService* service = GetSyncService();
1028 DCHECK(service);
1029 1033
1030 if (ProfileSyncService::IsSyncEnabled()) { 1034 if (service) {
1031 service->DisableForUser(); 1035 service->DisableForUser();
1032 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); 1036 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS);
1033 } 1037 }
1038 GetSignin()->SignOut();
1034 } 1039 }
1035 1040
1036 void SyncSetupHandler::HandleCloseTimeout(const ListValue* args) { 1041 void SyncSetupHandler::HandleCloseTimeout(const ListValue* args) {
1037 CloseSyncSetup(); 1042 CloseSyncSetup();
1038 } 1043 }
1039 1044
1040 void SyncSetupHandler::CloseSyncSetup() { 1045 void SyncSetupHandler::CloseSyncSetup() {
1041 // TODO(atwilson): Move UMA tracking of signin events out of sync module. 1046 // TODO(atwilson): Move UMA tracking of signin events out of sync module.
1042 ProfileSyncService* sync_service = GetSyncService(); 1047 ProfileSyncService* sync_service = GetSyncService();
1043 if (IsActiveLogin()) { 1048 if (IsActiveLogin()) {
1044 if (!sync_service->HasSyncSetupCompleted()) { 1049 if (!sync_service || !sync_service->HasSyncSetupCompleted()) {
1045 if (signin_tracker_.get()) { 1050 if (signin_tracker_.get()) {
1046 ProfileSyncService::SyncEvent( 1051 ProfileSyncService::SyncEvent(
1047 ProfileSyncService::CANCEL_DURING_SIGNON); 1052 ProfileSyncService::CANCEL_DURING_SIGNON);
1048 } else if (configuring_sync_) { 1053 } else if (configuring_sync_) {
1049 ProfileSyncService::SyncEvent( 1054 ProfileSyncService::SyncEvent(
1050 ProfileSyncService::CANCEL_DURING_CONFIGURE); 1055 ProfileSyncService::CANCEL_DURING_CONFIGURE);
1051 } else { 1056 } else {
1052 ProfileSyncService::SyncEvent( 1057 ProfileSyncService::SyncEvent(
1053 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); 1058 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH);
1054 } 1059 }
1055 } 1060 }
1056 1061
1057 // Let the various services know that we're no longer active. 1062 // Let the various services know that we're no longer active.
1058 if (SyncPromoUI::UseWebBasedSigninFlow()) 1063 if (SyncPromoUI::UseWebBasedSigninFlow())
1059 CloseGaiaSigninPage(); 1064 CloseGaiaSigninPage();
1060 1065
1061 GetLoginUIService()->LoginUIClosed(this); 1066 GetLoginUIService()->LoginUIClosed(this);
1062 } 1067 }
1063 1068
1064 if (sync_service) { 1069 if (sync_service) {
1065 // Make sure user isn't left half-logged-in (signed in, but without sync 1070 // Make sure user isn't left half-logged-in (signed in, but without sync
1066 // started up). If the user hasn't finished setting up sync, then sign out 1071 // started up). If the user hasn't finished setting up sync, then sign out
1067 // and shut down sync. 1072 // and shut down sync.
1068 if (!sync_service->HasSyncSetupCompleted()) { 1073 if (!sync_service->HasSyncSetupCompleted()) {
1069 DVLOG(1) << "Signin aborted by user action"; 1074 DVLOG(1) << "Signin aborted by user action";
1075 if (signin_tracker_.get() || sync_service->FirstSetupInProgress()) {
1076 // User was still in the process of signing in, so sign him out again.
1077 // This makes sure that the user isn't left signed in but with sync
1078 // un-configured.
1079 //
1080 // This has the side-effect of signing out the user in the following
1081 // scenario:
1082 // * User signs in while sync is disabled by policy.
1083 // * Sync is re-enabled by policy.
1084 // * User brings up sync setup dialog to do initial sync config.
1085 // * User cancels out of the dialog.
1086 //
1087 // This case is indistinguishable from the "one click signin" case where
1088 // the user checks the "advanced setup" checkbox, then cancels out of
1089 // the setup box, which is a much more common scenario, so we do the
1090 // right thing for the one-click case.
1091 GetSignin()->SignOut();
1092 }
1070 sync_service->DisableForUser(); 1093 sync_service->DisableForUser();
1071
1072 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); 1094 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs());
1073 sync_prefs.SetStartSuppressed(true); 1095 sync_prefs.SetStartSuppressed(true);
1074 } 1096 }
1075 sync_service->SetSetupInProgress(false); 1097 sync_service->SetSetupInProgress(false);
1076 } 1098 }
1077 1099
1078 // Reset the attempted email address and error, otherwise the sync setup 1100 // Reset the attempted email address and error, otherwise the sync setup
1079 // overlay in the settings page will stay in whatever error state it was last 1101 // overlay in the settings page will stay in whatever error state it was last
1080 // when it is reopened. 1102 // when it is reopened.
1081 last_attempted_user_email_.clear(); 1103 last_attempted_user_email_.clear();
1082 last_signin_error_ = GoogleServiceAuthError::None(); 1104 last_signin_error_ = GoogleServiceAuthError::None();
1083 1105
1084 configuring_sync_ = false; 1106 configuring_sync_ = false;
1085 signin_tracker_.reset(); 1107 signin_tracker_.reset();
1086 1108
1087 // Stop a timer to handle timeout in waiting for checking network connection. 1109 // Stop a timer to handle timeout in waiting for checking network connection.
1088 backend_start_timer_.reset(); 1110 backend_start_timer_.reset();
1089 } 1111 }
1090 1112
1091 void SyncSetupHandler::OpenSyncSetup(bool force_login) { 1113 void SyncSetupHandler::OpenSyncSetup(bool force_login) {
1092 if (!PrepareSyncSetup()) 1114 if (!PrepareSyncSetup())
1093 return; 1115 return;
1094 1116
1095 ProfileSyncService* service = GetSyncService();
1096
1097 // There are several different UI flows that can bring the user here: 1117 // There are several different UI flows that can bring the user here:
1098 // 1) Signin promo (passes force_login=true) 1118 // 1) Signin promo (passes force_login=true)
1099 // 2) Normal signin through options page (IsSyncEnabledAndLoggedIn() will 1119 // 2) Normal signin through options page (GetAuthenticatedUsername() is
1100 // return false). 1120 // empty).
1101 // 3) Previously working credentials have expired 1121 // 3) Previously working credentials have expired.
1102 // (service->GetAuthError() != NONE).
1103 // 4) User is already signed in, but App Notifications needs to force another 1122 // 4) User is already signed in, but App Notifications needs to force another
1104 // login so it can fetch an oauth token (passes force_login=true) 1123 // login so it can fetch an oauth token (passes force_login=true)
1105 // 5) User clicks [Advanced Settings] button on options page while already 1124 // 5) User clicks [Advanced Settings] button on options page while already
1106 // logged in. 1125 // logged in.
1107 // 6) One-click signin (credentials are already available, so should display 1126 // 6) One-click signin (credentials are already available, so should display
1108 // sync configure UI, not login UI). 1127 // sync configure UI, not login UI).
1109 // 7) ChromeOS re-enable after disabling sync. 1128 // 7) ChromeOS re-enable after disabling sync.
1129 SigninManager* signin = GetSignin();
1110 if (force_login || 1130 if (force_login ||
1111 !service->IsSyncEnabledAndLoggedIn() || 1131 signin->GetAuthenticatedUsername().empty() ||
1112 service->GetAuthError().state() != GoogleServiceAuthError::NONE) { 1132 signin->signin_global_error()->HasBadge()) {
1113 // User is not logged in, or login has been specially requested - need to 1133 // User is not logged in, or login has been specially requested - need to
1114 // display login UI (cases 1-4). 1134 // display login UI (cases 1-4).
1115 DisplayGaiaLogin(false); 1135 DisplayGaiaLogin(false);
1116 } else { 1136 } else {
1137 if (!GetSyncService()) {
1138 // Shouldn't happen, except in various race conditions where a policy
1139 // push comes down that disables sync while the user is trying to
1140 // configure it.
1141 DLOG(WARNING) << "Cannot display sync UI when sync is disabled";
1142 return;
1143 }
1144
1117 // User is already logged in. They must have brought up the config wizard 1145 // User is already logged in. They must have brought up the config wizard
1118 // via the "Advanced..." button or through One-Click signin (cases 5/6), or 1146 // via the "Advanced..." button or through One-Click signin (cases 5/6), or
1119 // they are re-enabling sync on Chrome OS. 1147 // they are re-enabling sync on Chrome OS.
1120 DisplayConfigureSync(true, false); 1148 DisplayConfigureSync(true, false);
1121 } 1149 }
1122 1150
1123 if (!SyncPromoUI::UseWebBasedSigninFlow()) 1151 if (!SyncPromoUI::UseWebBasedSigninFlow())
1124 ShowSetupUI(); 1152 ShowSetupUI();
1125 } 1153 }
1126 1154
1127 void SyncSetupHandler::OpenConfigureSync() { 1155 void SyncSetupHandler::OpenConfigureSync() {
1128 if (!PrepareSyncSetup()) 1156 if (!PrepareSyncSetup())
1129 return; 1157 return;
1130 1158
1131 DisplayConfigureSync(true, false); 1159 DisplayConfigureSync(true, false);
1132 ShowSetupUI(); 1160 ShowSetupUI();
1133 } 1161 }
1134 1162
1135 void SyncSetupHandler::FocusUI() { 1163 void SyncSetupHandler::FocusUI() {
1136 DCHECK(IsActiveLogin()); 1164 DCHECK(IsActiveLogin());
1137 if (SyncPromoUI::UseWebBasedSigninFlow() && signin_tracker_) { 1165 // Bring the GAIA tab to the foreground if there is one.
1166 if (SyncPromoUI::UseWebBasedSigninFlow() &&
1167 signin_tracker_ &&
1168 active_gaia_signin_tab_) {
1138 BringTabToFront(active_gaia_signin_tab_); 1169 BringTabToFront(active_gaia_signin_tab_);
1139 } else { 1170 } else {
1140 WebContents* web_contents = web_ui()->GetWebContents(); 1171 WebContents* web_contents = web_ui()->GetWebContents();
1141 web_contents->GetDelegate()->ActivateContents(web_contents); 1172 web_contents->GetDelegate()->ActivateContents(web_contents);
1142 } 1173 }
1143 } 1174 }
1144 1175
1145 void SyncSetupHandler::CloseUI() { 1176 void SyncSetupHandler::CloseUI() {
1146 DCHECK(IsActiveLogin()); 1177 DCHECK(IsActiveLogin());
1147 CloseOverlay(); 1178 CloseOverlay();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 if (i != current_profile_index && AreUserNamesEqual( 1256 if (i != current_profile_index && AreUserNamesEqual(
1226 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { 1257 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) {
1227 *error_message = l10n_util::GetStringUTF16( 1258 *error_message = l10n_util::GetStringUTF16(
1228 IDS_SYNC_USER_NAME_IN_USE_ERROR); 1259 IDS_SYNC_USER_NAME_IN_USE_ERROR);
1229 return false; 1260 return false;
1230 } 1261 }
1231 } 1262 }
1232 1263
1233 return true; 1264 return true;
1234 } 1265 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_promo/sync_promo_ui.cc ('k') | chrome/browser/ui/webui/sync_setup_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698