Chromium Code Reviews| Index: chrome/browser/ui/webui/options/reset_profile_settings_handler.cc |
| diff --git a/chrome/browser/ui/webui/options/reset_profile_settings_handler.cc b/chrome/browser/ui/webui/options/reset_profile_settings_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..94209cb276d93f146154654aef092a0f8a6fdd8a |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/options/reset_profile_settings_handler.cc |
| @@ -0,0 +1,128 @@ |
| +// Copyright (c) 2012 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/reset_profile_settings_handler.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "base/string16.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/google/google_util.h" |
| +#include "chrome/browser/profile_resetter/profile_resetter.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "content/public/browser/web_ui.h" |
| +#include "grit/generated_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +namespace { |
| +const char kResetProfileSettingsLearnMoreUrl[] = |
| + "https://support.google.com/chrome/?p=settings_reset_profile_settings"; |
| +} |
| + |
| +namespace options { |
| + |
| +ResetProfileSettingsHandler::ResetProfileSettingsHandler() |
| + : resetter_(NULL) { |
| +} |
| + |
| +ResetProfileSettingsHandler::~ResetProfileSettingsHandler() { |
| +} |
| + |
| +void ResetProfileSettingsHandler::InitializeHandler() { |
| + Profile* profile = Profile::FromWebUI(web_ui()); |
| + resetter_.reset(new ProfileResetter(profile)); |
| +} |
| + |
| +void ResetProfileSettingsHandler::GetLocalizedValues( |
| + DictionaryValue* localized_strings) { |
| + DCHECK(localized_strings); |
| + |
| + static OptionsStringResource resources[] = { |
| + { "resetProfileSettingsLabel", IDS_RESET_PROFILE_SETTINGS_LABEL }, |
| + { "resetDefaultSearchEngineCheckbox", |
| + IDS_RESET_PROFILE_DEFAULT_SEARCH_ENGINE_CHECKBOX }, |
| + { "resetHomepageCheckbox", IDS_RESET_PROFILE_HOMEPAGE_CHECKBOX }, |
| + { "resetContentSettingsCheckbox", |
| + IDS_RESET_PROFILE_CONTENT_SETTINGS_CHECKBOX }, |
| + { "resetCookiesAndSiteDataCheckbox", IDS_RESET_PROFILE_COOKIES_CHECKBOX }, |
| + { "resetExtensionsCheckbox", IDS_RESET_PROFILE_EXTENSIONS_CHECKBOX }, |
| + { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON }, |
| + }; |
| + |
| + RegisterStrings(localized_strings, resources, arraysize(resources)); |
| + RegisterTitle(localized_strings, "resetProfileSettingsOverlay", |
| + IDS_RESET_PROFILE_SETTINGS_TITLE); |
| + localized_strings->SetString( |
| + "resetProfileSettingsLearnMoreUrl", |
| + google_util::StringAppendGoogleLocaleParam( |
| + kResetProfileSettingsLearnMoreUrl)); |
| + |
| + ListValue* reset_extensions_handling = new ListValue; |
| + for (int i = 0; i < 2; i++) { |
| + string16 label_string; |
| + switch (i) { |
| + case 0: |
| + label_string = l10n_util::GetStringUTF16( |
| + IDS_RESET_PROFILE_EXTENSIONS_DISABLE); |
| + break; |
| + case 1: |
| + label_string = l10n_util::GetStringUTF16( |
| + IDS_RESET_PROFILE_EXTENSIONS_UNINSTALL); |
| + break; |
| + } |
| + ListValue* option = new ListValue(); |
| + option->Append(new base::FundamentalValue(i)); |
| + option->Append(new base::StringValue(label_string)); |
| + reset_extensions_handling->Append(option); |
| + } |
| + localized_strings->Set("resetExtensionsHandling", reset_extensions_handling); |
| +} |
| + |
| +void ResetProfileSettingsHandler::RegisterMessages() { |
| + // Setup handlers specific to this panel. |
| + web_ui()->RegisterMessageCallback("performResetProfileSettings", |
| + base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, |
| + base::Unretained(this))); |
| +} |
| + |
| +void ResetProfileSettingsHandler::HandleResetProfileSettings( |
| + const ListValue* /*value*/) { |
| + CHECK(resetter_); |
| + CHECK(!resetter_->IsActive()); |
| + |
| + Profile* profile = Profile::FromWebUI(web_ui()); |
| + PrefService* prefs = profile->GetPrefs(); |
| + |
| + ProfileResetter::ResettableFlags reset_mask = 0; |
| + |
| + if (prefs->GetBoolean(prefs::kResetDefaultSearchEngine)) |
| + reset_mask |= ProfileResetter::DEFAULT_SEARCH_ENGINE; |
|
vasilii
2013/05/13 09:13:06
What about this?
struct {
const char* flag_name
battre
2013/05/13 15:54:06
Done.
|
| + if (prefs->GetBoolean(prefs::kResetHomepage)) |
| + reset_mask |= ProfileResetter::HOMEPAGE; |
| + if (prefs->GetBoolean(prefs::kResetContentSettings)) |
| + reset_mask |= ProfileResetter::CONTENT_SETTINGS; |
| + if (prefs->GetBoolean(prefs::kResetCookiesAndSiteData)) |
| + reset_mask |= ProfileResetter::COOKIES_AND_SITE_DATA; |
| + if (prefs->GetBoolean(prefs::kResetExtensions)) |
| + reset_mask |= ProfileResetter::EXTENSIONS; |
| + |
| + ProfileResetter::ExtensionHandling extension_handling = |
| + (prefs->GetInteger(prefs::kResetExtensionsHandling) == 0) |
| + ? ProfileResetter::DISABLE_EXTENSIONS |
| + : ProfileResetter::UNINSTALL_EXTENSIONS; |
| + |
| + resetter_->Reset( |
| + reset_mask, |
| + extension_handling, |
| + base::Bind(&ResetProfileSettingsHandler::OnResetProfileSettingsDone, |
| + AsWeakPtr())); |
| +} |
| + |
| +void ResetProfileSettingsHandler::OnResetProfileSettingsDone() { |
| + web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting"); |
| +} |
| + |
| +} // namespace options |