| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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"; |
| 1070 sync_service->DisableForUser(); | 1075 sync_service->DisableForUser(); |
| 1071 | 1076 if (signin_tracker_.get()) { |
| 1077 // User was still in the process of signing in, so sign him out again. |
| 1078 // This makes sure that the user isn't left signed in but with sync |
| 1079 // un-configured. |
| 1080 GetSignin()->SignOut(); |
| 1081 } |
| 1072 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); | 1082 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); |
| 1073 sync_prefs.SetStartSuppressed(true); | 1083 sync_prefs.SetStartSuppressed(true); |
| 1074 } | 1084 } |
| 1075 sync_service->SetSetupInProgress(false); | 1085 sync_service->SetSetupInProgress(false); |
| 1076 } | 1086 } |
| 1077 | 1087 |
| 1078 // Reset the attempted email address and error, otherwise the sync setup | 1088 // 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 | 1089 // overlay in the settings page will stay in whatever error state it was last |
| 1080 // when it is reopened. | 1090 // when it is reopened. |
| 1081 last_attempted_user_email_.clear(); | 1091 last_attempted_user_email_.clear(); |
| 1082 last_signin_error_ = GoogleServiceAuthError::None(); | 1092 last_signin_error_ = GoogleServiceAuthError::None(); |
| 1083 | 1093 |
| 1084 configuring_sync_ = false; | 1094 configuring_sync_ = false; |
| 1085 signin_tracker_.reset(); | 1095 signin_tracker_.reset(); |
| 1086 | 1096 |
| 1087 // Stop a timer to handle timeout in waiting for checking network connection. | 1097 // Stop a timer to handle timeout in waiting for checking network connection. |
| 1088 backend_start_timer_.reset(); | 1098 backend_start_timer_.reset(); |
| 1089 } | 1099 } |
| 1090 | 1100 |
| 1091 void SyncSetupHandler::OpenSyncSetup(bool force_login) { | 1101 void SyncSetupHandler::OpenSyncSetup(bool force_login) { |
| 1092 if (!PrepareSyncSetup()) | 1102 if (!PrepareSyncSetup()) |
| 1093 return; | 1103 return; |
| 1094 | 1104 |
| 1095 ProfileSyncService* service = GetSyncService(); | |
| 1096 | |
| 1097 // There are several different UI flows that can bring the user here: | 1105 // There are several different UI flows that can bring the user here: |
| 1098 // 1) Signin promo (passes force_login=true) | 1106 // 1) Signin promo (passes force_login=true) |
| 1099 // 2) Normal signin through options page (IsSyncEnabledAndLoggedIn() will | 1107 // 2) Normal signin through options page (GetAuthenticatedUsername() is |
| 1100 // return false). | 1108 // empty). |
| 1101 // 3) Previously working credentials have expired | 1109 // 3) Previously working credentials have expired. |
| 1102 // (service->GetAuthError() != NONE). | |
| 1103 // 4) User is already signed in, but App Notifications needs to force another | 1110 // 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) | 1111 // login so it can fetch an oauth token (passes force_login=true) |
| 1105 // 5) User clicks [Advanced Settings] button on options page while already | 1112 // 5) User clicks [Advanced Settings] button on options page while already |
| 1106 // logged in. | 1113 // logged in. |
| 1107 // 6) One-click signin (credentials are already available, so should display | 1114 // 6) One-click signin (credentials are already available, so should display |
| 1108 // sync configure UI, not login UI). | 1115 // sync configure UI, not login UI). |
| 1109 // 7) ChromeOS re-enable after disabling sync. | 1116 // 7) ChromeOS re-enable after disabling sync. |
| 1117 SigninManager* signin = GetSignin(); |
| 1110 if (force_login || | 1118 if (force_login || |
| 1111 !service->IsSyncEnabledAndLoggedIn() || | 1119 signin->GetAuthenticatedUsername().empty() || |
| 1112 service->GetAuthError().state() != GoogleServiceAuthError::NONE) { | 1120 signin->signin_global_error()->HasBadge()) { |
| 1113 // User is not logged in, or login has been specially requested - need to | 1121 // User is not logged in, or login has been specially requested - need to |
| 1114 // display login UI (cases 1-4). | 1122 // display login UI (cases 1-4). |
| 1115 DisplayGaiaLogin(false); | 1123 DisplayGaiaLogin(false); |
| 1116 } else { | 1124 } else { |
| 1125 if (!GetSyncService()) { |
| 1126 // Shouldn't happen, except in various race conditions where a policy |
| 1127 // push comes down that disables sync while the user is trying to |
| 1128 // configure it. |
| 1129 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; |
| 1130 return; |
| 1131 } |
| 1132 |
| 1117 // User is already logged in. They must have brought up the config wizard | 1133 // 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 | 1134 // via the "Advanced..." button or through One-Click signin (cases 5/6), or |
| 1119 // they are re-enabling sync on Chrome OS. | 1135 // they are re-enabling sync on Chrome OS. |
| 1120 DisplayConfigureSync(true, false); | 1136 DisplayConfigureSync(true, false); |
| 1121 } | 1137 } |
| 1122 | 1138 |
| 1123 if (!SyncPromoUI::UseWebBasedSigninFlow()) | 1139 if (!SyncPromoUI::UseWebBasedSigninFlow()) |
| 1124 ShowSetupUI(); | 1140 ShowSetupUI(); |
| 1125 } | 1141 } |
| 1126 | 1142 |
| 1127 void SyncSetupHandler::OpenConfigureSync() { | 1143 void SyncSetupHandler::OpenConfigureSync() { |
| 1128 if (!PrepareSyncSetup()) | 1144 if (!PrepareSyncSetup()) |
| 1129 return; | 1145 return; |
| 1130 | 1146 |
| 1131 DisplayConfigureSync(true, false); | 1147 DisplayConfigureSync(true, false); |
| 1132 ShowSetupUI(); | 1148 ShowSetupUI(); |
| 1133 } | 1149 } |
| 1134 | 1150 |
| 1135 void SyncSetupHandler::FocusUI() { | 1151 void SyncSetupHandler::FocusUI() { |
| 1136 DCHECK(IsActiveLogin()); | 1152 DCHECK(IsActiveLogin()); |
| 1137 if (SyncPromoUI::UseWebBasedSigninFlow() && signin_tracker_) { | 1153 // Bring the GAIA tab to the foreground if there is one. |
| 1154 if (SyncPromoUI::UseWebBasedSigninFlow() && |
| 1155 signin_tracker_ && |
| 1156 active_gaia_signin_tab_) { |
| 1138 BringTabToFront(active_gaia_signin_tab_); | 1157 BringTabToFront(active_gaia_signin_tab_); |
| 1139 } else { | 1158 } else { |
| 1140 WebContents* web_contents = web_ui()->GetWebContents(); | 1159 WebContents* web_contents = web_ui()->GetWebContents(); |
| 1141 web_contents->GetDelegate()->ActivateContents(web_contents); | 1160 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 1142 } | 1161 } |
| 1143 } | 1162 } |
| 1144 | 1163 |
| 1145 void SyncSetupHandler::CloseUI() { | 1164 void SyncSetupHandler::CloseUI() { |
| 1146 DCHECK(IsActiveLogin()); | 1165 DCHECK(IsActiveLogin()); |
| 1147 CloseOverlay(); | 1166 CloseOverlay(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1225 if (i != current_profile_index && AreUserNamesEqual( | 1244 if (i != current_profile_index && AreUserNamesEqual( |
| 1226 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 1245 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
| 1227 *error_message = l10n_util::GetStringUTF16( | 1246 *error_message = l10n_util::GetStringUTF16( |
| 1228 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 1247 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
| 1229 return false; | 1248 return false; |
| 1230 } | 1249 } |
| 1231 } | 1250 } |
| 1232 | 1251 |
| 1233 return true; | 1252 return true; |
| 1234 } | 1253 } |
| OLD | NEW |