| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/options/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/settings/sync_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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/i18n/time_formatting.h" | 12 #include "base/i18n/time_formatting.h" |
| 13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/strings/utf_string_conversions.h" | |
| 18 #include "base/values.h" | 17 #include "base/values.h" |
| 19 #include "chrome/app/chrome_command_ids.h" | |
| 20 #include "chrome/browser/browser_process.h" | |
| 21 #include "chrome/browser/lifetime/application_lifetime.h" | 18 #include "chrome/browser/lifetime/application_lifetime.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/profiles/profile_info_cache.h" | 20 #include "chrome/browser/profiles/profile_info_cache.h" |
| 24 #include "chrome/browser/profiles/profile_metrics.h" | 21 #include "chrome/browser/profiles/profile_metrics.h" |
| 25 #include "chrome/browser/signin/chrome_signin_helper.h" | 22 #include "chrome/browser/signin/chrome_signin_helper.h" |
| 26 #include "chrome/browser/signin/signin_error_controller_factory.h" | 23 #include "chrome/browser/signin/signin_error_controller_factory.h" |
| 27 #include "chrome/browser/signin/signin_manager_factory.h" | 24 #include "chrome/browser/signin/signin_manager_factory.h" |
| 28 #include "chrome/browser/signin/signin_promo.h" | 25 #include "chrome/browser/signin/signin_promo.h" |
| 29 #include "chrome/browser/sync/profile_sync_service.h" | 26 #include "chrome/browser/sync/profile_sync_service.h" |
| 30 #include "chrome/browser/sync/profile_sync_service_factory.h" | 27 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 31 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
| 32 #include "chrome/browser/ui/browser_window.h" | 29 #include "chrome/browser/ui/browser_window.h" |
| 33 #include "chrome/browser/ui/singleton_tabs.h" | 30 #include "chrome/browser/ui/singleton_tabs.h" |
| 34 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" | 31 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" |
| 35 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 32 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 36 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 33 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 37 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/url_constants.h" | |
| 39 #include "chrome/grit/chromium_strings.h" | |
| 40 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
| 41 #include "chrome/grit/locale_settings.h" | |
| 42 #include "components/google/core/browser/google_util.h" | |
| 43 #include "components/signin/core/browser/signin_error_controller.h" | 36 #include "components/signin/core/browser/signin_error_controller.h" |
| 44 #include "components/signin/core/browser/signin_header_helper.h" | 37 #include "components/signin/core/browser/signin_header_helper.h" |
| 45 #include "components/signin/core/browser/signin_metrics.h" | 38 #include "components/signin/core/browser/signin_metrics.h" |
| 46 #include "components/signin/core/common/profile_management_switches.h" | 39 #include "components/signin/core/common/profile_management_switches.h" |
| 47 #include "components/sync_driver/sync_prefs.h" | 40 #include "components/sync_driver/sync_prefs.h" |
| 48 #include "content/public/browser/render_view_host.h" | 41 #include "content/public/browser/render_view_host.h" |
| 49 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
| 50 #include "content/public/browser/web_contents_delegate.h" | 43 #include "content/public/browser/web_contents_delegate.h" |
| 51 #include "google_apis/gaia/gaia_auth_util.h" | 44 #include "google_apis/gaia/gaia_auth_util.h" |
| 52 #include "google_apis/gaia/gaia_constants.h" | 45 #include "google_apis/gaia/gaia_constants.h" |
| 53 #include "grit/components_strings.h" | |
| 54 #include "net/base/url_util.h" | 46 #include "net/base/url_util.h" |
| 55 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 56 | 48 |
| 57 #if defined(OS_CHROMEOS) | 49 #if defined(OS_CHROMEOS) |
| 58 #include "components/signin/core/browser/signin_manager_base.h" | 50 #include "components/signin/core/browser/signin_manager_base.h" |
| 59 #else | 51 #else |
| 60 #include "components/signin/core/browser/signin_manager.h" | 52 #include "components/signin/core/browser/signin_manager.h" |
| 61 #endif | 53 #endif |
| 62 | 54 |
| 63 using content::WebContents; | 55 using content::WebContents; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 if (!result->GetString("passphrase", &config->passphrase)) { | 137 if (!result->GetString("passphrase", &config->passphrase)) { |
| 146 DLOG(ERROR) << "GetConfiguration() not passed a passphrase value"; | 138 DLOG(ERROR) << "GetConfiguration() not passed a passphrase value"; |
| 147 return false; | 139 return false; |
| 148 } | 140 } |
| 149 } | 141 } |
| 150 return true; | 142 return true; |
| 151 } | 143 } |
| 152 | 144 |
| 153 } // namespace | 145 } // namespace |
| 154 | 146 |
| 155 SyncSetupHandler::SyncSetupHandler() | 147 namespace settings { |
| 156 : configuring_sync_(false) { | 148 |
| 149 SyncHandler::SyncHandler() : configuring_sync_(false) { |
| 157 } | 150 } |
| 158 | 151 |
| 159 SyncSetupHandler::~SyncSetupHandler() { | 152 SyncHandler::~SyncHandler() { |
| 160 // Just exit if running unit tests (no actual WebUI is attached). | 153 // Just exit if running unit tests (no actual WebUI is attached). |
| 161 if (!web_ui()) | 154 if (!web_ui()) |
| 162 return; | 155 return; |
| 163 | 156 |
| 164 // This case is hit when the user performs a back navigation. | 157 // This case is hit when the user performs a back navigation. |
| 165 CloseSyncSetup(); | 158 CloseSyncSetup(); |
| 166 } | 159 } |
| 167 | 160 |
| 168 void SyncSetupHandler::GetLocalizedValues( | 161 void SyncHandler::ConfigureSyncDone() { |
| 169 base::DictionaryValue* localized_strings) { | |
| 170 GetStaticLocalizedValues(localized_strings, web_ui()); | |
| 171 } | |
| 172 | |
| 173 void SyncSetupHandler::GetStaticLocalizedValues( | |
| 174 base::DictionaryValue* localized_strings, | |
| 175 content::WebUI* web_ui) { | |
| 176 DCHECK(localized_strings); | |
| 177 | |
| 178 base::string16 product_name(GetStringUTF16(IDS_PRODUCT_NAME)); | |
| 179 localized_strings->SetString( | |
| 180 "chooseDataTypesInstructions", | |
| 181 GetStringFUTF16(IDS_SYNC_CHOOSE_DATATYPES_INSTRUCTIONS, product_name)); | |
| 182 localized_strings->SetString( | |
| 183 "encryptionInstructions", | |
| 184 GetStringFUTF16(IDS_SYNC_ENCRYPTION_INSTRUCTIONS, product_name)); | |
| 185 localized_strings->SetString( | |
| 186 "encryptionHelpURL", chrome::kSyncEncryptionHelpURL); | |
| 187 localized_strings->SetString( | |
| 188 "encryptionSectionMessage", | |
| 189 GetStringFUTF16(IDS_SYNC_ENCRYPTION_SECTION_MESSAGE, product_name)); | |
| 190 localized_strings->SetString( | |
| 191 "passphraseRecover", | |
| 192 GetStringFUTF16( | |
| 193 IDS_SYNC_PASSPHRASE_RECOVER, | |
| 194 base::ASCIIToUTF16( | |
| 195 google_util::AppendGoogleLocaleParam( | |
| 196 GURL(chrome::kSyncGoogleDashboardURL), | |
| 197 g_browser_process->GetApplicationLocale()).spec()))); | |
| 198 localized_strings->SetString( | |
| 199 "stopSyncingExplanation", | |
| 200 l10n_util::GetStringFUTF16( | |
| 201 IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL, | |
| 202 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | |
| 203 base::ASCIIToUTF16( | |
| 204 google_util::AppendGoogleLocaleParam( | |
| 205 GURL(chrome::kSyncGoogleDashboardURL), | |
| 206 g_browser_process->GetApplicationLocale()).spec()))); | |
| 207 localized_strings->SetString("deleteProfileLabel", | |
| 208 l10n_util::GetStringUTF16(IDS_SYNC_STOP_DELETE_PROFILE_LABEL)); | |
| 209 localized_strings->SetString("stopSyncingTitle", | |
| 210 l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_DIALOG_TITLE)); | |
| 211 localized_strings->SetString("stopSyncingConfirm", | |
| 212 l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL)); | |
| 213 | |
| 214 localized_strings->SetString( | |
| 215 "syncEverythingHelpURL", chrome::kSyncEverythingLearnMoreURL); | |
| 216 localized_strings->SetString( | |
| 217 "syncErrorHelpURL", chrome::kSyncErrorsHelpURL); | |
| 218 | |
| 219 static OptionsStringResource resources[] = { | |
| 220 { "syncSetupConfigureTitle", IDS_SYNC_SETUP_CONFIGURE_TITLE }, | |
| 221 { "syncSetupSpinnerTitle", IDS_SYNC_SETUP_SPINNER_TITLE }, | |
| 222 { "syncSetupTimeoutTitle", IDS_SYNC_SETUP_TIME_OUT_TITLE }, | |
| 223 { "syncSetupTimeoutContent", IDS_SYNC_SETUP_TIME_OUT_CONTENT }, | |
| 224 { "errorLearnMore", IDS_LEARN_MORE }, | |
| 225 { "cancel", IDS_CANCEL }, | |
| 226 { "loginSuccess", IDS_SYNC_SUCCESS }, | |
| 227 { "settingUp", IDS_SYNC_LOGIN_SETTING_UP }, | |
| 228 { "syncAllDataTypes", IDS_SYNC_EVERYTHING }, | |
| 229 { "chooseDataTypes", IDS_SYNC_CHOOSE_DATATYPES }, | |
| 230 { "syncNothing", IDS_SYNC_NOTHING }, | |
| 231 { "bookmarks", IDS_SYNC_DATATYPE_BOOKMARKS }, | |
| 232 { "preferences", IDS_SYNC_DATATYPE_PREFERENCES }, | |
| 233 { "autofill", IDS_SYNC_DATATYPE_AUTOFILL }, | |
| 234 { "themes", IDS_SYNC_DATATYPE_THEMES }, | |
| 235 { "passwords", IDS_SYNC_DATATYPE_PASSWORDS }, | |
| 236 { "extensions", IDS_SYNC_DATATYPE_EXTENSIONS }, | |
| 237 { "typedURLs", IDS_SYNC_DATATYPE_TYPED_URLS }, | |
| 238 { "apps", IDS_SYNC_DATATYPE_APPS }, | |
| 239 { "wifiCredentials", IDS_SYNC_DATATYPE_WIFI_CREDENTIALS }, | |
| 240 { "openTabs", IDS_SYNC_DATATYPE_TABS }, | |
| 241 { "serviceUnavailableError", IDS_SYNC_SETUP_ABORTED_BY_PENDING_CLEAR }, | |
| 242 { "confirmLabel", IDS_SYNC_CONFIRM_PASSPHRASE_LABEL }, | |
| 243 { "emptyErrorMessage", IDS_SYNC_EMPTY_PASSPHRASE_ERROR }, | |
| 244 { "mismatchErrorMessage", IDS_SYNC_PASSPHRASE_MISMATCH_ERROR }, | |
| 245 { "customizeLinkLabel", IDS_SYNC_CUSTOMIZE_LINK_LABEL }, | |
| 246 { "confirmSyncPreferences", IDS_SYNC_CONFIRM_SYNC_PREFERENCES }, | |
| 247 { "syncEverything", IDS_SYNC_SYNC_EVERYTHING }, | |
| 248 { "useDefaultSettings", IDS_SYNC_USE_DEFAULT_SETTINGS }, | |
| 249 { "enterPassphraseBody", IDS_SYNC_ENTER_PASSPHRASE_BODY }, | |
| 250 { "enterGooglePassphraseBody", IDS_SYNC_ENTER_GOOGLE_PASSPHRASE_BODY }, | |
| 251 { "passphraseLabel", IDS_SYNC_PASSPHRASE_LABEL }, | |
| 252 { "incorrectPassphrase", IDS_SYNC_INCORRECT_PASSPHRASE }, | |
| 253 { "passphraseWarning", IDS_SYNC_PASSPHRASE_WARNING }, | |
| 254 { "yes", IDS_SYNC_PASSPHRASE_CANCEL_YES }, | |
| 255 { "no", IDS_SYNC_PASSPHRASE_CANCEL_NO }, | |
| 256 { "sectionExplicitMessagePrefix", IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_PREFIX }, | |
| 257 { "sectionExplicitMessagePostfix", | |
| 258 IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_POSTFIX }, | |
| 259 // TODO(rogerta): browser/resource/sync_promo/sync_promo.html and related | |
| 260 // file may not be needed any more. If not, then the following promo | |
| 261 // strings can also be removed. | |
| 262 { "promoPageTitle", IDS_SYNC_PROMO_TAB_TITLE }, | |
| 263 { "promoSkipButton", IDS_SYNC_PROMO_SKIP_BUTTON }, | |
| 264 { "promoAdvanced", IDS_SYNC_PROMO_ADVANCED }, | |
| 265 { "promoLearnMore", IDS_LEARN_MORE }, | |
| 266 { "promoTitleShort", IDS_SYNC_PROMO_MESSAGE_TITLE_SHORT }, | |
| 267 { "encryptionSectionTitle", IDS_SYNC_ENCRYPTION_SECTION_TITLE }, | |
| 268 { "basicEncryptionOption", IDS_SYNC_BASIC_ENCRYPTION_DATA }, | |
| 269 { "fullEncryptionOption", IDS_SYNC_FULL_ENCRYPTION_DATA }, | |
| 270 }; | |
| 271 | |
| 272 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
| 273 RegisterTitle(localized_strings, "syncSetupOverlay", IDS_SYNC_SETUP_TITLE); | |
| 274 } | |
| 275 | |
| 276 void SyncSetupHandler::ConfigureSyncDone() { | |
| 277 base::StringValue page("done"); | 162 base::StringValue page("done"); |
| 278 web_ui()->CallJavascriptFunction( | 163 web_ui()->CallJavascriptFunction( |
| 279 "SyncSetupOverlay.showSyncSetupPage", page); | 164 "SyncSetupOverlay.showSyncSetupPage", page); |
| 280 | 165 |
| 281 // Suppress the sign in promo once the user starts sync. This way the user | 166 // Suppress the sign in promo once the user starts sync. This way the user |
| 282 // doesn't see the sign in promo even if they sign out later on. | 167 // doesn't see the sign in promo even if they sign out later on. |
| 283 signin::SetUserSkippedPromo(GetProfile()); | 168 signin::SetUserSkippedPromo(GetProfile()); |
| 284 | 169 |
| 285 ProfileSyncService* service = GetSyncService(); | 170 ProfileSyncService* service = GetSyncService(); |
| 286 DCHECK(service); | 171 DCHECK(service); |
| 287 if (!service->HasSyncSetupCompleted()) { | 172 if (!service->HasSyncSetupCompleted()) { |
| 288 // This is the first time configuring sync, so log it. | 173 // This is the first time configuring sync, so log it. |
| 289 base::FilePath profile_file_path = GetProfile()->GetPath(); | 174 base::FilePath profile_file_path = GetProfile()->GetPath(); |
| 290 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); | 175 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); |
| 291 | 176 |
| 292 // We're done configuring, so notify ProfileSyncService that it is OK to | 177 // We're done configuring, so notify ProfileSyncService that it is OK to |
| 293 // start syncing. | 178 // start syncing. |
| 294 service->SetSetupInProgress(false); | 179 service->SetSetupInProgress(false); |
| 295 service->SetSyncSetupCompleted(); | 180 service->SetSyncSetupCompleted(); |
| 296 } | 181 } |
| 297 } | 182 } |
| 298 | 183 |
| 299 bool SyncSetupHandler::IsActiveLogin() const { | 184 bool SyncHandler::IsActiveLogin() const { |
| 300 // LoginUIService can be NULL if page is brought up in incognito mode | 185 // LoginUIService can be NULL if page is brought up in incognito mode |
| 301 // (i.e. if the user is running in guest mode in cros and brings up settings). | 186 // (i.e. if the user is running in guest mode in cros and brings up settings). |
| 302 LoginUIService* service = GetLoginUIService(); | 187 LoginUIService* service = GetLoginUIService(); |
| 303 return service && (service->current_login_ui() == this); | 188 return service && (service->current_login_ui() == this); |
| 304 } | 189 } |
| 305 | 190 |
| 306 void SyncSetupHandler::RegisterMessages() { | 191 void SyncHandler::RegisterMessages() { |
| 307 web_ui()->RegisterMessageCallback( | 192 web_ui()->RegisterMessageCallback( |
| 308 "SyncSetupDidClosePage", | 193 "SyncSetupDidClosePage", |
| 309 base::Bind(&SyncSetupHandler::OnDidClosePage, | 194 base::Bind(&SyncHandler::OnDidClosePage, |
| 310 base::Unretained(this))); | 195 base::Unretained(this))); |
| 311 web_ui()->RegisterMessageCallback( | 196 web_ui()->RegisterMessageCallback( |
| 312 "SyncSetupConfigure", | 197 "SyncSetupConfigure", |
| 313 base::Bind(&SyncSetupHandler::HandleConfigure, | 198 base::Bind(&SyncHandler::HandleConfigure, |
| 314 base::Unretained(this))); | 199 base::Unretained(this))); |
| 315 web_ui()->RegisterMessageCallback( | 200 web_ui()->RegisterMessageCallback( |
| 316 "SyncSetupShowSetupUI", | 201 "SyncSetupShowSetupUI", |
| 317 base::Bind(&SyncSetupHandler::HandleShowSetupUI, | 202 base::Bind(&SyncHandler::HandleShowSetupUI, |
| 318 base::Unretained(this))); | 203 base::Unretained(this))); |
| 319 web_ui()->RegisterMessageCallback("CloseTimeout", | 204 web_ui()->RegisterMessageCallback("CloseTimeout", |
| 320 base::Bind(&SyncSetupHandler::HandleCloseTimeout, | 205 base::Bind(&SyncHandler::HandleCloseTimeout, |
| 321 base::Unretained(this))); | 206 base::Unretained(this))); |
| 322 #if defined(OS_CHROMEOS) | 207 #if defined(OS_CHROMEOS) |
| 323 web_ui()->RegisterMessageCallback( | 208 web_ui()->RegisterMessageCallback( |
| 324 "SyncSetupDoSignOutOnAuthError", | 209 "SyncSetupDoSignOutOnAuthError", |
| 325 base::Bind(&SyncSetupHandler::HandleDoSignOutOnAuthError, | 210 base::Bind(&SyncHandler::HandleDoSignOutOnAuthError, |
| 326 base::Unretained(this))); | 211 base::Unretained(this))); |
| 327 #else | 212 #else |
| 328 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", | 213 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", |
| 329 base::Bind(&SyncSetupHandler::HandleStopSyncing, | 214 base::Bind(&SyncHandler::HandleStopSyncing, |
| 330 base::Unretained(this))); | 215 base::Unretained(this))); |
| 331 web_ui()->RegisterMessageCallback("SyncSetupStartSignIn", | 216 web_ui()->RegisterMessageCallback("SyncSetupStartSignIn", |
| 332 base::Bind(&SyncSetupHandler::HandleStartSignin, | 217 base::Bind(&SyncHandler::HandleStartSignin, |
| 333 base::Unretained(this))); | 218 base::Unretained(this))); |
| 334 #endif | 219 #endif |
| 335 } | 220 } |
| 336 | 221 |
| 337 #if !defined(OS_CHROMEOS) | 222 #if !defined(OS_CHROMEOS) |
| 338 void SyncSetupHandler::DisplayGaiaLogin() { | 223 void SyncHandler::DisplayGaiaLogin() { |
| 339 DCHECK(!sync_startup_tracker_); | 224 DCHECK(!sync_startup_tracker_); |
| 340 // Advanced options are no longer being configured if the login screen is | 225 // Advanced options are no longer being configured if the login screen is |
| 341 // visible. If the user exits the signin wizard after this without | 226 // visible. If the user exits the signin wizard after this without |
| 342 // configuring sync, CloseSyncSetup() will ensure they are logged out. | 227 // configuring sync, CloseSyncSetup() will ensure they are logged out. |
| 343 configuring_sync_ = false; | 228 configuring_sync_ = false; |
| 344 DisplayGaiaLoginInNewTabOrWindow(); | 229 DisplayGaiaLoginInNewTabOrWindow(); |
| 345 } | 230 } |
| 346 | 231 |
| 347 void SyncSetupHandler::DisplayGaiaLoginInNewTabOrWindow() { | 232 void SyncHandler::DisplayGaiaLoginInNewTabOrWindow() { |
| 348 Browser* browser = chrome::FindBrowserWithWebContents( | 233 Browser* browser = chrome::FindBrowserWithWebContents( |
| 349 web_ui()->GetWebContents()); | 234 web_ui()->GetWebContents()); |
| 350 bool force_new_tab = false; | 235 bool force_new_tab = false; |
| 351 if (!browser) { | 236 if (!browser) { |
| 352 // Settings is not displayed in a browser window. Open a new window. | 237 // Settings is not displayed in a browser window. Open a new window. |
| 353 browser = new Browser(Browser::CreateParams( | 238 browser = new Browser(Browser::CreateParams( |
| 354 Browser::TYPE_TABBED, GetProfile(), chrome::GetActiveDesktop())); | 239 Browser::TYPE_TABBED, GetProfile(), chrome::GetActiveDesktop())); |
| 355 force_new_tab = true; | 240 force_new_tab = true; |
| 356 } | 241 } |
| 357 | 242 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 385 } else { | 270 } else { |
| 386 url = signin::GetPromoURL(signin_metrics::SOURCE_SETTINGS, true); | 271 url = signin::GetPromoURL(signin_metrics::SOURCE_SETTINGS, true); |
| 387 } | 272 } |
| 388 } | 273 } |
| 389 | 274 |
| 390 if (url.is_valid()) | 275 if (url.is_valid()) |
| 391 chrome::ShowSingletonTab(browser, url); | 276 chrome::ShowSingletonTab(browser, url); |
| 392 } | 277 } |
| 393 #endif | 278 #endif |
| 394 | 279 |
| 395 bool SyncSetupHandler::PrepareSyncSetup() { | 280 bool SyncHandler::PrepareSyncSetup() { |
| 396 // If the wizard is already visible, just focus that one. | 281 // If the wizard is already visible, just focus that one. |
| 397 if (FocusExistingWizardIfPresent()) { | 282 if (FocusExistingWizardIfPresent()) { |
| 398 if (!IsActiveLogin()) | 283 if (!IsActiveLogin()) |
| 399 CloseSyncSetup(); | 284 CloseSyncSetup(); |
| 400 return false; | 285 return false; |
| 401 } | 286 } |
| 402 | 287 |
| 403 // Notify services that login UI is now active. | 288 // Notify services that login UI is now active. |
| 404 GetLoginUIService()->SetLoginUI(this); | 289 GetLoginUIService()->SetLoginUI(this); |
| 405 | 290 |
| 406 ProfileSyncService* service = GetSyncService(); | 291 ProfileSyncService* service = GetSyncService(); |
| 407 if (service) | 292 if (service) |
| 408 service->SetSetupInProgress(true); | 293 service->SetSetupInProgress(true); |
| 409 | 294 |
| 410 return true; | 295 return true; |
| 411 } | 296 } |
| 412 | 297 |
| 413 void SyncSetupHandler::DisplaySpinner() { | 298 void SyncHandler::DisplaySpinner() { |
| 414 configuring_sync_ = true; | 299 configuring_sync_ = true; |
| 415 base::StringValue page("spinner"); | 300 base::StringValue page("spinner"); |
| 416 base::DictionaryValue args; | 301 base::DictionaryValue args; |
| 417 | 302 |
| 418 const int kTimeoutSec = 30; | 303 const int kTimeoutSec = 30; |
| 419 DCHECK(!backend_start_timer_); | 304 DCHECK(!backend_start_timer_); |
| 420 backend_start_timer_.reset(new base::OneShotTimer()); | 305 backend_start_timer_.reset(new base::OneShotTimer()); |
| 421 backend_start_timer_->Start(FROM_HERE, | 306 backend_start_timer_->Start(FROM_HERE, |
| 422 base::TimeDelta::FromSeconds(kTimeoutSec), | 307 base::TimeDelta::FromSeconds(kTimeoutSec), |
| 423 this, &SyncSetupHandler::DisplayTimeout); | 308 this, &SyncHandler::DisplayTimeout); |
| 424 | 309 |
| 425 web_ui()->CallJavascriptFunction( | 310 web_ui()->CallJavascriptFunction( |
| 426 "SyncSetupOverlay.showSyncSetupPage", page, args); | 311 "SyncSetupOverlay.showSyncSetupPage", page, args); |
| 427 } | 312 } |
| 428 | 313 |
| 429 // TODO(kochi): Handle error conditions other than timeout. | 314 // TODO(kochi): Handle error conditions other than timeout. |
| 430 // http://crbug.com/128692 | 315 // http://crbug.com/128692 |
| 431 void SyncSetupHandler::DisplayTimeout() { | 316 void SyncHandler::DisplayTimeout() { |
| 432 // Stop a timer to handle timeout in waiting for checking network connection. | 317 // Stop a timer to handle timeout in waiting for checking network connection. |
| 433 backend_start_timer_.reset(); | 318 backend_start_timer_.reset(); |
| 434 | 319 |
| 435 // Do not listen to sync startup events. | 320 // Do not listen to sync startup events. |
| 436 sync_startup_tracker_.reset(); | 321 sync_startup_tracker_.reset(); |
| 437 | 322 |
| 438 base::StringValue page("timeout"); | 323 base::StringValue page("timeout"); |
| 439 base::DictionaryValue args; | 324 base::DictionaryValue args; |
| 440 web_ui()->CallJavascriptFunction( | 325 web_ui()->CallJavascriptFunction( |
| 441 "SyncSetupOverlay.showSyncSetupPage", page, args); | 326 "SyncSetupOverlay.showSyncSetupPage", page, args); |
| 442 } | 327 } |
| 443 | 328 |
| 444 void SyncSetupHandler::OnDidClosePage(const base::ListValue* args) { | 329 void SyncHandler::OnDidClosePage(const base::ListValue* args) { |
| 445 CloseSyncSetup(); | 330 CloseSyncSetup(); |
| 446 } | 331 } |
| 447 | 332 |
| 448 void SyncSetupHandler::SyncStartupFailed() { | 333 void SyncHandler::SyncStartupFailed() { |
| 449 // Stop a timer to handle timeout in waiting for checking network connection. | 334 // Stop a timer to handle timeout in waiting for checking network connection. |
| 450 backend_start_timer_.reset(); | 335 backend_start_timer_.reset(); |
| 451 | 336 |
| 452 // Just close the sync overlay (the idea is that the base settings page will | 337 // Just close the sync overlay (the idea is that the base settings page will |
| 453 // display the current error.) | 338 // display the current error.) |
| 454 CloseUI(); | 339 CloseUI(); |
| 455 } | 340 } |
| 456 | 341 |
| 457 void SyncSetupHandler::SyncStartupCompleted() { | 342 void SyncHandler::SyncStartupCompleted() { |
| 458 ProfileSyncService* service = GetSyncService(); | 343 ProfileSyncService* service = GetSyncService(); |
| 459 DCHECK(service->IsBackendInitialized()); | 344 DCHECK(service->IsBackendInitialized()); |
| 460 | 345 |
| 461 // Stop a timer to handle timeout in waiting for checking network connection. | 346 // Stop a timer to handle timeout in waiting for checking network connection. |
| 462 backend_start_timer_.reset(); | 347 backend_start_timer_.reset(); |
| 463 | 348 |
| 464 DisplayConfigureSync(false); | 349 DisplayConfigureSync(false); |
| 465 } | 350 } |
| 466 | 351 |
| 467 Profile* SyncSetupHandler::GetProfile() const { | 352 Profile* SyncHandler::GetProfile() const { |
| 468 return Profile::FromWebUI(web_ui()); | 353 return Profile::FromWebUI(web_ui()); |
| 469 } | 354 } |
| 470 | 355 |
| 471 ProfileSyncService* SyncSetupHandler::GetSyncService() const { | 356 ProfileSyncService* SyncHandler::GetSyncService() const { |
| 472 Profile* profile = GetProfile(); | 357 return GetProfile()->IsSyncAllowed() ? |
| 473 return profile->IsSyncAllowed() ? | |
| 474 ProfileSyncServiceFactory::GetForProfile(GetProfile()) : NULL; | 358 ProfileSyncServiceFactory::GetForProfile(GetProfile()) : NULL; |
| 475 } | 359 } |
| 476 | 360 |
| 477 void SyncSetupHandler::HandleConfigure(const base::ListValue* args) { | 361 void SyncHandler::HandleConfigure(const base::ListValue* args) { |
| 478 DCHECK(!sync_startup_tracker_); | 362 DCHECK(!sync_startup_tracker_); |
| 479 std::string json; | 363 std::string json; |
| 480 if (!args->GetString(0, &json)) { | 364 if (!args->GetString(0, &json)) { |
| 481 NOTREACHED() << "Could not read JSON argument"; | 365 NOTREACHED() << "Could not read JSON argument"; |
| 482 return; | 366 return; |
| 483 } | 367 } |
| 484 if (json.empty()) { | 368 if (json.empty()) { |
| 485 NOTREACHED(); | 369 NOTREACHED(); |
| 486 return; | 370 return; |
| 487 } | 371 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 | 474 |
| 591 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CUSTOMIZE); | 475 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CUSTOMIZE); |
| 592 if (configuration.encrypt_all) | 476 if (configuration.encrypt_all) |
| 593 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_ENCRYPT); | 477 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_ENCRYPT); |
| 594 if (configuration.passphrase_is_gaia && !configuration.passphrase.empty()) | 478 if (configuration.passphrase_is_gaia && !configuration.passphrase.empty()) |
| 595 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE); | 479 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE); |
| 596 if (!configuration.sync_everything) | 480 if (!configuration.sync_everything) |
| 597 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE); | 481 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE); |
| 598 } | 482 } |
| 599 | 483 |
| 600 void SyncSetupHandler::HandleShowSetupUI(const base::ListValue* args) { | 484 void SyncHandler::HandleShowSetupUI(const base::ListValue* args) { |
| 601 if (!GetSyncService()) { | 485 if (!GetSyncService()) { |
| 602 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; | 486 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; |
| 603 CloseUI(); | 487 CloseUI(); |
| 604 return; | 488 return; |
| 605 } | 489 } |
| 606 | 490 |
| 607 SigninManagerBase* signin = | 491 SigninManagerBase* signin = |
| 608 SigninManagerFactory::GetForProfile(GetProfile()); | 492 SigninManagerFactory::GetForProfile(GetProfile()); |
| 609 if (!signin->IsAuthenticated()) { | 493 if (!signin->IsAuthenticated()) { |
| 610 // For web-based signin, the signin page is not displayed in an overlay | 494 // For web-based signin, the signin page is not displayed in an overlay |
| (...skipping 16 matching lines...) Expand all Loading... |
| 627 | 511 |
| 628 // If a setup wizard is present on this page or another, bring it to focus. | 512 // If a setup wizard is present on this page or another, bring it to focus. |
| 629 // Otherwise, display a new one on this page. | 513 // Otherwise, display a new one on this page. |
| 630 if (!FocusExistingWizardIfPresent()) | 514 if (!FocusExistingWizardIfPresent()) |
| 631 OpenSyncSetup(); | 515 OpenSyncSetup(); |
| 632 } | 516 } |
| 633 | 517 |
| 634 #if defined(OS_CHROMEOS) | 518 #if defined(OS_CHROMEOS) |
| 635 // On ChromeOS, we need to sign out the user session to fix an auth error, so | 519 // On ChromeOS, we need to sign out the user session to fix an auth error, so |
| 636 // the user goes through the real signin flow to generate a new auth token. | 520 // the user goes through the real signin flow to generate a new auth token. |
| 637 void SyncSetupHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { | 521 void SyncHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { |
| 638 DVLOG(1) << "Signing out the user to fix a sync error."; | 522 DVLOG(1) << "Signing out the user to fix a sync error."; |
| 639 chrome::AttemptUserExit(); | 523 chrome::AttemptUserExit(); |
| 640 } | 524 } |
| 641 #endif | 525 #endif |
| 642 | 526 |
| 643 #if !defined(OS_CHROMEOS) | 527 #if !defined(OS_CHROMEOS) |
| 644 void SyncSetupHandler::HandleStartSignin(const base::ListValue* args) { | 528 void SyncHandler::HandleStartSignin(const base::ListValue* args) { |
| 645 // Should only be called if the user is not already signed in. | 529 // Should only be called if the user is not already signed in. |
| 646 DCHECK(!SigninManagerFactory::GetForProfile(GetProfile())-> | 530 DCHECK(!SigninManagerFactory::GetForProfile(GetProfile())-> |
| 647 IsAuthenticated()); | 531 IsAuthenticated()); |
| 648 OpenSyncSetup(); | 532 OpenSyncSetup(); |
| 649 } | 533 } |
| 650 | 534 |
| 651 void SyncSetupHandler::HandleStopSyncing(const base::ListValue* args) { | 535 void SyncHandler::HandleStopSyncing(const base::ListValue* args) { |
| 652 if (GetSyncService()) | 536 if (GetSyncService()) |
| 653 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); | 537 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); |
| 654 SigninManagerFactory::GetForProfile(GetProfile())->SignOut( | 538 SigninManagerFactory::GetForProfile(GetProfile())->SignOut( |
| 655 signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); | 539 signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); |
| 656 | 540 |
| 657 bool delete_profile = false; | 541 bool delete_profile = false; |
| 658 if (args->GetBoolean(0, &delete_profile) && delete_profile) { | 542 if (args->GetBoolean(0, &delete_profile) && delete_profile) { |
| 659 // Do as BrowserOptionsHandler::DeleteProfile(). | 543 // Do as BrowserOptionsHandler::DeleteProfile(). |
| 660 options::helper::DeleteProfileAtPath(GetProfile()->GetPath(), web_ui()); | 544 options::helper::DeleteProfileAtPath(GetProfile()->GetPath(), web_ui()); |
| 661 } | 545 } |
| 662 } | 546 } |
| 663 #endif | 547 #endif |
| 664 | 548 |
| 665 void SyncSetupHandler::HandleCloseTimeout(const base::ListValue* args) { | 549 void SyncHandler::HandleCloseTimeout(const base::ListValue* args) { |
| 666 CloseSyncSetup(); | 550 CloseSyncSetup(); |
| 667 } | 551 } |
| 668 | 552 |
| 669 void SyncSetupHandler::CloseSyncSetup() { | 553 void SyncHandler::CloseSyncSetup() { |
| 670 // Stop a timer to handle timeout in waiting for checking network connection. | 554 // Stop a timer to handle timeout in waiting for checking network connection. |
| 671 backend_start_timer_.reset(); | 555 backend_start_timer_.reset(); |
| 672 | 556 |
| 673 // Clear the sync startup tracker, since the setup wizard is being closed. | 557 // Clear the sync startup tracker, since the setup wizard is being closed. |
| 674 sync_startup_tracker_.reset(); | 558 sync_startup_tracker_.reset(); |
| 675 | 559 |
| 676 ProfileSyncService* sync_service = GetSyncService(); | 560 ProfileSyncService* sync_service = GetSyncService(); |
| 677 if (IsActiveLogin()) { | 561 if (IsActiveLogin()) { |
| 678 // Don't log a cancel event if the sync setup dialog is being | 562 // Don't log a cancel event if the sync setup dialog is being |
| 679 // automatically closed due to an auth error. | 563 // automatically closed due to an auth error. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 710 | 594 |
| 711 // Alert the sync service anytime the sync setup dialog is closed. This can | 595 // Alert the sync service anytime the sync setup dialog is closed. This can |
| 712 // happen due to the user clicking the OK or Cancel button, or due to the | 596 // happen due to the user clicking the OK or Cancel button, or due to the |
| 713 // dialog being closed by virtue of sync being disabled in the background. | 597 // dialog being closed by virtue of sync being disabled in the background. |
| 714 if (sync_service) | 598 if (sync_service) |
| 715 sync_service->SetSetupInProgress(false); | 599 sync_service->SetSetupInProgress(false); |
| 716 | 600 |
| 717 configuring_sync_ = false; | 601 configuring_sync_ = false; |
| 718 } | 602 } |
| 719 | 603 |
| 720 void SyncSetupHandler::OpenSyncSetup() { | 604 void SyncHandler::OpenSyncSetup() { |
| 721 if (!PrepareSyncSetup()) | 605 if (!PrepareSyncSetup()) |
| 722 return; | 606 return; |
| 723 | 607 |
| 724 // There are several different UI flows that can bring the user here: | 608 // There are several different UI flows that can bring the user here: |
| 725 // 1) Signin promo. | 609 // 1) Signin promo. |
| 726 // 2) Normal signin through settings page (IsAuthenticated() is false). | 610 // 2) Normal signin through settings page (IsAuthenticated() is false). |
| 727 // 3) Previously working credentials have expired. | 611 // 3) Previously working credentials have expired. |
| 728 // 4) User is signed in, but has stopped sync via the google dashboard, and | 612 // 4) User is signed in, but has stopped sync via the google dashboard, and |
| 729 // signout is prohibited by policy so we need to force a re-auth. | 613 // signout is prohibited by policy so we need to force a re-auth. |
| 730 // 5) User clicks [Advanced Settings] button on options page while already | 614 // 5) User clicks [Advanced Settings] button on options page while already |
| (...skipping 22 matching lines...) Expand all Loading... |
| 753 CloseUI(); | 637 CloseUI(); |
| 754 return; | 638 return; |
| 755 } | 639 } |
| 756 | 640 |
| 757 // User is already logged in. They must have brought up the config wizard | 641 // User is already logged in. They must have brought up the config wizard |
| 758 // via the "Advanced..." button or through One-Click signin (cases 4-6), or | 642 // via the "Advanced..." button or through One-Click signin (cases 4-6), or |
| 759 // they are re-enabling sync after having disabled it (case 7). | 643 // they are re-enabling sync after having disabled it (case 7). |
| 760 DisplayConfigureSync(false); | 644 DisplayConfigureSync(false); |
| 761 } | 645 } |
| 762 | 646 |
| 763 void SyncSetupHandler::OpenConfigureSync() { | 647 void SyncHandler::OpenConfigureSync() { |
| 764 if (!PrepareSyncSetup()) | 648 if (!PrepareSyncSetup()) |
| 765 return; | 649 return; |
| 766 | 650 |
| 767 DisplayConfigureSync(false); | 651 DisplayConfigureSync(false); |
| 768 } | 652 } |
| 769 | 653 |
| 770 void SyncSetupHandler::FocusUI() { | 654 void SyncHandler::FocusUI() { |
| 771 DCHECK(IsActiveLogin()); | 655 DCHECK(IsActiveLogin()); |
| 772 WebContents* web_contents = web_ui()->GetWebContents(); | 656 WebContents* web_contents = web_ui()->GetWebContents(); |
| 773 web_contents->GetDelegate()->ActivateContents(web_contents); | 657 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 774 } | 658 } |
| 775 | 659 |
| 776 void SyncSetupHandler::CloseUI() { | 660 void SyncHandler::CloseUI() { |
| 777 CloseSyncSetup(); | 661 CloseSyncSetup(); |
| 778 base::StringValue page("done"); | 662 base::StringValue page("done"); |
| 779 web_ui()->CallJavascriptFunction( | 663 web_ui()->CallJavascriptFunction( |
| 780 "SyncSetupOverlay.showSyncSetupPage", page); | 664 "SyncSetupOverlay.showSyncSetupPage", page); |
| 781 } | 665 } |
| 782 | 666 |
| 783 bool SyncSetupHandler::IsExistingWizardPresent() { | 667 bool SyncHandler::IsExistingWizardPresent() { |
| 784 LoginUIService* service = GetLoginUIService(); | 668 LoginUIService* service = GetLoginUIService(); |
| 785 DCHECK(service); | 669 DCHECK(service); |
| 786 return service->current_login_ui() != NULL; | 670 return service->current_login_ui() != NULL; |
| 787 } | 671 } |
| 788 | 672 |
| 789 bool SyncSetupHandler::FocusExistingWizardIfPresent() { | 673 bool SyncHandler::FocusExistingWizardIfPresent() { |
| 790 if (!IsExistingWizardPresent()) | 674 if (!IsExistingWizardPresent()) |
| 791 return false; | 675 return false; |
| 792 | 676 |
| 793 LoginUIService* service = GetLoginUIService(); | 677 LoginUIService* service = GetLoginUIService(); |
| 794 DCHECK(service); | 678 DCHECK(service); |
| 795 service->current_login_ui()->FocusUI(); | 679 service->current_login_ui()->FocusUI(); |
| 796 return true; | 680 return true; |
| 797 } | 681 } |
| 798 | 682 |
| 799 void SyncSetupHandler::DisplayConfigureSync(bool passphrase_failed) { | 683 void SyncHandler::DisplayConfigureSync(bool passphrase_failed) { |
| 800 // Should never call this when we are not signed in. | 684 // Should never call this when we are not signed in. |
| 801 DCHECK(SigninManagerFactory::GetForProfile( | 685 DCHECK(SigninManagerFactory::GetForProfile( |
| 802 GetProfile())->IsAuthenticated()); | 686 GetProfile())->IsAuthenticated()); |
| 803 ProfileSyncService* service = GetSyncService(); | 687 ProfileSyncService* service = GetSyncService(); |
| 804 DCHECK(service); | 688 DCHECK(service); |
| 805 if (!service->IsBackendInitialized()) { | 689 if (!service->IsBackendInitialized()) { |
| 806 service->RequestStart(); | 690 service->RequestStart(); |
| 807 | 691 |
| 808 // See if it's even possible to bring up the sync backend - if not | 692 // See if it's even possible to bring up the sync backend - if not |
| 809 // (unrecoverable error?), don't bother displaying a spinner that will be | 693 // (unrecoverable error?), don't bother displaying a spinner that will be |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 | 800 |
| 917 base::StringValue page("configure"); | 801 base::StringValue page("configure"); |
| 918 web_ui()->CallJavascriptFunction( | 802 web_ui()->CallJavascriptFunction( |
| 919 "SyncSetupOverlay.showSyncSetupPage", page, args); | 803 "SyncSetupOverlay.showSyncSetupPage", page, args); |
| 920 | 804 |
| 921 // Make sure the tab used for the Gaia sign in does not cover the settings | 805 // Make sure the tab used for the Gaia sign in does not cover the settings |
| 922 // tab. | 806 // tab. |
| 923 FocusUI(); | 807 FocusUI(); |
| 924 } | 808 } |
| 925 | 809 |
| 926 LoginUIService* SyncSetupHandler::GetLoginUIService() const { | 810 LoginUIService* SyncHandler::GetLoginUIService() const { |
| 927 return LoginUIServiceFactory::GetForProfile(GetProfile()); | 811 return LoginUIServiceFactory::GetForProfile(GetProfile()); |
| 928 } | 812 } |
| 813 |
| 814 } // namespace settings |
| OLD | NEW |