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

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

Issue 2722113004: Flush UKM metrics when backgrounded on Android and iOS. (Closed)
Patch Set: address comment 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. The
207 // scheduler will instead be started via EnableReporting().
208 if (!initialize_started_)
209 return;
210
211 scheduler_->Start();
212 }
213
214 void UkmService::OnAppEnterBackground() {
215 DCHECK(thread_checker_.CalledOnValidThread());
216 DVLOG(1) << "UkmService::OnAppEnterBackground";
217
218 if (!initialize_started_)
219 return;
220
221 scheduler_->Stop();
222
223 // Give providers a chance to persist ukm data as part of being backgrounded.
224 for (auto& provider : metrics_providers_)
225 provider->OnAppEnterBackground();
226
227 Flush();
228 }
229 #endif
230
201 void UkmService::Flush() { 231 void UkmService::Flush() {
202 DCHECK(thread_checker_.CalledOnValidThread()); 232 DCHECK(thread_checker_.CalledOnValidThread());
203 if (initialize_complete_) 233 if (initialize_complete_)
204 BuildAndStoreLog(); 234 BuildAndStoreLog();
205 persisted_logs_.PersistUnsentLogs(); 235 persisted_logs_.PersistUnsentLogs();
206 } 236 }
207 237
208 void UkmService::Purge() { 238 void UkmService::Purge() {
209 DCHECK(thread_checker_.CalledOnValidThread()); 239 DCHECK(thread_checker_.CalledOnValidThread());
210 DVLOG(1) << "UkmService::Purge"; 240 DVLOG(1) << "UkmService::Purge";
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 440 }
411 if (entries_.size() >= kMaxEntries) { 441 if (entries_.size() >= kMaxEntries) {
412 RecordDroppedEntry(DroppedDataReason::MAX_HIT); 442 RecordDroppedEntry(DroppedDataReason::MAX_HIT);
413 return; 443 return;
414 } 444 }
415 445
416 entries_.push_back(std::move(entry)); 446 entries_.push_back(std::move(entry));
417 } 447 }
418 448
419 } // namespace ukm 449 } // 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