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

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: MetricsReporting handling moved to browser_options_handler. JS callback is not called if the… 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 SetupMetricsReportingSettingVisibility(); 926 SetupMetricsReportingSettingVisibility();
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();
936 SetupMetricsReportingCheckbox();
932 937
933 #if defined(OS_CHROMEOS) 938 #if defined(OS_CHROMEOS)
934 SetupAccessibilityFeatures(); 939 SetupAccessibilityFeatures();
935 policy::BrowserPolicyConnectorChromeOS* connector = 940 policy::BrowserPolicyConnectorChromeOS* connector =
936 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 941 g_browser_process->platform_part()->browser_policy_connector_chromeos();
937 if (!connector->IsEnterpriseManaged() && 942 if (!connector->IsEnterpriseManaged() &&
938 !user_manager::UserManager::Get()->IsLoggedInAsGuest() && 943 !user_manager::UserManager::Get()->IsLoggedInAsGuest() &&
939 !user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { 944 !user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) {
940 web_ui()->CallJavascriptFunction( 945 web_ui()->CallJavascriptFunction(
941 "BrowserOptions.enableFactoryResetSection"); 946 "BrowserOptions.enableFactoryResetSection");
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 // Check if an extension is overwriting the proxy setting. 1865 // Check if an extension is overwriting the proxy setting.
1861 extension = extensions::GetExtensionOverridingProxy( 1866 extension = extensions::GetExtensionOverridingProxy(
1862 Profile::FromWebUI(web_ui())); 1867 Profile::FromWebUI(web_ui()));
1863 AppendExtensionData("proxy", extension, &extension_controlled); 1868 AppendExtensionData("proxy", extension, &extension_controlled);
1864 1869
1865 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators", 1870 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
1866 extension_controlled); 1871 extension_controlled);
1867 #endif // defined(OS_WIN) 1872 #endif // defined(OS_WIN)
1868 } 1873 }
1869 1874
1875 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() {
1876 base::FundamentalValue checked(
1877 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
1878 base::FundamentalValue disabled(!IsMetricsReportingUserChangable());
1879
1880 web_ui()->CallJavascriptFunction(
1881 "BrowserOptions.setMetricsReportingCheckboxState", checked, disabled);
1882 }
1883
1884 void BrowserOptionsHandler::HandleMetricsReportingChange(
1885 const base::ListValue* args) {
1886 base::Callback<void(bool)> callback_fn = base::Bind(
Alexei Svitkine (slow) 2014/09/05 20:50:25 Nit: Move this to be right above where it's used.
gayane -on leave until 09-2017 2014/09/08 18:32:46 Done.
1887 &BrowserOptionsHandler::MetricsReportingChangeCallback,
1888 base::Unretained(this));
1889 bool enable;
1890 if (!args->GetBoolean(0, &enable))
1891 return;
1892
1893 InitiateMetricsReportingChange(enable, callback_fn);
1894 }
1895
1896 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool success) {
1897 if (!success) {
1898 web_ui()->CallJavascriptFunction(
1899 "BrowserOptions.reverseMetricsReportingState");
1900 }
1901 }
1902
1870 } // namespace options 1903 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698