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

Side by Side Diff: chrome/browser/ui/webui/settings/reset_settings_handler.cc

Issue 1418803004: MD Settings: Migrating C++ handlers for profile reset page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: renaming handler to to fix GN build Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/reset_profile_settings_handler.h" 5 #include "chrome/browser/ui/webui/settings/reset_settings_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/google/google_brand.h" 13 #include "chrome/browser/google/google_brand.h"
14 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h" 14 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h"
15 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h" 15 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
16 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" 16 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h"
17 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" 17 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
18 #include "chrome/browser/profile_resetter/profile_resetter.h" 18 #include "chrome/browser/profile_resetter/profile_resetter.h"
19 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" 19 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
22 #include "chrome/grit/chromium_strings.h" 22 #include "chrome/grit/chromium_strings.h"
23 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
24 #include "content/public/browser/user_metrics.h" 24 #include "content/public/browser/user_metrics.h"
25 #include "content/public/browser/web_ui.h" 25 #include "content/public/browser/web_ui.h"
26 #include "ui/base/l10n/l10n_util.h"
27 26
28 #if defined(OS_WIN) 27 #if defined(OS_WIN)
29 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" 28 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h"
30 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" 29 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h"
31 #endif // defined(OS_WIN) 30 #endif // defined(OS_WIN)
32 31
33 namespace options { 32 namespace settings {
34 33
35 ResetProfileSettingsHandler::ResetProfileSettingsHandler() 34 ResetSettingsHandler::ResetSettingsHandler(content::WebUI* web_ui)
36 : automatic_profile_resetter_(NULL), 35 : automatic_profile_resetter_(NULL),
37 has_shown_confirmation_dialog_(false) { 36 has_shown_confirmation_dialog_(false) {
38 google_brand::GetBrand(&brandcode_); 37 google_brand::GetBrand(&brandcode_);
39 } 38 Profile* profile = Profile::FromWebUI(web_ui);
40
41 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {}
42
43 void ResetProfileSettingsHandler::InitializeHandler() {
44 Profile* profile = Profile::FromWebUI(web_ui());
45 resetter_.reset(new ProfileResetter(profile)); 39 resetter_.reset(new ProfileResetter(profile));
46 automatic_profile_resetter_ = 40 automatic_profile_resetter_ =
47 AutomaticProfileResetterFactory::GetForBrowserContext(profile); 41 AutomaticProfileResetterFactory::GetForBrowserContext(profile);
48 } 42 }
49 43
50 void ResetProfileSettingsHandler::InitializePage() { 44 ResetSettingsHandler::~ResetSettingsHandler() {
51 web_ui()->CallJavascriptFunction(
52 "ResetProfileSettingsOverlay.setResettingState",
53 base::FundamentalValue(resetter_->IsActive()));
54 if (automatic_profile_resetter_ &&
55 automatic_profile_resetter_->ShouldShowResetBanner()) {
56 web_ui()->CallJavascriptFunction("ResetProfileSettingsBanner.show");
57 }
58 }
59
60 void ResetProfileSettingsHandler::Uninitialize() {
61 if (has_shown_confirmation_dialog_ && automatic_profile_resetter_) { 45 if (has_shown_confirmation_dialog_ && automatic_profile_resetter_) {
62 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( 46 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog(
63 false /*performed_reset*/); 47 false /*performed_reset*/);
64 } 48 }
65 } 49 }
66 50
67 void ResetProfileSettingsHandler::GetLocalizedValues( 51 void ResetSettingsHandler::RegisterMessages() {
68 base::DictionaryValue* localized_strings) {
69 DCHECK(localized_strings);
70
71 static OptionsStringResource resources[] = {
72 { "resetProfileSettingsBannerText",
73 IDS_RESET_PROFILE_SETTINGS_BANNER_TEXT },
74 { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON },
75 { "resetProfileSettingsExplanation",
76 IDS_RESET_PROFILE_SETTINGS_EXPLANATION },
77 { "resetProfileSettingsFeedback", IDS_RESET_PROFILE_SETTINGS_FEEDBACK }
78 };
79
80 RegisterStrings(localized_strings, resources, arraysize(resources));
81 RegisterTitle(localized_strings, "resetProfileSettingsOverlay",
82 IDS_RESET_PROFILE_SETTINGS_TITLE);
83 localized_strings->SetString(
84 "resetProfileSettingsLearnMoreUrl",
85 chrome::kResetProfileSettingsLearnMoreURL);
86
87 // Set up the localized strings for the triggered profile reset overlay.
88 // The reset tool name can currently only have a custom value on Windows.
89 base::string16 reset_tool_name;
90 #if defined(OS_WIN)
91 Profile* profile = Profile::FromWebUI(web_ui());
92 TriggeredProfileResetter* triggered_profile_resetter =
93 TriggeredProfileResetterFactory::GetForBrowserContext(profile);
94 // TriggeredProfileResetter instance will be nullptr for incognito profiles.
95 if (triggered_profile_resetter)
96 reset_tool_name = triggered_profile_resetter->GetResetToolName();
97 #endif
98
99 if (reset_tool_name.empty()) {
100 reset_tool_name = l10n_util::GetStringUTF16(
101 IDS_TRIGGERED_RESET_PROFILE_SETTINGS_DEFAULT_TOOL_NAME);
102 }
103 localized_strings->SetString(
104 "triggeredResetProfileSettingsOverlay",
105 l10n_util::GetStringFUTF16(IDS_TRIGGERED_RESET_PROFILE_SETTINGS_TITLE,
106 reset_tool_name));
107 // Set the title manually since RegisterTitle() wants an id.
108 base::string16 title_string(l10n_util::GetStringFUTF16(
109 IDS_TRIGGERED_RESET_PROFILE_SETTINGS_TITLE, reset_tool_name));
110 localized_strings->SetString("triggeredResetProfileSettingsOverlay",
111 title_string);
112 localized_strings->SetString(
113 "triggeredResetProfileSettingsOverlayTabTitle",
114 l10n_util::GetStringFUTF16(IDS_OPTIONS_TAB_TITLE,
115 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE),
116 title_string));
117 localized_strings->SetString(
118 "triggeredResetProfileSettingsExplanation",
119 l10n_util::GetStringFUTF16(
120 IDS_TRIGGERED_RESET_PROFILE_SETTINGS_EXPLANATION, reset_tool_name));
121 }
122
123 void ResetProfileSettingsHandler::RegisterMessages() {
124 // Setup handlers specific to this panel.
125 web_ui()->RegisterMessageCallback("performResetProfileSettings", 52 web_ui()->RegisterMessageCallback("performResetProfileSettings",
126 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, 53 base::Bind(&ResetSettingsHandler::HandleResetProfileSettings,
127 base::Unretained(this))); 54 base::Unretained(this)));
128 web_ui()->RegisterMessageCallback("onShowResetProfileDialog", 55 web_ui()->RegisterMessageCallback("onShowResetProfileDialog",
129 base::Bind(&ResetProfileSettingsHandler::OnShowResetProfileDialog, 56 base::Bind(&ResetSettingsHandler::OnShowResetProfileDialog,
130 base::Unretained(this))); 57 base::Unretained(this)));
131 web_ui()->RegisterMessageCallback("onHideResetProfileDialog", 58 web_ui()->RegisterMessageCallback("onHideResetProfileDialog",
132 base::Bind(&ResetProfileSettingsHandler::OnHideResetProfileDialog, 59 base::Bind(&ResetSettingsHandler::OnHideResetProfileDialog,
133 base::Unretained(this)));
134 web_ui()->RegisterMessageCallback("onDismissedResetProfileSettingsBanner",
135 base::Bind(&ResetProfileSettingsHandler::
136 OnDismissedResetProfileSettingsBanner,
137 base::Unretained(this))); 60 base::Unretained(this)));
138 } 61 }
139 62
140 void ResetProfileSettingsHandler::HandleResetProfileSettings( 63 void ResetSettingsHandler::HandleResetProfileSettings(
141 const base::ListValue* value) { 64 const base::ListValue* value) {
142 bool send_settings = false; 65 bool send_settings = false;
143 if (!value->GetBoolean(0, &send_settings)) 66 bool success = value->GetBoolean(0, &send_settings);
144 NOTREACHED(); 67 DCHECK(success);
145 68
146 DCHECK(brandcode_.empty() || config_fetcher_); 69 DCHECK(brandcode_.empty() || config_fetcher_);
147 if (config_fetcher_ && config_fetcher_->IsActive()) { 70 if (config_fetcher_ && config_fetcher_->IsActive()) {
148 // Reset once the prefs are fetched. 71 // Reset once the prefs are fetched.
149 config_fetcher_->SetCallback( 72 config_fetcher_->SetCallback(
150 base::Bind(&ResetProfileSettingsHandler::ResetProfile, 73 base::Bind(&ResetSettingsHandler::ResetProfile,
151 Unretained(this), 74 Unretained(this),
152 send_settings)); 75 send_settings));
153 } else { 76 } else {
154 ResetProfile(send_settings); 77 ResetProfile(send_settings);
155 } 78 }
156 } 79 }
157 80
158 void ResetProfileSettingsHandler::OnResetProfileSettingsDone( 81 void ResetSettingsHandler::OnResetProfileSettingsDone(
159 bool send_feedback) { 82 bool send_feedback) {
160 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting"); 83 web_ui()->CallJavascriptFunction("SettingsResetPage.doneResetting");
161 if (send_feedback && setting_snapshot_) { 84 if (send_feedback && setting_snapshot_) {
162 Profile* profile = Profile::FromWebUI(web_ui()); 85 Profile* profile = Profile::FromWebUI(web_ui());
163 ResettableSettingsSnapshot current_snapshot(profile); 86 ResettableSettingsSnapshot current_snapshot(profile);
164 int difference = setting_snapshot_->FindDifferentFields(current_snapshot); 87 int difference = setting_snapshot_->FindDifferentFields(current_snapshot);
165 if (difference) { 88 if (difference) {
166 setting_snapshot_->Subtract(current_snapshot); 89 setting_snapshot_->Subtract(current_snapshot);
167 std::string report = SerializeSettingsReport(*setting_snapshot_, 90 std::string report = SerializeSettingsReport(*setting_snapshot_,
168 difference); 91 difference);
169 bool is_reset_prompt_active = automatic_profile_resetter_ && 92 bool is_reset_prompt_active = automatic_profile_resetter_ &&
170 automatic_profile_resetter_->IsResetPromptFlowActive(); 93 automatic_profile_resetter_->IsResetPromptFlowActive();
171 SendSettingsFeedback(report, profile, is_reset_prompt_active ? 94 SendSettingsFeedback(report, profile, is_reset_prompt_active ?
172 PROFILE_RESET_PROMPT : PROFILE_RESET_WEBUI); 95 PROFILE_RESET_PROMPT : PROFILE_RESET_WEBUI);
173 } 96 }
174 } 97 }
175 setting_snapshot_.reset(); 98 setting_snapshot_.reset();
176 if (automatic_profile_resetter_) { 99 if (automatic_profile_resetter_) {
177 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( 100 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog(
178 true /*performed_reset*/); 101 true /*performed_reset*/);
179 } 102 }
180 } 103 }
181 104
182 void ResetProfileSettingsHandler::OnShowResetProfileDialog( 105 void ResetSettingsHandler::OnShowResetProfileDialog(
183 const base::ListValue* value) { 106 const base::ListValue* value) {
184 if (!resetter_->IsActive()) { 107 if (!resetter_->IsActive()) {
185 setting_snapshot_.reset( 108 setting_snapshot_.reset(
186 new ResettableSettingsSnapshot(Profile::FromWebUI(web_ui()))); 109 new ResettableSettingsSnapshot(Profile::FromWebUI(web_ui())));
187 setting_snapshot_->RequestShortcuts(base::Bind( 110 setting_snapshot_->RequestShortcuts(base::Bind(
188 &ResetProfileSettingsHandler::UpdateFeedbackUI, AsWeakPtr())); 111 &ResetSettingsHandler::UpdateFeedbackUI, AsWeakPtr()));
189 UpdateFeedbackUI(); 112 UpdateFeedbackUI();
190 } 113 }
191 114
192 if (automatic_profile_resetter_) 115 if (automatic_profile_resetter_)
193 automatic_profile_resetter_->NotifyDidOpenWebUIResetDialog(); 116 automatic_profile_resetter_->NotifyDidOpenWebUIResetDialog();
194 has_shown_confirmation_dialog_ = true; 117 has_shown_confirmation_dialog_ = true;
195 118
196 if (brandcode_.empty()) 119 if (brandcode_.empty())
197 return; 120 return;
198 config_fetcher_.reset(new BrandcodeConfigFetcher( 121 config_fetcher_.reset(new BrandcodeConfigFetcher(
199 base::Bind(&ResetProfileSettingsHandler::OnSettingsFetched, 122 base::Bind(&ResetSettingsHandler::OnSettingsFetched,
200 Unretained(this)), 123 Unretained(this)),
201 GURL("https://tools.google.com/service/update2"), 124 GURL("https://tools.google.com/service/update2"),
202 brandcode_)); 125 brandcode_));
203 } 126 }
204 127
205 void ResetProfileSettingsHandler::OnHideResetProfileDialog( 128 void ResetSettingsHandler::OnHideResetProfileDialog(
206 const base::ListValue* value) { 129 const base::ListValue* value) {
207 if (!resetter_->IsActive()) 130 if (!resetter_->IsActive())
208 setting_snapshot_.reset(); 131 setting_snapshot_.reset();
209 } 132 }
210 133
211 void ResetProfileSettingsHandler::OnDismissedResetProfileSettingsBanner( 134 void ResetSettingsHandler::OnSettingsFetched() {
212 const base::ListValue* args) {
213 if (automatic_profile_resetter_)
214 automatic_profile_resetter_->NotifyDidCloseWebUIResetBanner();
215 }
216
217 void ResetProfileSettingsHandler::OnSettingsFetched() {
218 DCHECK(config_fetcher_); 135 DCHECK(config_fetcher_);
219 DCHECK(!config_fetcher_->IsActive()); 136 DCHECK(!config_fetcher_->IsActive());
220 // The master prefs is fetched. We are waiting for user pressing 'Reset'. 137 // The master prefs is fetched. We are waiting for user pressing 'Reset'.
221 } 138 }
222 139
223 void ResetProfileSettingsHandler::ResetProfile(bool send_settings) { 140 void ResetSettingsHandler::ResetProfile(bool send_settings) {
224 DCHECK(resetter_); 141 DCHECK(resetter_);
225 DCHECK(!resetter_->IsActive()); 142 DCHECK(!resetter_->IsActive());
226 143
227 scoped_ptr<BrandcodedDefaultSettings> default_settings; 144 scoped_ptr<BrandcodedDefaultSettings> default_settings;
228 if (config_fetcher_) { 145 if (config_fetcher_) {
229 DCHECK(!config_fetcher_->IsActive()); 146 DCHECK(!config_fetcher_->IsActive());
230 default_settings = config_fetcher_->GetSettings(); 147 default_settings = config_fetcher_->GetSettings();
231 config_fetcher_.reset(); 148 config_fetcher_.reset();
232 } else { 149 } else {
233 DCHECK(brandcode_.empty()); 150 DCHECK(brandcode_.empty());
234 } 151 }
235 152
236 // If failed to fetch BrandcodedDefaultSettings or this is an organic 153 // If failed to fetch BrandcodedDefaultSettings or this is an organic
237 // installation, use default settings. 154 // installation, use default settings.
238 if (!default_settings) 155 if (!default_settings)
239 default_settings.reset(new BrandcodedDefaultSettings); 156 default_settings.reset(new BrandcodedDefaultSettings);
240 resetter_->Reset( 157 resetter_->Reset(
241 ProfileResetter::ALL, 158 ProfileResetter::ALL,
242 default_settings.Pass(), 159 default_settings.Pass(),
243 send_settings, 160 send_settings,
244 base::Bind(&ResetProfileSettingsHandler::OnResetProfileSettingsDone, 161 base::Bind(&ResetSettingsHandler::OnResetProfileSettingsDone,
245 AsWeakPtr(), 162 AsWeakPtr(),
246 send_settings)); 163 send_settings));
247 content::RecordAction(base::UserMetricsAction("ResetProfile")); 164 content::RecordAction(base::UserMetricsAction("ResetProfile"));
248 UMA_HISTOGRAM_BOOLEAN("ProfileReset.SendFeedback", send_settings); 165 UMA_HISTOGRAM_BOOLEAN("ProfileReset.SendFeedback", send_settings);
249 } 166 }
250 167
251 void ResetProfileSettingsHandler::UpdateFeedbackUI() { 168 void ResetSettingsHandler::UpdateFeedbackUI() {
252 if (!setting_snapshot_) 169 if (!setting_snapshot_)
253 return; 170 return;
254 scoped_ptr<base::ListValue> list = GetReadableFeedbackForSnapshot( 171 scoped_ptr<base::ListValue> list = GetReadableFeedbackForSnapshot(
255 Profile::FromWebUI(web_ui()), 172 Profile::FromWebUI(web_ui()),
256 *setting_snapshot_); 173 *setting_snapshot_);
257 base::DictionaryValue feedback_info; 174 base::DictionaryValue feedback_info;
258 feedback_info.Set("feedbackInfo", list.release()); 175 feedback_info.Set("feedbackInfo", list.release());
259 web_ui()->CallJavascriptFunction( 176 web_ui()->CallJavascriptFunction(
260 "ResetProfileSettingsOverlay.setFeedbackInfo", 177 "SettingsResetPage.setFeedbackInfo", feedback_info);
261 feedback_info);
262 } 178 }
263 179
264 } // namespace options 180 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/reset_settings_handler.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698