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

Side by Side Diff: chrome/browser/dom_ui/advanced_options_handler.cc

Issue 3419020: dom-ui settings: properly implement the 'metrics reporting' checkbox.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Rebase to r60664. Created 10 years, 2 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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/advanced_options_handler.h" 5 #include "chrome/browser/dom_ui/advanced_options_handler.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/dom_ui/options_managed_banner_handler.h" 14 #include "chrome/browser/dom_ui/options_managed_banner_handler.h"
14 #include "chrome/browser/download/download_manager.h" 15 #include "chrome/browser/download/download_manager.h"
15 #include "chrome/browser/download/download_prefs.h" 16 #include "chrome/browser/download/download_prefs.h"
16 #include "chrome/browser/metrics/user_metrics.h" 17 #include "chrome/browser/metrics/user_metrics.h"
17 #include "chrome/browser/options_util.h" 18 #include "chrome/browser/options_util.h"
18 #include "chrome/browser/options_window.h" 19 #include "chrome/browser/options_window.h"
19 #include "chrome/browser/prefs/pref_service.h" 20 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/profile.h" 21 #include "chrome/browser/profile.h"
21 #include "chrome/browser/tab_contents/tab_contents.h" 22 #include "chrome/browser/tab_contents/tab_contents.h"
22 #include "chrome/browser/tab_contents/tab_contents_view.h" 23 #include "chrome/browser/tab_contents/tab_contents_view.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 localized_strings->SetString("disableServices", 144 localized_strings->SetString("disableServices",
144 l10n_util::GetStringUTF16(IDS_OPTIONS_DISABLE_SERVICES)); 145 l10n_util::GetStringUTF16(IDS_OPTIONS_DISABLE_SERVICES));
145 localized_strings->SetString("optionsReset", 146 localized_strings->SetString("optionsReset",
146 l10n_util::GetStringUTF16(IDS_OPTIONS_RESET)); 147 l10n_util::GetStringUTF16(IDS_OPTIONS_RESET));
147 localized_strings->SetString("optionsResetMessage", 148 localized_strings->SetString("optionsResetMessage",
148 l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_MESSAGE)); 149 l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_MESSAGE));
149 localized_strings->SetString("optionsResetOkLabel", 150 localized_strings->SetString("optionsResetOkLabel",
150 l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_OKLABEL)); 151 l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_OKLABEL));
151 localized_strings->SetString("optionsResetCancelLabel", 152 localized_strings->SetString("optionsResetCancelLabel",
152 l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_CANCELLABEL)); 153 l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_CANCELLABEL));
154 localized_strings->SetString("optionsRestartRequired",
155 l10n_util::GetStringUTF16(IDS_OPTIONS_RESTART_REQUIRED));
153 } 156 }
154 157
155 void AdvancedOptionsHandler::Initialize() { 158 void AdvancedOptionsHandler::Initialize() {
156 DCHECK(dom_ui_); 159 DCHECK(dom_ui_);
160 SetupMetricsReportingCheckbox(false);
157 SetupDownloadLocationPath(); 161 SetupDownloadLocationPath();
158 SetupAutoOpenFileTypesDisabledAttribute(); 162 SetupAutoOpenFileTypesDisabledAttribute();
159 SetupProxySettingsSection(); 163 SetupProxySettingsSection();
160 #if defined(OS_WIN) 164 #if defined(OS_WIN)
161 SetupSSLConfigSettings(); 165 SetupSSLConfigSettings();
162 #endif 166 #endif
163 banner_handler_.reset( 167 banner_handler_.reset(
164 new OptionsManagedBannerHandler(dom_ui_, 168 new OptionsManagedBannerHandler(dom_ui_,
165 ASCIIToUTF16("AdvancedOptions"), 169 ASCIIToUTF16("AdvancedOptions"),
166 OPTIONS_PAGE_ADVANCED)); 170 OPTIONS_PAGE_ADVANCED));
167 } 171 }
168 172
169 DOMMessageHandler* AdvancedOptionsHandler::Attach(DOMUI* dom_ui) { 173 DOMMessageHandler* AdvancedOptionsHandler::Attach(DOMUI* dom_ui) {
170 // Call through to superclass. 174 // Call through to superclass.
171 DOMMessageHandler* handler = OptionsPageUIHandler::Attach(dom_ui); 175 DOMMessageHandler* handler = OptionsPageUIHandler::Attach(dom_ui);
172 176
173 // Register for preferences that we need to observe manually. These have 177 // Register for preferences that we need to observe manually. These have
174 // special behaviors that aren't handled by the standard prefs UI. 178 // special behaviors that aren't handled by the standard prefs UI.
175 DCHECK(dom_ui_); 179 DCHECK(dom_ui_);
176 PrefService* prefs = dom_ui_->GetProfile()->GetPrefs(); 180 PrefService* prefs = dom_ui_->GetProfile()->GetPrefs();
181 enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled,
182 g_browser_process->local_state(), this);
177 default_download_location_.Init(prefs::kDownloadDefaultDirectory, 183 default_download_location_.Init(prefs::kDownloadDefaultDirectory,
178 prefs, this); 184 prefs, this);
179 auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, prefs, this); 185 auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, prefs, this);
180 proxy_prefs_.reset( 186 proxy_prefs_.reset(
181 PrefSetObserver::CreateProxyPrefSetObserver(prefs, this)); 187 PrefSetObserver::CreateProxyPrefSetObserver(prefs, this));
182 188
183 // Return result from the superclass. 189 // Return result from the superclass.
184 return handler; 190 return handler;
185 } 191 }
186 192
187 void AdvancedOptionsHandler::RegisterMessages() { 193 void AdvancedOptionsHandler::RegisterMessages() {
188 // Setup handlers specific to this panel. 194 // Setup handlers specific to this panel.
189 DCHECK(dom_ui_); 195 DCHECK(dom_ui_);
190 dom_ui_->RegisterMessageCallback("selectDownloadLocation", 196 dom_ui_->RegisterMessageCallback("selectDownloadLocation",
191 NewCallback(this, 197 NewCallback(this,
192 &AdvancedOptionsHandler::HandleSelectDownloadLocation)); 198 &AdvancedOptionsHandler::HandleSelectDownloadLocation));
193 dom_ui_->RegisterMessageCallback("autoOpenFileTypesAction", 199 dom_ui_->RegisterMessageCallback("autoOpenFileTypesAction",
194 NewCallback(this, 200 NewCallback(this,
195 &AdvancedOptionsHandler::HandleAutoOpenButton)); 201 &AdvancedOptionsHandler::HandleAutoOpenButton));
196 dom_ui_->RegisterMessageCallback("resetToDefaults", 202 dom_ui_->RegisterMessageCallback("resetToDefaults",
197 NewCallback(this, 203 NewCallback(this,
198 &AdvancedOptionsHandler::HandleResetToDefaults)); 204 &AdvancedOptionsHandler::HandleResetToDefaults));
205 dom_ui_->RegisterMessageCallback("metricsReportingCheckboxAction",
206 NewCallback(this,
207 &AdvancedOptionsHandler::HandleMetricsReportingCheckbox));
199 #if !defined(OS_CHROMEOS) 208 #if !defined(OS_CHROMEOS)
200 dom_ui_->RegisterMessageCallback("showManageSSLCertificates", 209 dom_ui_->RegisterMessageCallback("showManageSSLCertificates",
201 NewCallback(this, 210 NewCallback(this,
202 &AdvancedOptionsHandler::ShowManageSSLCertificates)); 211 &AdvancedOptionsHandler::ShowManageSSLCertificates));
203 dom_ui_->RegisterMessageCallback("showNetworkProxySettings", 212 dom_ui_->RegisterMessageCallback("showNetworkProxySettings",
204 NewCallback(this, 213 NewCallback(this,
205 &AdvancedOptionsHandler::ShowNetworkProxySettings)); 214 &AdvancedOptionsHandler::ShowNetworkProxySettings));
206 #endif 215 #endif
207 216
208 #if defined(OS_WIN) 217 #if defined(OS_WIN)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 UserMetricsRecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); 266 UserMetricsRecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
258 DownloadManager* manager = dom_ui_->GetProfile()->GetDownloadManager(); 267 DownloadManager* manager = dom_ui_->GetProfile()->GetDownloadManager();
259 if (manager) 268 if (manager)
260 manager->download_prefs()->ResetAutoOpen(); 269 manager->download_prefs()->ResetAutoOpen();
261 } 270 }
262 271
263 void AdvancedOptionsHandler::HandleResetToDefaults(const ListValue* args) { 272 void AdvancedOptionsHandler::HandleResetToDefaults(const ListValue* args) {
264 OptionsUtil::ResetToDefaults(dom_ui_->GetProfile()); 273 OptionsUtil::ResetToDefaults(dom_ui_->GetProfile());
265 } 274 }
266 275
276 void AdvancedOptionsHandler::HandleMetricsReportingCheckbox(
277 const ListValue* args) {
278 #if defined(GOOGLE_CHROME_BUILD)
279 std::string checked_str = WideToUTF8(ExtractStringValue(args));
280 bool enabled = (checked_str == "true");
281 UserMetricsRecordAction(
282 enabled ?
283 UserMetricsAction("Options_MetricsReportingCheckbox_Enable") :
284 UserMetricsAction("Options_MetricsReportingCheckbox_Disable"));
285 bool is_enabled = OptionsUtil::ResolveMetricsReportingEnabled(enabled);
286 enable_metrics_recording_.SetValue(is_enabled);
287
288 bool user_changed = (enabled == is_enabled);
289 SetupMetricsReportingCheckbox(user_changed);
290 #endif
291 }
292
267 #if defined(OS_WIN) 293 #if defined(OS_WIN)
268 void AdvancedOptionsHandler::HandleCheckRevocationCheckbox( 294 void AdvancedOptionsHandler::HandleCheckRevocationCheckbox(
269 const ListValue* args) { 295 const ListValue* args) {
270 std::string checked_str = WideToUTF8(ExtractStringValue(args)); 296 std::string checked_str = WideToUTF8(ExtractStringValue(args));
271 std::string metric = 297 std::string metric =
272 (checked_str == "true" ? "Options_CheckCertRevocation_Enable" 298 (checked_str == "true" ? "Options_CheckCertRevocation_Enable"
273 : "Options_CheckCertRevocation_Disable"); 299 : "Options_CheckCertRevocation_Disable");
274 UserMetricsRecordAction(UserMetricsAction(metric.c_str())); 300 UserMetricsRecordAction(UserMetricsAction(metric.c_str()));
275 net::SSLConfigServiceWin::SetRevCheckingEnabled(checked_str == "true"); 301 net::SSLConfigServiceWin::SetRevCheckingEnabled(checked_str == "true");
276 } 302 }
(...skipping 19 matching lines...) Expand all
296 UserMetricsRecordAction(UserMetricsAction("Options_ShowProxySettings")); 322 UserMetricsRecordAction(UserMetricsAction("Options_ShowProxySettings"));
297 AdvancedOptionsUtilities::ShowNetworkProxySettings(dom_ui_->tab_contents()); 323 AdvancedOptionsUtilities::ShowNetworkProxySettings(dom_ui_->tab_contents());
298 } 324 }
299 325
300 void AdvancedOptionsHandler::ShowManageSSLCertificates(const ListValue* args) { 326 void AdvancedOptionsHandler::ShowManageSSLCertificates(const ListValue* args) {
301 UserMetricsRecordAction(UserMetricsAction("Options_ManageSSLCertificates")); 327 UserMetricsRecordAction(UserMetricsAction("Options_ManageSSLCertificates"));
302 AdvancedOptionsUtilities::ShowManageSSLCertificates(dom_ui_->tab_contents()); 328 AdvancedOptionsUtilities::ShowManageSSLCertificates(dom_ui_->tab_contents());
303 } 329 }
304 #endif 330 #endif
305 331
332 void AdvancedOptionsHandler::SetupMetricsReportingCheckbox(bool user_changed) {
333 #if defined(GOOGLE_CHROME_BUILD)
334 FundamentalValue checked(enable_metrics_recording_.GetValue());
335 FundamentalValue disabled(enable_metrics_recording_.IsManaged());
336 FundamentalValue user_has_changed(user_changed);
337 dom_ui_->CallJavascriptFunction(
338 L"options.AdvancedOptions.SetMetricsReportingCheckboxState", checked,
339 disabled, user_has_changed);
340 #endif
341 }
342
306 void AdvancedOptionsHandler::SetupDownloadLocationPath() { 343 void AdvancedOptionsHandler::SetupDownloadLocationPath() {
307 StringValue value(default_download_location_.GetValue().value()); 344 StringValue value(default_download_location_.GetValue().value());
308 dom_ui_->CallJavascriptFunction( 345 dom_ui_->CallJavascriptFunction(
309 L"options.AdvancedOptions.SetDownloadLocationPath", value); 346 L"options.AdvancedOptions.SetDownloadLocationPath", value);
310 } 347 }
311 348
312 void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() { 349 void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() {
313 // Set the enabled state for the AutoOpenFileTypesResetToDefault button. 350 // Set the enabled state for the AutoOpenFileTypesResetToDefault button.
314 // We enable the button if the user has any auto-open file types registered. 351 // We enable the button if the user has any auto-open file types registered.
315 DownloadManager* manager = dom_ui_->GetProfile()->GetDownloadManager(); 352 DownloadManager* manager = dom_ui_->GetProfile()->GetDownloadManager();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 393 }
357 FundamentalValue checkRevocationValue(checkRevocationSetting); 394 FundamentalValue checkRevocationValue(checkRevocationSetting);
358 dom_ui_->CallJavascriptFunction( 395 dom_ui_->CallJavascriptFunction(
359 L"options.AdvancedOptions.SetCheckRevocationCheckboxState", 396 L"options.AdvancedOptions.SetCheckRevocationCheckboxState",
360 checkRevocationValue); 397 checkRevocationValue);
361 FundamentalValue useSSLValue(useSSLSetting); 398 FundamentalValue useSSLValue(useSSLSetting);
362 dom_ui_->CallJavascriptFunction( 399 dom_ui_->CallJavascriptFunction(
363 L"options.AdvancedOptions.SetUseSSL2CheckboxStatechecked", useSSLValue); 400 L"options.AdvancedOptions.SetUseSSL2CheckboxStatechecked", useSSLValue);
364 } 401 }
365 #endif 402 #endif
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/advanced_options_handler.h ('k') | chrome/browser/resources/options/advanced_options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698