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 #if !defined(OFFICIAL_BUILD) |
| 109 // TODO(holte): Make UKM check sync state instead of official build. |
| 110 if (ukm) |
| 111 ukm->EnableReporting(); |
| 112 #endif |
| 113 } else { |
102 metrics->DisableReporting(); | 114 metrics->DisableReporting(); |
| 115 if (ukm) |
| 116 ukm->DisableReporting(); |
| 117 } |
103 } else { | 118 } else { |
104 metrics->Stop(); | 119 metrics->Stop(); |
105 } | 120 } |
106 | 121 |
107 int recording_groups = 0; | 122 int recording_groups = 0; |
108 #if defined(GOOGLE_CHROME_BUILD) | 123 #if defined(GOOGLE_CHROME_BUILD) |
109 if (may_record_) | 124 if (may_record_) |
110 recording_groups |= rappor::UMA_RAPPOR_GROUP; | 125 recording_groups |= rappor::UMA_RAPPOR_GROUP; |
111 | 126 |
112 // NOTE: It is safe to use a raw pointer to |this| because this object owns | 127 // NOTE: It is safe to use a raw pointer to |this| because this object owns |
113 // |client_|, and the contract of | 128 // |client_|, and the contract of |
114 // MetricsServicesManagerClient::IsSafeBrowsingEnabled() states that the | 129 // MetricsServicesManagerClient::IsSafeBrowsingEnabled() states that the |
115 // callback passed in must not be used beyond the lifetime of the client | 130 // callback passed in must not be used beyond the lifetime of the client |
116 // instance. | 131 // instance. |
117 base::Closure on_safe_browsing_update_callback = base::Bind( | 132 base::Closure on_safe_browsing_update_callback = base::Bind( |
118 &MetricsServicesManager::UpdateRunningServices, base::Unretained(this)); | 133 &MetricsServicesManager::UpdateRunningServices, base::Unretained(this)); |
119 if (client_->IsSafeBrowsingEnabled(on_safe_browsing_update_callback)) | 134 if (client_->IsSafeBrowsingEnabled(on_safe_browsing_update_callback)) |
120 recording_groups |= rappor::SAFEBROWSING_RAPPOR_GROUP; | 135 recording_groups |= rappor::SAFEBROWSING_RAPPOR_GROUP; |
121 #endif // defined(GOOGLE_CHROME_BUILD) | 136 #endif // defined(GOOGLE_CHROME_BUILD) |
122 GetRapporServiceImpl()->Update(recording_groups, may_upload_); | 137 GetRapporServiceImpl()->Update(recording_groups, may_upload_); |
123 } | 138 } |
124 | 139 |
125 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { | 140 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { |
126 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload); | 141 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload); |
127 } | 142 } |
128 | 143 |
129 } // namespace metrics_services_manager | 144 } // namespace metrics_services_manager |
OLD | NEW |