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.h" | 14 #include "components/rappor/rappor_service_impl.h" |
15 #include "components/variations/service/variations_service.h" | 15 #include "components/variations/service/variations_service.h" |
16 | 16 |
17 namespace metrics_services_manager { | 17 namespace metrics_services_manager { |
18 | 18 |
19 MetricsServicesManager::MetricsServicesManager( | 19 MetricsServicesManager::MetricsServicesManager( |
20 std::unique_ptr<MetricsServicesManagerClient> client) | 20 std::unique_ptr<MetricsServicesManagerClient> client) |
21 : client_(std::move(client)), may_upload_(false), may_record_(false) { | 21 : client_(std::move(client)), may_upload_(false), may_record_(false) { |
22 DCHECK(client_); | 22 DCHECK(client_); |
23 } | 23 } |
24 | 24 |
25 MetricsServicesManager::~MetricsServicesManager() {} | 25 MetricsServicesManager::~MetricsServicesManager() {} |
26 | 26 |
27 std::unique_ptr<const base::FieldTrial::EntropyProvider> | 27 std::unique_ptr<const base::FieldTrial::EntropyProvider> |
28 MetricsServicesManager::CreateEntropyProvider() { | 28 MetricsServicesManager::CreateEntropyProvider() { |
29 return client_->CreateEntropyProvider(); | 29 return client_->CreateEntropyProvider(); |
30 } | 30 } |
31 | 31 |
32 metrics::MetricsService* MetricsServicesManager::GetMetricsService() { | 32 metrics::MetricsService* MetricsServicesManager::GetMetricsService() { |
33 DCHECK(thread_checker_.CalledOnValidThread()); | 33 DCHECK(thread_checker_.CalledOnValidThread()); |
34 return GetMetricsServiceClient()->GetMetricsService(); | 34 return GetMetricsServiceClient()->GetMetricsService(); |
35 } | 35 } |
36 | 36 |
37 rappor::RapporService* MetricsServicesManager::GetRapporService() { | 37 rappor::RapporServiceImpl* MetricsServicesManager::GetRapporServiceImpl() { |
38 DCHECK(thread_checker_.CalledOnValidThread()); | 38 DCHECK(thread_checker_.CalledOnValidThread()); |
39 if (!rappor_service_) { | 39 if (!rappor_service_) { |
40 rappor_service_ = client_->CreateRapporService(); | 40 rappor_service_ = client_->CreateRapporServiceImpl(); |
41 rappor_service_->Initialize(client_->GetURLRequestContext()); | 41 rappor_service_->Initialize(client_->GetURLRequestContext()); |
42 } | 42 } |
43 return rappor_service_.get(); | 43 return rappor_service_.get(); |
44 } | 44 } |
45 | 45 |
46 variations::VariationsService* MetricsServicesManager::GetVariationsService() { | 46 variations::VariationsService* MetricsServicesManager::GetVariationsService() { |
47 DCHECK(thread_checker_.CalledOnValidThread()); | 47 DCHECK(thread_checker_.CalledOnValidThread()); |
48 if (!variations_service_) | 48 if (!variations_service_) |
49 variations_service_ = client_->CreateVariationsService(); | 49 variations_service_ = client_->CreateVariationsService(); |
50 return variations_service_.get(); | 50 return variations_service_.get(); |
(...skipping 12 matching lines...) Expand all Loading... |
63 MetricsServicesManager::GetMetricsServiceClient() { | 63 MetricsServicesManager::GetMetricsServiceClient() { |
64 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
65 if (!metrics_service_client_) | 65 if (!metrics_service_client_) |
66 metrics_service_client_ = client_->CreateMetricsServiceClient(); | 66 metrics_service_client_ = client_->CreateMetricsServiceClient(); |
67 return metrics_service_client_.get(); | 67 return metrics_service_client_.get(); |
68 } | 68 } |
69 | 69 |
70 void MetricsServicesManager::UpdatePermissions(bool may_record, | 70 void MetricsServicesManager::UpdatePermissions(bool may_record, |
71 bool may_upload) { | 71 bool may_upload) { |
72 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
73 // Stash the current permissions so that we can update the RapporService | 73 // Stash the current permissions so that we can update the RapporServiceImpl |
74 // correctly when the Rappor preference changes. The metrics recording | 74 // correctly when the Rappor preference changes. The metrics recording |
75 // preference partially determines the initial rappor setting, and also | 75 // preference partially determines the initial rappor setting, and also |
76 // controls whether FINE metrics are sent. | 76 // controls whether FINE metrics are sent. |
77 may_record_ = may_record; | 77 may_record_ = may_record; |
78 may_upload_ = may_upload; | 78 may_upload_ = may_upload; |
79 UpdateRunningServices(); | 79 UpdateRunningServices(); |
80 } | 80 } |
81 | 81 |
82 void MetricsServicesManager::UpdateRunningServices() { | 82 void MetricsServicesManager::UpdateRunningServices() { |
83 DCHECK(thread_checker_.CalledOnValidThread()); | 83 DCHECK(thread_checker_.CalledOnValidThread()); |
84 metrics::MetricsService* metrics = GetMetricsService(); | 84 metrics::MetricsService* metrics = GetMetricsService(); |
85 | 85 |
86 if (client_->OnlyDoMetricsRecording()) { | 86 if (client_->OnlyDoMetricsRecording()) { |
87 metrics->StartRecordingForTests(); | 87 metrics->StartRecordingForTests(); |
88 GetRapporService()->Update( | 88 GetRapporServiceImpl()->Update( |
89 rappor::UMA_RAPPOR_GROUP | rappor::SAFEBROWSING_RAPPOR_GROUP, false); | 89 rappor::UMA_RAPPOR_GROUP | rappor::SAFEBROWSING_RAPPOR_GROUP, false); |
90 return; | 90 return; |
91 } | 91 } |
92 | 92 |
93 client_->UpdateRunningServices(may_record_, may_upload_); | 93 client_->UpdateRunningServices(may_record_, may_upload_); |
94 | 94 |
95 if (may_record_) { | 95 if (may_record_) { |
96 if (!metrics->recording_active()) | 96 if (!metrics->recording_active()) |
97 metrics->Start(); | 97 metrics->Start(); |
98 | 98 |
(...skipping 13 matching lines...) Expand all Loading... |
112 // NOTE: It is safe to use a raw pointer to |this| because this object owns | 112 // NOTE: It is safe to use a raw pointer to |this| because this object owns |
113 // |client_|, and the contract of | 113 // |client_|, and the contract of |
114 // MetricsServicesManagerClient::IsSafeBrowsingEnabled() states that the | 114 // MetricsServicesManagerClient::IsSafeBrowsingEnabled() states that the |
115 // callback passed in must not be used beyond the lifetime of the client | 115 // callback passed in must not be used beyond the lifetime of the client |
116 // instance. | 116 // instance. |
117 base::Closure on_safe_browsing_update_callback = base::Bind( | 117 base::Closure on_safe_browsing_update_callback = base::Bind( |
118 &MetricsServicesManager::UpdateRunningServices, base::Unretained(this)); | 118 &MetricsServicesManager::UpdateRunningServices, base::Unretained(this)); |
119 if (client_->IsSafeBrowsingEnabled(on_safe_browsing_update_callback)) | 119 if (client_->IsSafeBrowsingEnabled(on_safe_browsing_update_callback)) |
120 recording_groups |= rappor::SAFEBROWSING_RAPPOR_GROUP; | 120 recording_groups |= rappor::SAFEBROWSING_RAPPOR_GROUP; |
121 #endif // defined(GOOGLE_CHROME_BUILD) | 121 #endif // defined(GOOGLE_CHROME_BUILD) |
122 GetRapporService()->Update(recording_groups, may_upload_); | 122 GetRapporServiceImpl()->Update(recording_groups, may_upload_); |
123 } | 123 } |
124 | 124 |
125 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { | 125 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { |
126 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload); | 126 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload); |
127 } | 127 } |
128 | 128 |
129 } // namespace metrics_services_manager | 129 } // namespace metrics_services_manager |
OLD | NEW |