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

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

Issue 2722113004: Flush UKM metrics when backgrounded on Android and iOS. (Closed)
Patch Set: add missing newline 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
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_)
Alexei Svitkine (slow) 2017/03/01 22:56:13 Can you add a comment about this case?
Bryan McQuade 2017/03/01 23:06:50 Done
207 return;
208
209 scheduler_->Start();
210 }
211
212 void UkmService::OnAppEnterBackground() {
213 DCHECK(thread_checker_.CalledOnValidThread());
214 DVLOG(1) << "UkmService::OnAppEnterBackground";
215
216 if (!initialize_started_)
217 return;
218
219 scheduler_->Stop();
220
221 // Give providers a chance to persist ukm data as part of being backgrounded.
222 for (auto& provider : metrics_providers_)
223 provider->OnAppEnterBackground();
224
225 Flush();
226 }
227 #endif
228
201 void UkmService::Flush() { 229 void UkmService::Flush() {
202 DCHECK(thread_checker_.CalledOnValidThread()); 230 DCHECK(thread_checker_.CalledOnValidThread());
203 if (initialize_complete_) 231 if (initialize_complete_)
204 BuildAndStoreLog(); 232 BuildAndStoreLog();
205 persisted_logs_.PersistUnsentLogs(); 233 persisted_logs_.PersistUnsentLogs();
206 } 234 }
207 235
208 void UkmService::Purge() { 236 void UkmService::Purge() {
209 DCHECK(thread_checker_.CalledOnValidThread()); 237 DCHECK(thread_checker_.CalledOnValidThread());
210 DVLOG(1) << "UkmService::Purge"; 238 DVLOG(1) << "UkmService::Purge";
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 438 }
411 if (entries_.size() >= kMaxEntries) { 439 if (entries_.size() >= kMaxEntries) {
412 RecordDroppedEntry(DroppedDataReason::MAX_HIT); 440 RecordDroppedEntry(DroppedDataReason::MAX_HIT);
413 return; 441 return;
414 } 442 }
415 443
416 entries_.push_back(std::move(entry)); 444 entries_.push_back(std::move(entry));
417 } 445 }
418 446
419 } // namespace ukm 447 } // namespace ukm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698