OLD | NEW |
---|---|
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_profile_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" | 26 #include "ui/base/l10n/l10n_util.h" |
27 | 27 |
28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
29 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" | 29 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" |
30 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" | 30 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" |
31 #endif // defined(OS_WIN) | 31 #endif // defined(OS_WIN) |
32 | 32 |
33 namespace options { | 33 namespace settings { |
34 | 34 |
35 ResetProfileSettingsHandler::ResetProfileSettingsHandler() | 35 ResetProfileSettingsHandler::ResetProfileSettingsHandler(content::WebUI* web_ui) |
36 : automatic_profile_resetter_(NULL), | 36 : automatic_profile_resetter_(NULL), |
37 has_shown_confirmation_dialog_(false) { | 37 has_shown_confirmation_dialog_(false) { |
38 google_brand::GetBrand(&brandcode_); | 38 google_brand::GetBrand(&brandcode_); |
39 } | 39 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)); | 40 resetter_.reset(new ProfileResetter(profile)); |
46 automatic_profile_resetter_ = | 41 automatic_profile_resetter_ = |
47 AutomaticProfileResetterFactory::GetForBrowserContext(profile); | 42 AutomaticProfileResetterFactory::GetForBrowserContext(profile); |
48 } | 43 } |
49 | 44 |
50 void ResetProfileSettingsHandler::InitializePage() { | 45 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() { |
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"); | |
Dan Beam
2015/11/06 23:52:23
so this seems to re-show the banner on refresh. d
dpapad
2015/11/07 00:31:08
I have removed anything related to the banner unti
| |
57 } | |
58 } | |
59 | |
60 void ResetProfileSettingsHandler::Uninitialize() { | |
61 if (has_shown_confirmation_dialog_ && automatic_profile_resetter_) { | 46 if (has_shown_confirmation_dialog_ && automatic_profile_resetter_) { |
62 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( | 47 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( |
63 false /*performed_reset*/); | 48 false /*performed_reset*/); |
64 } | 49 } |
65 } | 50 } |
66 | 51 |
67 void ResetProfileSettingsHandler::GetLocalizedValues( | |
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() { | 52 void ResetProfileSettingsHandler::RegisterMessages() { |
124 // Setup handlers specific to this panel. | |
125 web_ui()->RegisterMessageCallback("performResetProfileSettings", | 53 web_ui()->RegisterMessageCallback("performResetProfileSettings", |
126 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, | 54 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, |
127 base::Unretained(this))); | 55 base::Unretained(this))); |
128 web_ui()->RegisterMessageCallback("onShowResetProfileDialog", | 56 web_ui()->RegisterMessageCallback("onShowResetProfileDialog", |
129 base::Bind(&ResetProfileSettingsHandler::OnShowResetProfileDialog, | 57 base::Bind(&ResetProfileSettingsHandler::OnShowResetProfileDialog, |
130 base::Unretained(this))); | 58 base::Unretained(this))); |
131 web_ui()->RegisterMessageCallback("onHideResetProfileDialog", | 59 web_ui()->RegisterMessageCallback("onHideResetProfileDialog", |
132 base::Bind(&ResetProfileSettingsHandler::OnHideResetProfileDialog, | 60 base::Bind(&ResetProfileSettingsHandler::OnHideResetProfileDialog, |
133 base::Unretained(this))); | 61 base::Unretained(this))); |
134 web_ui()->RegisterMessageCallback("onDismissedResetProfileSettingsBanner", | |
135 base::Bind(&ResetProfileSettingsHandler:: | |
136 OnDismissedResetProfileSettingsBanner, | |
137 base::Unretained(this))); | |
138 } | 62 } |
139 | 63 |
140 void ResetProfileSettingsHandler::HandleResetProfileSettings( | 64 void ResetProfileSettingsHandler::HandleResetProfileSettings( |
141 const base::ListValue* value) { | 65 const base::ListValue* value) { |
142 bool send_settings = false; | 66 bool send_settings = false; |
143 if (!value->GetBoolean(0, &send_settings)) | 67 if (!value->GetBoolean(0, &send_settings)) |
144 NOTREACHED(); | 68 NOTREACHED(); |
Dan Beam
2015/11/06 23:52:23
should this be NOTREACHED() + return?
dpapad
2015/11/07 00:31:08
Adding a return statement here will cause the prof
Dan Beam
2015/11/07 00:52:00
there are only 2 states AFAICT: the parameter is o
dpapad
2015/11/07 01:49:51
Resolved per chat discussion.
| |
145 | 69 |
146 DCHECK(brandcode_.empty() || config_fetcher_); | 70 DCHECK(brandcode_.empty() || config_fetcher_); |
147 if (config_fetcher_ && config_fetcher_->IsActive()) { | 71 if (config_fetcher_ && config_fetcher_->IsActive()) { |
148 // Reset once the prefs are fetched. | 72 // Reset once the prefs are fetched. |
149 config_fetcher_->SetCallback( | 73 config_fetcher_->SetCallback( |
150 base::Bind(&ResetProfileSettingsHandler::ResetProfile, | 74 base::Bind(&ResetProfileSettingsHandler::ResetProfile, |
151 Unretained(this), | 75 Unretained(this), |
152 send_settings)); | 76 send_settings)); |
153 } else { | 77 } else { |
154 ResetProfile(send_settings); | 78 ResetProfile(send_settings); |
155 } | 79 } |
156 } | 80 } |
157 | 81 |
158 void ResetProfileSettingsHandler::OnResetProfileSettingsDone( | 82 void ResetProfileSettingsHandler::OnResetProfileSettingsDone( |
159 bool send_feedback) { | 83 bool send_feedback) { |
160 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting"); | 84 web_ui()->CallJavascriptFunction("SettingsResetPage.doneResetting"); |
161 if (send_feedback && setting_snapshot_) { | 85 if (send_feedback && setting_snapshot_) { |
162 Profile* profile = Profile::FromWebUI(web_ui()); | 86 Profile* profile = Profile::FromWebUI(web_ui()); |
163 ResettableSettingsSnapshot current_snapshot(profile); | 87 ResettableSettingsSnapshot current_snapshot(profile); |
164 int difference = setting_snapshot_->FindDifferentFields(current_snapshot); | 88 int difference = setting_snapshot_->FindDifferentFields(current_snapshot); |
165 if (difference) { | 89 if (difference) { |
166 setting_snapshot_->Subtract(current_snapshot); | 90 setting_snapshot_->Subtract(current_snapshot); |
167 std::string report = SerializeSettingsReport(*setting_snapshot_, | 91 std::string report = SerializeSettingsReport(*setting_snapshot_, |
168 difference); | 92 difference); |
169 bool is_reset_prompt_active = automatic_profile_resetter_ && | 93 bool is_reset_prompt_active = automatic_profile_resetter_ && |
170 automatic_profile_resetter_->IsResetPromptFlowActive(); | 94 automatic_profile_resetter_->IsResetPromptFlowActive(); |
171 SendSettingsFeedback(report, profile, is_reset_prompt_active ? | 95 SendSettingsFeedback(report, profile, is_reset_prompt_active ? |
172 PROFILE_RESET_PROMPT : PROFILE_RESET_WEBUI); | 96 PROFILE_RESET_PROMPT : PROFILE_RESET_WEBUI); |
173 } | 97 } |
174 } | 98 } |
175 setting_snapshot_.reset(); | 99 setting_snapshot_.reset(); |
176 if (automatic_profile_resetter_) { | 100 if (automatic_profile_resetter_) { |
177 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( | 101 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( |
178 true /*performed_reset*/); | 102 true /*performed_reset*/); |
179 } | 103 } |
180 } | 104 } |
181 | 105 |
182 void ResetProfileSettingsHandler::OnShowResetProfileDialog( | 106 void ResetProfileSettingsHandler::OnShowResetProfileDialog( |
183 const base::ListValue* value) { | 107 const base::ListValue* value) { |
184 if (!resetter_->IsActive()) { | 108 if (!resetter_->IsActive()) { |
185 setting_snapshot_.reset( | 109 setting_snapshot_.reset( |
186 new ResettableSettingsSnapshot(Profile::FromWebUI(web_ui()))); | 110 new ResettableSettingsSnapshot(Profile::FromWebUI(web_ui()))); |
187 setting_snapshot_->RequestShortcuts(base::Bind( | 111 setting_snapshot_->RequestShortcuts(base::Bind( |
188 &ResetProfileSettingsHandler::UpdateFeedbackUI, AsWeakPtr())); | 112 &ResetProfileSettingsHandler::UpdateFeedbackUI, AsWeakPtr())); |
189 UpdateFeedbackUI(); | |
Dan Beam
2015/11/06 23:52:23
why did you remove this?
dpapad
2015/11/07 00:31:08
I could not justify what it was doing. It was call
Dan Beam
2015/11/07 00:52:00
should this be removed from options/ as well, then
dpapad
2015/11/07 01:49:51
Actually after further inspection, I decided to ad
| |
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(&ResetProfileSettingsHandler::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 ResetProfileSettingsHandler::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( | |
212 const base::ListValue* args) { | |
213 if (automatic_profile_resetter_) | |
214 automatic_profile_resetter_->NotifyDidCloseWebUIResetBanner(); | |
215 } | |
216 | |
217 void ResetProfileSettingsHandler::OnSettingsFetched() { | 134 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 ResetProfileSettingsHandler::ResetProfile(bool send_settings) { |
224 DCHECK(resetter_); | 141 DCHECK(resetter_); |
225 DCHECK(!resetter_->IsActive()); | 142 DCHECK(!resetter_->IsActive()); |
226 | 143 |
(...skipping 23 matching lines...) Expand all Loading... | |
250 | 167 |
251 void ResetProfileSettingsHandler::UpdateFeedbackUI() { | 168 void ResetProfileSettingsHandler::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 |
OLD | NEW |