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 "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" |
| 11 #include "components/metrics/metrics_service_client.h" | 11 #include "components/metrics/metrics_service_client.h" |
| 12 #include "components/metrics/metrics_state_manager.h" | 12 #include "components/metrics/metrics_state_manager.h" |
| 13 #include "components/metrics_services_manager/metrics_services_manager_client.h" | 13 #include "components/metrics_services_manager/metrics_services_manager_client.h" |
| 14 #include "components/rappor/rappor_service_impl.h" | 14 #include "components/rappor/rappor_service_impl.h" |
| 15 #include "components/ukm/ukm_service.h" | |
| 15 #include "components/variations/service/variations_service.h" | 16 #include "components/variations/service/variations_service.h" |
| 16 | 17 |
| 17 namespace metrics_services_manager { | 18 namespace metrics_services_manager { |
| 18 | 19 |
| 19 MetricsServicesManager::MetricsServicesManager( | 20 MetricsServicesManager::MetricsServicesManager( |
| 20 std::unique_ptr<MetricsServicesManagerClient> client) | 21 std::unique_ptr<MetricsServicesManagerClient> client) |
| 21 : client_(std::move(client)), may_upload_(false), may_record_(false) { | 22 : client_(std::move(client)), may_upload_(false), may_record_(false) { |
| 22 DCHECK(client_); | 23 DCHECK(client_); |
| 23 } | 24 } |
| 24 | 25 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 36 | 37 |
| 37 rappor::RapporServiceImpl* MetricsServicesManager::GetRapporServiceImpl() { | 38 rappor::RapporServiceImpl* MetricsServicesManager::GetRapporServiceImpl() { |
| 38 DCHECK(thread_checker_.CalledOnValidThread()); | 39 DCHECK(thread_checker_.CalledOnValidThread()); |
| 39 if (!rappor_service_) { | 40 if (!rappor_service_) { |
| 40 rappor_service_ = client_->CreateRapporServiceImpl(); | 41 rappor_service_ = client_->CreateRapporServiceImpl(); |
| 41 rappor_service_->Initialize(client_->GetURLRequestContext()); | 42 rappor_service_->Initialize(client_->GetURLRequestContext()); |
| 42 } | 43 } |
| 43 return rappor_service_.get(); | 44 return rappor_service_.get(); |
| 44 } | 45 } |
| 45 | 46 |
| 47 ukm::UkmService* MetricsServicesManager::GetUkmService() { | |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 49 return GetMetricsServiceClient()->GetUkmService(); | |
| 50 } | |
| 51 | |
| 46 variations::VariationsService* MetricsServicesManager::GetVariationsService() { | 52 variations::VariationsService* MetricsServicesManager::GetVariationsService() { |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
| 48 if (!variations_service_) | 54 if (!variations_service_) |
| 49 variations_service_ = client_->CreateVariationsService(); | 55 variations_service_ = client_->CreateVariationsService(); |
| 50 return variations_service_.get(); | 56 return variations_service_.get(); |
| 51 } | 57 } |
| 52 | 58 |
| 53 void MetricsServicesManager::OnPluginLoadingError( | 59 void MetricsServicesManager::OnPluginLoadingError( |
| 54 const base::FilePath& plugin_path) { | 60 const base::FilePath& plugin_path) { |
| 55 GetMetricsServiceClient()->OnPluginLoadingError(plugin_path); | 61 GetMetricsServiceClient()->OnPluginLoadingError(plugin_path); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 75 // preference partially determines the initial rappor setting, and also | 81 // preference partially determines the initial rappor setting, and also |
| 76 // controls whether FINE metrics are sent. | 82 // controls whether FINE metrics are sent. |
| 77 may_record_ = may_record; | 83 may_record_ = may_record; |
| 78 may_upload_ = may_upload; | 84 may_upload_ = may_upload; |
| 79 UpdateRunningServices(); | 85 UpdateRunningServices(); |
| 80 } | 86 } |
| 81 | 87 |
| 82 void MetricsServicesManager::UpdateRunningServices() { | 88 void MetricsServicesManager::UpdateRunningServices() { |
| 83 DCHECK(thread_checker_.CalledOnValidThread()); | 89 DCHECK(thread_checker_.CalledOnValidThread()); |
| 84 metrics::MetricsService* metrics = GetMetricsService(); | 90 metrics::MetricsService* metrics = GetMetricsService(); |
| 91 ukm::UkmService* ukm = GetUkmService(); | |
| 85 | 92 |
| 86 if (client_->OnlyDoMetricsRecording()) { | 93 if (client_->OnlyDoMetricsRecording()) { |
| 87 metrics->StartRecordingForTests(); | 94 metrics->StartRecordingForTests(); |
| 88 GetRapporServiceImpl()->Update( | 95 GetRapporServiceImpl()->Update( |
| 89 rappor::UMA_RAPPOR_GROUP | rappor::SAFEBROWSING_RAPPOR_GROUP, false); | 96 rappor::UMA_RAPPOR_GROUP | rappor::SAFEBROWSING_RAPPOR_GROUP, false); |
| 90 return; | 97 return; |
| 91 } | 98 } |
| 92 | 99 |
| 93 client_->UpdateRunningServices(may_record_, may_upload_); | 100 client_->UpdateRunningServices(may_record_, may_upload_); |
| 94 | 101 |
| 95 if (may_record_) { | 102 if (may_record_) { |
| 96 if (!metrics->recording_active()) | 103 if (!metrics->recording_active()) |
| 97 metrics->Start(); | 104 metrics->Start(); |
| 98 | 105 |
| 99 if (may_upload_) | 106 if (may_upload_) { |
| 100 metrics->EnableReporting(); | 107 metrics->EnableReporting(); |
| 101 else | 108 // TODO(holte): Make UKM checks sync state |
|
battre
2017/01/20 07:42:30
Can you add something like this into EnableReporti
Steven Holte
2017/01/20 20:07:39
Done, and added a #if around the call in MSM to ma
| |
| 109 if (ukm) | |
| 110 ukm->EnableReporting(); | |
| 111 } else { | |
| 102 metrics->DisableReporting(); | 112 metrics->DisableReporting(); |
| 113 if (ukm) | |
| 114 ukm->DisableReporting(); | |
| 115 } | |
| 103 } else { | 116 } else { |
| 104 metrics->Stop(); | 117 metrics->Stop(); |
| 105 } | 118 } |
| 106 | 119 |
| 107 int recording_groups = 0; | 120 int recording_groups = 0; |
| 108 #if defined(GOOGLE_CHROME_BUILD) | 121 #if defined(GOOGLE_CHROME_BUILD) |
| 109 if (may_record_) | 122 if (may_record_) |
| 110 recording_groups |= rappor::UMA_RAPPOR_GROUP; | 123 recording_groups |= rappor::UMA_RAPPOR_GROUP; |
| 111 | 124 |
| 112 // NOTE: It is safe to use a raw pointer to |this| because this object owns | 125 // NOTE: It is safe to use a raw pointer to |this| because this object owns |
| 113 // |client_|, and the contract of | 126 // |client_|, and the contract of |
| 114 // MetricsServicesManagerClient::IsSafeBrowsingEnabled() states that the | 127 // MetricsServicesManagerClient::IsSafeBrowsingEnabled() states that the |
| 115 // callback passed in must not be used beyond the lifetime of the client | 128 // callback passed in must not be used beyond the lifetime of the client |
| 116 // instance. | 129 // instance. |
| 117 base::Closure on_safe_browsing_update_callback = base::Bind( | 130 base::Closure on_safe_browsing_update_callback = base::Bind( |
| 118 &MetricsServicesManager::UpdateRunningServices, base::Unretained(this)); | 131 &MetricsServicesManager::UpdateRunningServices, base::Unretained(this)); |
| 119 if (client_->IsSafeBrowsingEnabled(on_safe_browsing_update_callback)) | 132 if (client_->IsSafeBrowsingEnabled(on_safe_browsing_update_callback)) |
| 120 recording_groups |= rappor::SAFEBROWSING_RAPPOR_GROUP; | 133 recording_groups |= rappor::SAFEBROWSING_RAPPOR_GROUP; |
| 121 #endif // defined(GOOGLE_CHROME_BUILD) | 134 #endif // defined(GOOGLE_CHROME_BUILD) |
| 122 GetRapporServiceImpl()->Update(recording_groups, may_upload_); | 135 GetRapporServiceImpl()->Update(recording_groups, may_upload_); |
| 123 } | 136 } |
| 124 | 137 |
| 125 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { | 138 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { |
| 126 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload); | 139 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload); |
| 127 } | 140 } |
| 128 | 141 |
| 129 } // namespace metrics_services_manager | 142 } // namespace metrics_services_manager |
| OLD | NEW |