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

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

Issue 2722113004: Flush UKM metrics when backgrounded on Android and iOS. (Closed)
Patch Set: fix ios build Created 3 years, 9 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') | ios/chrome/browser/BUILD.gn » ('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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 DCHECK(thread_checker_.CalledOnValidThread()); 191 DCHECK(thread_checker_.CalledOnValidThread());
192 DVLOG(1) << "UkmService::DisableReporting"; 192 DVLOG(1) << "UkmService::DisableReporting";
193 193
194 for (auto& provider : metrics_providers_) 194 for (auto& provider : metrics_providers_)
195 provider->OnRecordingDisabled(); 195 provider->OnRecordingDisabled();
196 196
197 scheduler_->Stop(); 197 scheduler_->Stop();
198 Flush(); 198 Flush();
199 } 199 }
200 200
201 #if defined(OS_ANDROID) || defined(OS_IOS)
202 void UkmService::OnAppEnterForeground() {
203 DCHECK(thread_checker_.CalledOnValidThread());
204 DVLOG(1) << "UkmService::OnAppEnterForeground";
205
206 // If initialize_started_ is false, UKM has not yet been started, so bail.
Alexei Svitkine (slow) 2017/03/01 23:24:02 Nit: Mention that the scheduler will instead be st
Bryan McQuade 2017/03/01 23:37:10 sure, done, thanks!
207 if (!initialize_started_)
208 return;
209
210 scheduler_->Start();
211 }
212
213 void UkmService::OnAppEnterBackground() {
214 DCHECK(thread_checker_.CalledOnValidThread());
215 DVLOG(1) << "UkmService::OnAppEnterBackground";
216
217 if (!initialize_started_)
218 return;
219
220 scheduler_->Stop();
221
222 // Give providers a chance to persist ukm data as part of being backgrounded.
223 for (auto& provider : metrics_providers_)
224 provider->OnAppEnterBackground();
225
226 Flush();
227 }
228 #endif
229
201 void UkmService::Flush() { 230 void UkmService::Flush() {
202 DCHECK(thread_checker_.CalledOnValidThread()); 231 DCHECK(thread_checker_.CalledOnValidThread());
203 if (initialize_complete_) 232 if (initialize_complete_)
204 BuildAndStoreLog(); 233 BuildAndStoreLog();
205 persisted_logs_.PersistUnsentLogs(); 234 persisted_logs_.PersistUnsentLogs();
206 } 235 }
207 236
208 void UkmService::Purge() { 237 void UkmService::Purge() {
209 DCHECK(thread_checker_.CalledOnValidThread()); 238 DCHECK(thread_checker_.CalledOnValidThread());
210 DVLOG(1) << "UkmService::Purge"; 239 DVLOG(1) << "UkmService::Purge";
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 439 }
411 if (entries_.size() >= kMaxEntries) { 440 if (entries_.size() >= kMaxEntries) {
412 RecordDroppedEntry(DroppedDataReason::MAX_HIT); 441 RecordDroppedEntry(DroppedDataReason::MAX_HIT);
413 return; 442 return;
414 } 443 }
415 444
416 entries_.push_back(std::move(entry)); 445 entries_.push_back(std::move(entry));
417 } 446 }
418 447
419 } // namespace ukm 448 } // namespace ukm
OLDNEW
« no previous file with comments | « components/ukm/ukm_service.h ('k') | ios/chrome/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698