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

Unified Diff: chrome/browser/ui/webui/options/browser_options_handler.cc

Issue 1411863002: Use kMetricsReportingEnabled instead of kStatsReporingPref on metrics side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add default value for device setting Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/options/browser_options_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/options/browser_options_handler.cc
diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc
index 095cb140bad0edcd1256c1aded02dabeda9cd85e..3a93fbc1b172fd1a96240af684246f89913c9628 100644
--- a/chrome/browser/ui/webui/options/browser_options_handler.cc
+++ b/chrome/browser/ui/webui/options/browser_options_handler.cc
@@ -569,11 +569,9 @@ void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue* values) {
values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL);
-#if !defined(OS_CHROMEOS)
values->SetBoolean(
"metricsReportingEnabledAtStart",
ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
-#endif
#if defined(OS_CHROMEOS)
// TODO(pastarmovj): replace this with a call to the CrosSettings list
@@ -2074,14 +2072,18 @@ void BrowserOptionsHandler::SetupExtensionControlledIndicators() {
}
void BrowserOptionsHandler::SetupMetricsReportingCheckbox() {
- // This function does not work for ChromeOS and non-official builds.
-#if !defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
+// As the metrics and crash reporting checkbox only exists for official builds
+// it doesn't need to be set up for non-official builds.
+#if defined(GOOGLE_CHROME_BUILD)
bool checked =
ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled();
- bool disabled = !IsMetricsReportingUserChangable();
-
- SetMetricsReportingCheckbox(checked, disabled);
-#endif
+ bool policy_managed = IsMetricsReportingPolicyManaged();
+ bool owner_managed = false;
+#if defined(OS_CHROMEOS)
+ owner_managed = !IsDeviceOwnerProfile();
+#endif // defined(OS_CHROMEOS)
+ SetMetricsReportingCheckbox(checked, policy_managed, owner_managed);
+#endif // defined(GOOGLE_CHROME_BUILD)
}
void BrowserOptionsHandler::HandleMetricsReportingChange(
@@ -2089,23 +2091,43 @@ void BrowserOptionsHandler::HandleMetricsReportingChange(
bool enable;
if (!args->GetBoolean(0, &enable))
return;
+ // Decline the change if current user shouldn't be able to change metrics
+ // reporting.
+ if (!IsDeviceOwnerProfile() || IsMetricsReportingPolicyManaged()) {
+ NotifyUIOfMetricsReportingChange(
+ ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
+ return;
+ }
+// For Chrome OS updating device settings will notify an observer to update
+// metrics pref, however we still need to call |InitiateMetricsReportingChange|
+// with a proper callback so that UI gets updated in case of failure to update
+// the metrics pref.
+// TODO(gayane): Don't call |InitiateMetricsReportingChange| twice so that
+// metrics service pref changes only as a result of device settings change for
+// Chrome OS .crbug.com/552550.
+#if defined(OS_CHROMEOS)
+ chromeos::CrosSettings::Get()->SetBoolean(chromeos::kStatsReportingPref,
+ enable);
+#endif // defined(OS_CHROMEOS)
InitiateMetricsReportingChange(
enable,
- base::Bind(&BrowserOptionsHandler::MetricsReportingChangeCallback,
+ base::Bind(&BrowserOptionsHandler::NotifyUIOfMetricsReportingChange,
base::Unretained(this)));
}
-void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled) {
- SetMetricsReportingCheckbox(enabled, !IsMetricsReportingUserChangable());
+void BrowserOptionsHandler::NotifyUIOfMetricsReportingChange(bool enabled) {
+ SetMetricsReportingCheckbox(enabled, IsMetricsReportingPolicyManaged(),
+ !IsDeviceOwnerProfile());
}
void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked,
- bool disabled) {
+ bool policy_managed,
+ bool owner_managed) {
web_ui()->CallJavascriptFunction(
"BrowserOptions.setMetricsReportingCheckboxState",
- base::FundamentalValue(checked),
- base::FundamentalValue(disabled));
+ base::FundamentalValue(checked), base::FundamentalValue(policy_managed),
+ base::FundamentalValue(owner_managed));
}
void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
@@ -2117,4 +2139,12 @@ void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
SetupMetricsReportingCheckbox();
}
+bool BrowserOptionsHandler::IsDeviceOwnerProfile() {
+#if defined(OS_CHROMEOS)
+ return chromeos::ProfileHelper::IsOwnerProfile(Profile::FromWebUI(web_ui()));
+#else
+ return true;
+#endif
+}
+
} // namespace options
« no previous file with comments | « chrome/browser/ui/webui/options/browser_options_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698