Commit 227e27bb authored by Yue Ru Sun's avatar Yue Ru Sun Committed by Commit Bot

Rename PersistedLogs to UnsentLogStore in metrics components

Bug: 959378
Change-Id: I727cd1464c8e4c72461184871e989eec299729d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1598337Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Commit-Queue: Yue Ru Sun <yrsun@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658821}
parent 742a867b
......@@ -222,7 +222,7 @@ class UkmBrowserTestBase : public SyncTest {
ukm::Report GetUkmReport() {
EXPECT_TRUE(HasUnsentUkmLogs());
metrics::PersistedLogs* log_store =
metrics::UnsentLogStore* log_store =
ukm_service()->reporting_service_.ukm_log_store();
EXPECT_FALSE(log_store->has_staged_log());
log_store->StageNextLog();
......
......@@ -202,7 +202,7 @@ const char* const kPersistentPrefNames[] = {
// changed by UMA/Sync/Unity consent, and need to be the same between
// incognito and regular modes.
ukm::prefs::kUkmClientId,
ukm::prefs::kUkmPersistedLogs,
ukm::prefs::kUkmUnsentLogStore,
ukm::prefs::kUkmSessionId,
// Variations preferences maybe changed from incognito mode and should be
......
......@@ -81,11 +81,11 @@ jumbo_static_library("metrics") {
"metrics_switches.h",
"metrics_upload_scheduler.cc",
"metrics_upload_scheduler.h",
"persisted_logs.cc",
"persisted_logs.h",
"persisted_logs_metrics.h",
"persisted_logs_metrics_impl.cc",
"persisted_logs_metrics_impl.h",
"unsent_log_store.cc",
"unsent_log_store.h",
"unsent_log_store_metrics.h",
"unsent_log_store_metrics_impl.cc",
"unsent_log_store_metrics_impl.h",
"persistent_system_profile.cc",
"persistent_system_profile.h",
"reporting_service.cc",
......@@ -380,7 +380,7 @@ source_set("unit_tests") {
"metrics_state_manager_unittest.cc",
"net/net_metrics_log_uploader_unittest.cc",
"net/network_metrics_provider_unittest.cc",
"persisted_logs_unittest.cc",
"unsent_log_store_unittest.cc",
"persistent_system_profile_unittest.cc",
"reporting_service_unittest.cc",
"single_sample_metrics_factory_impl_unittest.cc",
......
......@@ -14,7 +14,6 @@
#include "components/metrics/metrics_log.h"
#include "components/metrics/metrics_log_store.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/persisted_logs_metrics_impl.h"
#include "components/metrics/test_metrics_service_client.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
......
......@@ -5,7 +5,7 @@
#include "components/metrics/metrics_log_store.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/persisted_logs_metrics_impl.h"
#include "components/metrics/unsent_log_store_metrics_impl.h"
#include "components/prefs/pref_registry_simple.h"
namespace metrics {
......@@ -13,19 +13,19 @@ namespace metrics {
namespace {
// The number of "initial" logs to save, and hope to send during a future Chrome
// session. Initial logs contain crash stats, and are pretty small.
const size_t kInitialLogsPersistLimit = 20;
// session. Initial logs contain crash stats, and are pretty small.
const size_t kInitialLogsSaveLimit = 20;
// The number of ongoing logs to save persistently, and hope to
// send during a this or future sessions. Note that each log may be pretty
// send during a this or future sessions. Note that each log may be pretty
// large, as presumably the related "initial" log wasn't sent (probably nothing
// was, as the user was probably off-line). As a result, the log probably kept
// accumulating while the "initial" log was stalled, and couldn't be sent. As a
// was, as the user was probably off-line). As a result, the log probably kept
// accumulating while the "initial" log was stalled, and couldn't be sent. As a
// result, we don't want to save too many of these mega-logs.
// A "standard shutdown" will create a small log, including just the data that
// was not yet been transmitted, and that is normal (to have exactly one
// ongoing_log_ at startup).
const size_t kOngoingLogsPersistLimit = 8;
const size_t kOngoingLogsSaveLimit = 8;
// 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
......@@ -44,19 +44,19 @@ MetricsLogStore::MetricsLogStore(PrefService* local_state,
size_t max_ongoing_log_size,
const std::string& signing_key)
: unsent_logs_loaded_(false),
initial_log_queue_(std::unique_ptr<PersistedLogsMetricsImpl>(
new PersistedLogsMetricsImpl()),
initial_log_queue_(std::unique_ptr<UnsentLogStoreMetricsImpl>(
new UnsentLogStoreMetricsImpl()),
local_state,
prefs::kMetricsInitialLogs,
kInitialLogsPersistLimit,
kInitialLogsSaveLimit,
kStorageByteLimitPerLogType,
0,
signing_key),
ongoing_log_queue_(std::unique_ptr<PersistedLogsMetricsImpl>(
new PersistedLogsMetricsImpl()),
ongoing_log_queue_(std::unique_ptr<UnsentLogStoreMetricsImpl>(
new UnsentLogStoreMetricsImpl()),
local_state,
prefs::kMetricsOngoingLogs,
kOngoingLogsPersistLimit,
kOngoingLogsSaveLimit,
kStorageByteLimitPerLogType,
max_ongoing_log_size,
signing_key) {}
......
......@@ -10,7 +10,7 @@
#include "base/macros.h"
#include "components/metrics/log_store.h"
#include "components/metrics/metrics_log.h"
#include "components/metrics/persisted_logs.h"
#include "components/metrics/unsent_log_store.h"
class PrefService;
class PrefRegistrySimple;
......@@ -19,7 +19,7 @@ namespace metrics {
// A LogStore implementation for storing UMA logs.
// This implementation keeps track of two types of logs, initial and ongoing,
// each stored in PersistedLogs. It prioritizes staging initial logs over
// each stored in UnsentLogStore. It prioritizes staging initial logs over
// ongoing logs.
class MetricsLogStore : public LogStore {
public:
......@@ -59,9 +59,9 @@ class MetricsLogStore : public LogStore {
// Logs stored with the INITIAL_STABILITY_LOG type that haven't been sent yet.
// These logs will be staged first when staging new logs.
PersistedLogs initial_log_queue_;
UnsentLogStore initial_log_queue_;
// Logs stored with the ONGOING_LOG type that haven't been sent yet.
PersistedLogs ongoing_log_queue_;
UnsentLogStore ongoing_log_queue_;
DISALLOW_COPY_AND_ASSIGN(MetricsLogStore);
};
......
......@@ -11,7 +11,7 @@
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/persisted_logs_metrics_impl.h"
#include "components/metrics/unsent_log_store_metrics_impl.h"
#include "components/metrics/url_constants.h"
#include "components/prefs/pref_registry_simple.h"
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/metrics/persisted_logs.h"
#include "components/metrics/unsent_log_store.h"
#include <memory>
#include <string>
......@@ -14,7 +14,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/timer/elapsed_timer.h"
#include "components/metrics/persisted_logs_metrics.h"
#include "components/metrics/unsent_log_store_metrics.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "crypto/hmac.h"
......@@ -44,11 +44,12 @@ std::string DecodeFromBase64(const std::string& to_convert) {
} // namespace
PersistedLogs::LogInfo::LogInfo() {}
PersistedLogs::LogInfo::LogInfo(const PersistedLogs::LogInfo& other) = default;
PersistedLogs::LogInfo::~LogInfo() {}
UnsentLogStore::LogInfo::LogInfo() {}
UnsentLogStore::LogInfo::LogInfo(
const UnsentLogStore::LogInfo& other) = default;
UnsentLogStore::LogInfo::~LogInfo() {}
void PersistedLogs::LogInfo::Init(PersistedLogsMetrics* metrics,
void UnsentLogStore::LogInfo::Init(UnsentLogStoreMetrics* metrics,
const std::string& log_data,
const std::string& log_timestamp,
const std::string& signing_key) {
......@@ -76,7 +77,7 @@ void PersistedLogs::LogInfo::Init(PersistedLogsMetrics* metrics,
timestamp = log_timestamp;
}
PersistedLogs::PersistedLogs(std::unique_ptr<PersistedLogsMetrics> metrics,
UnsentLogStore::UnsentLogStore(std::unique_ptr<UnsentLogStoreMetrics> metrics,
PrefService* local_state,
const char* pref_name,
size_t min_log_count,
......@@ -96,42 +97,42 @@ PersistedLogs::PersistedLogs(std::unique_ptr<PersistedLogsMetrics> metrics,
DCHECK(min_log_count_ > 0 || min_log_bytes_ > 0);
}
PersistedLogs::~PersistedLogs() {}
UnsentLogStore::~UnsentLogStore() {}
bool PersistedLogs::has_unsent_logs() const {
bool UnsentLogStore::has_unsent_logs() const {
return !!size();
}
// True if a log has been staged.
bool PersistedLogs::has_staged_log() const {
bool UnsentLogStore::has_staged_log() const {
return staged_log_index_ != -1;
}
// Returns the compressed data of the element in the front of the list.
const std::string& PersistedLogs::staged_log() const {
const std::string& UnsentLogStore::staged_log() const {
DCHECK(has_staged_log());
return list_[staged_log_index_].compressed_log_data;
}
// Returns the hash of element in the front of the list.
const std::string& PersistedLogs::staged_log_hash() const {
const std::string& UnsentLogStore::staged_log_hash() const {
DCHECK(has_staged_log());
return list_[staged_log_index_].hash;
}
// Returns the signature of element in the front of the list.
const std::string& PersistedLogs::staged_log_signature() const {
const std::string& UnsentLogStore::staged_log_signature() const {
DCHECK(has_staged_log());
return list_[staged_log_index_].signature;
}
// Returns the timestamp of the element in the front of the list.
const std::string& PersistedLogs::staged_log_timestamp() const {
const std::string& UnsentLogStore::staged_log_timestamp() const {
DCHECK(has_staged_log());
return list_[staged_log_index_].timestamp;
}
void PersistedLogs::StageNextLog() {
void UnsentLogStore::StageNextLog() {
// CHECK, rather than DCHECK, because swap()ing with an empty list causes
// hard-to-identify crashes much later.
CHECK(!list_.empty());
......@@ -140,14 +141,14 @@ void PersistedLogs::StageNextLog() {
DCHECK(has_staged_log());
}
void PersistedLogs::DiscardStagedLog() {
void UnsentLogStore::DiscardStagedLog() {
DCHECK(has_staged_log());
DCHECK_LT(static_cast<size_t>(staged_log_index_), list_.size());
list_.erase(list_.begin() + staged_log_index_);
staged_log_index_ = -1;
}
void PersistedLogs::PersistUnsentLogs() const {
void UnsentLogStore::PersistUnsentLogs() const {
ListPrefUpdate update(local_state_, pref_name_);
// TODO(crbug.com/859477): Verify that the preference has been properly
// registered.
......@@ -155,18 +156,18 @@ void PersistedLogs::PersistUnsentLogs() const {
WriteLogsToPrefList(update.Get());
}
void PersistedLogs::LoadPersistedUnsentLogs() {
void UnsentLogStore::LoadPersistedUnsentLogs() {
ReadLogsFromPrefList(*local_state_->GetList(pref_name_));
}
void PersistedLogs::StoreLog(const std::string& log_data) {
void UnsentLogStore::StoreLog(const std::string& log_data) {
list_.push_back(LogInfo());
list_.back().Init(metrics_.get(), log_data,
base::NumberToString(base::Time::Now().ToTimeT()),
signing_key_);
}
void PersistedLogs::Purge() {
void UnsentLogStore::Purge() {
if (has_staged_log()) {
DiscardStagedLog();
}
......@@ -174,9 +175,9 @@ void PersistedLogs::Purge() {
local_state_->ClearPref(pref_name_);
}
void PersistedLogs::ReadLogsFromPrefList(const base::ListValue& list_value) {
void UnsentLogStore::ReadLogsFromPrefList(const base::ListValue& list_value) {
if (list_value.empty()) {
metrics_->RecordLogReadStatus(PersistedLogsMetrics::LIST_EMPTY);
metrics_->RecordLogReadStatus(UnsentLogStoreMetrics::LIST_EMPTY);
return;
}
......@@ -193,7 +194,7 @@ void PersistedLogs::ReadLogsFromPrefList(const base::ListValue& list_value) {
!dict->GetString(kLogSignatureKey, &list_[i].signature)) {
list_.clear();
metrics_->RecordLogReadStatus(
PersistedLogsMetrics::LOG_STRING_CORRUPTION);
UnsentLogStoreMetrics::LOG_STRING_CORRUPTION);
return;
}
......@@ -209,10 +210,10 @@ void PersistedLogs::ReadLogsFromPrefList(const base::ListValue& list_value) {
dict->GetString(kLogTimestampKey, &list_[i].timestamp);
}
metrics_->RecordLogReadStatus(PersistedLogsMetrics::RECALL_SUCCESS);
metrics_->RecordLogReadStatus(UnsentLogStoreMetrics::RECALL_SUCCESS);
}
void PersistedLogs::WriteLogsToPrefList(base::ListValue* list_value) const {
void UnsentLogStore::WriteLogsToPrefList(base::ListValue* list_value) const {
list_value->Clear();
// Keep the most recent logs which are smaller than |max_log_size_|.
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_METRICS_PERSISTED_LOGS_H_
#define COMPONENTS_METRICS_PERSISTED_LOGS_H_
#ifndef COMPONENTS_METRICS_UNSENT_LOG_STORE_H_
#define COMPONENTS_METRICS_UNSENT_LOG_STORE_H_
#include <stddef.h>
......@@ -20,15 +20,15 @@ class PrefService;
namespace metrics {
class PersistedLogsMetrics;
class UnsentLogStoreMetrics;
// Maintains a list of unsent logs that are written and restored from disk.
class PersistedLogs : public LogStore {
class UnsentLogStore : public LogStore {
public:
// Constructs a PersistedLogs that stores data in |local_state| under the
// Constructs an UnsentLogStore that stores data in |local_state| under the
// preference |pref_name|.
// Calling code is responsible for ensuring that the lifetime of |local_state|
// is longer than the lifetime of PersistedLogs.
// is longer than the lifetime of UnsentLogStore.
//
// When saving logs to disk, stores either the first |min_log_count| logs, or
// at least |min_log_bytes| bytes of logs, whichever is greater.
......@@ -39,14 +39,14 @@ class PersistedLogs : public LogStore {
// |signing_key| is used to produce an HMAC-SHA256 signature of the logged
// data, which will be uploaded with the log and used to validate data
// integrity.
PersistedLogs(std::unique_ptr<PersistedLogsMetrics> metrics,
UnsentLogStore(std::unique_ptr<UnsentLogStoreMetrics> metrics,
PrefService* local_state,
const char* pref_name,
size_t min_log_count,
size_t min_log_bytes,
size_t max_log_size,
const std::string& signing_key);
~PersistedLogs();
~UnsentLogStore();
// LogStore:
bool has_unsent_logs() const override;
......@@ -79,11 +79,11 @@ class PersistedLogs : public LogStore {
void ReadLogsFromPrefList(const base::ListValue& list);
// An object for recording UMA metrics.
std::unique_ptr<PersistedLogsMetrics> metrics_;
std::unique_ptr<UnsentLogStoreMetrics> metrics_;
// A weak pointer to the PrefService object to read and write the preference
// from. Calling code should ensure this object continues to exist for the
// lifetime of the PersistedLogs object.
// lifetime of the UnsentLogStore object.
PrefService* local_state_;
// The name of the preference to serialize logs to/from.
......@@ -111,10 +111,10 @@ class PersistedLogs : public LogStore {
// |log_timestamp|, and |signing_key|. |log_data| is the uncompressed
// serialized log protobuf. A hash and a signature are computed from
// |log_data|. The signature is produced using |signing_key|. |log_data|
// will be compressed and storred in |compressed_log_data|. |log_timestamp|
// will be compressed and stored in |compressed_log_data|. |log_timestamp|
// is stored as is.
// |metrics| is the parent's metrics_ object, and should not be held.
void Init(PersistedLogsMetrics* metrics,
void Init(UnsentLogStoreMetrics* metrics,
const std::string& log_data,
const std::string& log_timestamp,
const std::string& signing_key);
......@@ -142,9 +142,9 @@ class PersistedLogs : public LogStore {
// staged, the index will be -1.
int staged_log_index_;
DISALLOW_COPY_AND_ASSIGN(PersistedLogs);
DISALLOW_COPY_AND_ASSIGN(UnsentLogStore);
};
} // namespace metrics
#endif // COMPONENTS_METRICS_PERSISTED_LOGS_H_
#endif // COMPONENTS_METRICS_UNSENT_LOG_STORE_H_
......@@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_METRICS_PERSISTED_LOGS_METRICS_H_
#define COMPONENTS_METRICS_PERSISTED_LOGS_METRICS_H_
#ifndef COMPONENTS_METRICS_UNSENT_LOG_STORE_METRICS_H_
#define COMPONENTS_METRICS_UNSENT_LOG_STORE_METRICS_H_
#include "base/macros.h"
#include "components/metrics/persisted_logs.h"
#include "components/metrics/unsent_log_store.h"
namespace metrics {
// Interface for recording metrics from PersistedLogs.
class PersistedLogsMetrics {
// Interface for recording metrics from UnsentLogStore.
class UnsentLogStoreMetrics {
public:
// Used to produce a histogram that keeps track of the status of recalling
// persisted per logs.
......@@ -31,8 +31,8 @@ class PersistedLogsMetrics {
END_RECALL_STATUS // Number of bins to use to create the histogram.
};
PersistedLogsMetrics() {}
virtual ~PersistedLogsMetrics() {}
UnsentLogStoreMetrics() {}
virtual ~UnsentLogStoreMetrics() {}
virtual void RecordLogReadStatus(LogReadStatus status) {}
......@@ -44,9 +44,9 @@ class PersistedLogsMetrics {
virtual void RecordDroppedLogsNum(int dropped_logs_num) {}
private:
DISALLOW_COPY_AND_ASSIGN(PersistedLogsMetrics);
DISALLOW_COPY_AND_ASSIGN(UnsentLogStoreMetrics);
};
} // namespace metrics
#endif // COMPONENTS_METRICS_PERSISTED_LOGS_METRICS_H_
#endif // COMPONENTS_METRICS_UNSENT_LOG_STORE_METRICS_H_
......@@ -2,31 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/metrics/persisted_logs_metrics_impl.h"
#include "components/metrics/unsent_log_store_metrics_impl.h"
#include "base/metrics/histogram_macros.h"
namespace metrics {
void PersistedLogsMetricsImpl::RecordLogReadStatus(
PersistedLogsMetrics::LogReadStatus status) {
void UnsentLogStoreMetricsImpl::RecordLogReadStatus(
UnsentLogStoreMetrics::LogReadStatus status) {
UMA_HISTOGRAM_ENUMERATION("PrefService.PersistentLogRecallProtobufs", status,
PersistedLogsMetrics::END_RECALL_STATUS);
UnsentLogStoreMetrics::END_RECALL_STATUS);
}
void PersistedLogsMetricsImpl::RecordCompressionRatio(
void UnsentLogStoreMetricsImpl::RecordCompressionRatio(
size_t compressed_size, size_t original_size) {
UMA_HISTOGRAM_PERCENTAGE(
"UMA.ProtoCompressionRatio",
static_cast<int>(100 * compressed_size / original_size));
}
void PersistedLogsMetricsImpl::RecordDroppedLogSize(size_t size) {
void UnsentLogStoreMetricsImpl::RecordDroppedLogSize(size_t size) {
UMA_HISTOGRAM_COUNTS_1M("UMA.Large Accumulated Log Not Persisted",
static_cast<int>(size));
}
void PersistedLogsMetricsImpl::RecordDroppedLogsNum(int dropped_logs_num) {
void UnsentLogStoreMetricsImpl::RecordDroppedLogsNum(int dropped_logs_num) {
UMA_HISTOGRAM_COUNTS_1M("UMA.UnsentLogs.Dropped", dropped_logs_num);
}
......
......@@ -2,31 +2,32 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_METRICS_PERSISTED_LOGS_METRICS_IMPL_H_
#define COMPONENTS_METRICS_PERSISTED_LOGS_METRICS_IMPL_H_
#ifndef COMPONENTS_METRICS_UNSENT_LOG_STORE_METRICS_IMPL_H_
#define COMPONENTS_METRICS_UNSENT_LOG_STORE_METRICS_IMPL_H_
#include "base/macros.h"
#include "components/metrics/persisted_logs_metrics.h"
#include "components/metrics/unsent_log_store_metrics.h"
namespace metrics {
// Implementation for recording metrics from PersistedLogs.
class PersistedLogsMetricsImpl : public PersistedLogsMetrics {
// Implementation for recording metrics from UnsentLogStore.
class UnsentLogStoreMetricsImpl : public UnsentLogStoreMetrics {
public:
PersistedLogsMetricsImpl() {}
~PersistedLogsMetricsImpl() override {}
UnsentLogStoreMetricsImpl() {}
~UnsentLogStoreMetricsImpl() override {}
// PersistedLogsMetrics:
void RecordLogReadStatus(PersistedLogsMetrics::LogReadStatus status) override;
// UnsentLogStoreMetrics:
void RecordLogReadStatus(
UnsentLogStoreMetrics::LogReadStatus status) override;
void RecordCompressionRatio(
size_t compressed_size, size_t original_size) override;
void RecordDroppedLogSize(size_t size) override;
void RecordDroppedLogsNum(int dropped_logs_num) override;
private:
DISALLOW_COPY_AND_ASSIGN(PersistedLogsMetricsImpl);
DISALLOW_COPY_AND_ASSIGN(UnsentLogStoreMetricsImpl);
};
} // namespace metrics
#endif // COMPONENTS_METRICS_PERSISTED_LOGS_METRICS_IMPL_H_
#endif // COMPONENTS_METRICS_UNSENT_LOG_STORE_METRICS_IMPL_H_
......@@ -11,8 +11,8 @@ static_library("ukm") {
sources = [
"app_source_url_recorder.cc",
"app_source_url_recorder.h",
"persisted_logs_metrics_impl.cc",
"persisted_logs_metrics_impl.h",
"unsent_log_store_metrics_impl.cc",
"unsent_log_store_metrics_impl.h",
"ukm_pref_names.cc",
"ukm_pref_names.h",
"ukm_recorder_impl.cc",
......
......@@ -11,7 +11,7 @@ namespace prefs {
const char kUkmClientId[] = "ukm.client_id";
// Preference which stores serialized UKM logs to be uploaded.
const char kUkmPersistedLogs[] = "ukm.persisted_logs";
const char kUkmUnsentLogStore[] = "ukm.persisted_logs";
// Preference which stores the UKM session id.
const char kUkmSessionId[] = "ukm.session_id";
......
......@@ -11,7 +11,7 @@ namespace prefs {
// Alphabetical list of preference names specific to the UKM
// component. Keep alphabetized, and document each in the .cc file.
extern const char kUkmClientId[];
extern const char kUkmPersistedLogs[];
extern const char kUkmUnsentLogStore[];
extern const char kUkmSessionId[];
} // namespace prefs
......
......@@ -13,7 +13,7 @@
#include "base/metrics/histogram_macros.h"
#include "components/metrics/metrics_service_client.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/ukm/persisted_logs_metrics_impl.h"
#include "components/ukm/unsent_log_store_metrics_impl.h"
#include "components/ukm/ukm_pref_names.h"
#include "components/ukm/ukm_service.h"
......@@ -24,15 +24,15 @@ namespace {
// The UKM server's URL.
constexpr char kMimeType[] = "application/vnd.chrome.ukm";
// The number of UKM logs that will be stored in PersistedLogs before logs
// The number of UKM logs that will be stored in UnsentLogStore before logs
// start being dropped.
constexpr int kMinPersistedLogs = 8;
constexpr int kMinUnsentLogCount = 8;
// The number of bytes UKM logs that will be stored in PersistedLogs before
// The number of bytes UKM logs that will be stored in UnsentLogStore before
// logs start being dropped.
// This ensures that a reasonable amount of history will be stored even if there
// is a long series of very small logs.
constexpr int kMinPersistedBytes = 300000;
constexpr int kMinUnsentLogBytes = 300000;
// If an upload fails, and the transmission was over this byte count, then we
// will discard the log, and not try to retransmit it. We also don't persist
......@@ -53,7 +53,7 @@ GURL GetServerUrl() {
// static
void UkmReportingService::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterListPref(prefs::kUkmPersistedLogs);
registry->RegisterListPref(prefs::kUkmUnsentLogStore);
// Base class already registered by MetricsReportingService::RegisterPrefs
// ReportingService::RegisterPrefs(registry);
}
......@@ -61,18 +61,18 @@ void UkmReportingService::RegisterPrefs(PrefRegistrySimple* registry) {
UkmReportingService::UkmReportingService(metrics::MetricsServiceClient* client,
PrefService* local_state)
: ReportingService(client, local_state, kMaxLogRetransmitSize),
persisted_logs_(std::make_unique<ukm::PersistedLogsMetricsImpl>(),
unsent_log_store_(std::make_unique<ukm::UnsentLogStoreMetricsImpl>(),
local_state,
prefs::kUkmPersistedLogs,
kMinPersistedLogs,
kMinPersistedBytes,
prefs::kUkmUnsentLogStore,
kMinUnsentLogCount,
kMinUnsentLogBytes,
kMaxLogRetransmitSize,
client->GetUploadSigningKey()) {}
UkmReportingService::~UkmReportingService() {}
metrics::LogStore* UkmReportingService::log_store() {
return &persisted_logs_;
return &unsent_log_store_;
}
GURL UkmReportingService::GetUploadUrl() const {
......
......@@ -12,7 +12,7 @@
#include <string>
#include "base/macros.h"
#include "components/metrics/persisted_logs.h"
#include "components/metrics/unsent_log_store.h"
#include "components/metrics/reporting_service.h"
class PrefService;
......@@ -39,9 +39,9 @@ class UkmReportingService : public metrics::ReportingService {
// types we'll be using.
static void RegisterPrefs(PrefRegistrySimple* registry);
metrics::PersistedLogs* ukm_log_store() { return &persisted_logs_; }
const metrics::PersistedLogs* ukm_log_store() const {
return &persisted_logs_;
metrics::UnsentLogStore* ukm_log_store() { return &unsent_log_store_; }
const metrics::UnsentLogStore* ukm_log_store() const {
return &unsent_log_store_;
}
private:
......@@ -59,7 +59,7 @@ class UkmReportingService : public metrics::ReportingService {
void LogSuccess(size_t log_size) override;
void LogLargeRejection(size_t log_size) override;
metrics::PersistedLogs persisted_logs_;
metrics::UnsentLogStore unsent_log_store_;
DISALLOW_COPY_AND_ASSIGN(UkmReportingService);
};
......
......@@ -20,7 +20,6 @@
#include "components/metrics/metrics_service_client.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/ukm/persisted_logs_metrics_impl.h"
#include "components/ukm/ukm_pref_names.h"
#include "components/ukm/ukm_rotation_scheduler.h"
#include "services/metrics/public/cpp/delegating_ukm_recorder.h"
......
......@@ -109,10 +109,10 @@ class UkmService : public UkmRecorderImpl {
void RotateLog();
// Constructs a new Report from available data and stores it in
// persisted_logs_.
// unsent_log_store_.
void BuildAndStoreLog();
// Starts an upload of the next log from persisted_logs_.
// Starts an upload of the next log from unsent_log_store_.
void StartScheduledUpload();
// Called by log_uploader_ when the an upload is completed.
......
......@@ -23,7 +23,7 @@
#include "components/metrics/test_metrics_provider.h"
#include "components/metrics/test_metrics_service_client.h"
#include "components/prefs/testing_pref_service.h"
#include "components/ukm/persisted_logs_metrics_impl.h"
#include "components/ukm/unsent_log_store_metrics_impl.h"
#include "components/ukm/ukm_pref_names.h"
#include "components/variations/variations_associated_data.h"
#include "services/metrics/public/cpp/ukm_builders.h"
......@@ -135,30 +135,30 @@ class UkmServiceTest : public testing::Test {
void ClearPrefs() {
prefs_.ClearPref(prefs::kUkmClientId);
prefs_.ClearPref(prefs::kUkmSessionId);
prefs_.ClearPref(prefs::kUkmPersistedLogs);
prefs_.ClearPref(prefs::kUkmUnsentLogStore);
}
int GetPersistedLogCount() {
const base::ListValue* list_value =
prefs_.GetList(prefs::kUkmPersistedLogs);
prefs_.GetList(prefs::kUkmUnsentLogStore);
return list_value->GetSize();
}
Report GetPersistedReport() {
EXPECT_GE(GetPersistedLogCount(), 1);
metrics::PersistedLogs result_persisted_logs(
std::make_unique<ukm::PersistedLogsMetricsImpl>(), &prefs_,
prefs::kUkmPersistedLogs,
metrics::UnsentLogStore result_unsent_log_store(
std::make_unique<ukm::UnsentLogStoreMetricsImpl>(), &prefs_,
prefs::kUkmUnsentLogStore,
3, // log count limit
1000, // byte limit
0, std::string());
result_persisted_logs.LoadPersistedUnsentLogs();
result_persisted_logs.StageNextLog();
result_unsent_log_store.LoadPersistedUnsentLogs();
result_unsent_log_store.StageNextLog();
std::string uncompressed_log_data;
EXPECT_TRUE(compression::GzipUncompress(result_persisted_logs.staged_log(),
&uncompressed_log_data));
EXPECT_TRUE(compression::GzipUncompress(
result_unsent_log_store.staged_log(), &uncompressed_log_data));
Report report;
EXPECT_TRUE(report.ParseFromString(uncompressed_log_data));
......
......@@ -2,34 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/ukm/persisted_logs_metrics_impl.h"
#include "components/ukm/unsent_log_store_metrics_impl.h"
#include "base/metrics/histogram_macros.h"
namespace ukm {
PersistedLogsMetricsImpl::PersistedLogsMetricsImpl() = default;
UnsentLogStoreMetricsImpl::UnsentLogStoreMetricsImpl() = default;
PersistedLogsMetricsImpl::~PersistedLogsMetricsImpl() = default;
UnsentLogStoreMetricsImpl::~UnsentLogStoreMetricsImpl() = default;
void PersistedLogsMetricsImpl::RecordLogReadStatus(
metrics::PersistedLogsMetrics::LogReadStatus status) {
void UnsentLogStoreMetricsImpl::RecordLogReadStatus(
metrics::UnsentLogStoreMetrics::LogReadStatus status) {
UMA_HISTOGRAM_ENUMERATION("UKM.PersistentLogRecall.Status", status,
metrics::PersistedLogsMetrics::END_RECALL_STATUS);
metrics::UnsentLogStoreMetrics::END_RECALL_STATUS);
}
void PersistedLogsMetricsImpl::RecordCompressionRatio(size_t compressed_size,
void UnsentLogStoreMetricsImpl::RecordCompressionRatio(size_t compressed_size,
size_t original_size) {
UMA_HISTOGRAM_PERCENTAGE(
"UKM.ProtoCompressionRatio",
static_cast<int>(100 * compressed_size / original_size));
}
void PersistedLogsMetricsImpl::RecordDroppedLogSize(size_t size) {
void UnsentLogStoreMetricsImpl::RecordDroppedLogSize(size_t size) {
UMA_HISTOGRAM_COUNTS_1M("UKM.UnsentLogs.DroppedSize", static_cast<int>(size));
}
void PersistedLogsMetricsImpl::RecordDroppedLogsNum(int dropped_logs_num) {
void UnsentLogStoreMetricsImpl::RecordDroppedLogsNum(int dropped_logs_num) {
UMA_HISTOGRAM_COUNTS_10000("UKM.UnsentLogs.NumDropped", dropped_logs_num);
}
......
......@@ -2,32 +2,32 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_UKM_PERSISTED_LOGS_METRICS_IMPL_H_
#define COMPONENTS_UKM_PERSISTED_LOGS_METRICS_IMPL_H_
#ifndef COMPONENTS_UKM_UNSENT_LOG_STORE_METRICS_IMPL_H_
#define COMPONENTS_UKM_UNSENT_LOG_STORE_METRICS_IMPL_H_
#include "base/macros.h"
#include "components/metrics/persisted_logs_metrics.h"
#include "components/metrics/unsent_log_store_metrics.h"
namespace ukm {
// Implementation for recording metrics from PersistedLogs.
class PersistedLogsMetricsImpl : public metrics::PersistedLogsMetrics {
// Implementation for recording metrics from UnsentLogStore.
class UnsentLogStoreMetricsImpl : public metrics::UnsentLogStoreMetrics {
public:
PersistedLogsMetricsImpl();
~PersistedLogsMetricsImpl() override;
UnsentLogStoreMetricsImpl();
~UnsentLogStoreMetricsImpl() override;
// metrics::PersistedLogsMetrics:
// metrics::UnsentLogStoreMetrics:
void RecordLogReadStatus(
metrics::PersistedLogsMetrics::LogReadStatus status) override;
metrics::UnsentLogStoreMetrics::LogReadStatus status) override;
void RecordCompressionRatio(size_t compressed_size,
size_t original_size) override;
void RecordDroppedLogSize(size_t size) override;
void RecordDroppedLogsNum(int dropped_logs_num) override;
private:
DISALLOW_COPY_AND_ASSIGN(PersistedLogsMetricsImpl);
DISALLOW_COPY_AND_ASSIGN(UnsentLogStoreMetricsImpl);
};
} // namespace ukm
#endif // COMPONENTS_UKM_PERSISTED_LOGS_METRICS_IMPL_H_
#endif // COMPONENTS_UKM_UNSENT_LOG_STORE_METRICS_IMPL_H_
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