Chromium Code Reviews| Index: chrome/browser/metrics/metrics_reporting_state.cc |
| diff --git a/chrome/browser/metrics/metrics_reporting_state.cc b/chrome/browser/metrics/metrics_reporting_state.cc |
| index 0666443ab7fedd295dff34b461a5296985cffb99..f3b975fe89f0d0535f637b80db69efa97036ff5d 100644 |
| --- a/chrome/browser/metrics/metrics_reporting_state.cc |
| +++ b/chrome/browser/metrics/metrics_reporting_state.cc |
| @@ -14,6 +14,11 @@ |
| #include "components/metrics/metrics_service.h" |
| #include "content/public/browser/browser_thread.h" |
| +#if defined(OS_CHROMEOS) |
| +#include "chrome/browser/chromeos/settings/cros_settings.h" |
| +#include "chromeos/settings/cros_settings_names.h" |
| +#endif // defined(OS_CHROMEOS) |
| + |
| namespace { |
| enum MetricsReportingChangeHistogramValue { |
| @@ -58,10 +63,12 @@ void SetMetricsReporting(bool to_update_pref, |
| else |
| metrics->Stop(); |
| } |
| -#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| + |
| +#if !defined(OS_ANDROID) |
| g_browser_process->local_state()->SetBoolean( |
| metrics::prefs::kMetricsReportingEnabled, updated_pref); |
| -#endif |
| +#endif // !defined(OS_ANDROID) |
| + |
| // When a user opts in to the metrics reporting service, the previously |
| // collected data should be cleared to ensure that nothing is reported before |
| // a user opts in and all reported data is accurate. |
| @@ -78,13 +85,24 @@ void SetMetricsReporting(bool to_update_pref, |
| callback_fn.Run(updated_pref); |
| } |
| +#if defined(OS_CHROMEOS) |
| +void onDeviceSettingChange() { |
|
Alexei Svitkine (slow)
2015/11/03 23:18:23
Nit: Capitalize. Also, add a comment.
gayane -on leave until 09-2017
2015/11/05 18:53:32
Done.
|
| + bool enable_metrics = false; |
| + chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, |
| + &enable_metrics); |
| + InitiateMetricsReportingChange(enable_metrics, |
| + OnMetricsReportingCallbackType()); |
| +} |
| +#endif |
| } // namespace |
|
Alexei Svitkine (slow)
2015/11/03 23:18:23
Nit: Add an empty line above.
gayane -on leave until 09-2017
2015/11/05 18:53:32
Done.
|
| +// TODO(gayane): Instead of checking policy before setting the metrics pref set |
| +// the pref and register for notifications for the rest of the changes. |
| void InitiateMetricsReportingChange( |
| bool enabled, |
| const OnMetricsReportingCallbackType& callback_fn) { |
| -#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| - if (!IsMetricsReportingUserChangable()) { |
| +#if !defined(OS_ANDROID) |
| + if (IsMetricsReportingPolicyManaged()) { |
| if (!callback_fn.is_null()) { |
| callback_fn.Run( |
| ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); |
| @@ -100,9 +118,18 @@ void InitiateMetricsReportingChange( |
| base::Bind(&SetMetricsReporting, enabled, callback_fn)); |
| } |
| -bool IsMetricsReportingUserChangable() { |
| +bool IsMetricsReportingPolicyManaged() { |
| const PrefService* pref_service = g_browser_process->local_state(); |
| const PrefService::Preference* pref = |
| pref_service->FindPreference(metrics::prefs::kMetricsReportingEnabled); |
| - return pref && !pref->IsManaged(); |
| + return pref && pref->IsManaged(); |
| +} |
| + |
| +void SetupMetricsStateForChromeOS() { |
| +#if defined(OS_CHROMEOS) |
| + chromeos::CrosSettings::Get()->AddSettingsObserver( |
| + chromeos::kStatsReportingPref, base::Bind(&onDeviceSettingChange)); |
|
Alexei Svitkine (slow)
2015/11/03 23:18:23
Is it possible to add a unit test for this?
i.e.
gayane -on leave until 09-2017
2015/11/05 18:53:32
As to discussion, I added a TODO to add unittests
|
| + |
| + onDeviceSettingChange(); |
| +#endif // defined(OS_CHROMEOS) |
| } |