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

Unified Diff: chrome/browser/ui/webui/settings/sync_handler.cc

Issue 1421893005: Settings Rewrite: Fork SyncSetupHandler for MD-Settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/settings/sync_handler.cc
diff --git a/chrome/browser/ui/webui/options/sync_setup_handler.cc b/chrome/browser/ui/webui/settings/sync_handler.cc
similarity index 78%
copy from chrome/browser/ui/webui/options/sync_setup_handler.cc
copy to chrome/browser/ui/webui/settings/sync_handler.cc
index 5c9a617927970760b460e0667eca5a4675daed7a..702d64912cccac28c2c8971af92441a78f73db6c 100644
--- a/chrome/browser/ui/webui/options/sync_setup_handler.cc
+++ b/chrome/browser/ui/webui/settings/sync_handler.cc
@@ -1,8 +1,8 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/webui/options/sync_setup_handler.h"
+#include "chrome/browser/ui/webui/settings/sync_handler.h"
#include "base/basictypes.h"
#include "base/bind.h"
@@ -14,10 +14,7 @@
#include "base/json/json_writer.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
-#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
-#include "chrome/app/chrome_command_ids.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h"
@@ -35,11 +32,7 @@
#include "chrome/browser/ui/webui/signin/login_ui_service.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/url_constants.h"
-#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
-#include "chrome/grit/locale_settings.h"
-#include "components/google/core/browser/google_util.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/core/browser/signin_header_helper.h"
#include "components/signin/core/browser/signin_metrics.h"
@@ -50,7 +43,6 @@
#include "content/public/browser/web_contents_delegate.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_constants.h"
-#include "grit/components_strings.h"
#include "net/base/url_util.h"
#include "ui/base/l10n/l10n_util.h"
@@ -152,11 +144,12 @@ bool GetConfiguration(const std::string& json, SyncConfigInfo* config) {
} // namespace
-SyncSetupHandler::SyncSetupHandler()
- : configuring_sync_(false) {
+namespace settings {
+
+SyncHandler::SyncHandler() : configuring_sync_(false) {
}
-SyncSetupHandler::~SyncSetupHandler() {
+SyncHandler::~SyncHandler() {
// Just exit if running unit tests (no actual WebUI is attached).
if (!web_ui())
return;
@@ -165,115 +158,7 @@ SyncSetupHandler::~SyncSetupHandler() {
CloseSyncSetup();
}
-void SyncSetupHandler::GetLocalizedValues(
- base::DictionaryValue* localized_strings) {
- GetStaticLocalizedValues(localized_strings, web_ui());
-}
-
-void SyncSetupHandler::GetStaticLocalizedValues(
- base::DictionaryValue* localized_strings,
- content::WebUI* web_ui) {
- DCHECK(localized_strings);
-
- base::string16 product_name(GetStringUTF16(IDS_PRODUCT_NAME));
- localized_strings->SetString(
- "chooseDataTypesInstructions",
- GetStringFUTF16(IDS_SYNC_CHOOSE_DATATYPES_INSTRUCTIONS, product_name));
- localized_strings->SetString(
- "encryptionInstructions",
- GetStringFUTF16(IDS_SYNC_ENCRYPTION_INSTRUCTIONS, product_name));
- localized_strings->SetString(
- "encryptionHelpURL", chrome::kSyncEncryptionHelpURL);
- localized_strings->SetString(
- "encryptionSectionMessage",
- GetStringFUTF16(IDS_SYNC_ENCRYPTION_SECTION_MESSAGE, product_name));
- localized_strings->SetString(
- "passphraseRecover",
- GetStringFUTF16(
- IDS_SYNC_PASSPHRASE_RECOVER,
- base::ASCIIToUTF16(
- google_util::AppendGoogleLocaleParam(
- GURL(chrome::kSyncGoogleDashboardURL),
- g_browser_process->GetApplicationLocale()).spec())));
- localized_strings->SetString(
- "stopSyncingExplanation",
- l10n_util::GetStringFUTF16(
- IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL,
- l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
- base::ASCIIToUTF16(
- google_util::AppendGoogleLocaleParam(
- GURL(chrome::kSyncGoogleDashboardURL),
- g_browser_process->GetApplicationLocale()).spec())));
- localized_strings->SetString("deleteProfileLabel",
- l10n_util::GetStringUTF16(IDS_SYNC_STOP_DELETE_PROFILE_LABEL));
- localized_strings->SetString("stopSyncingTitle",
- l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_DIALOG_TITLE));
- localized_strings->SetString("stopSyncingConfirm",
- l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL));
-
- localized_strings->SetString(
- "syncEverythingHelpURL", chrome::kSyncEverythingLearnMoreURL);
- localized_strings->SetString(
- "syncErrorHelpURL", chrome::kSyncErrorsHelpURL);
-
- static OptionsStringResource resources[] = {
- { "syncSetupConfigureTitle", IDS_SYNC_SETUP_CONFIGURE_TITLE },
- { "syncSetupSpinnerTitle", IDS_SYNC_SETUP_SPINNER_TITLE },
- { "syncSetupTimeoutTitle", IDS_SYNC_SETUP_TIME_OUT_TITLE },
- { "syncSetupTimeoutContent", IDS_SYNC_SETUP_TIME_OUT_CONTENT },
- { "errorLearnMore", IDS_LEARN_MORE },
- { "cancel", IDS_CANCEL },
- { "loginSuccess", IDS_SYNC_SUCCESS },
- { "settingUp", IDS_SYNC_LOGIN_SETTING_UP },
- { "syncAllDataTypes", IDS_SYNC_EVERYTHING },
- { "chooseDataTypes", IDS_SYNC_CHOOSE_DATATYPES },
- { "syncNothing", IDS_SYNC_NOTHING },
- { "bookmarks", IDS_SYNC_DATATYPE_BOOKMARKS },
- { "preferences", IDS_SYNC_DATATYPE_PREFERENCES },
- { "autofill", IDS_SYNC_DATATYPE_AUTOFILL },
- { "themes", IDS_SYNC_DATATYPE_THEMES },
- { "passwords", IDS_SYNC_DATATYPE_PASSWORDS },
- { "extensions", IDS_SYNC_DATATYPE_EXTENSIONS },
- { "typedURLs", IDS_SYNC_DATATYPE_TYPED_URLS },
- { "apps", IDS_SYNC_DATATYPE_APPS },
- { "wifiCredentials", IDS_SYNC_DATATYPE_WIFI_CREDENTIALS },
- { "openTabs", IDS_SYNC_DATATYPE_TABS },
- { "serviceUnavailableError", IDS_SYNC_SETUP_ABORTED_BY_PENDING_CLEAR },
- { "confirmLabel", IDS_SYNC_CONFIRM_PASSPHRASE_LABEL },
- { "emptyErrorMessage", IDS_SYNC_EMPTY_PASSPHRASE_ERROR },
- { "mismatchErrorMessage", IDS_SYNC_PASSPHRASE_MISMATCH_ERROR },
- { "customizeLinkLabel", IDS_SYNC_CUSTOMIZE_LINK_LABEL },
- { "confirmSyncPreferences", IDS_SYNC_CONFIRM_SYNC_PREFERENCES },
- { "syncEverything", IDS_SYNC_SYNC_EVERYTHING },
- { "useDefaultSettings", IDS_SYNC_USE_DEFAULT_SETTINGS },
- { "enterPassphraseBody", IDS_SYNC_ENTER_PASSPHRASE_BODY },
- { "enterGooglePassphraseBody", IDS_SYNC_ENTER_GOOGLE_PASSPHRASE_BODY },
- { "passphraseLabel", IDS_SYNC_PASSPHRASE_LABEL },
- { "incorrectPassphrase", IDS_SYNC_INCORRECT_PASSPHRASE },
- { "passphraseWarning", IDS_SYNC_PASSPHRASE_WARNING },
- { "yes", IDS_SYNC_PASSPHRASE_CANCEL_YES },
- { "no", IDS_SYNC_PASSPHRASE_CANCEL_NO },
- { "sectionExplicitMessagePrefix", IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_PREFIX },
- { "sectionExplicitMessagePostfix",
- IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_POSTFIX },
- // TODO(rogerta): browser/resource/sync_promo/sync_promo.html and related
- // file may not be needed any more. If not, then the following promo
- // strings can also be removed.
- { "promoPageTitle", IDS_SYNC_PROMO_TAB_TITLE },
- { "promoSkipButton", IDS_SYNC_PROMO_SKIP_BUTTON },
- { "promoAdvanced", IDS_SYNC_PROMO_ADVANCED },
- { "promoLearnMore", IDS_LEARN_MORE },
- { "promoTitleShort", IDS_SYNC_PROMO_MESSAGE_TITLE_SHORT },
- { "encryptionSectionTitle", IDS_SYNC_ENCRYPTION_SECTION_TITLE },
- { "basicEncryptionOption", IDS_SYNC_BASIC_ENCRYPTION_DATA },
- { "fullEncryptionOption", IDS_SYNC_FULL_ENCRYPTION_DATA },
- };
-
- RegisterStrings(localized_strings, resources, arraysize(resources));
- RegisterTitle(localized_strings, "syncSetupOverlay", IDS_SYNC_SETUP_TITLE);
-}
-
-void SyncSetupHandler::ConfigureSyncDone() {
+void SyncHandler::ConfigureSyncDone() {
base::StringValue page("done");
web_ui()->CallJavascriptFunction(
"SyncSetupOverlay.showSyncSetupPage", page);
@@ -296,46 +181,46 @@ void SyncSetupHandler::ConfigureSyncDone() {
}
}
-bool SyncSetupHandler::IsActiveLogin() const {
+bool SyncHandler::IsActiveLogin() const {
// LoginUIService can be NULL if page is brought up in incognito mode
// (i.e. if the user is running in guest mode in cros and brings up settings).
LoginUIService* service = GetLoginUIService();
return service && (service->current_login_ui() == this);
}
-void SyncSetupHandler::RegisterMessages() {
+void SyncHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"SyncSetupDidClosePage",
- base::Bind(&SyncSetupHandler::OnDidClosePage,
+ base::Bind(&SyncHandler::OnDidClosePage,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"SyncSetupConfigure",
- base::Bind(&SyncSetupHandler::HandleConfigure,
+ base::Bind(&SyncHandler::HandleConfigure,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"SyncSetupShowSetupUI",
- base::Bind(&SyncSetupHandler::HandleShowSetupUI,
+ base::Bind(&SyncHandler::HandleShowSetupUI,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("CloseTimeout",
- base::Bind(&SyncSetupHandler::HandleCloseTimeout,
+ base::Bind(&SyncHandler::HandleCloseTimeout,
base::Unretained(this)));
#if defined(OS_CHROMEOS)
web_ui()->RegisterMessageCallback(
"SyncSetupDoSignOutOnAuthError",
- base::Bind(&SyncSetupHandler::HandleDoSignOutOnAuthError,
+ base::Bind(&SyncHandler::HandleDoSignOutOnAuthError,
base::Unretained(this)));
#else
web_ui()->RegisterMessageCallback("SyncSetupStopSyncing",
- base::Bind(&SyncSetupHandler::HandleStopSyncing,
+ base::Bind(&SyncHandler::HandleStopSyncing,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("SyncSetupStartSignIn",
- base::Bind(&SyncSetupHandler::HandleStartSignin,
+ base::Bind(&SyncHandler::HandleStartSignin,
base::Unretained(this)));
#endif
}
#if !defined(OS_CHROMEOS)
-void SyncSetupHandler::DisplayGaiaLogin() {
+void SyncHandler::DisplayGaiaLogin() {
DCHECK(!sync_startup_tracker_);
// Advanced options are no longer being configured if the login screen is
// visible. If the user exits the signin wizard after this without
@@ -344,7 +229,7 @@ void SyncSetupHandler::DisplayGaiaLogin() {
DisplayGaiaLoginInNewTabOrWindow();
}
-void SyncSetupHandler::DisplayGaiaLoginInNewTabOrWindow() {
+void SyncHandler::DisplayGaiaLoginInNewTabOrWindow() {
Browser* browser = chrome::FindBrowserWithWebContents(
web_ui()->GetWebContents());
bool force_new_tab = false;
@@ -392,7 +277,7 @@ void SyncSetupHandler::DisplayGaiaLoginInNewTabOrWindow() {
}
#endif
-bool SyncSetupHandler::PrepareSyncSetup() {
+bool SyncHandler::PrepareSyncSetup() {
// If the wizard is already visible, just focus that one.
if (FocusExistingWizardIfPresent()) {
if (!IsActiveLogin())
@@ -410,7 +295,7 @@ bool SyncSetupHandler::PrepareSyncSetup() {
return true;
}
-void SyncSetupHandler::DisplaySpinner() {
+void SyncHandler::DisplaySpinner() {
configuring_sync_ = true;
base::StringValue page("spinner");
base::DictionaryValue args;
@@ -420,7 +305,7 @@ void SyncSetupHandler::DisplaySpinner() {
backend_start_timer_.reset(new base::OneShotTimer());
backend_start_timer_->Start(FROM_HERE,
base::TimeDelta::FromSeconds(kTimeoutSec),
- this, &SyncSetupHandler::DisplayTimeout);
+ this, &SyncHandler::DisplayTimeout);
web_ui()->CallJavascriptFunction(
"SyncSetupOverlay.showSyncSetupPage", page, args);
@@ -428,7 +313,7 @@ void SyncSetupHandler::DisplaySpinner() {
// TODO(kochi): Handle error conditions other than timeout.
// http://crbug.com/128692
-void SyncSetupHandler::DisplayTimeout() {
+void SyncHandler::DisplayTimeout() {
// Stop a timer to handle timeout in waiting for checking network connection.
backend_start_timer_.reset();
@@ -441,11 +326,11 @@ void SyncSetupHandler::DisplayTimeout() {
"SyncSetupOverlay.showSyncSetupPage", page, args);
}
-void SyncSetupHandler::OnDidClosePage(const base::ListValue* args) {
+void SyncHandler::OnDidClosePage(const base::ListValue* args) {
CloseSyncSetup();
}
-void SyncSetupHandler::SyncStartupFailed() {
+void SyncHandler::SyncStartupFailed() {
// Stop a timer to handle timeout in waiting for checking network connection.
backend_start_timer_.reset();
@@ -454,7 +339,7 @@ void SyncSetupHandler::SyncStartupFailed() {
CloseUI();
}
-void SyncSetupHandler::SyncStartupCompleted() {
+void SyncHandler::SyncStartupCompleted() {
ProfileSyncService* service = GetSyncService();
DCHECK(service->IsBackendInitialized());
@@ -464,17 +349,16 @@ void SyncSetupHandler::SyncStartupCompleted() {
DisplayConfigureSync(false);
}
-Profile* SyncSetupHandler::GetProfile() const {
+Profile* SyncHandler::GetProfile() const {
return Profile::FromWebUI(web_ui());
}
-ProfileSyncService* SyncSetupHandler::GetSyncService() const {
- Profile* profile = GetProfile();
- return profile->IsSyncAllowed() ?
+ProfileSyncService* SyncHandler::GetSyncService() const {
+ return GetProfile()->IsSyncAllowed() ?
ProfileSyncServiceFactory::GetForProfile(GetProfile()) : NULL;
}
-void SyncSetupHandler::HandleConfigure(const base::ListValue* args) {
+void SyncHandler::HandleConfigure(const base::ListValue* args) {
DCHECK(!sync_startup_tracker_);
std::string json;
if (!args->GetString(0, &json)) {
@@ -597,7 +481,7 @@ void SyncSetupHandler::HandleConfigure(const base::ListValue* args) {
ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE);
}
-void SyncSetupHandler::HandleShowSetupUI(const base::ListValue* args) {
+void SyncHandler::HandleShowSetupUI(const base::ListValue* args) {
if (!GetSyncService()) {
DLOG(WARNING) << "Cannot display sync UI when sync is disabled";
CloseUI();
@@ -634,21 +518,21 @@ void SyncSetupHandler::HandleShowSetupUI(const base::ListValue* args) {
#if defined(OS_CHROMEOS)
// On ChromeOS, we need to sign out the user session to fix an auth error, so
// the user goes through the real signin flow to generate a new auth token.
-void SyncSetupHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) {
+void SyncHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) {
DVLOG(1) << "Signing out the user to fix a sync error.";
chrome::AttemptUserExit();
}
#endif
#if !defined(OS_CHROMEOS)
-void SyncSetupHandler::HandleStartSignin(const base::ListValue* args) {
+void SyncHandler::HandleStartSignin(const base::ListValue* args) {
// Should only be called if the user is not already signed in.
DCHECK(!SigninManagerFactory::GetForProfile(GetProfile())->
IsAuthenticated());
OpenSyncSetup();
}
-void SyncSetupHandler::HandleStopSyncing(const base::ListValue* args) {
+void SyncHandler::HandleStopSyncing(const base::ListValue* args) {
if (GetSyncService())
ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS);
SigninManagerFactory::GetForProfile(GetProfile())->SignOut(
@@ -662,11 +546,11 @@ void SyncSetupHandler::HandleStopSyncing(const base::ListValue* args) {
}
#endif
-void SyncSetupHandler::HandleCloseTimeout(const base::ListValue* args) {
+void SyncHandler::HandleCloseTimeout(const base::ListValue* args) {
CloseSyncSetup();
}
-void SyncSetupHandler::CloseSyncSetup() {
+void SyncHandler::CloseSyncSetup() {
// Stop a timer to handle timeout in waiting for checking network connection.
backend_start_timer_.reset();
@@ -717,7 +601,7 @@ void SyncSetupHandler::CloseSyncSetup() {
configuring_sync_ = false;
}
-void SyncSetupHandler::OpenSyncSetup() {
+void SyncHandler::OpenSyncSetup() {
if (!PrepareSyncSetup())
return;
@@ -760,33 +644,33 @@ void SyncSetupHandler::OpenSyncSetup() {
DisplayConfigureSync(false);
}
-void SyncSetupHandler::OpenConfigureSync() {
+void SyncHandler::OpenConfigureSync() {
if (!PrepareSyncSetup())
return;
DisplayConfigureSync(false);
}
-void SyncSetupHandler::FocusUI() {
+void SyncHandler::FocusUI() {
DCHECK(IsActiveLogin());
WebContents* web_contents = web_ui()->GetWebContents();
web_contents->GetDelegate()->ActivateContents(web_contents);
}
-void SyncSetupHandler::CloseUI() {
+void SyncHandler::CloseUI() {
CloseSyncSetup();
base::StringValue page("done");
web_ui()->CallJavascriptFunction(
"SyncSetupOverlay.showSyncSetupPage", page);
}
-bool SyncSetupHandler::IsExistingWizardPresent() {
+bool SyncHandler::IsExistingWizardPresent() {
LoginUIService* service = GetLoginUIService();
DCHECK(service);
return service->current_login_ui() != NULL;
}
-bool SyncSetupHandler::FocusExistingWizardIfPresent() {
+bool SyncHandler::FocusExistingWizardIfPresent() {
if (!IsExistingWizardPresent())
return false;
@@ -796,7 +680,7 @@ bool SyncSetupHandler::FocusExistingWizardIfPresent() {
return true;
}
-void SyncSetupHandler::DisplayConfigureSync(bool passphrase_failed) {
+void SyncHandler::DisplayConfigureSync(bool passphrase_failed) {
// Should never call this when we are not signed in.
DCHECK(SigninManagerFactory::GetForProfile(
GetProfile())->IsAuthenticated());
@@ -923,6 +807,8 @@ void SyncSetupHandler::DisplayConfigureSync(bool passphrase_failed) {
FocusUI();
}
-LoginUIService* SyncSetupHandler::GetLoginUIService() const {
+LoginUIService* SyncHandler::GetLoginUIService() const {
return LoginUIServiceFactory::GetForProfile(GetProfile());
}
+
+} // namespace settings
« no previous file with comments | « chrome/browser/ui/webui/settings/sync_handler.h ('k') | chrome/browser/ui/webui/settings/sync_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698