| Index: components/metrics/metrics_log_store.cc
|
| diff --git a/components/metrics/metrics_log_manager.cc b/components/metrics/metrics_log_store.cc
|
| similarity index 57%
|
| copy from components/metrics/metrics_log_manager.cc
|
| copy to components/metrics/metrics_log_store.cc
|
| index cc35bbd5346060135ae67927289eb389d1f64872..8b1ec2a710ff7ff53f488f7d1142096e2d857002 100644
|
| --- a/components/metrics/metrics_log_manager.cc
|
| +++ b/components/metrics/metrics_log_store.cc
|
| @@ -1,16 +1,12 @@
|
| -// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "components/metrics/metrics_log_manager.h"
|
| +#include "components/metrics/metrics_log_store.h"
|
|
|
| -#include <algorithm>
|
| -#include <utility>
|
| -
|
| -#include "base/strings/string_util.h"
|
| -#include "components/metrics/metrics_log.h"
|
| #include "components/metrics/metrics_pref_names.h"
|
| #include "components/metrics/persisted_logs_metrics_impl.h"
|
| +#include "components/prefs/pref_registry_simple.h"
|
|
|
| namespace metrics {
|
|
|
| @@ -31,15 +27,21 @@ const size_t kInitialLogsPersistLimit = 20;
|
| // ongoing_log_ at startup).
|
| const size_t kOngoingLogsPersistLimit = 8;
|
|
|
| -// The number of bytes each of initial and ongoing logs that must be stored.
|
| +// The number of bytes of logs to save of each type (initial/ongoing).
|
| // This ensures that a reasonable amount of history will be stored even if there
|
| // is a long series of very small logs.
|
| -const size_t kStorageByteLimitPerLogType = 300000;
|
| +const size_t kStorageByteLimitPerLogType = 300 * 1000; // ~300kB
|
|
|
| } // namespace
|
|
|
| -MetricsLogManager::MetricsLogManager(PrefService* local_state,
|
| - size_t max_ongoing_log_size)
|
| +// static
|
| +void MetricsLogStore::RegisterPrefs(PrefRegistrySimple* registry) {
|
| + registry->RegisterListPref(prefs::kMetricsInitialLogs);
|
| + registry->RegisterListPref(prefs::kMetricsOngoingLogs);
|
| +}
|
| +
|
| +MetricsLogStore::MetricsLogStore(PrefService* local_state,
|
| + size_t max_ongoing_log_size)
|
| : unsent_logs_loaded_(false),
|
| initial_log_queue_(std::unique_ptr<PersistedLogsMetricsImpl>(
|
| new PersistedLogsMetricsImpl()),
|
| @@ -56,80 +58,71 @@ MetricsLogManager::MetricsLogManager(PrefService* local_state,
|
| kStorageByteLimitPerLogType,
|
| max_ongoing_log_size) {}
|
|
|
| -MetricsLogManager::~MetricsLogManager() {}
|
| +MetricsLogStore::~MetricsLogStore() {}
|
|
|
| -void MetricsLogManager::BeginLoggingWithLog(std::unique_ptr<MetricsLog> log) {
|
| - DCHECK(!current_log_);
|
| - current_log_ = std::move(log);
|
| +void MetricsLogStore::LoadPersistedUnsentLogs() {
|
| + initial_log_queue_.LoadPersistedUnsentLogs();
|
| + ongoing_log_queue_.LoadPersistedUnsentLogs();
|
| + unsent_logs_loaded_ = true;
|
| }
|
|
|
| -void MetricsLogManager::FinishCurrentLog() {
|
| - DCHECK(current_log_.get());
|
| - current_log_->CloseLog();
|
| - std::string log_data;
|
| - current_log_->GetEncodedLog(&log_data);
|
| - if (!log_data.empty())
|
| - StoreLog(log_data, current_log_->log_type());
|
| - current_log_.reset();
|
| +void MetricsLogStore::StoreLog(const std::string& log_data,
|
| + MetricsLog::LogType log_type) {
|
| + switch (log_type) {
|
| + case MetricsLog::INITIAL_STABILITY_LOG:
|
| + initial_log_queue_.StoreLog(log_data);
|
| + break;
|
| + case MetricsLog::ONGOING_LOG:
|
| + ongoing_log_queue_.StoreLog(log_data);
|
| + break;
|
| + }
|
| }
|
|
|
| -void MetricsLogManager::StageNextLogForUpload() {
|
| - DCHECK(!has_staged_log());
|
| - if (!initial_log_queue_.empty())
|
| - initial_log_queue_.StageLog();
|
| - else
|
| - ongoing_log_queue_.StageLog();
|
| +bool MetricsLogStore::has_unsent_logs() const {
|
| + return initial_log_queue_.has_unsent_logs() ||
|
| + ongoing_log_queue_.has_unsent_logs();
|
| }
|
|
|
| -void MetricsLogManager::DiscardStagedLog() {
|
| - DCHECK(has_staged_log());
|
| - if (initial_log_queue_.has_staged_log())
|
| - initial_log_queue_.DiscardStagedLog();
|
| - else
|
| - ongoing_log_queue_.DiscardStagedLog();
|
| - DCHECK(!has_staged_log());
|
| +bool MetricsLogStore::has_staged_log() const {
|
| + return initial_log_queue_.has_staged_log() ||
|
| + ongoing_log_queue_.has_staged_log();
|
| }
|
|
|
| -void MetricsLogManager::DiscardCurrentLog() {
|
| - current_log_->CloseLog();
|
| - current_log_.reset();
|
| +const std::string& MetricsLogStore::staged_log() const {
|
| + return initial_log_queue_.has_staged_log() ? initial_log_queue_.staged_log()
|
| + : ongoing_log_queue_.staged_log();
|
| }
|
|
|
| -void MetricsLogManager::PauseCurrentLog() {
|
| - DCHECK(!paused_log_.get());
|
| - paused_log_ = std::move(current_log_);
|
| +const std::string& MetricsLogStore::staged_log_hash() const {
|
| + return initial_log_queue_.has_staged_log()
|
| + ? initial_log_queue_.staged_log_hash()
|
| + : ongoing_log_queue_.staged_log_hash();
|
| }
|
|
|
| -void MetricsLogManager::ResumePausedLog() {
|
| - DCHECK(!current_log_.get());
|
| - current_log_ = std::move(paused_log_);
|
| +void MetricsLogStore::StageNextLog() {
|
| + DCHECK(!has_staged_log());
|
| + if (initial_log_queue_.has_unsent_logs())
|
| + initial_log_queue_.StageNextLog();
|
| + else
|
| + ongoing_log_queue_.StageNextLog();
|
| }
|
|
|
| -void MetricsLogManager::StoreLog(const std::string& log_data,
|
| - MetricsLog::LogType log_type) {
|
| - switch (log_type) {
|
| - case MetricsLog::INITIAL_STABILITY_LOG:
|
| - initial_log_queue_.StoreLog(log_data);
|
| - break;
|
| - case MetricsLog::ONGOING_LOG:
|
| - ongoing_log_queue_.StoreLog(log_data);
|
| - break;
|
| - }
|
| +void MetricsLogStore::DiscardStagedLog() {
|
| + DCHECK(has_staged_log());
|
| + if (initial_log_queue_.has_staged_log())
|
| + initial_log_queue_.DiscardStagedLog();
|
| + else
|
| + ongoing_log_queue_.DiscardStagedLog();
|
| + DCHECK(!has_staged_log());
|
| }
|
|
|
| -void MetricsLogManager::PersistUnsentLogs() {
|
| +void MetricsLogStore::PersistUnsentLogs() const {
|
| DCHECK(unsent_logs_loaded_);
|
| if (!unsent_logs_loaded_)
|
| return;
|
|
|
| - initial_log_queue_.SerializeLogs();
|
| - ongoing_log_queue_.SerializeLogs();
|
| -}
|
| -
|
| -void MetricsLogManager::LoadPersistedUnsentLogs() {
|
| - initial_log_queue_.DeserializeLogs();
|
| - ongoing_log_queue_.DeserializeLogs();
|
| - unsent_logs_loaded_ = true;
|
| + initial_log_queue_.PersistUnsentLogs();
|
| + ongoing_log_queue_.PersistUnsentLogs();
|
| }
|
|
|
| } // namespace metrics
|
|
|