Chromium Code Reviews| 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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread | 49 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread |
| 50 // because it needs access to IO and cannot work from UI thread. | 50 // because it needs access to IO and cannot work from UI thread. |
| 51 void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { | 51 void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { |
| 52 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, | 52 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, |
| 53 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); | 53 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 MetricsServicesManager::MetricsServicesManager(PrefService* local_state) | 58 MetricsServicesManager::MetricsServicesManager(PrefService* local_state) |
| 59 : local_state_(local_state) { | 59 : local_state_(local_state), |
| 60 may_upload_(false), | |
| 61 may_record_(false) { | |
| 60 DCHECK(local_state); | 62 DCHECK(local_state); |
| 63 pref_change_registrar_.Init(local_state); | |
| 64 pref_change_registrar_.Add(rappor::prefs::kRapporEnabled, | |
| 65 base::Bind(&MetricsServicesManager::UpdateRapporService, | |
| 66 base::Unretained(this))); | |
|
Alexei Svitkine (slow)
2015/02/19 15:04:58
Don't use Unretained. Instead, use a weak pointer
Steven Holte
2015/02/19 20:25:12
I'm not sure I understand the logic here. Why her
Alexei Svitkine (slow)
2015/02/19 20:32:01
You're right.
I was thinking of the case where th
| |
| 61 } | 67 } |
| 62 | 68 |
| 63 MetricsServicesManager::~MetricsServicesManager() { | 69 MetricsServicesManager::~MetricsServicesManager() { |
| 64 } | 70 } |
| 65 | 71 |
| 66 metrics::MetricsService* MetricsServicesManager::GetMetricsService() { | 72 metrics::MetricsService* MetricsServicesManager::GetMetricsService() { |
| 67 DCHECK(thread_checker_.CalledOnValidThread()); | 73 DCHECK(thread_checker_.CalledOnValidThread()); |
| 68 return GetChromeMetricsServiceClient()->metrics_service(); | 74 return GetChromeMetricsServiceClient()->metrics_service(); |
| 69 } | 75 } |
| 70 | 76 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 if (IsRapporEnabled(metrics_enabled)) { | 146 if (IsRapporEnabled(metrics_enabled)) { |
| 141 recording_level = metrics_enabled ? | 147 recording_level = metrics_enabled ? |
| 142 rappor::FINE_LEVEL : | 148 rappor::FINE_LEVEL : |
| 143 rappor::COARSE_LEVEL; | 149 rappor::COARSE_LEVEL; |
| 144 } | 150 } |
| 145 #endif // defined(OS_IOS) || defined(OS_ANDROID) | 151 #endif // defined(OS_IOS) || defined(OS_ANDROID) |
| 146 #endif // defined(GOOGLE_CHROME_BUILD) | 152 #endif // defined(GOOGLE_CHROME_BUILD) |
| 147 return recording_level; | 153 return recording_level; |
| 148 } | 154 } |
| 149 | 155 |
| 156 void MetricsServicesManager::UpdateRapporService() { | |
| 157 GetRapporService()->Update(GetRapporRecordingLevel(may_record_), may_upload_); | |
|
Alexei Svitkine (slow)
2015/02/19 15:04:58
I don't understand this.
Now that RAPPOR has its
Alexei Svitkine (slow)
2015/02/19 15:13:45
Ah, just read your other CL and it makes sense now
Steven Holte
2015/02/19 20:25:12
That's not the only reason. Even with the new rap
Alexei Svitkine (slow)
2015/02/19 20:32:01
Acknowledged.
| |
| 158 } | |
| 159 | |
| 150 void MetricsServicesManager::UpdatePermissions(bool may_record, | 160 void MetricsServicesManager::UpdatePermissions(bool may_record, |
| 151 bool may_upload) { | 161 bool may_upload) { |
| 162 may_record_ = may_record; | |
| 163 may_upload_ = may_upload; | |
| 164 | |
| 152 metrics::MetricsService* metrics = GetMetricsService(); | 165 metrics::MetricsService* metrics = GetMetricsService(); |
| 153 | 166 |
| 154 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 167 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 155 | 168 |
| 156 const bool only_do_metrics_recording = | 169 const bool only_do_metrics_recording = |
| 157 cmdline->HasSwitch(switches::kMetricsRecordingOnly) || | 170 cmdline->HasSwitch(switches::kMetricsRecordingOnly) || |
| 158 cmdline->HasSwitch(switches::kEnableBenchmarking); | 171 cmdline->HasSwitch(switches::kEnableBenchmarking); |
| 159 | 172 |
| 160 if (only_do_metrics_recording) { | 173 if (only_do_metrics_recording) { |
| 161 metrics->StartRecordingForTests(); | 174 metrics->StartRecordingForTests(); |
| 162 GetRapporService()->Update(rappor::FINE_LEVEL, false); | 175 GetRapporService()->Update(rappor::FINE_LEVEL, false); |
| 163 return; | 176 return; |
| 164 } | 177 } |
| 165 | 178 |
| 166 if (may_record) { | 179 if (may_record) { |
| 167 if (!metrics->recording_active()) | 180 if (!metrics->recording_active()) |
| 168 metrics->Start(); | 181 metrics->Start(); |
| 169 | 182 |
| 170 if (may_upload) | 183 if (may_upload) |
| 171 metrics->EnableReporting(); | 184 metrics->EnableReporting(); |
| 172 else | 185 else |
| 173 metrics->DisableReporting(); | 186 metrics->DisableReporting(); |
| 174 } else if (metrics->recording_active() || metrics->reporting_active()) { | 187 } else if (metrics->recording_active() || metrics->reporting_active()) { |
| 175 metrics->Stop(); | 188 metrics->Stop(); |
| 176 } | 189 } |
| 177 | 190 |
| 178 GetRapporService()->Update(GetRapporRecordingLevel(may_record), may_upload); | 191 UpdateRapporService(); |
| 179 } | 192 } |
| 180 | 193 |
| 181 // TODO(asvitkine): This function does not report the correct value on Android, | 194 // TODO(asvitkine): This function does not report the correct value on Android, |
| 182 // see http://crbug.com/362192. | 195 // see http://crbug.com/362192. |
| 183 bool MetricsServicesManager::IsMetricsReportingEnabled() const { | 196 bool MetricsServicesManager::IsMetricsReportingEnabled() const { |
| 184 // If the user permits metrics reporting with the checkbox in the | 197 // If the user permits metrics reporting with the checkbox in the |
| 185 // prefs, we turn on recording. We disable metrics completely for | 198 // prefs, we turn on recording. We disable metrics completely for |
| 186 // non-official builds, or when field trials are forced. | 199 // non-official builds, or when field trials are forced. |
| 187 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 200 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 188 switches::kForceFieldTrials)) | 201 switches::kForceFieldTrials)) |
| 189 return false; | 202 return false; |
| 190 | 203 |
| 191 bool enabled = false; | 204 bool enabled = false; |
| 192 #if defined(GOOGLE_CHROME_BUILD) | 205 #if defined(GOOGLE_CHROME_BUILD) |
| 193 #if defined(OS_CHROMEOS) | 206 #if defined(OS_CHROMEOS) |
| 194 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, | 207 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, |
| 195 &enabled); | 208 &enabled); |
| 196 #else | 209 #else |
| 197 enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled); | 210 enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled); |
| 198 #endif // #if defined(OS_CHROMEOS) | 211 #endif // #if defined(OS_CHROMEOS) |
| 199 #endif // defined(GOOGLE_CHROME_BUILD) | 212 #endif // defined(GOOGLE_CHROME_BUILD) |
| 200 return enabled; | 213 return enabled; |
| 201 } | 214 } |
| OLD | NEW |