| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 #endif | 118 #endif |
| 119 // Posts to FILE thread as SetGoogleUpdateSettings does IO operations. | 119 // Posts to FILE thread as SetGoogleUpdateSettings does IO operations. |
| 120 content::BrowserThread::PostTaskAndReplyWithResult( | 120 content::BrowserThread::PostTaskAndReplyWithResult( |
| 121 content::BrowserThread::FILE, | 121 content::BrowserThread::FILE, |
| 122 FROM_HERE, | 122 FROM_HERE, |
| 123 base::Bind(&SetGoogleUpdateSettings, enabled), | 123 base::Bind(&SetGoogleUpdateSettings, enabled), |
| 124 base::Bind(&SetMetricsReporting, enabled, callback_fn)); | 124 base::Bind(&SetMetricsReporting, enabled, callback_fn)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void RegisterMetricsReportingStatePrefs(PrefRegistrySimple* registry) { | |
| 128 registry->RegisterIntegerPref(prefs::kMetricsDefaultOptIn, | |
| 129 metrics::MetricsServiceClient::DEFAULT_UNKNOWN); | |
| 130 } | |
| 131 | |
| 132 bool IsMetricsReportingPolicyManaged() { | 127 bool IsMetricsReportingPolicyManaged() { |
| 133 const PrefService* pref_service = g_browser_process->local_state(); | 128 const PrefService* pref_service = g_browser_process->local_state(); |
| 134 const PrefService::Preference* pref = | 129 const PrefService::Preference* pref = |
| 135 pref_service->FindPreference(metrics::prefs::kMetricsReportingEnabled); | 130 pref_service->FindPreference(metrics::prefs::kMetricsReportingEnabled); |
| 136 return pref && pref->IsManaged(); | 131 return pref && pref->IsManaged(); |
| 137 } | 132 } |
| 138 | 133 |
| 139 void RecordMetricsReportingDefaultOptIn(PrefService* local_state, bool opt_in) { | |
| 140 DCHECK(GetMetricsReportingDefaultOptIn(local_state) == | |
| 141 metrics::MetricsServiceClient::DEFAULT_UNKNOWN); | |
| 142 local_state->SetInteger(prefs::kMetricsDefaultOptIn, | |
| 143 opt_in ? metrics::MetricsServiceClient::OPT_IN | |
| 144 : metrics::MetricsServiceClient::OPT_OUT); | |
| 145 } | |
| 146 | |
| 147 metrics::MetricsServiceClient::EnableMetricsDefault | |
| 148 GetMetricsReportingDefaultOptIn(PrefService* local_state) { | |
| 149 return static_cast<metrics::MetricsServiceClient::EnableMetricsDefault>( | |
| 150 local_state->GetInteger(prefs::kMetricsDefaultOptIn)); | |
| 151 } | |
| 152 | |
| 153 // TODO(gayane): Add unittest which will check that observer on device settings | 134 // TODO(gayane): Add unittest which will check that observer on device settings |
| 154 // will trigger this function and kMetricsReportinEnabled as well as metrics | 135 // will trigger this function and kMetricsReportinEnabled as well as metrics |
| 155 // service state will be updated accordingly. | 136 // service state will be updated accordingly. |
| 156 void SetupMetricsStateForChromeOS() { | 137 void SetupMetricsStateForChromeOS() { |
| 157 #if defined(OS_CHROMEOS) | 138 #if defined(OS_CHROMEOS) |
| 158 chromeos::CrosSettings::Get()->AddSettingsObserver( | 139 chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 159 chromeos::kStatsReportingPref, base::Bind(&OnDeviceSettingChange)); | 140 chromeos::kStatsReportingPref, base::Bind(&OnDeviceSettingChange)); |
| 160 | 141 |
| 161 OnDeviceSettingChange(); | 142 OnDeviceSettingChange(); |
| 162 #endif // defined(OS_CHROMEOS) | 143 #endif // defined(OS_CHROMEOS) |
| 163 } | 144 } |
| OLD | NEW |