chromium/components/metrics/metrics_log.cc

// Copyright 2014 The Chromium Authors
// 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.h"

#include <stddef.h>

#include <algorithm>
#include <cstring>
#include <string>
#include <string_view>
#include <vector>

#include "base/build_time.h"
#include "base/command_line.h"
#include "base/cpu.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/histogram_samples.h"
#include "base/metrics/histogram_snapshot_manager.h"
#include "base/metrics/metrics_hashes.h"
#include "base/strings/string_util.h"
#include "base/system/sys_info.h"
#include "base/time/clock.h"
#include "base/time/default_clock.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/flags_ui/flags_ui_switches.h"
#include "components/metrics/delegating_provider.h"
#include "components/metrics/environment_recorder.h"
#include "components/metrics/histogram_encoder.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_provider.h"
#include "components/metrics/metrics_service_client.h"
#include "components/network_time/network_time_tracker.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/variations/hashing.h"
#include "crypto/random.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
#include "third_party/metrics_proto/histogram_event.pb.h"
#include "third_party/metrics_proto/system_profile.pb.h"
#include "third_party/metrics_proto/user_action_event.pb.h"

#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif

#if BUILDFLAG(IS_WIN)
#include <windows.h>

#include "base/win/current_module.h"
#endif

#if BUILDFLAG(IS_LINUX)
#include "base/environment.h"
#include "base/nix/xdg_util.h"
#endif

SampleCountIterator;

namespace metrics {

LogMetadata::LogMetadata()
    :{}
LogMetadata::LogMetadata(
    const std::optional<base::HistogramBase::Count> samples_count,
    const std::optional<uint64_t> user_id,
    const std::optional<metrics::UkmLogSourceType> log_source_type)
    :{}
LogMetadata::LogMetadata(const LogMetadata& other) = default;
LogMetadata::~LogMetadata() = default;

void LogMetadata::AddSampleCount(base::HistogramBase::Count sample_count) {}

namespace {

// Convenience function to return the given time at a resolution in seconds.
static int64_t ToMonotonicSeconds(base::TimeTicks time_ticks) {}

// Helper function to get, increment, update and return an integer value stored
// in |local_state| using |key|. This helper is used to manage the log record id
// and the finalized log record id.
int IncrementAndUpdate(PrefService* local_state, const std::string& key) {}

// Populates |time| with information about the current time and, if
// |record_time_zone| is true, the time zone.
void RecordCurrentTime(
    const base::Clock* clock,
    const network_time::NetworkTimeTracker* network_time_tracker,
    bool record_time_zone,
    metrics::ChromeUserMetricsExtension::RealLocalTime* time) {}

#if BUILDFLAG(IS_LINUX)
metrics::SystemProfileProto::OS::XdgSessionType ToProtoSessionType(
    base::nix::SessionType session_type) {}

metrics::SystemProfileProto::OS::XdgCurrentDesktop ToProtoCurrentDesktop(
    base::nix::DesktopEnvironment desktop_environment) {}
#endif  // BUILDFLAG(IS_LINUX)

// Gets the hash of this session. A random hash is generated the first time this
// is called (which is cached and returned for the remainder of the session).
uint64_t GetSessionHash() {}

}  // namespace

namespace internal {

SystemProfileProto::InstallerPackage ToInstallerPackage(
    std::string_view installer_package_name) {}

}  // namespace internal

MetricsLog::MetricsLog(const std::string& client_id,
                       int session_id,
                       LogType log_type,
                       MetricsServiceClient* client)
    :{}

MetricsLog::MetricsLog(const std::string& client_id,
                       int session_id,
                       LogType log_type,
                       base::Clock* clock,
                       const network_time::NetworkTimeTracker* network_clock,
                       MetricsServiceClient* client)
    :{}

MetricsLog::~MetricsLog() = default;

// static
void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {}

// static
uint64_t MetricsLog::Hash(const std::string& value) {}

// static
int64_t MetricsLog::GetBuildTime() {}

// static
int64_t MetricsLog::GetCurrentTime() {}

void MetricsLog::AssignFinalizedRecordId(PrefService* local_state) {}

void MetricsLog::AssignRecordId(PrefService* local_state) {}

void MetricsLog::RecordUserAction(const std::string& key,
                                  base::TimeTicks action_time) {}

// static
void MetricsLog::RecordCoreSystemProfile(MetricsServiceClient* client,
                                         SystemProfileProto* system_profile) {}

// static
void MetricsLog::RecordCoreSystemProfile(
    const std::string& version,
    metrics::SystemProfileProto::Channel channel,
    bool is_extended_stable_channel,
    const std::string& application_locale,
    const std::string& package_name,
    SystemProfileProto* system_profile) {}

void MetricsLog::RecordHistogramDelta(const std::string& histogram_name,
                                      const base::HistogramSamples& snapshot) {}

void MetricsLog::RecordPreviousSessionData(
    DelegatingProvider* delegating_provider,
    PrefService* local_state) {}

void MetricsLog::RecordCurrentSessionData(
    base::TimeDelta incremental_uptime,
    base::TimeDelta uptime,
    DelegatingProvider* delegating_provider,
    PrefService* local_state) {}

void MetricsLog::WriteMetricsEnableDefault(EnableMetricsDefault metrics_default,
                                           SystemProfileProto* system_profile) {}

void MetricsLog::WriteRealtimeStabilityAttributes(
    base::TimeDelta incremental_uptime,
    base::TimeDelta uptime) {}

const SystemProfileProto& MetricsLog::RecordEnvironment(
    DelegatingProvider* delegating_provider) {}

bool MetricsLog::LoadSavedEnvironmentFromPrefs(PrefService* local_state) {}

metrics::ChromeUserMetricsExtension::RealLocalTime
MetricsLog::GetCurrentClockTime(bool record_time_zone) {}

void MetricsLog::FinalizeLog(
    bool truncate_events,
    const std::string& current_app_version,
    std::optional<ChromeUserMetricsExtension::RealLocalTime> close_time,
    std::string* encoded_log) {}

void MetricsLog::CloseLog() {}

void MetricsLog::RecordLogWrittenByAppVersionIfNeeded(
    const std::string& current_version) {}

void MetricsLog::TruncateEvents() {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
void MetricsLog::SetUserId(const std::string& user_id) {
  uint64_t hashed_user_id = Hash(user_id);
  uma_proto_.set_user_id(hashed_user_id);
  log_metadata_.user_id = hashed_user_id;
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace metrics