OLD | NEW |
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.h" | 8 #include "base/metrics/histogram.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" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 void SetMetricsReporting(bool to_update_pref, | 60 void SetMetricsReporting(bool to_update_pref, |
61 const OnMetricsReportingCallbackType& callback_fn, | 61 const OnMetricsReportingCallbackType& callback_fn, |
62 bool updated_pref) { | 62 bool updated_pref) { |
63 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 63 metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
64 | 64 |
65 #if !defined(OS_ANDROID) | 65 #if !defined(OS_ANDROID) |
66 g_browser_process->local_state()->SetBoolean( | 66 g_browser_process->local_state()->SetBoolean( |
67 metrics::prefs::kMetricsReportingEnabled, updated_pref); | 67 metrics::prefs::kMetricsReportingEnabled, updated_pref); |
68 #endif // !defined(OS_ANDROID) | 68 #endif // !defined(OS_ANDROID) |
69 | 69 |
70 // Uses the current state of whether reporting is enabled to enabled services. | 70 // Clear the client id pref when opting out. Note: Mirrors code in |
| 71 // uma_session_stats.cc. TODO(asvitkine): Unify. |
| 72 if (!updated_pref) { |
| 73 // Note: Clearing client id will not affect the running state (e.g. field |
| 74 // trial randomization), as the pref is only read on startup. |
| 75 g_browser_process->local_state()->ClearPref( |
| 76 metrics::prefs::kMetricsClientID); |
| 77 g_browser_process->local_state()->ClearPref( |
| 78 metrics::prefs::kMetricsReportingEnabledTimestamp); |
| 79 } |
| 80 |
| 81 // Uses the current state of whether reporting is enabled to enable services. |
71 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(true); | 82 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(true); |
72 | 83 |
73 // When a user opts in to the metrics reporting service, the previously | 84 // When a user opts in to the metrics reporting service, the previously |
74 // collected data should be cleared to ensure that nothing is reported before | 85 // collected data should be cleared to ensure that nothing is reported before |
75 // a user opts in and all reported data is accurate. | 86 // a user opts in and all reported data is accurate. |
| 87 // TODO(asvitkine): This logic should be added to uma_session_stats.cc too. |
76 if (updated_pref && metrics) | 88 if (updated_pref && metrics) |
77 metrics->ClearSavedStabilityMetrics(); | 89 metrics->ClearSavedStabilityMetrics(); |
78 | 90 |
79 if (to_update_pref == updated_pref) { | 91 if (to_update_pref == updated_pref) { |
80 RecordMetricsReportingHistogramValue(updated_pref ? | 92 RecordMetricsReportingHistogramValue(updated_pref ? |
81 METRICS_REPORTING_ENABLED : METRICS_REPORTING_DISABLED); | 93 METRICS_REPORTING_ENABLED : METRICS_REPORTING_DISABLED); |
82 } else { | 94 } else { |
83 RecordMetricsReportingHistogramValue(METRICS_REPORTING_ERROR); | 95 RecordMetricsReportingHistogramValue(METRICS_REPORTING_ERROR); |
84 } | 96 } |
85 if (!callback_fn.is_null()) | 97 if (!callback_fn.is_null()) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // will trigger this function and kMetricsReportinEnabled as well as metrics | 149 // will trigger this function and kMetricsReportinEnabled as well as metrics |
138 // service state will be updated accordingly. | 150 // service state will be updated accordingly. |
139 void SetupMetricsStateForChromeOS() { | 151 void SetupMetricsStateForChromeOS() { |
140 #if defined(OS_CHROMEOS) | 152 #if defined(OS_CHROMEOS) |
141 chromeos::CrosSettings::Get()->AddSettingsObserver( | 153 chromeos::CrosSettings::Get()->AddSettingsObserver( |
142 chromeos::kStatsReportingPref, base::Bind(&OnDeviceSettingChange)); | 154 chromeos::kStatsReportingPref, base::Bind(&OnDeviceSettingChange)); |
143 | 155 |
144 OnDeviceSettingChange(); | 156 OnDeviceSettingChange(); |
145 #endif // defined(OS_CHROMEOS) | 157 #endif // defined(OS_CHROMEOS) |
146 } | 158 } |
OLD | NEW |