| 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 "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 void SetMetricsReporting(bool to_update_pref, | 51 void SetMetricsReporting(bool to_update_pref, |
| 52 const OnMetricsReportingCallbackType& callback_fn, | 52 const OnMetricsReportingCallbackType& callback_fn, |
| 53 bool updated_pref) { | 53 bool updated_pref) { |
| 54 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 54 metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
| 55 if (metrics) { | 55 if (metrics) { |
| 56 if (updated_pref) | 56 if (updated_pref) |
| 57 metrics->Start(); | 57 metrics->Start(); |
| 58 else | 58 else |
| 59 metrics->Stop(); | 59 metrics->Stop(); |
| 60 } | 60 } |
| 61 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 61 #if !defined(OS_ANDROID) |
| 62 g_browser_process->local_state()->SetBoolean( | 62 g_browser_process->local_state()->SetBoolean( |
| 63 metrics::prefs::kMetricsReportingEnabled, updated_pref); | 63 metrics::prefs::kMetricsReportingEnabled, updated_pref); |
| 64 #endif | 64 #endif |
| 65 // When a user opts in to the metrics reporting service, the previously | 65 // When a user opts in to the metrics reporting service, the previously |
| 66 // collected data should be cleared to ensure that nothing is reported before | 66 // collected data should be cleared to ensure that nothing is reported before |
| 67 // a user opts in and all reported data is accurate. | 67 // a user opts in and all reported data is accurate. |
| 68 if (updated_pref && metrics) | 68 if (updated_pref && metrics) |
| 69 metrics->ClearSavedStabilityMetrics(); | 69 metrics->ClearSavedStabilityMetrics(); |
| 70 | 70 |
| 71 if (to_update_pref == updated_pref) { | 71 if (to_update_pref == updated_pref) { |
| 72 RecordMetricsReportingHistogramValue(updated_pref ? | 72 RecordMetricsReportingHistogramValue(updated_pref ? |
| 73 METRICS_REPORTING_ENABLED : METRICS_REPORTING_DISABLED); | 73 METRICS_REPORTING_ENABLED : METRICS_REPORTING_DISABLED); |
| 74 } else { | 74 } else { |
| 75 RecordMetricsReportingHistogramValue(METRICS_REPORTING_ERROR); | 75 RecordMetricsReportingHistogramValue(METRICS_REPORTING_ERROR); |
| 76 } | 76 } |
| 77 if (!callback_fn.is_null()) | 77 if (!callback_fn.is_null()) |
| 78 callback_fn.Run(updated_pref); | 78 callback_fn.Run(updated_pref); |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| 83 void InitiateMetricsReportingChange( | 83 void InitiateMetricsReportingChange( |
| 84 bool enabled, | 84 bool enabled, |
| 85 const OnMetricsReportingCallbackType& callback_fn) { | 85 const OnMetricsReportingCallbackType& callback_fn) { |
| 86 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 86 #if !defined(OS_ANDROID) |
| 87 if (!IsMetricsReportingUserChangable()) { | 87 if (IsMetricsReportingPolicyManaged()) { |
| 88 if (!callback_fn.is_null()) { | 88 if (!callback_fn.is_null()) { |
| 89 callback_fn.Run( | 89 callback_fn.Run( |
| 90 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); | 90 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); |
| 91 } | 91 } |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 #endif | 94 #endif |
| 95 // Posts to FILE thread as SetGoogleUpdateSettings does IO operations. | 95 // Posts to FILE thread as SetGoogleUpdateSettings does IO operations. |
| 96 content::BrowserThread::PostTaskAndReplyWithResult( | 96 content::BrowserThread::PostTaskAndReplyWithResult( |
| 97 content::BrowserThread::FILE, | 97 content::BrowserThread::FILE, |
| 98 FROM_HERE, | 98 FROM_HERE, |
| 99 base::Bind(&SetGoogleUpdateSettings, enabled), | 99 base::Bind(&SetGoogleUpdateSettings, enabled), |
| 100 base::Bind(&SetMetricsReporting, enabled, callback_fn)); | 100 base::Bind(&SetMetricsReporting, enabled, callback_fn)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool IsMetricsReportingUserChangable() { | 103 bool IsMetricsReportingPolicyManaged() { |
| 104 const PrefService* pref_service = g_browser_process->local_state(); | 104 const PrefService* pref_service = g_browser_process->local_state(); |
| 105 const PrefService::Preference* pref = | 105 const PrefService::Preference* pref = |
| 106 pref_service->FindPreference(metrics::prefs::kMetricsReportingEnabled); | 106 pref_service->FindPreference(metrics::prefs::kMetricsReportingEnabled); |
| 107 return pref && !pref->IsManaged(); | 107 return pref && pref->IsManaged(); |
| 108 } | 108 } |
| OLD | NEW |