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

Side by Side Diff: chrome/browser/ui/webui/options/reset_profile_settings_handler.cc

Issue 14924002: WebUI for Profile Settings Reset (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser test 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/options/reset_profile_settings_handler.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/prefs/pref_service.h"
10 #include "base/string16.h"
11 #include "base/values.h"
12 #include "chrome/browser/google/google_util.h"
13 #include "chrome/browser/profile_resetter/profile_resetter.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/web_ui.h"
17 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util.h"
19
20 namespace {
21 const char kResetProfileSettingsLearnMoreUrl[] =
22 "https://support.google.com/chrome/?p=settings_reset_profile_settings";
23 }
24
25 namespace options {
26
27 ResetProfileSettingsHandler::ResetProfileSettingsHandler()
28 : resetter_(NULL) {
29 }
30
31 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {
32 }
33
34 void ResetProfileSettingsHandler::InitializeHandler() {
35 Profile* profile = Profile::FromWebUI(web_ui());
36 resetter_.reset(new ProfileResetter(profile));
37 }
38
39 void ResetProfileSettingsHandler::GetLocalizedValues(
40 DictionaryValue* localized_strings) {
41 DCHECK(localized_strings);
42
43 static OptionsStringResource resources[] = {
44 { "resetProfileSettingsLabel", IDS_RESET_PROFILE_SETTINGS_LABEL },
45 { "resetDefaultSearchEngineCheckbox",
46 IDS_RESET_PROFILE_DEFAULT_SEARCH_ENGINE_CHECKBOX },
47 { "resetHomepageCheckbox", IDS_RESET_PROFILE_HOMEPAGE_CHECKBOX },
48 { "resetContentSettingsCheckbox",
49 IDS_RESET_PROFILE_CONTENT_SETTINGS_CHECKBOX },
50 { "resetCookiesAndSiteDataCheckbox", IDS_RESET_PROFILE_COOKIES_CHECKBOX },
51 { "resetExtensionsCheckbox", IDS_RESET_PROFILE_EXTENSIONS_CHECKBOX },
52 { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON },
53 };
54
55 RegisterStrings(localized_strings, resources, arraysize(resources));
56 RegisterTitle(localized_strings, "resetProfileSettingsOverlay",
57 IDS_RESET_PROFILE_SETTINGS_TITLE);
58 localized_strings->SetString(
59 "resetProfileSettingsLearnMoreUrl",
60 google_util::StringAppendGoogleLocaleParam(
61 kResetProfileSettingsLearnMoreUrl));
62
63 ListValue* reset_extensions_handling = new ListValue;
64 for (int i = 0; i < 2; i++) {
65 string16 label_string;
66 switch (i) {
67 case 0:
68 label_string = l10n_util::GetStringUTF16(
69 IDS_RESET_PROFILE_EXTENSIONS_DISABLE);
70 break;
71 case 1:
72 label_string = l10n_util::GetStringUTF16(
73 IDS_RESET_PROFILE_EXTENSIONS_UNINSTALL);
74 break;
75 }
76 ListValue* option = new ListValue();
77 option->Append(new base::FundamentalValue(i));
78 option->Append(new base::StringValue(label_string));
79 reset_extensions_handling->Append(option);
80 }
81 localized_strings->Set("resetExtensionsHandling", reset_extensions_handling);
82 }
83
84 void ResetProfileSettingsHandler::RegisterMessages() {
85 // Setup handlers specific to this panel.
86 web_ui()->RegisterMessageCallback("performResetProfileSettings",
87 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings,
88 base::Unretained(this)));
89 }
90
91 void ResetProfileSettingsHandler::HandleResetProfileSettings(
92 const ListValue* /*value*/) {
93 CHECK(resetter_);
94 CHECK(!resetter_->IsActive());
95
96 Profile* profile = Profile::FromWebUI(web_ui());
97 PrefService* prefs = profile->GetPrefs();
98
99 ProfileResetter::ResettableFlags reset_mask = 0;
100
101 if (prefs->GetBoolean(prefs::kResetDefaultSearchEngine))
102 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.
103 if (prefs->GetBoolean(prefs::kResetHomepage))
104 reset_mask |= ProfileResetter::HOMEPAGE;
105 if (prefs->GetBoolean(prefs::kResetContentSettings))
106 reset_mask |= ProfileResetter::CONTENT_SETTINGS;
107 if (prefs->GetBoolean(prefs::kResetCookiesAndSiteData))
108 reset_mask |= ProfileResetter::COOKIES_AND_SITE_DATA;
109 if (prefs->GetBoolean(prefs::kResetExtensions))
110 reset_mask |= ProfileResetter::EXTENSIONS;
111
112 ProfileResetter::ExtensionHandling extension_handling =
113 (prefs->GetInteger(prefs::kResetExtensionsHandling) == 0)
114 ? ProfileResetter::DISABLE_EXTENSIONS
115 : ProfileResetter::UNINSTALL_EXTENSIONS;
116
117 resetter_->Reset(
118 reset_mask,
119 extension_handling,
120 base::Bind(&ResetProfileSettingsHandler::OnResetProfileSettingsDone,
121 AsWeakPtr()));
122 }
123
124 void ResetProfileSettingsHandler::OnResetProfileSettingsDone() {
125 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting");
126 }
127
128 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698