#include "components/metrics/metrics_state_manager.h"
#include <cstddef>
#include <cstdint>
#include <limits>
#include <memory>
#include <random>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include "base/base_switches.h"
#include "base/check.h"
#include "base/command_line.h"
#include "base/debug/leak_annotations.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "components/metrics/cloned_install_detector.h"
#include "components/metrics/enabled_state_provider.h"
#include "components/metrics/entropy_state.h"
#include "components/metrics/metrics_data_validation.h"
#include "components/metrics/metrics_log.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_provider.h"
#include "components/metrics/metrics_switches.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/variations/entropy_provider.h"
#include "components/variations/field_trial_config/field_trial_util.h"
#include "components/variations/pref_names.h"
#include "components/variations/variations_switches.h"
#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
#include "third_party/metrics_proto/system_profile.pb.h"
namespace metrics {
namespace {
int64_t ReadEnabledDate(PrefService* local_state) { … }
int64_t ReadInstallDate(PrefService* local_state) { … }
std::string ReadClientId(PrefService* local_state) { … }
int64_t RoundSecondsToHour(int64_t time_in_seconds) { … }
void LogClonedInstall() { … }
std::unique_ptr<metrics::ClientInfo> NoOpLoadClientInfoBackup() { … }
void ExitWithMessage(const std::string& message) { … }
std::lognormal_distribution<double> GetLogNormalDist() { … }
struct LogNormalMetricState { … };
class MetricsStateMetricsProvider : public MetricsProvider { … };
bool ShouldEnableBenchmarking(bool force_benchmarking_mode) { … }
}
bool MetricsStateManager::instance_exists_ = …;
bool MetricsStateManager::enable_provisional_client_id_for_testing_ = …;
MetricsStateManager::MetricsStateManager(
PrefService* local_state,
EnabledStateProvider* enabled_state_provider,
const std::wstring& backup_registry_key,
const base::FilePath& user_data_dir,
EntropyParams entropy_params,
StartupVisibility startup_visibility,
StoreClientInfoCallback store_client_info,
LoadClientInfoCallback retrieve_client_info,
std::string_view external_client_id)
: … { … }
MetricsStateManager::~MetricsStateManager() { … }
std::unique_ptr<MetricsProvider> MetricsStateManager::GetProvider() { … }
std::unique_ptr<MetricsProvider>
MetricsStateManager::GetProviderAndSetRandomSeedForTesting(int64_t seed) { … }
bool MetricsStateManager::IsMetricsReportingEnabled() { … }
bool MetricsStateManager::IsExtendedSafeModeSupported() const { … }
int MetricsStateManager::GetLowEntropySource() { … }
int MetricsStateManager::GetOldLowEntropySource() { … }
int MetricsStateManager::GetPseudoLowEntropySource() { … }
void MetricsStateManager::InstantiateFieldTrialList() { … }
void MetricsStateManager::LogHasSessionShutdownCleanly(
bool has_session_shutdown_cleanly,
bool is_extended_safe_mode) { … }
void MetricsStateManager::ForceClientIdCreation() { … }
void MetricsStateManager::SetExternalClientId(const std::string& id) { … }
void MetricsStateManager::CheckForClonedInstall() { … }
bool MetricsStateManager::ShouldResetClientIdsOnClonedInstall() { … }
base::CallbackListSubscription
MetricsStateManager::AddOnClonedInstallDetectedCallback(
base::OnceClosure callback) { … }
std::unique_ptr<const variations::EntropyProviders>
MetricsStateManager::CreateEntropyProviders(bool enable_limited_entropy_mode) { … }
std::unique_ptr<MetricsStateManager> MetricsStateManager::Create(
PrefService* local_state,
EnabledStateProvider* enabled_state_provider,
const std::wstring& backup_registry_key,
const base::FilePath& user_data_dir,
StartupVisibility startup_visibility,
EntropyParams entropy_params,
StoreClientInfoCallback store_client_info,
LoadClientInfoCallback retrieve_client_info,
std::string_view external_client_id) { … }
void MetricsStateManager::RegisterPrefs(PrefRegistrySimple* registry) { … }
void MetricsStateManager::BackUpCurrentClientInfo() { … }
std::unique_ptr<ClientInfo> MetricsStateManager::LoadClientInfo() { … }
std::string_view MetricsStateManager::GetLimitedEntropyRandomizationSource() { … }
std::string MetricsStateManager::GetHighEntropySource() { … }
void MetricsStateManager::UpdateEntropySourceReturnedValue(
EntropySourceType type) { … }
void MetricsStateManager::ResetMetricsIDsIfNecessary() { … }
bool MetricsStateManager::ShouldGenerateProvisionalClientId(bool is_first_run) { … }
}