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

Side by Side Diff: chrome/browser/metrics/metrics_reporting_state.cc

Issue 2793393002: CrOS settings/metrics: Correctly store Subscriptions (Closed)
Patch Set: . Created 3 years, 8 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/metrics/metrics_reporting_state.h" 5 #include "chrome/browser/metrics/metrics_reporting_state.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 11 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
12 #include "chrome/common/crash_keys.h" 12 #include "chrome/common/crash_keys.h"
13 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 #include "chrome/installer/util/google_update_settings.h" 14 #include "chrome/installer/util/google_update_settings.h"
15 #include "components/metrics/metrics_pref_names.h" 15 #include "components/metrics/metrics_pref_names.h"
16 #include "components/metrics/metrics_service.h" 16 #include "components/metrics/metrics_service.h"
17 #include "components/metrics_services_manager/metrics_services_manager.h" 17 #include "components/metrics_services_manager/metrics_services_manager.h"
18 #include "components/prefs/pref_registry_simple.h" 18 #include "components/prefs/pref_registry_simple.h"
19 #include "components/prefs/pref_service.h" 19 #include "components/prefs/pref_service.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 21
22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/chromeos/settings/cros_settings.h"
24 #include "chromeos/settings/cros_settings_names.h"
25 #endif // defined(OS_CHROMEOS)
26
27 namespace { 22 namespace {
28 23
29 enum MetricsReportingChangeHistogramValue { 24 enum MetricsReportingChangeHistogramValue {
30 METRICS_REPORTING_ERROR, 25 METRICS_REPORTING_ERROR,
31 METRICS_REPORTING_DISABLED, 26 METRICS_REPORTING_DISABLED,
32 METRICS_REPORTING_ENABLED, 27 METRICS_REPORTING_ENABLED,
33 METRICS_REPORTING_MAX 28 METRICS_REPORTING_MAX
34 }; 29 };
35 30
36 void RecordMetricsReportingHistogramValue( 31 void RecordMetricsReportingHistogramValue(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 if (to_update_pref == updated_pref) { 67 if (to_update_pref == updated_pref) {
73 RecordMetricsReportingHistogramValue(updated_pref ? 68 RecordMetricsReportingHistogramValue(updated_pref ?
74 METRICS_REPORTING_ENABLED : METRICS_REPORTING_DISABLED); 69 METRICS_REPORTING_ENABLED : METRICS_REPORTING_DISABLED);
75 } else { 70 } else {
76 RecordMetricsReportingHistogramValue(METRICS_REPORTING_ERROR); 71 RecordMetricsReportingHistogramValue(METRICS_REPORTING_ERROR);
77 } 72 }
78 if (!callback_fn.is_null()) 73 if (!callback_fn.is_null())
79 callback_fn.Run(updated_pref); 74 callback_fn.Run(updated_pref);
80 } 75 }
81 76
82 #if defined(OS_CHROMEOS)
83 // Callback function for Chrome OS device settings change, so that the update is
84 // applied to metrics reporting state.
85 void OnDeviceSettingChange() {
86 bool enable_metrics = false;
87 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
88 &enable_metrics);
89 ChangeMetricsReportingState(enable_metrics);
90 }
91 #endif
92
93 } // namespace 77 } // namespace
94 78
95 void ChangeMetricsReportingState(bool enabled) { 79 void ChangeMetricsReportingState(bool enabled) {
96 ChangeMetricsReportingStateWithReply(enabled, 80 ChangeMetricsReportingStateWithReply(enabled,
97 OnMetricsReportingCallbackType()); 81 OnMetricsReportingCallbackType());
98 } 82 }
99 83
100 // TODO(gayane): Instead of checking policy before setting the metrics pref set 84 // TODO(gayane): Instead of checking policy before setting the metrics pref set
101 // the pref and register for notifications for the rest of the changes. 85 // the pref and register for notifications for the rest of the changes.
102 void ChangeMetricsReportingStateWithReply( 86 void ChangeMetricsReportingStateWithReply(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 crash_keys::ClearMetricsClientId(); 120 crash_keys::ClearMetricsClientId();
137 } 121 }
138 } 122 }
139 123
140 bool IsMetricsReportingPolicyManaged() { 124 bool IsMetricsReportingPolicyManaged() {
141 const PrefService* pref_service = g_browser_process->local_state(); 125 const PrefService* pref_service = g_browser_process->local_state();
142 const PrefService::Preference* pref = 126 const PrefService::Preference* pref =
143 pref_service->FindPreference(metrics::prefs::kMetricsReportingEnabled); 127 pref_service->FindPreference(metrics::prefs::kMetricsReportingEnabled);
144 return pref && pref->IsManaged(); 128 return pref && pref->IsManaged();
145 } 129 }
146
147 // TODO(gayane): Add unittest which will check that observer on device settings
148 // will trigger this function and kMetricsReportinEnabled as well as metrics
149 // service state will be updated accordingly.
150 void SetupMetricsStateForChromeOS() {
151 #if defined(OS_CHROMEOS)
152 chromeos::CrosSettings::Get()->AddSettingsObserver(
153 chromeos::kStatsReportingPref, base::Bind(&OnDeviceSettingChange));
154
155 OnDeviceSettingChange();
156 #endif // defined(OS_CHROMEOS)
157 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_reporting_state.h ('k') | chrome/browser/ui/webui/options/browser_options_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698