diff options
author | csilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-27 22:15:50 +0000 |
---|---|---|
committer | csilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-27 22:15:50 +0000 |
commit | c046d235f747163601784b2da8bbbeba3e2cfe0b (patch) | |
tree | 77626f0439f32562b55585a1684d31a6be2863f7 | |
parent | 8a0274817911e955b017fd7d98ad61174c751654 (diff) | |
download | chromium_src-c046d235f747163601784b2da8bbbeba3e2cfe0b.zip chromium_src-c046d235f747163601784b2da8bbbeba3e2cfe0b.tar.gz chromium_src-c046d235f747163601784b2da8bbbeba3e2cfe0b.tar.bz2 |
dom-ui settings: properly implement the 'metrics reporting' checkbox.
- the metrics reporting preference is unique, so handle it correctly.
- show a 'restart required' alert when changing the metrics reporting setting.
- enhance alert overlay to allow only an OK button.
- fix a bug in the alert overlay where it was incorrectly loading default strings.
BUG=56536
TEST=Verify that the metrics reporting checkbox works properly on Chrome branded builds.
Review URL: http://codereview.chromium.org/3419020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60717 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 87 insertions, 10 deletions
diff --git a/chrome/browser/dom_ui/advanced_options_handler.cc b/chrome/browser/dom_ui/advanced_options_handler.cc index 9c743c4..b64f736 100644 --- a/chrome/browser/dom_ui/advanced_options_handler.cc +++ b/chrome/browser/dom_ui/advanced_options_handler.cc @@ -10,6 +10,7 @@ #include "base/command_line.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/dom_ui/options_managed_banner_handler.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_prefs.h" @@ -150,10 +151,13 @@ void AdvancedOptionsHandler::GetLocalizedValues( l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_OKLABEL)); localized_strings->SetString("optionsResetCancelLabel", l10n_util::GetStringUTF16(IDS_OPTIONS_RESET_CANCELLABEL)); + localized_strings->SetString("optionsRestartRequired", + l10n_util::GetStringUTF16(IDS_OPTIONS_RESTART_REQUIRED)); } void AdvancedOptionsHandler::Initialize() { DCHECK(dom_ui_); + SetupMetricsReportingCheckbox(false); SetupDownloadLocationPath(); SetupAutoOpenFileTypesDisabledAttribute(); SetupProxySettingsSection(); @@ -174,6 +178,8 @@ DOMMessageHandler* AdvancedOptionsHandler::Attach(DOMUI* dom_ui) { // special behaviors that aren't handled by the standard prefs UI. DCHECK(dom_ui_); PrefService* prefs = dom_ui_->GetProfile()->GetPrefs(); + enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, + g_browser_process->local_state(), this); default_download_location_.Init(prefs::kDownloadDefaultDirectory, prefs, this); auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, prefs, this); @@ -196,6 +202,9 @@ void AdvancedOptionsHandler::RegisterMessages() { dom_ui_->RegisterMessageCallback("resetToDefaults", NewCallback(this, &AdvancedOptionsHandler::HandleResetToDefaults)); + dom_ui_->RegisterMessageCallback("metricsReportingCheckboxAction", + NewCallback(this, + &AdvancedOptionsHandler::HandleMetricsReportingCheckbox)); #if !defined(OS_CHROMEOS) dom_ui_->RegisterMessageCallback("showManageSSLCertificates", NewCallback(this, @@ -264,6 +273,23 @@ void AdvancedOptionsHandler::HandleResetToDefaults(const ListValue* args) { OptionsUtil::ResetToDefaults(dom_ui_->GetProfile()); } +void AdvancedOptionsHandler::HandleMetricsReportingCheckbox( + const ListValue* args) { +#if defined(GOOGLE_CHROME_BUILD) + std::string checked_str = WideToUTF8(ExtractStringValue(args)); + bool enabled = (checked_str == "true"); + UserMetricsRecordAction( + enabled ? + UserMetricsAction("Options_MetricsReportingCheckbox_Enable") : + UserMetricsAction("Options_MetricsReportingCheckbox_Disable")); + bool is_enabled = OptionsUtil::ResolveMetricsReportingEnabled(enabled); + enable_metrics_recording_.SetValue(is_enabled); + + bool user_changed = (enabled == is_enabled); + SetupMetricsReportingCheckbox(user_changed); +#endif +} + #if defined(OS_WIN) void AdvancedOptionsHandler::HandleCheckRevocationCheckbox( const ListValue* args) { @@ -303,6 +329,17 @@ void AdvancedOptionsHandler::ShowManageSSLCertificates(const ListValue* args) { } #endif +void AdvancedOptionsHandler::SetupMetricsReportingCheckbox(bool user_changed) { +#if defined(GOOGLE_CHROME_BUILD) + FundamentalValue checked(enable_metrics_recording_.GetValue()); + FundamentalValue disabled(enable_metrics_recording_.IsManaged()); + FundamentalValue user_has_changed(user_changed); + dom_ui_->CallJavascriptFunction( + L"options.AdvancedOptions.SetMetricsReportingCheckboxState", checked, + disabled, user_has_changed); +#endif +} + void AdvancedOptionsHandler::SetupDownloadLocationPath() { StringValue value(default_download_location_.GetValue().value()); dom_ui_->CallJavascriptFunction( diff --git a/chrome/browser/dom_ui/advanced_options_handler.h b/chrome/browser/dom_ui/advanced_options_handler.h index ecabad7..2896d97 100644 --- a/chrome/browser/dom_ui/advanced_options_handler.h +++ b/chrome/browser/dom_ui/advanced_options_handler.h @@ -50,6 +50,9 @@ class AdvancedOptionsHandler // they want to reset all options to their default values. void HandleResetToDefaults(const ListValue* args); + // Callback for the "metricsReportingCheckboxAction" message. This is called + // if the user toggles the metrics reporting checkbox. + void HandleMetricsReportingCheckbox(const ListValue* args); #if defined(OS_WIN) // Callback for the "Check SSL Revocation" checkbox. This is needed so we // can support manual handling on Windows. @@ -73,6 +76,9 @@ class AdvancedOptionsHandler void ShowManageSSLCertificates(const ListValue* args); #endif + // Setup the checked state for the metrics reporting checkbox. + void SetupMetricsReportingCheckbox(bool user_changed); + // Setup the download path based on user preferences. void SetupDownloadLocationPath(); @@ -83,11 +89,12 @@ class AdvancedOptionsHandler void SetupProxySettingsSection(); #if defined(OS_WIN) - // Setup the checked state SSL related checkboxes. + // Setup the checked state for SSL related checkboxes. void SetupSSLConfigSettings(); #endif scoped_refptr<SelectFileDialog> select_folder_dialog_; + BooleanPrefMember enable_metrics_recording_; FilePathPrefMember default_download_location_; StringPrefMember auto_open_files_; scoped_ptr<PrefSetObserver> proxy_prefs_; diff --git a/chrome/browser/resources/options/advanced_options.html b/chrome/browser/resources/options/advanced_options.html index 103dd5d..8faf6ed 100644 --- a/chrome/browser/resources/options/advanced_options.html +++ b/chrome/browser/resources/options/advanced_options.html @@ -28,10 +28,8 @@ type="checkbox"><span i18n-content="safeBrowsingEnableProtection"> </span></label> <if expr="pp_ifdef('_google_chrome')"> - <label><input id="metricsReportingEnabled" - pref="user_experience_metrics.reporting_enabled" - metric="Options_MetricsReportingCheckbox" type="checkbox"> - <span i18n-content="enableLogging"></span></label> + <label><input id="metricsReportingEnabled" type="checkbox"><span + i18n-content="enableLogging"></span></label> </if> </div> </section> diff --git a/chrome/browser/resources/options/advanced_options.js b/chrome/browser/resources/options/advanced_options.js index 0818628..64011ce 100644 --- a/chrome/browser/resources/options/advanced_options.js +++ b/chrome/browser/resources/options/advanced_options.js @@ -21,7 +21,9 @@ var OptionsPage = options.OptionsPage; // Inherit AdvancedOptions from OptionsPage. __proto__: options.OptionsPage.prototype, - // Initialize AdvancedOptions page. + /** + * Initializes the page. + */ initializePage: function() { // Call base class implementation to starts preference initialization. OptionsPage.prototype.initializePage.call(this); @@ -37,6 +39,14 @@ var OptionsPage = options.OptionsPage; OptionsPage.showOverlay('clearBrowserDataOverlay'); chrome.send('coreOptionsUserMetricsAction', ['Options_ClearData']); }; + // 'metricsReportingEnabled' element is only present on Chrome branded + // builds. + if ($('metricsReportingEnabled')) { + $('metricsReportingEnabled').onclick = function(event) { + chrome.send('metricsReportingCheckboxAction', + [String(event.target.checked)]); + }; + } $('autoOpenFileTypesResetToDefault').onclick = function(event) { chrome.send('autoOpenFileTypesAction'); }; @@ -89,6 +99,16 @@ var OptionsPage = options.OptionsPage; chrome.send('showGearsSettings'); }; } + }, + + /** + * Show a 'restart required' alert. + * @private + */ + showRestartRequiredAlert_: function() { + AlertOverlay.show(undefined, + localStrings.getString('optionsRestartRequired'), + undefined, '', undefined); } }; @@ -96,6 +116,16 @@ var OptionsPage = options.OptionsPage; // Chrome callbacks // + // Set the checked state of the metrics reporting checkbox. + AdvancedOptions.SetMetricsReportingCheckboxState = function(checked, + disabled, user_changed) { + $('metricsReportingEnabled').checked = checked; + $('metricsReportingEnabled').disabled = disabled; + + if (user_changed) + AdvancedOptions.getInstance().showRestartRequiredAlert_(); + } + // Set the download path. AdvancedOptions.SetDownloadLocationPath = function(path) { if (!cr.isChromeOS) diff --git a/chrome/browser/resources/options/alert_overlay.js b/chrome/browser/resources/options/alert_overlay.js index 68c23d9..11b965d 100644 --- a/chrome/browser/resources/options/alert_overlay.js +++ b/chrome/browser/resources/options/alert_overlay.js @@ -94,10 +94,15 @@ cr.define('options', function() { } $('alertOverlayOk').textContent = (okTitle != undefined ? okTitle - : LocalStrings.getString('ok')); - $('alertOverlayCancel').textContent = - (cancelTitle != undefined ? cancelTitle - : LocalStrings.getString('cancel')); + : localStrings.getString('ok')); + if (cancelTitle != '') { + $('alertOverlayCancel').textContent = + (cancelTitle != undefined ? cancelTitle + : localStrings.getString('cancel')); + $('alertOverlayCancel').style.display = 'inline'; + } else { + $('alertOverlayCancel').style.display = 'none'; + } AlertOverlay.getInstance().okCallback = okCallback; AlertOverlay.getInstance().cancelCallback = cancelCallback; |