OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_services_manager.h" | 5 #include "chrome/browser/metrics/metrics_services_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
13 #include "chrome/browser/metrics/chrome_metrics_service_client.h" | 14 #include "chrome/browser/metrics/chrome_metrics_service_client.h" |
14 #include "chrome/browser/metrics/variations/variations_service.h" | 15 #include "chrome/browser/metrics/variations/variations_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/ui/browser_otr_state.h" | 18 #include "chrome/browser/ui/browser_otr_state.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "chrome/installer/util/google_update_settings.h" | 21 #include "chrome/installer/util/google_update_settings.h" |
21 #include "components/metrics/metrics_service.h" | 22 #include "components/metrics/metrics_service.h" |
22 #include "components/metrics/metrics_state_manager.h" | 23 #include "components/metrics/metrics_state_manager.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 GetMetricsStateManager(), local_state_); | 103 GetMetricsStateManager(), local_state_); |
103 } | 104 } |
104 return metrics_service_client_.get(); | 105 return metrics_service_client_.get(); |
105 } | 106 } |
106 | 107 |
107 metrics::MetricsStateManager* MetricsServicesManager::GetMetricsStateManager() { | 108 metrics::MetricsStateManager* MetricsServicesManager::GetMetricsStateManager() { |
108 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
109 if (!metrics_state_manager_) { | 110 if (!metrics_state_manager_) { |
110 metrics_state_manager_ = metrics::MetricsStateManager::Create( | 111 metrics_state_manager_ = metrics::MetricsStateManager::Create( |
111 local_state_, | 112 local_state_, |
112 base::Bind(&MetricsServicesManager::IsMetricsReportingEnabled, | 113 base::Bind(&ChromeMetricsServiceAccessor::IsMetricsReportingEnabled), |
113 base::Unretained(this)), | |
114 base::Bind(&PostStoreMetricsClientInfo), | 114 base::Bind(&PostStoreMetricsClientInfo), |
115 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); | 115 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); |
116 } | 116 } |
117 return metrics_state_manager_.get(); | 117 return metrics_state_manager_.get(); |
118 } | 118 } |
119 | 119 |
120 bool MetricsServicesManager::IsRapporEnabled(bool metrics_enabled) const { | 120 bool MetricsServicesManager::IsRapporEnabled(bool metrics_enabled) const { |
121 if (!local_state_->HasPrefPath(rappor::prefs::kRapporEnabled)) { | 121 if (!local_state_->HasPrefPath(rappor::prefs::kRapporEnabled)) { |
122 // For upgrading users, derive an initial setting from UMA / safe browsing. | 122 // For upgrading users, derive an initial setting from UMA / safe browsing. |
123 bool should_enable = metrics_enabled || CheckSafeBrowsingSettings(); | 123 bool should_enable = metrics_enabled || CheckSafeBrowsingSettings(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 metrics->EnableReporting(); | 171 metrics->EnableReporting(); |
172 else | 172 else |
173 metrics->DisableReporting(); | 173 metrics->DisableReporting(); |
174 } else if (metrics->recording_active() || metrics->reporting_active()) { | 174 } else if (metrics->recording_active() || metrics->reporting_active()) { |
175 metrics->Stop(); | 175 metrics->Stop(); |
176 } | 176 } |
177 | 177 |
178 GetRapporService()->Update(GetRapporRecordingLevel(may_record), may_upload); | 178 GetRapporService()->Update(GetRapporRecordingLevel(may_record), may_upload); |
179 } | 179 } |
180 | 180 |
181 // TODO(asvitkine): This function does not report the correct value on Android, | 181 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { |
182 // see http://crbug.com/362192. | 182 return UpdatePermissions( |
183 bool MetricsServicesManager::IsMetricsReportingEnabled() const { | 183 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled(), may_upload); |
184 // If the user permits metrics reporting with the checkbox in the | |
185 // prefs, we turn on recording. We disable metrics completely for | |
186 // non-official builds, or when field trials are forced. | |
187 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
188 switches::kForceFieldTrials)) | |
189 return false; | |
190 | |
191 bool enabled = false; | |
192 #if defined(GOOGLE_CHROME_BUILD) | |
193 #if defined(OS_CHROMEOS) | |
194 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, | |
195 &enabled); | |
196 #else | |
197 enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled); | |
198 #endif // #if defined(OS_CHROMEOS) | |
199 #endif // defined(GOOGLE_CHROME_BUILD) | |
200 return enabled; | |
201 } | 184 } |
OLD | NEW |