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

Side by Side Diff: components/metrics/metrics_service.cc

Issue 2175743002: Add MetricsProvider::OnAppEnterBackground callback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 4 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/metrics/metrics_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 //------------------------------------------------------------------------------ 5 //------------------------------------------------------------------------------
6 // Description of the life cycle of a instance of MetricsService. 6 // Description of the life cycle of a instance of MetricsService.
7 // 7 //
8 // OVERVIEW 8 // OVERVIEW
9 // 9 //
10 // A MetricsService instance is typically created at application startup. It is 10 // A MetricsService instance is typically created at application startup. It is
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 LogCleanShutdown(); 462 LogCleanShutdown();
463 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true); 463 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true);
464 } 464 }
465 465
466 #if defined(OS_ANDROID) || defined(OS_IOS) 466 #if defined(OS_ANDROID) || defined(OS_IOS)
467 void MetricsService::OnAppEnterBackground() { 467 void MetricsService::OnAppEnterBackground() {
468 scheduler_->Stop(); 468 scheduler_->Stop();
469 469
470 MarkAppCleanShutdownAndCommit(&clean_exit_beacon_, local_state_); 470 MarkAppCleanShutdownAndCommit(&clean_exit_beacon_, local_state_);
471 471
472 // Give providers a chance to persist histograms as part of being
473 // backgrounded.
474 for (MetricsProvider* provider : metrics_providers_)
475 provider->OnAppEnterBackground();
476
472 // At this point, there's no way of knowing when the process will be 477 // At this point, there's no way of knowing when the process will be
473 // killed, so this has to be treated similar to a shutdown, closing and 478 // killed, so this has to be treated similar to a shutdown, closing and
474 // persisting all logs. Unlinke a shutdown, the state is primed to be ready 479 // persisting all logs. Unlinke a shutdown, the state is primed to be ready
475 // to continue logging and uploading if the process does return. 480 // to continue logging and uploading if the process does return.
476 if (recording_active() && state_ >= SENDING_LOGS) { 481 if (recording_active() && state_ >= SENDING_LOGS) {
477 PushPendingLogsToPersistentStorage(); 482 PushPendingLogsToPersistentStorage();
478 // Persisting logs closes the current log, so start recording a new log 483 // Persisting logs closes the current log, so start recording a new log
479 // immediately to capture any background work that might be done before the 484 // immediately to capture any background work that might be done before the
480 // process is killed. 485 // process is killed.
481 OpenNewLog(); 486 OpenNewLog();
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 base::Time::Now().ToTimeT()); 1179 base::Time::Now().ToTimeT());
1175 } 1180 }
1176 1181
1177 void MetricsService::SkipAndDiscardUpload() { 1182 void MetricsService::SkipAndDiscardUpload() {
1178 log_manager_.DiscardStagedLog(); 1183 log_manager_.DiscardStagedLog();
1179 scheduler_->UploadCancelled(); 1184 scheduler_->UploadCancelled();
1180 log_upload_in_progress_ = false; 1185 log_upload_in_progress_ = false;
1181 } 1186 }
1182 1187
1183 } // namespace metrics 1188 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698