| Index: components/metrics/metrics_service.cc
|
| diff --git a/components/metrics/metrics_service.cc b/components/metrics/metrics_service.cc
|
| index 2d97d28d9306a1b5d2754b5f781e888c827e062c..7f2e2c741238dc9e3f73e409fc3218c53368dab7 100644
|
| --- a/components/metrics/metrics_service.cc
|
| +++ b/components/metrics/metrics_service.cc
|
| @@ -551,6 +551,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)) {
|
| @@ -881,13 +883,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;
|
| @@ -923,8 +921,6 @@ void MetricsService::PrepareInitialStabilityLog() {
|
| if (!initial_stability_log->LoadSavedEnvironmentFromPrefs())
|
| return;
|
|
|
| - log_manager_.LoadPersistedUnsentLogs();
|
| -
|
| log_manager_.PauseCurrentLog();
|
| log_manager_.BeginLoggingWithLog(initial_stability_log.Pass());
|
|
|
| @@ -976,6 +972,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();
|
| }
|
| @@ -1039,31 +1039,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;
|
|
|