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

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

Issue 14691004: [sync] Separate sign in from sync on Desktop Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 7 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 namespace { 59 namespace {
60 60
61 // A structure which contains all the configuration information for sync. 61 // A structure which contains all the configuration information for sync.
62 struct SyncConfigInfo { 62 struct SyncConfigInfo {
63 SyncConfigInfo(); 63 SyncConfigInfo();
64 ~SyncConfigInfo(); 64 ~SyncConfigInfo();
65 65
66 bool encrypt_all; 66 bool encrypt_all;
67 bool sync_everything; 67 bool sync_everything;
68 bool sync_nothing;
68 syncer::ModelTypeSet data_types; 69 syncer::ModelTypeSet data_types;
69 std::string passphrase; 70 std::string passphrase;
70 bool passphrase_is_gaia; 71 bool passphrase_is_gaia;
71 }; 72 };
72 73
73 SyncConfigInfo::SyncConfigInfo() 74 SyncConfigInfo::SyncConfigInfo()
74 : encrypt_all(false), 75 : encrypt_all(false),
75 sync_everything(false), 76 sync_everything(false),
77 sync_nothing(false),
76 passphrase_is_gaia(false) { 78 passphrase_is_gaia(false) {
77 } 79 }
78 80
79 SyncConfigInfo::~SyncConfigInfo() {} 81 SyncConfigInfo::~SyncConfigInfo() {}
80 82
81 // Note: The order of these types must match the ordering of 83 // Note: The order of these types must match the ordering of
82 // the respective types in ModelType 84 // the respective types in ModelType
83 const char* kDataTypeNames[] = { 85 const char* kDataTypeNames[] = {
84 "bookmarks", 86 "bookmarks",
85 "preferences", 87 "preferences",
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 if (!parsed_value.get() || !parsed_value->GetAsDictionary(&result)) { 180 if (!parsed_value.get() || !parsed_value->GetAsDictionary(&result)) {
179 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary"; 181 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary";
180 return false; 182 return false;
181 } 183 }
182 184
183 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) { 185 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) {
184 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value"; 186 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value";
185 return false; 187 return false;
186 } 188 }
187 189
190 if (!result->GetBoolean("syncNothing", &config->sync_nothing)) {
191 DLOG(ERROR) << "GetConfiguration() not passed a syncNothing value";
192 return false;
193 }
194
195 DCHECK(!(config->sync_everything && config->sync_nothing))
196 << "syncAllDataTypes and syncNothing cannot both be true";
197
188 ModelTypeNameMap type_names = GetSelectableTypeNameMap(); 198 ModelTypeNameMap type_names = GetSelectableTypeNameMap();
189 199
190 for (ModelTypeNameMap::const_iterator it = type_names.begin(); 200 for (ModelTypeNameMap::const_iterator it = type_names.begin();
191 it != type_names.end(); ++it) { 201 it != type_names.end(); ++it) {
192 std::string key_name = it->second + std::string("Synced"); 202 std::string key_name = it->second + std::string("Synced");
193 bool sync_value; 203 bool sync_value;
194 if (!result->GetBoolean(key_name, &sync_value)) { 204 if (!result->GetBoolean(key_name, &sync_value)) {
195 DLOG(ERROR) << "GetConfiguration() not passed a value for " << key_name; 205 DLOG(ERROR) << "GetConfiguration() not passed a value for " << key_name;
196 return false; 206 return false;
197 } 207 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 { "invalidAccessCode", IDS_SYNC_INVALID_ACCESS_CODE_LABEL }, 364 { "invalidAccessCode", IDS_SYNC_INVALID_ACCESS_CODE_LABEL },
355 { "enterAccessCode", IDS_SYNC_ENTER_ACCESS_CODE_LABEL }, 365 { "enterAccessCode", IDS_SYNC_ENTER_ACCESS_CODE_LABEL },
356 { "getAccessCodeHelp", IDS_SYNC_ACCESS_CODE_HELP_LABEL }, 366 { "getAccessCodeHelp", IDS_SYNC_ACCESS_CODE_HELP_LABEL },
357 { "getAccessCodeURL", IDS_SYNC_GET_ACCESS_CODE_URL }, 367 { "getAccessCodeURL", IDS_SYNC_GET_ACCESS_CODE_URL },
358 { "invalidOtp", IDS_SYNC_INVALID_OTP_LABEL }, 368 { "invalidOtp", IDS_SYNC_INVALID_OTP_LABEL },
359 { "enterOtp", IDS_SYNC_ENTER_OTP_LABEL }, 369 { "enterOtp", IDS_SYNC_ENTER_OTP_LABEL },
360 { "getOtpHelp", IDS_SYNC_OTP_HELP_LABEL }, 370 { "getOtpHelp", IDS_SYNC_OTP_HELP_LABEL },
361 { "getOtpURL", IDS_SYNC_GET_OTP_URL }, 371 { "getOtpURL", IDS_SYNC_GET_OTP_URL },
362 { "syncAllDataTypes", IDS_SYNC_EVERYTHING }, 372 { "syncAllDataTypes", IDS_SYNC_EVERYTHING },
363 { "chooseDataTypes", IDS_SYNC_CHOOSE_DATATYPES }, 373 { "chooseDataTypes", IDS_SYNC_CHOOSE_DATATYPES },
374 { "syncNothing", IDS_SYNC_NOTHING },
364 { "bookmarks", IDS_SYNC_DATATYPE_BOOKMARKS }, 375 { "bookmarks", IDS_SYNC_DATATYPE_BOOKMARKS },
365 { "preferences", IDS_SYNC_DATATYPE_PREFERENCES }, 376 { "preferences", IDS_SYNC_DATATYPE_PREFERENCES },
366 { "autofill", IDS_SYNC_DATATYPE_AUTOFILL }, 377 { "autofill", IDS_SYNC_DATATYPE_AUTOFILL },
367 { "themes", IDS_SYNC_DATATYPE_THEMES }, 378 { "themes", IDS_SYNC_DATATYPE_THEMES },
368 { "passwords", IDS_SYNC_DATATYPE_PASSWORDS }, 379 { "passwords", IDS_SYNC_DATATYPE_PASSWORDS },
369 { "extensions", IDS_SYNC_DATATYPE_EXTENSIONS }, 380 { "extensions", IDS_SYNC_DATATYPE_EXTENSIONS },
370 { "typedURLs", IDS_SYNC_DATATYPE_TYPED_URLS }, 381 { "typedURLs", IDS_SYNC_DATATYPE_TYPED_URLS },
371 { "apps", IDS_SYNC_DATATYPE_APPS }, 382 { "apps", IDS_SYNC_DATATYPE_APPS },
372 { "openTabs", IDS_SYNC_DATATYPE_TABS }, 383 { "openTabs", IDS_SYNC_DATATYPE_TABS },
373 { "syncZeroDataTypesError", IDS_SYNC_ZERO_DATA_TYPES_ERROR }, 384 { "syncZeroDataTypesError", IDS_SYNC_ZERO_DATA_TYPES_ERROR },
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // Should only be called if user is signed in, so no longer need our 453 // Should only be called if user is signed in, so no longer need our
443 // SigninTracker. 454 // SigninTracker.
444 signin_tracker_.reset(); 455 signin_tracker_.reset();
445 configuring_sync_ = true; 456 configuring_sync_ = true;
446 DCHECK(service->sync_initialized()) << 457 DCHECK(service->sync_initialized()) <<
447 "Cannot configure sync until the sync backend is initialized"; 458 "Cannot configure sync until the sync backend is initialized";
448 459
449 // Setup args for the sync configure screen: 460 // Setup args for the sync configure screen:
450 // showSyncEverythingPage: false to skip directly to the configure screen 461 // showSyncEverythingPage: false to skip directly to the configure screen
451 // syncAllDataTypes: true if the user wants to sync everything 462 // syncAllDataTypes: true if the user wants to sync everything
463 // syncNothing: true if the user wants to sync nothing
452 // <data_type>Registered: true if the associated data type is supported 464 // <data_type>Registered: true if the associated data type is supported
453 // <data_type>Synced: true if the user wants to sync that specific data type 465 // <data_type>Synced: true if the user wants to sync that specific data type
454 // encryptionEnabled: true if sync supports encryption 466 // encryptionEnabled: true if sync supports encryption
455 // encryptAllData: true if user wants to encrypt all data (not just 467 // encryptAllData: true if user wants to encrypt all data (not just
456 // passwords) 468 // passwords)
457 // usePassphrase: true if the data is encrypted with a secondary passphrase 469 // usePassphrase: true if the data is encrypted with a secondary passphrase
458 // show_passphrase: true if a passphrase is needed to decrypt the sync data 470 // show_passphrase: true if a passphrase is needed to decrypt the sync data
459 DictionaryValue args; 471 DictionaryValue args;
460 472
461 // Tell the UI layer which data types are registered/enabled by the user. 473 // Tell the UI layer which data types are registered/enabled by the user.
462 const syncer::ModelTypeSet registered_types = 474 const syncer::ModelTypeSet registered_types =
463 service->GetRegisteredDataTypes(); 475 service->GetRegisteredDataTypes();
464 const syncer::ModelTypeSet preferred_types = 476 const syncer::ModelTypeSet preferred_types =
465 service->GetPreferredDataTypes(); 477 service->GetPreferredDataTypes();
466 ModelTypeNameMap type_names = GetSelectableTypeNameMap(); 478 ModelTypeNameMap type_names = GetSelectableTypeNameMap();
467 for (ModelTypeNameMap::const_iterator it = type_names.begin(); 479 for (ModelTypeNameMap::const_iterator it = type_names.begin();
468 it != type_names.end(); ++it) { 480 it != type_names.end(); ++it) {
469 syncer::ModelType sync_type = it->first; 481 syncer::ModelType sync_type = it->first;
470 const std::string key_name = it->second; 482 const std::string key_name = it->second;
471 args.SetBoolean(key_name + "Registered", 483 args.SetBoolean(key_name + "Registered",
472 registered_types.Has(sync_type)); 484 registered_types.Has(sync_type));
473 args.SetBoolean(key_name + "Synced", preferred_types.Has(sync_type)); 485 args.SetBoolean(key_name + "Synced", preferred_types.Has(sync_type));
474 } 486 }
475 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); 487 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs());
476 args.SetBoolean("passphraseFailed", passphrase_failed); 488 args.SetBoolean("passphraseFailed", passphrase_failed);
477 args.SetBoolean("showSyncEverythingPage", !show_advanced); 489 args.SetBoolean("showSyncEverythingPage", !show_advanced);
478 args.SetBoolean("syncAllDataTypes", sync_prefs.HasKeepEverythingSynced()); 490 args.SetBoolean("syncAllDataTypes", sync_prefs.HasKeepEverythingSynced());
491 args.SetBoolean("syncNothing", false); // Always false during initial setup.
479 args.SetBoolean("encryptAllData", service->EncryptEverythingEnabled()); 492 args.SetBoolean("encryptAllData", service->EncryptEverythingEnabled());
480 493
481 // We call IsPassphraseRequired() here, instead of calling 494 // We call IsPassphraseRequired() here, instead of calling
482 // IsPassphraseRequiredForDecryption(), because we want to show the passphrase 495 // IsPassphraseRequiredForDecryption(), because we want to show the passphrase
483 // UI even if no encrypted data types are enabled. 496 // UI even if no encrypted data types are enabled.
484 args.SetBoolean("showPassphrase", service->IsPassphraseRequired()); 497 args.SetBoolean("showPassphrase", service->IsPassphraseRequired());
485 // Keystore encryption is behind a flag. Only show the new encryption settings 498 // Keystore encryption is behind a flag. Only show the new encryption settings
486 // if keystore encryption is enabled. 499 // if keystore encryption is enabled.
487 args.SetBoolean("keystoreEncryptionEnabled", IsKeystoreEncryptionEnabled()); 500 args.SetBoolean("keystoreEncryptionEnabled", IsKeystoreEncryptionEnabled());
488 501
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 572
560 ProfileSyncService* service = GetSyncService(); 573 ProfileSyncService* service = GetSyncService();
561 DCHECK(service); 574 DCHECK(service);
562 if (!service->HasSyncSetupCompleted()) { 575 if (!service->HasSyncSetupCompleted()) {
563 // This is the first time configuring sync, so log it. 576 // This is the first time configuring sync, so log it.
564 base::FilePath profile_file_path = GetProfile()->GetPath(); 577 base::FilePath profile_file_path = GetProfile()->GetPath();
565 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); 578 ProfileMetrics::LogProfileSyncSignIn(profile_file_path);
566 579
567 // We're done configuring, so notify ProfileSyncService that it is OK to 580 // We're done configuring, so notify ProfileSyncService that it is OK to
568 // start syncing. 581 // start syncing.
582 service->SetSetupInProgress(false);
569 service->SetSyncSetupCompleted(); 583 service->SetSyncSetupCompleted();
570 } 584 }
571 } 585 }
572 586
573 bool SyncSetupHandler::IsActiveLogin() const { 587 bool SyncSetupHandler::IsActiveLogin() const {
574 // LoginUIService can be NULL if page is brought up in incognito mode 588 // LoginUIService can be NULL if page is brought up in incognito mode
575 // (i.e. if the user is running in guest mode in cros and brings up settings). 589 // (i.e. if the user is running in guest mode in cros and brings up settings).
576 LoginUIService* service = GetLoginUIService(); 590 LoginUIService* service = GetLoginUIService();
577 return service && (service->current_login_ui() == this); 591 return service && (service->current_login_ui() == this);
578 } 592 }
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { 912 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) {
899 // Stop a timer to handle timeout in waiting for checking network connection. 913 // Stop a timer to handle timeout in waiting for checking network connection.
900 backend_start_timer_.reset(); 914 backend_start_timer_.reset();
901 915
902 #if defined(OS_CHROMEOS) 916 #if defined(OS_CHROMEOS)
903 // TODO(peria): Show error dialog for prompting sign in and out on 917 // TODO(peria): Show error dialog for prompting sign in and out on
904 // Chrome OS. http://crbug.com/128692 918 // Chrome OS. http://crbug.com/128692
905 CloseOverlay(); 919 CloseOverlay();
906 #else 920 #else
907 last_signin_error_ = error; 921 last_signin_error_ = error;
908
909 // If using web-based sign in flow, don't show the gaia sign in page again
910 // since there is no way to show the user an error message.
911 if (SyncPromoUI::UseWebBasedSigninFlow()) { 922 if (SyncPromoUI::UseWebBasedSigninFlow()) {
912 CloseSyncSetup(); 923 // If using web-based sign in flow, don't show the gaia sign in page again
924 // since there is no way to show the user an error message. Terminate sync
925 // setup and close the overlay. If there is a sign in error, the user will
926 // see a badge in the menu and a re-auth link in the settings page.
927 CloseOverlay();
913 } else if (retry_on_signin_failure_) { 928 } else if (retry_on_signin_failure_) {
914 // Got a failed signin - this is either just a typical auth error, or a 929 // Got a failed signin - this is either just a typical auth error, or a
915 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). 930 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors).
916 // On ChromeOS, this condition can happen when auth token is invalid and 931 // On ChromeOS, this condition can happen when auth token is invalid and
917 // cannot start sync backend. 932 // cannot start sync backend.
918 // If using web-based sign in flow, don't show the gaia sign in page again
919 // since there is no way to show the user an error message.
920 ProfileSyncService* service = GetSyncService(); 933 ProfileSyncService* service = GetSyncService();
921 DisplayGaiaLogin(service && service->HasUnrecoverableError()); 934 DisplayGaiaLogin(service && service->HasUnrecoverableError());
922 } else { 935 } else {
936 // TODO(rsimha): Clean up this if block once the non-webui code path is
937 // removed.
923 CloseOverlay(); 938 CloseOverlay();
924 } 939 }
925 #endif 940 #endif
926 } 941 }
927 942
928 Profile* SyncSetupHandler::GetProfile() const { 943 Profile* SyncSetupHandler::GetProfile() const {
929 return Profile::FromWebUI(web_ui()); 944 return Profile::FromWebUI(web_ui());
930 } 945 }
931 946
932 ProfileSyncService* SyncSetupHandler::GetSyncService() const { 947 ProfileSyncService* SyncSetupHandler::GetSyncService() const {
(...skipping 11 matching lines...) Expand all
944 // If we have signed in while sync is already setup, it must be due to some 959 // If we have signed in while sync is already setup, it must be due to some
945 // kind of re-authentication flow. In that case, just close the signin dialog 960 // kind of re-authentication flow. In that case, just close the signin dialog
946 // rather than forcing the user to go through sync configuration. 961 // rather than forcing the user to go through sync configuration.
947 if (!service || service->HasSyncSetupCompleted()) 962 if (!service || service->HasSyncSetupCompleted())
948 DisplayGaiaSuccessAndClose(); 963 DisplayGaiaSuccessAndClose();
949 else 964 else
950 DisplayConfigureSync(false, false); 965 DisplayConfigureSync(false, false);
951 } 966 }
952 967
953 void SyncSetupHandler::HandleConfigure(const ListValue* args) { 968 void SyncSetupHandler::HandleConfigure(const ListValue* args) {
969 DCHECK(!signin_tracker_.get());
954 std::string json; 970 std::string json;
955 if (!args->GetString(0, &json)) { 971 if (!args->GetString(0, &json)) {
956 NOTREACHED() << "Could not read JSON argument"; 972 NOTREACHED() << "Could not read JSON argument";
957 return; 973 return;
958 } 974 }
959 if (json.empty()) { 975 if (json.empty()) {
960 NOTREACHED(); 976 NOTREACHED();
961 return; 977 return;
962 } 978 }
963 979
964 SyncConfigInfo configuration; 980 SyncConfigInfo configuration;
965 if (!GetConfiguration(json, &configuration)) { 981 if (!GetConfiguration(json, &configuration)) {
966 // The page sent us something that we didn't understand. 982 // The page sent us something that we didn't understand.
967 // This probably indicates a programming error. 983 // This probably indicates a programming error.
968 NOTREACHED(); 984 NOTREACHED();
969 return; 985 return;
970 } 986 }
971 987
972 // Start configuring the ProfileSyncService using the configuration passed 988 // Start configuring the ProfileSyncService using the configuration passed
973 // to us from the JS layer. 989 // to us from the JS layer.
974 ProfileSyncService* service = GetSyncService(); 990 ProfileSyncService* service = GetSyncService();
975 991
976 // If the sync engine has shutdown for some reason, just close the sync 992 // If the sync engine has shutdown for some reason, just close the sync
977 // dialog. 993 // dialog.
978 if (!service || !service->sync_initialized()) { 994 if (!service || !service->sync_initialized()) {
979 CloseOverlay(); 995 CloseOverlay();
980 return; 996 return;
981 } 997 }
982 998
999 // Disable sync, but remain signed in if the user selected "Sync nothing" in
1000 // the advanced settings dialog. Note: In order to disable sync across
1001 // restarts on Chrome OS, we must call OnStopSyncingPermanently(), which
1002 // suppresses sync startup in addition to disabling it.
1003 if (configuration.sync_nothing) {
1004 ProfileSyncService::SyncEvent(
1005 ProfileSyncService::STOP_FROM_ADVANCED_DIALOG);
1006 CloseOverlay();
1007 service->OnStopSyncingPermanently();
1008 service->SetSetupInProgress(false);
1009 return;
1010 }
1011
983 // Note: Data encryption will not occur until configuration is complete 1012 // Note: Data encryption will not occur until configuration is complete
984 // (when the PSS receives its CONFIGURE_DONE notification from the sync 1013 // (when the PSS receives its CONFIGURE_DONE notification from the sync
985 // backend), so the user still has a chance to cancel out of the operation 1014 // backend), so the user still has a chance to cancel out of the operation
986 // if (for example) some kind of passphrase error is encountered. 1015 // if (for example) some kind of passphrase error is encountered.
987 if (configuration.encrypt_all) 1016 if (configuration.encrypt_all)
988 service->EnableEncryptEverything(); 1017 service->EnableEncryptEverything();
989 1018
990 bool passphrase_failed = false; 1019 bool passphrase_failed = false;
991 if (!configuration.passphrase.empty()) { 1020 if (!configuration.passphrase.empty()) {
992 // We call IsPassphraseRequired() here (instead of 1021 // We call IsPassphraseRequired() here (instead of
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 #endif 1138 #endif
1110 1139
1111 void SyncSetupHandler::HandleCloseTimeout(const ListValue* args) { 1140 void SyncSetupHandler::HandleCloseTimeout(const ListValue* args) {
1112 CloseSyncSetup(); 1141 CloseSyncSetup();
1113 } 1142 }
1114 1143
1115 void SyncSetupHandler::CloseSyncSetup() { 1144 void SyncSetupHandler::CloseSyncSetup() {
1116 // TODO(atwilson): Move UMA tracking of signin events out of sync module. 1145 // TODO(atwilson): Move UMA tracking of signin events out of sync module.
1117 ProfileSyncService* sync_service = GetSyncService(); 1146 ProfileSyncService* sync_service = GetSyncService();
1118 if (IsActiveLogin()) { 1147 if (IsActiveLogin()) {
1119 if (!sync_service || !sync_service->HasSyncSetupCompleted()) { 1148 // Don't log a cancel event if the sync setup dialog is being
1149 // automatically closed due to an auth error.
1150 if ((!sync_service || !sync_service->HasSyncSetupCompleted()) &&
1151 sync_service->GetAuthError().state() == GoogleServiceAuthError::NONE) {
1120 if (signin_tracker_.get()) { 1152 if (signin_tracker_.get()) {
1121 ProfileSyncService::SyncEvent( 1153 ProfileSyncService::SyncEvent(
1122 ProfileSyncService::CANCEL_DURING_SIGNON); 1154 ProfileSyncService::CANCEL_DURING_SIGNON);
1123 } else if (configuring_sync_) { 1155 } else if (configuring_sync_) {
1124 ProfileSyncService::SyncEvent( 1156 ProfileSyncService::SyncEvent(
1125 ProfileSyncService::CANCEL_DURING_CONFIGURE); 1157 ProfileSyncService::CANCEL_DURING_CONFIGURE);
1126 } else { 1158 } else {
1127 ProfileSyncService::SyncEvent( 1159 ProfileSyncService::SyncEvent(
1128 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); 1160 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH);
1129 } 1161 }
1162
1163 // If the user clicked "Cancel" while setting up sync, disable sync
1164 // because we don't want the sync backend to remain in the initialized
1165 // state. Note: In order to disable sync across restarts on Chrome OS, we
1166 // must call OnStopSyncingPermanently(), which suppresses sync startup in
1167 // addition to disabling it.
1168 if (sync_service) {
1169 DVLOG(1) << "Sync setup aborted by user action";
1170 sync_service->OnStopSyncingPermanently();
1171 sync_service->SetSetupInProgress(false);
1172 }
1130 } 1173 }
1131 1174
1132 #if !defined(OS_CHROMEOS) 1175 #if !defined(OS_CHROMEOS)
1133 // Let the various services know that we're no longer active. 1176 // Let the various services know that we're no longer active.
1134 if (SyncPromoUI::UseWebBasedSigninFlow()) 1177 if (SyncPromoUI::UseWebBasedSigninFlow())
1135 CloseGaiaSigninPage(); 1178 CloseGaiaSigninPage();
1136 #endif 1179 #endif
1137 1180
1138 GetLoginUIService()->LoginUIClosed(this); 1181 GetLoginUIService()->LoginUIClosed(this);
1139 } 1182 }
1140 1183
1141 if (sync_service) {
1142 // Make sure user isn't left half-logged-in (signed in, but without sync
1143 // started up). If the user hasn't finished setting up sync, then sign out
1144 // and shut down sync.
1145 if (!sync_service->HasSyncSetupCompleted()) {
1146 DVLOG(1) << "Signin aborted by user action";
1147 #if !defined(OS_CHROMEOS)
1148 // Don't sign the user out on chromeos, even if they cancel sync setup
1149 // after a dashboard clear.
1150 if (signin_tracker_.get() || sync_service->FirstSetupInProgress()) {
1151 // User was still in the process of signing in, so sign him out again.
1152 // This makes sure that the user isn't left signed in but with sync
1153 // un-configured.
1154 //
1155 // This has the side-effect of signing out the user in the following
1156 // scenario:
1157 // * User signs in while sync is disabled by policy.
1158 // * Sync is re-enabled by policy.
1159 // * User brings up sync setup dialog to do initial sync config.
1160 // * User cancels out of the dialog.
1161 //
1162 // This case is indistinguishable from the "one click signin" case where
1163 // the user checks the "advanced setup" checkbox, then cancels out of
1164 // the setup box, which is a much more common scenario, so we do the
1165 // right thing for the one-click case.
1166 SigninManagerFactory::GetForProfile(GetProfile())->SignOut();
1167 }
1168 #endif
1169 sync_service->DisableForUser();
1170 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs());
1171 sync_prefs.SetStartSuppressed(true);
1172 }
1173 sync_service->SetSetupInProgress(false);
1174 }
1175
1176 #if !defined(OS_CHROMEOS) 1184 #if !defined(OS_CHROMEOS)
1177 // Reset the attempted email address and error, otherwise the sync setup 1185 // Reset the attempted email address and error, otherwise the sync setup
1178 // overlay in the settings page will stay in whatever error state it was last 1186 // overlay in the settings page will stay in whatever error state it was last
1179 // when it is reopened. 1187 // when it is reopened.
1180 last_attempted_user_email_.clear(); 1188 last_attempted_user_email_.clear();
1181 last_signin_error_ = GoogleServiceAuthError::AuthErrorNone(); 1189 last_signin_error_ = GoogleServiceAuthError::AuthErrorNone();
1182 #endif 1190 #endif
1183 1191
1184 configuring_sync_ = false; 1192 configuring_sync_ = false;
1185 signin_tracker_.reset(); 1193 signin_tracker_.reset();
(...skipping 10 matching lines...) Expand all
1196 // 1) Signin promo. 1204 // 1) Signin promo.
1197 // 2) Normal signin through settings page (GetAuthenticatedUsername() is 1205 // 2) Normal signin through settings page (GetAuthenticatedUsername() is
1198 // empty). 1206 // empty).
1199 // 3) Previously working credentials have expired. 1207 // 3) Previously working credentials have expired.
1200 // 4) User is signed in, but has stopped sync via the google dashboard, and 1208 // 4) User is signed in, but has stopped sync via the google dashboard, and
1201 // signout is prohibited by policy so we need to force a re-auth. 1209 // signout is prohibited by policy so we need to force a re-auth.
1202 // 5) User clicks [Advanced Settings] button on options page while already 1210 // 5) User clicks [Advanced Settings] button on options page while already
1203 // logged in. 1211 // logged in.
1204 // 6) One-click signin (credentials are already available, so should display 1212 // 6) One-click signin (credentials are already available, so should display
1205 // sync configure UI, not login UI). 1213 // sync configure UI, not login UI).
1206 // 7) ChromeOS re-enable after disabling sync. 1214 // 7) User re-enables sync after disabling it via advanced settings.
1207 #if !defined(OS_CHROMEOS) 1215 #if !defined(OS_CHROMEOS)
1208 SigninManagerBase* signin = 1216 SigninManagerBase* signin =
1209 SigninManagerFactory::GetForProfile(GetProfile()); 1217 SigninManagerFactory::GetForProfile(GetProfile());
1210 if (signin->GetAuthenticatedUsername().empty() || 1218 if (signin->GetAuthenticatedUsername().empty() ||
1211 (GetSyncService() && GetSyncService()->IsStartSuppressed()) ||
1212 signin->signin_global_error()->HasMenuItem()) { 1219 signin->signin_global_error()->HasMenuItem()) {
1213 // User is not logged in, or login has been specially requested - need to 1220 // User is not logged in, or login has been specially requested - need to
1214 // display login UI (cases 1-3). 1221 // display login UI (cases 1-3).
1215 DisplayGaiaLogin(false); 1222 DisplayGaiaLogin(false);
1216 if (!SyncPromoUI::UseWebBasedSigninFlow()) 1223 if (!SyncPromoUI::UseWebBasedSigninFlow())
1217 ShowSetupUI(); 1224 ShowSetupUI();
1218 return; 1225 return;
1219 } 1226 }
1220 #endif 1227 #endif
1221 if (!GetSyncService()) { 1228 if (!GetSyncService()) {
1222 // This can happen if the user directly navigates to /settings/syncSetup. 1229 // This can happen if the user directly navigates to /settings/syncSetup.
1223 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; 1230 DLOG(WARNING) << "Cannot display sync UI when sync is disabled";
1224 CloseOverlay(); 1231 CloseOverlay();
1225 return; 1232 return;
1226 } 1233 }
1227 1234
1228 // User is already logged in. They must have brought up the config wizard 1235 // User is already logged in. They must have brought up the config wizard
1229 // via the "Advanced..." button or through One-Click signin (cases 4-6), or 1236 // via the "Advanced..." button or through One-Click signin (cases 4-6), or
1230 // they are re-enabling sync on Chrome OS. 1237 // they are re-enabling sync after having disabled it (case 7).
1231 DisplayConfigureSync(true, false); 1238 DisplayConfigureSync(true, false);
1232 ShowSetupUI(); 1239 ShowSetupUI();
1233 } 1240 }
1234 1241
1235 void SyncSetupHandler::OpenConfigureSync() { 1242 void SyncSetupHandler::OpenConfigureSync() {
1236 if (!PrepareSyncSetup()) 1243 if (!PrepareSyncSetup())
1237 return; 1244 return;
1238 1245
1239 DisplayConfigureSync(true, false); 1246 DisplayConfigureSync(true, false);
1240 ShowSetupUI(); 1247 ShowSetupUI();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 return LoginUIServiceFactory::GetForProfile(GetProfile()); 1373 return LoginUIServiceFactory::GetForProfile(GetProfile());
1367 } 1374 }
1368 1375
1369 void SyncSetupHandler::CloseOverlay() { 1376 void SyncSetupHandler::CloseOverlay() {
1370 // Stop a timer to handle timeout in waiting for sync setup. 1377 // Stop a timer to handle timeout in waiting for sync setup.
1371 backend_start_timer_.reset(); 1378 backend_start_timer_.reset();
1372 1379
1373 CloseSyncSetup(); 1380 CloseSyncSetup();
1374 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); 1381 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay");
1375 } 1382 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_setup_handler.h ('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