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

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: Addressed comments 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 2013 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 } // namespace
24
25 namespace options {
26
27 ResetProfileSettingsHandler::ResetProfileSettingsHandler() {
28 }
29
30 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {
31 }
32
33 void ResetProfileSettingsHandler::InitializeHandler() {
34 Profile* profile = Profile::FromWebUI(web_ui());
35 resetter_.reset(new ProfileResetter(profile));
36 }
37
38 void ResetProfileSettingsHandler::GetLocalizedValues(
39 DictionaryValue* localized_strings) {
40 DCHECK(localized_strings);
41
42 static OptionsStringResource resources[] = {
43 { "resetProfileSettingsLabel", IDS_RESET_PROFILE_SETTINGS_LABEL },
44 { "resetDefaultSearchEngineCheckbox",
45 IDS_RESET_PROFILE_DEFAULT_SEARCH_ENGINE_CHECKBOX },
46 { "resetHomepageCheckbox", IDS_RESET_PROFILE_HOMEPAGE_CHECKBOX },
47 { "resetContentSettingsCheckbox",
48 IDS_RESET_PROFILE_CONTENT_SETTINGS_CHECKBOX },
49 { "resetCookiesAndSiteDataCheckbox", IDS_RESET_PROFILE_COOKIES_CHECKBOX },
50 { "resetExtensionsCheckbox", IDS_RESET_PROFILE_EXTENSIONS_CHECKBOX },
51 { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON },
52 };
53
54 RegisterStrings(localized_strings, resources, arraysize(resources));
55 RegisterTitle(localized_strings, "resetProfileSettingsOverlay",
56 IDS_RESET_PROFILE_SETTINGS_TITLE);
57 localized_strings->SetString(
58 "resetProfileSettingsLearnMoreUrl",
59 google_util::StringAppendGoogleLocaleParam(
60 kResetProfileSettingsLearnMoreUrl));
61
62 scoped_ptr<ListValue> reset_extensions_handling(new ListValue);
63 for (int i = 0; i < 2; i++) {
64 string16 label_string;
65 switch (i) {
66 case 0:
67 label_string = l10n_util::GetStringUTF16(
68 IDS_RESET_PROFILE_EXTENSIONS_DISABLE);
69 break;
70 case 1:
71 label_string = l10n_util::GetStringUTF16(
72 IDS_RESET_PROFILE_EXTENSIONS_UNINSTALL);
73 break;
74 }
75 scoped_ptr<ListValue> option(new ListValue);
76 option->Append(new base::FundamentalValue(i));
77 option->Append(new base::StringValue(label_string));
78 reset_extensions_handling->Append(option.release());
79 }
80 localized_strings->Set("resetExtensionsHandling",
81 reset_extensions_handling.release());
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 DCHECK(resetter_);
94 DCHECK(!resetter_->IsActive());
95
96 Profile* profile = Profile::FromWebUI(web_ui());
97 PrefService* prefs = profile->GetPrefs();
98
99 ProfileResetter::ResettableFlags reset_mask = 0;
100
101 struct {
102 const char* flag_name;
103 ProfileResetter::Resettable mask;
104 } name_to_flag[] = {
105 { prefs::kResetDefaultSearchEngine,
106 ProfileResetter::DEFAULT_SEARCH_ENGINE },
107 { prefs::kResetHomepage, ProfileResetter::HOMEPAGE },
108 { prefs::kResetContentSettings, ProfileResetter::CONTENT_SETTINGS },
109 { prefs::kResetCookiesAndSiteData, ProfileResetter::COOKIES_AND_SITE_DATA },
110 { prefs::kResetExtensions, ProfileResetter::EXTENSIONS },
111 };
112 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(name_to_flag); ++i) {
113 if (prefs->GetBoolean(name_to_flag[i].flag_name))
114 reset_mask |= name_to_flag[i].mask;
115 }
116
117 ProfileResetter::ExtensionHandling extension_handling =
118 (prefs->GetInteger(prefs::kResetExtensionsHandling) == 0)
119 ? ProfileResetter::DISABLE_EXTENSIONS
120 : ProfileResetter::UNINSTALL_EXTENSIONS;
121
122 resetter_->Reset(
123 reset_mask,
124 extension_handling,
125 base::Bind(&ResetProfileSettingsHandler::OnResetProfileSettingsDone,
126 AsWeakPtr()));
127 }
128
129 void ResetProfileSettingsHandler::OnResetProfileSettingsDone() {
130 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting");
131 }
132
133 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/reset_profile_settings_handler.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698