| 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 "components/metrics_services_manager/metrics_services_manager.h" | 5 #include "components/metrics_services_manager/metrics_services_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "components/metrics/metrics_service.h" | 10 #include "components/metrics/metrics_service.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 may_upload_ = current_may_upload; | 98 may_upload_ = current_may_upload; |
| 99 UpdateRunningServices(); | 99 UpdateRunningServices(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void MetricsServicesManager::UpdateRunningServices() { | 102 void MetricsServicesManager::UpdateRunningServices() { |
| 103 DCHECK(thread_checker_.CalledOnValidThread()); | 103 DCHECK(thread_checker_.CalledOnValidThread()); |
| 104 metrics::MetricsService* metrics = GetMetricsService(); | 104 metrics::MetricsService* metrics = GetMetricsService(); |
| 105 | 105 |
| 106 if (client_->OnlyDoMetricsRecording()) { | 106 if (client_->OnlyDoMetricsRecording()) { |
| 107 metrics->StartRecordingForTests(); | 107 metrics->StartRecordingForTests(); |
| 108 GetRapporServiceImpl()->Update( | 108 GetRapporServiceImpl()->Update(true, false); |
| 109 rappor::UMA_RAPPOR_GROUP | rappor::SAFEBROWSING_RAPPOR_GROUP, false); | |
| 110 return; | 109 return; |
| 111 } | 110 } |
| 112 | 111 |
| 113 client_->UpdateRunningServices(may_record_, may_upload_); | 112 client_->UpdateRunningServices(may_record_, may_upload_); |
| 114 | 113 |
| 115 if (may_record_) { | 114 if (may_record_) { |
| 116 if (!metrics->recording_active()) | 115 if (!metrics->recording_active()) |
| 117 metrics->Start(); | 116 metrics->Start(); |
| 118 if (may_upload_) | 117 if (may_upload_) |
| 119 metrics->EnableReporting(); | 118 metrics->EnableReporting(); |
| 120 else | 119 else |
| 121 metrics->DisableReporting(); | 120 metrics->DisableReporting(); |
| 122 } else { | 121 } else { |
| 123 metrics->Stop(); | 122 metrics->Stop(); |
| 124 } | 123 } |
| 125 | 124 |
| 126 UpdateUkmService(); | 125 UpdateUkmService(); |
| 127 | 126 |
| 128 int recording_groups = 0; | 127 GetRapporServiceImpl()->Update(may_record_, may_upload_); |
| 129 #if defined(GOOGLE_CHROME_BUILD) | |
| 130 if (may_record_) | |
| 131 recording_groups |= rappor::UMA_RAPPOR_GROUP; | |
| 132 | |
| 133 // NOTE: It is safe to use a raw pointer to |this| because this object owns | |
| 134 // |client_|, and the contract of | |
| 135 // MetricsServicesManagerClient::IsSafeBrowsingEnabled() states that the | |
| 136 // callback passed in must not be used beyond the lifetime of the client | |
| 137 // instance. | |
| 138 base::Closure on_safe_browsing_update_callback = base::Bind( | |
| 139 &MetricsServicesManager::UpdateRunningServices, base::Unretained(this)); | |
| 140 if (client_->IsSafeBrowsingEnabled(on_safe_browsing_update_callback)) | |
| 141 recording_groups |= rappor::SAFEBROWSING_RAPPOR_GROUP; | |
| 142 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 143 GetRapporServiceImpl()->Update(recording_groups, may_upload_); | |
| 144 } | 128 } |
| 145 | 129 |
| 146 void MetricsServicesManager::UpdateUkmService() { | 130 void MetricsServicesManager::UpdateUkmService() { |
| 147 ukm::UkmService* ukm = GetUkmService(); | 131 ukm::UkmService* ukm = GetUkmService(); |
| 148 if (!ukm) | 132 if (!ukm) |
| 149 return; | 133 return; |
| 150 bool sync_enabled = | 134 bool sync_enabled = |
| 151 metrics_service_client_->IsHistorySyncEnabledOnAllProfiles(); | 135 metrics_service_client_->IsHistorySyncEnabledOnAllProfiles(); |
| 152 if (may_record_ && sync_enabled) { | 136 if (may_record_ && sync_enabled) { |
| 153 ukm->EnableRecording(); | 137 ukm->EnableRecording(); |
| 154 if (may_upload_) | 138 if (may_upload_) |
| 155 ukm->EnableReporting(); | 139 ukm->EnableReporting(); |
| 156 else | 140 else |
| 157 ukm->DisableReporting(); | 141 ukm->DisableReporting(); |
| 158 } else { | 142 } else { |
| 159 ukm->DisableRecording(); | 143 ukm->DisableRecording(); |
| 160 ukm->DisableReporting(); | 144 ukm->DisableReporting(); |
| 161 } | 145 } |
| 162 } | 146 } |
| 163 | 147 |
| 164 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { | 148 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { |
| 165 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload); | 149 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload); |
| 166 } | 150 } |
| 167 | 151 |
| 168 } // namespace metrics_services_manager | 152 } // namespace metrics_services_manager |
| OLD | NEW |