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

Side by Side Diff: chrome/browser/ui/webui/options/browser_options_handler.cc

Issue 506663003: Consolidates accessing and setting the UMA pref to be within metrics code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typedef for callback type Created 6 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser_options_handler.h" 5 #include "chrome/browser/ui/webui/options/browser_options_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 12 matching lines...) Expand all
23 #include "base/value_conversions.h" 23 #include "base/value_conversions.h"
24 #include "base/values.h" 24 #include "base/values.h"
25 #include "chrome/browser/auto_launch_trial.h" 25 #include "chrome/browser/auto_launch_trial.h"
26 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/chrome_notification_types.h" 27 #include "chrome/browser/chrome_notification_types.h"
28 #include "chrome/browser/chrome_page_zoom.h" 28 #include "chrome/browser/chrome_page_zoom.h"
29 #include "chrome/browser/custom_home_pages_table_model.h" 29 #include "chrome/browser/custom_home_pages_table_model.h"
30 #include "chrome/browser/download/download_prefs.h" 30 #include "chrome/browser/download/download_prefs.h"
31 #include "chrome/browser/gpu/gpu_mode_manager.h" 31 #include "chrome/browser/gpu/gpu_mode_manager.h"
32 #include "chrome/browser/lifetime/application_lifetime.h" 32 #include "chrome/browser/lifetime/application_lifetime.h"
33 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
34 #include "chrome/browser/metrics/metrics_reporting_state.h"
33 #include "chrome/browser/net/prediction_options.h" 35 #include "chrome/browser/net/prediction_options.h"
34 #include "chrome/browser/prefs/session_startup_pref.h" 36 #include "chrome/browser/prefs/session_startup_pref.h"
35 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 37 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
36 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" 38 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h"
37 #include "chrome/browser/profiles/profile.h" 39 #include "chrome/browser/profiles/profile.h"
38 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 40 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
39 #include "chrome/browser/profiles/profile_info_cache.h" 41 #include "chrome/browser/profiles/profile_info_cache.h"
40 #include "chrome/browser/profiles/profile_manager.h" 42 #include "chrome/browser/profiles/profile_manager.h"
41 #include "chrome/browser/profiles/profile_metrics.h" 43 #include "chrome/browser/profiles/profile_metrics.h"
42 #include "chrome/browser/profiles/profile_shortcut_manager.h" 44 #include "chrome/browser/profiles/profile_shortcut_manager.h"
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 values->SetString("username", username); 535 values->SetString("username", username);
534 #endif 536 #endif
535 537
536 // Pass along sync status early so it will be available during page init. 538 // Pass along sync status early so it will be available during page init.
537 values->Set("syncData", GetSyncStateDictionary().release()); 539 values->Set("syncData", GetSyncStateDictionary().release());
538 540
539 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); 541 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL);
540 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL); 542 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL);
541 543
542 #if !defined(OS_CHROMEOS) 544 #if !defined(OS_CHROMEOS)
543 PrefService* pref_service = g_browser_process->local_state(); 545 values->SetBoolean("metricsReportingEnabledAtStart",
544 values->SetBoolean("metricsReportingEnabledAtStart", pref_service->GetBoolean( 546 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
545 prefs::kMetricsReportingEnabled));
546 #endif 547 #endif
547 548
548 #if defined(OS_CHROMEOS) 549 #if defined(OS_CHROMEOS)
549 // TODO(pastarmovj): replace this with a call to the CrosSettings list 550 // TODO(pastarmovj): replace this with a call to the CrosSettings list
550 // handling functionality to come. 551 // handling functionality to come.
551 values->Set("timezoneList", chromeos::system::GetTimezoneList().release()); 552 values->Set("timezoneList", chromeos::system::GetTimezoneList().release());
552 553
553 values->SetString("accessibilityLearnMoreURL", 554 values->SetString("accessibilityLearnMoreURL",
554 chrome::kChromeAccessibilityHelpURL); 555 chrome::kChromeAccessibilityHelpURL);
555 556
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 "launchEasyUnlockSetup", 755 "launchEasyUnlockSetup",
755 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup, 756 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup,
756 base::Unretained(this))); 757 base::Unretained(this)));
757 #if defined(OS_WIN) 758 #if defined(OS_WIN)
758 web_ui()->RegisterMessageCallback( 759 web_ui()->RegisterMessageCallback(
759 "refreshExtensionControlIndicators", 760 "refreshExtensionControlIndicators",
760 base::Bind( 761 base::Bind(
761 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators, 762 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators,
762 base::Unretained(this))); 763 base::Unretained(this)));
763 #endif // defined(OS_WIN) 764 #endif // defined(OS_WIN)
765 web_ui()->RegisterMessageCallback("metricsReportingCheckboxChanged",
766 base::Bind(&BrowserOptionsHandler::HandleMetricsReportingChange,
767 base::Unretained(this)));
764 } 768 }
765 769
766 void BrowserOptionsHandler::Uninitialize() { 770 void BrowserOptionsHandler::Uninitialize() {
767 registrar_.RemoveAll(); 771 registrar_.RemoveAll();
768 #if defined(OS_WIN) 772 #if defined(OS_WIN)
769 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this); 773 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
770 #endif 774 #endif
771 } 775 }
772 776
773 void BrowserOptionsHandler::OnStateChanged() { 777 void BrowserOptionsHandler::OnStateChanged() {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 void BrowserOptionsHandler::InitializePage() { 919 void BrowserOptionsHandler::InitializePage() {
916 page_initialized_ = true; 920 page_initialized_ = true;
917 921
918 OnTemplateURLServiceChanged(); 922 OnTemplateURLServiceChanged();
919 923
920 ObserveThemeChanged(); 924 ObserveThemeChanged();
921 OnStateChanged(); 925 OnStateChanged();
922 UpdateDefaultBrowserState(); 926 UpdateDefaultBrowserState();
923 927
924 SetupMetricsReportingSettingVisibility(); 928 SetupMetricsReportingSettingVisibility();
929 SetupMetricsReportingCheckbox();
925 SetupNetworkPredictionControl(); 930 SetupNetworkPredictionControl();
926 SetupFontSizeSelector(); 931 SetupFontSizeSelector();
927 SetupPageZoomSelector(); 932 SetupPageZoomSelector();
928 SetupAutoOpenFileTypes(); 933 SetupAutoOpenFileTypes();
929 SetupProxySettingsSection(); 934 SetupProxySettingsSection();
930 SetupManageCertificatesSection(); 935 SetupManageCertificatesSection();
931 SetupManagingSupervisedUsers(); 936 SetupManagingSupervisedUsers();
932 SetupEasyUnlock(); 937 SetupEasyUnlock();
933 SetupExtensionControlledIndicators(); 938 SetupExtensionControlledIndicators();
934 939
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 // Check if an extension is overwriting the proxy setting. 1867 // Check if an extension is overwriting the proxy setting.
1863 extension = extensions::GetExtensionOverridingProxy( 1868 extension = extensions::GetExtensionOverridingProxy(
1864 Profile::FromWebUI(web_ui())); 1869 Profile::FromWebUI(web_ui()));
1865 AppendExtensionData("proxy", extension, &extension_controlled); 1870 AppendExtensionData("proxy", extension, &extension_controlled);
1866 1871
1867 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators", 1872 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
1868 extension_controlled); 1873 extension_controlled);
1869 #endif // defined(OS_WIN) 1874 #endif // defined(OS_WIN)
1870 } 1875 }
1871 1876
1877 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() {
1878 // This function does not work for ChromeOS. In ChromeOS a different
1879 // preference is used. It is tied to HTML element, and therefore, no special
1880 // setup is needed.
1881 #if !defined(OS_CHROMEOS)
1882 bool checked = ChromeMetricsServiceAccessor::IsMetricsReportingEnabled();
1883 bool disabled = !IsMetricsReportingUserChangable();
1884
1885 SetMetricsReportingCheckbox(checked, disabled);
1886 #endif
1887 }
1888
1889 void BrowserOptionsHandler::HandleMetricsReportingChange(
1890 const base::ListValue* args) {
1891 bool enable;
1892 if (!args->GetBoolean(0, &enable))
1893 return;
1894
1895 OnMetricsReportingCallbackType callback_fn = base::Bind(
1896 &BrowserOptionsHandler::MetricsReportingChangeCallback,
1897 base::Unretained(this));
stevenjb 2014/09/12 18:07:41 nit: no need for local here
gayane -on leave until 09-2017 2014/09/12 18:20:12 Done.
1898 InitiateMetricsReportingChange(enable, callback_fn);
1899 }
1900
1901 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled) {
1902 SetMetricsReportingCheckbox(enabled, !IsMetricsReportingUserChangable());
1903 }
1904
1905 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked,
1906 bool disabled) {
1907 web_ui()->CallJavascriptFunction(
1908 "BrowserOptions.setMetricsReportingCheckboxState",
1909 base::FundamentalValue(checked),
1910 base::FundamentalValue(disabled));
1911 }
1912
1872 } // namespace options 1913 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698