Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: components/metrics_services_manager/metrics_services_manager.cc

Issue 2567263003: Basic UkmService implementation (Closed)
Patch Set: RegisterPrefs Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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_) {
Alexei Svitkine (slow) 2017/01/10 17:37:19 Add some TODOs that UKM needs to check sync state?
Steven Holte 2017/01/10 22:52:44 Done
100 metrics->EnableReporting(); 107 metrics->EnableReporting();
101 else 108 if (ukm)
109 ukm->EnableReporting();
110 } else {
102 metrics->DisableReporting(); 111 metrics->DisableReporting();
112 if (ukm)
113 ukm->DisableReporting();
114 }
103 } else { 115 } else {
104 metrics->Stop(); 116 metrics->Stop();
105 } 117 }
106 118
107 int recording_groups = 0; 119 int recording_groups = 0;
108 #if defined(GOOGLE_CHROME_BUILD) 120 #if defined(GOOGLE_CHROME_BUILD)
109 if (may_record_) 121 if (may_record_)
110 recording_groups |= rappor::UMA_RAPPOR_GROUP; 122 recording_groups |= rappor::UMA_RAPPOR_GROUP;
111 123
112 // NOTE: It is safe to use a raw pointer to |this| because this object owns 124 // NOTE: It is safe to use a raw pointer to |this| because this object owns
113 // |client_|, and the contract of 125 // |client_|, and the contract of
114 // MetricsServicesManagerClient::IsSafeBrowsingEnabled() states that the 126 // MetricsServicesManagerClient::IsSafeBrowsingEnabled() states that the
115 // callback passed in must not be used beyond the lifetime of the client 127 // callback passed in must not be used beyond the lifetime of the client
116 // instance. 128 // instance.
117 base::Closure on_safe_browsing_update_callback = base::Bind( 129 base::Closure on_safe_browsing_update_callback = base::Bind(
118 &MetricsServicesManager::UpdateRunningServices, base::Unretained(this)); 130 &MetricsServicesManager::UpdateRunningServices, base::Unretained(this));
119 if (client_->IsSafeBrowsingEnabled(on_safe_browsing_update_callback)) 131 if (client_->IsSafeBrowsingEnabled(on_safe_browsing_update_callback))
120 recording_groups |= rappor::SAFEBROWSING_RAPPOR_GROUP; 132 recording_groups |= rappor::SAFEBROWSING_RAPPOR_GROUP;
121 #endif // defined(GOOGLE_CHROME_BUILD) 133 #endif // defined(GOOGLE_CHROME_BUILD)
122 GetRapporServiceImpl()->Update(recording_groups, may_upload_); 134 GetRapporServiceImpl()->Update(recording_groups, may_upload_);
123 } 135 }
124 136
125 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) { 137 void MetricsServicesManager::UpdateUploadPermissions(bool may_upload) {
126 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload); 138 UpdatePermissions(client_->IsMetricsReportingEnabled(), may_upload);
127 } 139 }
128 140
129 } // namespace metrics_services_manager 141 } // namespace metrics_services_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698