Commit 94dce121 authored by holte@chromium.org's avatar holte@chromium.org

Standardize persisted log loading

BUG=328417

Review URL: https://codereview.chromium.org/384063004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283329 0039d316-1c4b-4281-b951-d872f2087c98
parent bc3cca84
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment