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

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: Always pass all params to setMetricsReportingCheckboxState, minor changes 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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 values->SetString("username", username); 533 values->SetString("username", username);
532 #endif 534 #endif
533 535
534 // Pass along sync status early so it will be available during page init. 536 // Pass along sync status early so it will be available during page init.
535 values->Set("syncData", GetSyncStateDictionary().release()); 537 values->Set("syncData", GetSyncStateDictionary().release());
536 538
537 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); 539 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL);
538 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL); 540 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL);
539 541
540 #if !defined(OS_CHROMEOS) 542 #if !defined(OS_CHROMEOS)
541 PrefService* pref_service = g_browser_process->local_state(); 543 values->SetBoolean("metricsReportingEnabledAtStart",
542 values->SetBoolean("metricsReportingEnabledAtStart", pref_service->GetBoolean( 544 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
543 prefs::kMetricsReportingEnabled));
544 #endif 545 #endif
545 546
546 #if defined(OS_CHROMEOS) 547 #if defined(OS_CHROMEOS)
547 // TODO(pastarmovj): replace this with a call to the CrosSettings list 548 // TODO(pastarmovj): replace this with a call to the CrosSettings list
548 // handling functionality to come. 549 // handling functionality to come.
549 values->Set("timezoneList", chromeos::system::GetTimezoneList().release()); 550 values->Set("timezoneList", chromeos::system::GetTimezoneList().release());
550 551
551 values->SetString("accessibilityLearnMoreURL", 552 values->SetString("accessibilityLearnMoreURL",
552 chrome::kChromeAccessibilityHelpURL); 553 chrome::kChromeAccessibilityHelpURL);
553 554
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 "launchEasyUnlockSetup", 753 "launchEasyUnlockSetup",
753 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup, 754 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup,
754 base::Unretained(this))); 755 base::Unretained(this)));
755 #if defined(OS_WIN) 756 #if defined(OS_WIN)
756 web_ui()->RegisterMessageCallback( 757 web_ui()->RegisterMessageCallback(
757 "refreshExtensionControlIndicators", 758 "refreshExtensionControlIndicators",
758 base::Bind( 759 base::Bind(
759 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators, 760 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators,
760 base::Unretained(this))); 761 base::Unretained(this)));
761 #endif // defined(OS_WIN) 762 #endif // defined(OS_WIN)
763 web_ui()->RegisterMessageCallback("metricsReportingCheckboxChanged",
764 base::Bind(&BrowserOptionsHandler::HandleMetricsReportingChange,
765 base::Unretained(this)));
762 } 766 }
763 767
764 void BrowserOptionsHandler::Uninitialize() { 768 void BrowserOptionsHandler::Uninitialize() {
765 registrar_.RemoveAll(); 769 registrar_.RemoveAll();
766 #if defined(OS_WIN) 770 #if defined(OS_WIN)
767 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this); 771 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
768 #endif 772 #endif
769 } 773 }
770 774
771 void BrowserOptionsHandler::OnStateChanged() { 775 void BrowserOptionsHandler::OnStateChanged() {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 SetupNetworkPredictionControl(); 927 SetupNetworkPredictionControl();
924 SetupFontSizeSelector(); 928 SetupFontSizeSelector();
925 SetupPageZoomSelector(); 929 SetupPageZoomSelector();
926 SetupAutoOpenFileTypes(); 930 SetupAutoOpenFileTypes();
927 SetupProxySettingsSection(); 931 SetupProxySettingsSection();
928 SetupManageCertificatesSection(); 932 SetupManageCertificatesSection();
929 SetupManagingSupervisedUsers(); 933 SetupManagingSupervisedUsers();
930 SetupEasyUnlock(); 934 SetupEasyUnlock();
931 SetupExtensionControlledIndicators(); 935 SetupExtensionControlledIndicators();
932 936
937 SetupMetricsReportingCheckbox();
Alexei Svitkine (slow) 2014/09/09 20:30:05 Move this to be right after the SetupMetricsReport
gayane -on leave until 09-2017 2014/09/10 16:58:27 Done.
938
933 #if defined(OS_CHROMEOS) 939 #if defined(OS_CHROMEOS)
934 SetupAccessibilityFeatures(); 940 SetupAccessibilityFeatures();
935 policy::BrowserPolicyConnectorChromeOS* connector = 941 policy::BrowserPolicyConnectorChromeOS* connector =
936 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 942 g_browser_process->platform_part()->browser_policy_connector_chromeos();
937 if (!connector->IsEnterpriseManaged() && 943 if (!connector->IsEnterpriseManaged() &&
938 !user_manager::UserManager::Get()->IsLoggedInAsGuest() && 944 !user_manager::UserManager::Get()->IsLoggedInAsGuest() &&
939 !user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { 945 !user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) {
940 web_ui()->CallJavascriptFunction( 946 web_ui()->CallJavascriptFunction(
941 "BrowserOptions.enableFactoryResetSection"); 947 "BrowserOptions.enableFactoryResetSection");
942 } 948 }
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 // Check if an extension is overwriting the proxy setting. 1866 // Check if an extension is overwriting the proxy setting.
1861 extension = extensions::GetExtensionOverridingProxy( 1867 extension = extensions::GetExtensionOverridingProxy(
1862 Profile::FromWebUI(web_ui())); 1868 Profile::FromWebUI(web_ui()));
1863 AppendExtensionData("proxy", extension, &extension_controlled); 1869 AppendExtensionData("proxy", extension, &extension_controlled);
1864 1870
1865 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators", 1871 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
1866 extension_controlled); 1872 extension_controlled);
1867 #endif // defined(OS_WIN) 1873 #endif // defined(OS_WIN)
1868 } 1874 }
1869 1875
1876 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() {
1877 #if !defined(OS_CHROMEOS)
Alexei Svitkine (slow) 2014/09/09 20:30:05 Add a comment about why this isn't enabled for CrO
gayane -on leave until 09-2017 2014/09/10 16:58:27 Done.
1878 bool checked = ChromeMetricsServiceAccessor::IsMetricsReportingEnabled();
1879 bool disabled = !IsMetricsReportingUserChangable();
1880
1881 SetMetricsReportingCheckbox(checked, disabled);
1882 #endif
1883 }
1884
1885 void BrowserOptionsHandler::HandleMetricsReportingChange(
1886 const base::ListValue* args) {
1887 bool enable;
1888 if (!args->GetBoolean(0, &enable))
1889 return;
1890
1891 base::Callback<void(bool)> callback_fn = base::Bind(
1892 &BrowserOptionsHandler::MetricsReportingChangeCallback,
1893 base::Unretained(this));
1894 InitiateMetricsReportingChange(enable, callback_fn);
1895 }
1896
1897 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled) {
1898 SetMetricsReportingCheckbox(enabled, !IsMetricsReportingUserChangable());
1899 }
1900
1901 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked,
1902 bool disabled) {
1903 base::FundamentalValue checkedValue(checked);
Alexei Svitkine (slow) 2014/09/09 20:30:05 Nit: This should use camel_case since it's on the
gayane -on leave until 09-2017 2014/09/10 16:58:27 Done.
1904 base::FundamentalValue disabledValue(disabled);
1905 web_ui()->CallJavascriptFunction(
1906 "BrowserOptions.setMetricsReportingCheckboxState",
1907 checkedValue,
1908 disabledValue);
1909 }
1910
1870 } // namespace options 1911 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698