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

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: ChromeOS and Android support in IsMetricsReportingUserChangable 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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 values->SetString("username", username); 538 values->SetString("username", username);
537 #endif 539 #endif
538 540
539 // Pass along sync status early so it will be available during page init. 541 // Pass along sync status early so it will be available during page init.
540 values->Set("syncData", GetSyncStateDictionary().release()); 542 values->Set("syncData", GetSyncStateDictionary().release());
541 543
542 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); 544 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL);
543 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL); 545 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL);
544 546
545 #if !defined(OS_CHROMEOS) 547 #if !defined(OS_CHROMEOS)
546 PrefService* pref_service = g_browser_process->local_state(); 548 values->SetBoolean("metricsReportingEnabledAtStart",
547 values->SetBoolean("metricsReportingEnabledAtStart", pref_service->GetBoolean( 549 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
548 prefs::kMetricsReportingEnabled));
549 #endif 550 #endif
550 551
551 #if defined(OS_CHROMEOS) 552 #if defined(OS_CHROMEOS)
552 // TODO(pastarmovj): replace this with a call to the CrosSettings list 553 // TODO(pastarmovj): replace this with a call to the CrosSettings list
553 // handling functionality to come. 554 // handling functionality to come.
554 values->Set("timezoneList", chromeos::system::GetTimezoneList().release()); 555 values->Set("timezoneList", chromeos::system::GetTimezoneList().release());
555 556
556 values->SetString("accessibilityLearnMoreURL", 557 values->SetString("accessibilityLearnMoreURL",
557 chrome::kChromeAccessibilityHelpURL); 558 chrome::kChromeAccessibilityHelpURL);
558 559
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 "launchEasyUnlockSetup", 750 "launchEasyUnlockSetup",
750 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup, 751 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup,
751 base::Unretained(this))); 752 base::Unretained(this)));
752 #if defined(OS_WIN) 753 #if defined(OS_WIN)
753 web_ui()->RegisterMessageCallback( 754 web_ui()->RegisterMessageCallback(
754 "refreshExtensionControlIndicators", 755 "refreshExtensionControlIndicators",
755 base::Bind( 756 base::Bind(
756 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators, 757 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators,
757 base::Unretained(this))); 758 base::Unretained(this)));
758 #endif // defined(OS_WIN) 759 #endif // defined(OS_WIN)
760 web_ui()->RegisterMessageCallback("metricsReportingCheckboxChanged",
761 base::Bind(&BrowserOptionsHandler::HandleMetricsReportingChange,
762 base::Unretained(this)));
759 } 763 }
760 764
761 void BrowserOptionsHandler::Uninitialize() { 765 void BrowserOptionsHandler::Uninitialize() {
762 registrar_.RemoveAll(); 766 registrar_.RemoveAll();
763 #if defined(OS_WIN) 767 #if defined(OS_WIN)
764 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this); 768 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
765 #endif 769 #endif
766 #if defined(OS_CHROMEOS) 770 #if defined(OS_CHROMEOS)
767 policy::ConsumerManagementService* consumer_management = 771 policy::ConsumerManagementService* consumer_management =
768 g_browser_process->platform_part()->browser_policy_connector_chromeos()-> 772 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 void BrowserOptionsHandler::InitializePage() { 921 void BrowserOptionsHandler::InitializePage() {
918 page_initialized_ = true; 922 page_initialized_ = true;
919 923
920 OnTemplateURLServiceChanged(); 924 OnTemplateURLServiceChanged();
921 925
922 ObserveThemeChanged(); 926 ObserveThemeChanged();
923 OnStateChanged(); 927 OnStateChanged();
924 UpdateDefaultBrowserState(); 928 UpdateDefaultBrowserState();
925 929
926 SetupMetricsReportingSettingVisibility(); 930 SetupMetricsReportingSettingVisibility();
931 SetupMetricsReportingCheckbox();
927 SetupNetworkPredictionControl(); 932 SetupNetworkPredictionControl();
928 SetupFontSizeSelector(); 933 SetupFontSizeSelector();
929 SetupPageZoomSelector(); 934 SetupPageZoomSelector();
930 SetupAutoOpenFileTypes(); 935 SetupAutoOpenFileTypes();
931 SetupProxySettingsSection(); 936 SetupProxySettingsSection();
932 SetupManageCertificatesSection(); 937 SetupManageCertificatesSection();
933 SetupManagingSupervisedUsers(); 938 SetupManagingSupervisedUsers();
934 SetupEasyUnlock(); 939 SetupEasyUnlock();
935 SetupExtensionControlledIndicators(); 940 SetupExtensionControlledIndicators();
936 941
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 // Check if an extension is overwriting the proxy setting. 1885 // Check if an extension is overwriting the proxy setting.
1881 extension = extensions::GetExtensionOverridingProxy( 1886 extension = extensions::GetExtensionOverridingProxy(
1882 Profile::FromWebUI(web_ui())); 1887 Profile::FromWebUI(web_ui()));
1883 AppendExtensionData("proxy", extension, &extension_controlled); 1888 AppendExtensionData("proxy", extension, &extension_controlled);
1884 1889
1885 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators", 1890 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
1886 extension_controlled); 1891 extension_controlled);
1887 #endif // defined(OS_WIN) 1892 #endif // defined(OS_WIN)
1888 } 1893 }
1889 1894
1895 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() {
1896 // This function does not work for ChromeOS and non-official builds. In both
1897 // casesChromeOS a different preference is used. It is tied to HTML element.
Alexei Svitkine (slow) 2014/09/15 20:59:43 Nit: casesChromeOS? This comment isn't quite righ
gayane -on leave until 09-2017 2014/09/15 21:09:17 Done.
1898 // Therefore, no special setup is needed.
1899 #if !defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
1900 bool checked = ChromeMetricsServiceAccessor::IsMetricsReportingEnabled();
1901 bool disabled = !IsMetricsReportingUserChangable();
1902
1903 SetMetricsReportingCheckbox(checked, disabled);
1904 #endif
1905 }
1906
1907 void BrowserOptionsHandler::HandleMetricsReportingChange(
1908 const base::ListValue* args) {
1909 bool enable;
1910 if (!args->GetBoolean(0, &enable))
1911 return;
1912
1913 InitiateMetricsReportingChange(
1914 enable,
1915 base::Bind(&BrowserOptionsHandler::MetricsReportingChangeCallback,
1916 base::Unretained(this)));
1917 }
1918
1919 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled) {
1920 SetMetricsReportingCheckbox(enabled, !IsMetricsReportingUserChangable());
1921 }
1922
1923 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked,
1924 bool disabled) {
1925 web_ui()->CallJavascriptFunction(
1926 "BrowserOptions.setMetricsReportingCheckboxState",
1927 base::FundamentalValue(checked),
1928 base::FundamentalValue(disabled));
1929 }
1930
1890 } // namespace options 1931 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698