OLD | NEW |
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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 StartSchedulerIfNecessary(); | 439 StartSchedulerIfNecessary(); |
440 idle_since_last_transmission_ = in_idle; | 440 idle_since_last_transmission_ = in_idle; |
441 } | 441 } |
442 | 442 |
443 void MetricsService::OnApplicationNotIdle() { | 443 void MetricsService::OnApplicationNotIdle() { |
444 if (recording_state_ == ACTIVE) | 444 if (recording_state_ == ACTIVE) |
445 HandleIdleSinceLastTransmission(false); | 445 HandleIdleSinceLastTransmission(false); |
446 } | 446 } |
447 | 447 |
448 void MetricsService::RecordStartOfSessionEnd() { | 448 void MetricsService::RecordStartOfSessionEnd() { |
449 LogCleanShutdown(); | 449 LogCleanShutdown(false); |
450 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, false); | |
451 } | 450 } |
452 | 451 |
453 void MetricsService::RecordCompletedSessionEnd() { | 452 void MetricsService::RecordCompletedSessionEnd() { |
454 LogCleanShutdown(); | 453 LogCleanShutdown(true); |
455 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true); | |
456 } | 454 } |
457 | 455 |
458 #if defined(OS_ANDROID) || defined(OS_IOS) | 456 #if defined(OS_ANDROID) || defined(OS_IOS) |
459 void MetricsService::OnAppEnterBackground() { | 457 void MetricsService::OnAppEnterBackground() { |
460 scheduler_->Stop(); | 458 scheduler_->Stop(); |
461 | 459 |
462 MarkAppCleanShutdownAndCommit(&clean_exit_beacon_, local_state_); | 460 MarkAppCleanShutdownAndCommit(&clean_exit_beacon_, local_state_); |
463 | 461 |
464 // Give providers a chance to persist histograms as part of being | 462 // Give providers a chance to persist histograms as part of being |
465 // backgrounded. | 463 // backgrounded. |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 DCHECK(log_manager_.current_log()); | 1200 DCHECK(log_manager_.current_log()); |
1203 // "true" indicates that StatisticsRecorder should include histograms in | 1201 // "true" indicates that StatisticsRecorder should include histograms in |
1204 // persistent storage. | 1202 // persistent storage. |
1205 histogram_snapshot_manager_.PrepareDeltas( | 1203 histogram_snapshot_manager_.PrepareDeltas( |
1206 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), | 1204 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), |
1207 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); | 1205 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); |
1208 for (MetricsProvider* provider : metrics_providers_) | 1206 for (MetricsProvider* provider : metrics_providers_) |
1209 provider->RecordInitialHistogramSnapshots(&histogram_snapshot_manager_); | 1207 provider->RecordInitialHistogramSnapshots(&histogram_snapshot_manager_); |
1210 } | 1208 } |
1211 | 1209 |
1212 void MetricsService::LogCleanShutdown() { | 1210 void MetricsService::LogCleanShutdown(bool end_completed) { |
| 1211 DCHECK(IsSingleThreaded()); |
1213 // Redundant setting to assure that we always reset this value at shutdown | 1212 // Redundant setting to assure that we always reset this value at shutdown |
1214 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 1213 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
1215 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1214 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
1216 client_->OnLogCleanShutdown(); | 1215 client_->OnLogCleanShutdown(); |
1217 clean_exit_beacon_.WriteBeaconValue(true); | 1216 clean_exit_beacon_.WriteBeaconValue(true); |
1218 RecordCurrentState(local_state_); | 1217 RecordCurrentState(local_state_); |
1219 SetExecutionPhase(MetricsService::SHUTDOWN_COMPLETE, local_state_); | 1218 SetExecutionPhase(MetricsService::SHUTDOWN_COMPLETE, local_state_); |
1220 } | 1219 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, end_completed); |
1221 | |
1222 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { | |
1223 DCHECK(IsSingleThreaded()); | |
1224 local_state_->SetBoolean(path, value); | |
1225 RecordCurrentState(local_state_); | 1220 RecordCurrentState(local_state_); |
1226 } | 1221 } |
1227 | 1222 |
1228 void MetricsService::RecordCurrentState(PrefService* pref) { | 1223 void MetricsService::RecordCurrentState(PrefService* pref) { |
1229 pref->SetInt64(prefs::kStabilityLastTimestampSec, | 1224 pref->SetInt64(prefs::kStabilityLastTimestampSec, |
1230 base::Time::Now().ToTimeT()); | 1225 base::Time::Now().ToTimeT()); |
1231 } | 1226 } |
1232 | 1227 |
1233 void MetricsService::SkipAndDiscardUpload() { | 1228 void MetricsService::SkipAndDiscardUpload() { |
1234 log_manager_.DiscardStagedLog(); | 1229 log_manager_.DiscardStagedLog(); |
1235 scheduler_->UploadCancelled(); | 1230 scheduler_->UploadCancelled(); |
1236 log_upload_in_progress_ = false; | 1231 log_upload_in_progress_ = false; |
1237 } | 1232 } |
1238 | 1233 |
1239 } // namespace metrics | 1234 } // namespace metrics |
OLD | NEW |