| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread | 51 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread |
| 52 // because it needs access to IO and cannot work from UI thread. | 52 // because it needs access to IO and cannot work from UI thread. |
| 53 void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { | 53 void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { |
| 54 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, | 54 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, |
| 55 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); | 55 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 MetricsServicesManager::MetricsServicesManager(PrefService* local_state) | 60 MetricsServicesManager::MetricsServicesManager(PrefService* local_state) |
| 61 : local_state_(local_state) { | 61 : local_state_(local_state), |
| 62 may_upload_(false), |
| 63 may_record_(false) { |
| 62 DCHECK(local_state); | 64 DCHECK(local_state); |
| 65 pref_change_registrar_.Init(local_state); |
| 66 pref_change_registrar_.Add(rappor::prefs::kRapporEnabled, |
| 67 base::Bind(&MetricsServicesManager::UpdateRapporService, |
| 68 base::Unretained(this))); |
| 63 } | 69 } |
| 64 | 70 |
| 65 MetricsServicesManager::~MetricsServicesManager() { | 71 MetricsServicesManager::~MetricsServicesManager() { |
| 66 } | 72 } |
| 67 | 73 |
| 68 metrics::MetricsService* MetricsServicesManager::GetMetricsService() { | 74 metrics::MetricsService* MetricsServicesManager::GetMetricsService() { |
| 69 DCHECK(thread_checker_.CalledOnValidThread()); | 75 DCHECK(thread_checker_.CalledOnValidThread()); |
| 70 return GetChromeMetricsServiceClient()->metrics_service(); | 76 return GetChromeMetricsServiceClient()->metrics_service(); |
| 71 } | 77 } |
| 72 | 78 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 rappor::FINE_LEVEL : | 143 rappor::FINE_LEVEL : |
| 138 rappor::COARSE_LEVEL; | 144 rappor::COARSE_LEVEL; |
| 139 } | 145 } |
| 140 } else if (metrics_enabled) { | 146 } else if (metrics_enabled) { |
| 141 recording_level = rappor::FINE_LEVEL; | 147 recording_level = rappor::FINE_LEVEL; |
| 142 } | 148 } |
| 143 #endif // defined(GOOGLE_CHROME_BUILD) | 149 #endif // defined(GOOGLE_CHROME_BUILD) |
| 144 return recording_level; | 150 return recording_level; |
| 145 } | 151 } |
| 146 | 152 |
| 153 void MetricsServicesManager::UpdateRapporService() { |
| 154 GetRapporService()->Update(GetRapporRecordingLevel(may_record_), may_upload_); |
| 155 } |
| 156 |
| 147 void MetricsServicesManager::UpdatePermissions(bool may_record, | 157 void MetricsServicesManager::UpdatePermissions(bool may_record, |
| 148 bool may_upload) { | 158 bool may_upload) { |
| 159 // Stash the current permissions so that we can update the RapporService |
| 160 // correctly when the Rappor preference changes. The metrics recording |
| 161 // preference partially determines the initial rappor setting, and also |
| 162 // controls whether FINE metrics are sent. |
| 163 may_record_ = may_record; |
| 164 may_upload_ = may_upload; |
| 165 |
| 149 metrics::MetricsService* metrics = GetMetricsService(); | 166 metrics::MetricsService* metrics = GetMetricsService(); |
| 150 | 167 |
| 151 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 168 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 152 | 169 |
| 153 const bool only_do_metrics_recording = | 170 const bool only_do_metrics_recording = |
| 154 cmdline->HasSwitch(switches::kMetricsRecordingOnly) || | 171 cmdline->HasSwitch(switches::kMetricsRecordingOnly) || |
| 155 cmdline->HasSwitch(switches::kEnableBenchmarking); | 172 cmdline->HasSwitch(switches::kEnableBenchmarking); |
| 156 | 173 |
| 157 if (only_do_metrics_recording) { | 174 if (only_do_metrics_recording) { |
| 158 metrics->StartRecordingForTests(); | 175 metrics->StartRecordingForTests(); |
| 159 GetRapporService()->Update(rappor::FINE_LEVEL, false); | 176 GetRapporService()->Update(rappor::FINE_LEVEL, false); |
| 160 return; | 177 return; |
| 161 } | 178 } |
| 162 | 179 |
| 163 if (may_record) { | 180 if (may_record) { |
| 164 if (!metrics->recording_active()) | 181 if (!metrics->recording_active()) |
| 165 metrics->Start(); | 182 metrics->Start(); |
| 166 | 183 |
| 167 if (may_upload) | 184 if (may_upload) |
| 168 metrics->EnableReporting(); | 185 metrics->EnableReporting(); |
| 169 else | 186 else |
| 170 metrics->DisableReporting(); | 187 metrics->DisableReporting(); |
| 171 } else if (metrics->recording_active() || metrics->reporting_active()) { | 188 } else if (metrics->recording_active() || metrics->reporting_active()) { |
| 172 metrics->Stop(); | 189 metrics->Stop(); |
| 173 } | 190 } |
| 174 | 191 |
| 175 GetRapporService()->Update(GetRapporRecordingLevel(may_record), may_upload); | 192 UpdateRapporService(); |
| 176 } | 193 } |
| 177 | 194 |
| 178 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { | 195 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { |
| 179 return UpdatePermissions( | 196 return UpdatePermissions( |
| 180 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled(), may_upload); | 197 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled(), may_upload); |
| 181 } | 198 } |
| OLD | NEW |