#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/metrics/unsent_log_store.h"
#include <cmath>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include "base/base64.h"
#include "base/hash/sha1.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/timer/elapsed_timer.h"
#include "components/metrics/metrics_features.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"
#include "third_party/zlib/google/compression_utils.h"
namespace metrics {
namespace {
const char kLogHashKey[] = …;
const char kLogSignatureKey[] = …;
const char kLogTimestampKey[] = …;
const char kLogDataKey[] = …;
const char kLogUnsentCountKey[] = …;
const char kLogSentCountKey[] = …;
const char kLogPersistedSizeInKbKey[] = …;
const char kLogUserIdKey[] = …;
const char kLogSourceType[] = …;
std::string EncodeToBase64(const std::string& to_convert) { … }
std::string DecodeFromBase64(const std::string& to_convert) { … }
class LogsPrefWriter { … };
bool GetString(const base::Value::Dict& dict,
std::string_view key,
std::string& out) { … }
}
UnsentLogStore::LogInfo::LogInfo() = default;
UnsentLogStore::LogInfo::~LogInfo() = default;
void UnsentLogStore::LogInfo::Init(const std::string& log_data,
const std::string& log_timestamp,
const std::string& signing_key,
const LogMetadata& optional_log_metadata) { … }
void UnsentLogStore::LogInfo::Init(const std::string& log_data,
const std::string& signing_key,
const LogMetadata& optional_log_metadata) { … }
UnsentLogStore::UnsentLogStore(std::unique_ptr<UnsentLogStoreMetrics> metrics,
PrefService* local_state,
const char* log_data_pref_name,
const char* metadata_pref_name,
UnsentLogStoreLimits log_store_limits,
const std::string& signing_key,
MetricsLogsEventManager* logs_event_manager)
: … { … }
UnsentLogStore::~UnsentLogStore() = default;
bool UnsentLogStore::has_unsent_logs() const { … }
bool UnsentLogStore::has_staged_log() const { … }
const std::string& UnsentLogStore::staged_log() const { … }
const std::string& UnsentLogStore::staged_log_hash() const { … }
const std::string& UnsentLogStore::staged_log_signature() const { … }
const std::string& UnsentLogStore::staged_log_timestamp() const { … }
std::optional<uint64_t> UnsentLogStore::staged_log_user_id() const { … }
const LogMetadata UnsentLogStore::staged_log_metadata() const { … }
bool UnsentLogStore::ComputeHMACForLog(const std::string& log_data,
const std::string& signing_key,
std::string* signature) { … }
void UnsentLogStore::StageNextLog() { … }
void UnsentLogStore::DiscardStagedLog(std::string_view reason) { … }
void UnsentLogStore::MarkStagedLogAsSent() { … }
void UnsentLogStore::TrimAndPersistUnsentLogs(bool overwrite_in_memory_store) { … }
void UnsentLogStore::LoadPersistedUnsentLogs() { … }
void UnsentLogStore::StoreLog(const std::string& log_data,
const LogMetadata& log_metadata,
MetricsLogsEventManager::CreateReason reason) { … }
void UnsentLogStore::StoreLogInfo(
std::unique_ptr<LogInfo> log_info,
size_t uncompressed_log_size,
MetricsLogsEventManager::CreateReason reason) { … }
const std::string& UnsentLogStore::GetLogAtIndex(size_t index) { … }
std::string UnsentLogStore::ReplaceLogAtIndex(size_t index,
const std::string& new_log_data,
const LogMetadata& log_metadata) { … }
void UnsentLogStore::Purge() { … }
void UnsentLogStore::SetLogsEventManager(
MetricsLogsEventManager* logs_event_manager) { … }
void UnsentLogStore::ReadLogsFromPrefList(const base::Value::List& list_value) { … }
void UnsentLogStore::WriteToMetricsPref(
base::HistogramBase::Count unsent_samples_count,
base::HistogramBase::Count sent_samples_count,
size_t unsent_persisted_size) const { … }
void UnsentLogStore::RecordMetaDataMetrics() { … }
void UnsentLogStore::NotifyLogCreated(
const LogInfo& info,
MetricsLogsEventManager::CreateReason reason) { … }
void UnsentLogStore::NotifyLogsCreated(
base::span<std::unique_ptr<LogInfo>> logs,
MetricsLogsEventManager::CreateReason reason) { … }
void UnsentLogStore::NotifyLogEvent(MetricsLogsEventManager::LogEvent event,
std::string_view log_hash,
std::string_view message) { … }
void UnsentLogStore::NotifyLogsEvent(base::span<std::unique_ptr<LogInfo>> logs,
MetricsLogsEventManager::LogEvent event,
std::string_view message) { … }
}