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

Unified Diff: components/metrics/metrics_service.cc

Issue 384063004: Standardize persisted log loading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/metrics/metrics_service.cc
diff --git a/components/metrics/metrics_service.cc b/components/metrics/metrics_service.cc
index 797ec70fdc09d959ec804e018d67d2070b4675c0..ae2c80ff46cd6ad446d64c35565985951db2c760 100644
--- a/components/metrics/metrics_service.cc
+++ b/components/metrics/metrics_service.cc
@@ -557,6 +557,8 @@ void MetricsService::InitializeMetricsState() {
local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime,
MetricsLog::GetBuildTime());
+ log_manager_.LoadPersistedUnsentLogs();
+
session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID);
if (!local_state_->GetBoolean(metrics::prefs::kStabilityExitedCleanly)) {
@@ -741,8 +743,7 @@ void MetricsService::CloseCurrentLog() {
// end of all log transmissions (initial log handles this separately).
// RecordIncrementalStabilityElements only exists on the derived
// MetricsLog class.
- MetricsLog* current_log =
- static_cast<MetricsLog*>(log_manager_.current_log());
+ MetricsLog* current_log = log_manager_.current_log();
DCHECK(current_log);
std::vector<variations::ActiveGroupId> synthetic_trials;
GetCurrentSyntheticFieldTrials(&synthetic_trials);
@@ -888,13 +889,9 @@ void MetricsService::StageNewLog() {
// There's an initial stability log, ready to send.
log_manager_.StageNextLogForUpload();
has_initial_stability_log_ = false;
- // Note: No need to call LoadPersistedUnsentLogs() here because unsent
- // logs have already been loaded by PrepareInitialStabilityLog().
state_ = SENDING_INITIAL_STABILITY_LOG;
} else {
PrepareInitialMetricsLog();
- // Load unsent logs (if any) from local state.
- log_manager_.LoadPersistedUnsentLogs();
state_ = SENDING_INITIAL_METRICS_LOG;
}
break;
@@ -930,8 +927,6 @@ void MetricsService::PrepareInitialStabilityLog() {
if (!initial_stability_log->LoadSavedEnvironmentFromPrefs())
return;
- log_manager_.LoadPersistedUnsentLogs();
-
log_manager_.PauseCurrentLog();
log_manager_.BeginLoggingWithLog(initial_stability_log.Pass());
@@ -973,8 +968,7 @@ void MetricsService::PrepareInitialMetricsLog() {
// Note: Some stability providers may record stability stats via histograms,
// so this call has to be after BeginLoggingWithLog().
- MetricsLog* current_log =
- static_cast<MetricsLog*>(log_manager_.current_log());
+ MetricsLog* current_log = log_manager_.current_log();
current_log->RecordStabilityMetrics(metrics_providers_.get(),
base::TimeDelta(), base::TimeDelta());
RecordCurrentHistograms();
@@ -984,6 +978,10 @@ void MetricsService::PrepareInitialMetricsLog() {
log_manager_.FinishCurrentLog();
log_manager_.ResumePausedLog();
+ // Store unsent logs, including the initial log that was just saved, so
+ // that they're not lost in case of a crash before upload time.
+ log_manager_.PersistUnsentLogs();
+
DCHECK(!log_manager_.has_staged_log());
log_manager_.StageNextLogForUpload();
}
@@ -1047,31 +1045,26 @@ void MetricsService::OnLogUploadComplete(int response_code) {
discard_log = true;
}
- if (upload_succeeded || discard_log)
+ if (upload_succeeded || discard_log) {
log_manager_.DiscardStagedLog();
+ // Store the updated list to disk now that the removed log is uploaded.
+ log_manager_.PersistUnsentLogs();
+ }
if (!log_manager_.has_staged_log()) {
switch (state_) {
case SENDING_INITIAL_STABILITY_LOG:
- // Store the updated list to disk now that the removed log is uploaded.
- log_manager_.PersistUnsentLogs();
PrepareInitialMetricsLog();
SendStagedLog();
state_ = SENDING_INITIAL_METRICS_LOG;
break;
case SENDING_INITIAL_METRICS_LOG:
- // The initial metrics log never gets persisted to local state, so it's
- // not necessary to call log_manager_.PersistUnsentLogs() here.
- // TODO(asvitkine): It should be persisted like the initial stability
- // log and old unsent logs. http://crbug.com/328417
state_ = log_manager_.has_unsent_logs() ? SENDING_OLD_LOGS
: SENDING_CURRENT_LOGS;
break;
case SENDING_OLD_LOGS:
- // Store the updated list to disk now that the removed log is uploaded.
- log_manager_.PersistUnsentLogs();
if (!log_manager_.has_unsent_logs())
state_ = SENDING_CURRENT_LOGS;
break;
@@ -1151,8 +1144,7 @@ void MetricsService::GetCurrentSyntheticFieldTrials(
std::vector<variations::ActiveGroupId>* synthetic_trials) {
DCHECK(synthetic_trials);
synthetic_trials->clear();
- const MetricsLog* current_log =
- static_cast<const MetricsLog*>(log_manager_.current_log());
+ const MetricsLog* current_log = log_manager_.current_log();
for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) {
if (synthetic_trial_groups_[i].start_time <= current_log->creation_time())
synthetic_trials->push_back(synthetic_trial_groups_[i].id);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698