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

Side by Side Diff: components/ukm/ukm_service.cc

Issue 2671603002: Add network information to UKM (Closed)
Patch Set: fix comments and includes Created 3 years, 10 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
« no previous file with comments | « components/ukm/ukm_service.h ('k') | components/ukm/ukm_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/ukm/ukm_service.h" 5 #include "components/ukm/ukm_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 base::Closure rotate_callback = 108 base::Closure rotate_callback =
109 base::Bind(&UkmService::RotateLog, self_ptr_factory_.GetWeakPtr()); 109 base::Bind(&UkmService::RotateLog, self_ptr_factory_.GetWeakPtr());
110 // MetricsServiceClient outlives UkmService, and 110 // MetricsServiceClient outlives UkmService, and
111 // MetricsReportingScheduler is tied to the lifetime of |this|. 111 // MetricsReportingScheduler is tied to the lifetime of |this|.
112 const base::Callback<base::TimeDelta(void)>& get_upload_interval_callback = 112 const base::Callback<base::TimeDelta(void)>& get_upload_interval_callback =
113 base::Bind(&metrics::MetricsServiceClient::GetStandardUploadInterval, 113 base::Bind(&metrics::MetricsServiceClient::GetStandardUploadInterval,
114 base::Unretained(client_)); 114 base::Unretained(client_));
115 scheduler_.reset(new ukm::MetricsReportingScheduler( 115 scheduler_.reset(new ukm::MetricsReportingScheduler(
116 rotate_callback, get_upload_interval_callback)); 116 rotate_callback, get_upload_interval_callback));
117
118 for (auto& provider : metrics_providers_)
119 provider->Init();
117 } 120 }
118 121
119 UkmService::~UkmService() { 122 UkmService::~UkmService() {
120 DisableReporting(); 123 DisableReporting();
121 } 124 }
122 125
123 void UkmService::Initialize() { 126 void UkmService::Initialize() {
124 DCHECK(thread_checker_.CalledOnValidThread()); 127 DCHECK(thread_checker_.CalledOnValidThread());
125 DVLOG(1) << "UkmService::Initialize"; 128 DVLOG(1) << "UkmService::Initialize";
126 initialize_started_ = true; 129 initialize_started_ = true;
127 130
128 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 131 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
129 FROM_HERE, 132 FROM_HERE,
130 base::Bind(&UkmService::StartInitTask, self_ptr_factory_.GetWeakPtr()), 133 base::Bind(&UkmService::StartInitTask, self_ptr_factory_.GetWeakPtr()),
131 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); 134 base::TimeDelta::FromSeconds(kInitializationDelaySeconds));
132 } 135 }
133 136
134 void UkmService::EnableReporting() { 137 void UkmService::EnableReporting() {
135 DCHECK(thread_checker_.CalledOnValidThread()); 138 DCHECK(thread_checker_.CalledOnValidThread());
136 DVLOG(1) << "UkmService::EnableReporting"; 139 DVLOG(1) << "UkmService::EnableReporting";
140
141 for (auto& provider : metrics_providers_)
142 provider->OnRecordingEnabled();
143
137 if (!initialize_started_) 144 if (!initialize_started_)
138 Initialize(); 145 Initialize();
139 scheduler_->Start(); 146 scheduler_->Start();
140 } 147 }
141 148
142 void UkmService::DisableReporting() { 149 void UkmService::DisableReporting() {
143 DCHECK(thread_checker_.CalledOnValidThread()); 150 DCHECK(thread_checker_.CalledOnValidThread());
144 DVLOG(1) << "UkmService::DisableReporting"; 151 DVLOG(1) << "UkmService::DisableReporting";
152
153 for (auto& provider : metrics_providers_)
154 provider->OnRecordingDisabled();
155
145 scheduler_->Stop(); 156 scheduler_->Stop();
146 Flush(); 157 Flush();
147 } 158 }
148 159
149 void UkmService::Flush() { 160 void UkmService::Flush() {
150 if (initialize_complete_) 161 if (initialize_complete_)
151 BuildAndStoreLog(); 162 BuildAndStoreLog();
152 persisted_logs_.SerializeLogs(); 163 persisted_logs_.SerializeLogs();
153 } 164 }
154 165
155 void UkmService::Purge() { 166 void UkmService::Purge() {
156 DVLOG(1) << "UkmService::Purge"; 167 DVLOG(1) << "UkmService::Purge";
157 persisted_logs_.Purge(); 168 persisted_logs_.Purge();
158 sources_.clear(); 169 sources_.clear();
159 } 170 }
160 171
172 void UkmService::RegisterMetricsProvider(
173 std::unique_ptr<metrics::MetricsProvider> provider) {
174 metrics_providers_.push_back(std::move(provider));
175 }
176
161 // static 177 // static
162 void UkmService::RegisterPrefs(PrefRegistrySimple* registry) { 178 void UkmService::RegisterPrefs(PrefRegistrySimple* registry) {
163 registry->RegisterInt64Pref(prefs::kUkmClientId, 0); 179 registry->RegisterInt64Pref(prefs::kUkmClientId, 0);
164 registry->RegisterListPref(prefs::kUkmPersistedLogs); 180 registry->RegisterListPref(prefs::kUkmPersistedLogs);
165 } 181 }
166 182
167 void UkmService::StartInitTask() { 183 void UkmService::StartInitTask() {
168 DCHECK(thread_checker_.CalledOnValidThread()); 184 DCHECK(thread_checker_.CalledOnValidThread());
169 DVLOG(1) << "UkmService::StartInitTask"; 185 DVLOG(1) << "UkmService::StartInitTask";
170 client_id_ = LoadOrGenerateClientId(pref_service_); 186 client_id_ = LoadOrGenerateClientId(pref_service_);
(...skipping 26 matching lines...) Expand all
197 213
198 for (const auto& source : sources_) { 214 for (const auto& source : sources_) {
199 Source* proto_source = report.add_sources(); 215 Source* proto_source = report.add_sources();
200 source->PopulateProto(proto_source); 216 source->PopulateProto(proto_source);
201 } 217 }
202 UMA_HISTOGRAM_COUNTS_1000("UKM.Sources.SerializedCount", sources_.size()); 218 UMA_HISTOGRAM_COUNTS_1000("UKM.Sources.SerializedCount", sources_.size());
203 sources_.clear(); 219 sources_.clear();
204 220
205 metrics::MetricsLog::RecordCoreSystemProfile(client_, 221 metrics::MetricsLog::RecordCoreSystemProfile(client_,
206 report.mutable_system_profile()); 222 report.mutable_system_profile());
207 // TODO(rkaplow): Populate network information. 223
224 for (auto& provider : metrics_providers_) {
225 provider->ProvideSystemProfileMetrics(report.mutable_system_profile());
226 }
227
208 std::string serialized_log; 228 std::string serialized_log;
209 report.SerializeToString(&serialized_log); 229 report.SerializeToString(&serialized_log);
210 persisted_logs_.StoreLog(serialized_log); 230 persisted_logs_.StoreLog(serialized_log);
211 } 231 }
212 232
213 void UkmService::StartScheduledUpload() { 233 void UkmService::StartScheduledUpload() {
214 DCHECK(thread_checker_.CalledOnValidThread()); 234 DCHECK(thread_checker_.CalledOnValidThread());
215 DCHECK(!log_upload_in_progress_); 235 DCHECK(!log_upload_in_progress_);
216 if (!persisted_logs_.has_staged_log()) 236 if (!persisted_logs_.has_staged_log())
217 persisted_logs_.StageLog(); 237 persisted_logs_.StageLog();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 void UkmService::RecordSource(std::unique_ptr<UkmSource> source) { 284 void UkmService::RecordSource(std::unique_ptr<UkmSource> source) {
265 if (sources_.size() >= kMaxSources) { 285 if (sources_.size() >= kMaxSources) {
266 UMA_HISTOGRAM_BOOLEAN("UKM.Sources.MaxSourcesHit", true); 286 UMA_HISTOGRAM_BOOLEAN("UKM.Sources.MaxSourcesHit", true);
267 return; 287 return;
268 } 288 }
269 289
270 sources_.push_back(std::move(source)); 290 sources_.push_back(std::move(source));
271 } 291 }
272 292
273 } // namespace ukm 293 } // namespace ukm
OLDNEW
« no previous file with comments | « components/ukm/ukm_service.h ('k') | components/ukm/ukm_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698