#include "components/metrics/entropy_state.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/token.h"
#include "base/unguessable_token.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_switches.h"
#include "components/prefs/pref_service.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/jni_android.h"
#include "components/metrics/jni_headers/LowEntropySource_jni.h"
#endif
namespace metrics {
namespace {
#if BUILDFLAG(IS_CHROMEOS_LACROS)
bool g_entropy_source_has_been_retrieved = false;
bool g_entropy_source_has_been_set = false;
#endif
int GenerateLowEntropySource() { … }
int GeneratePseudoLowEntropySource() { … }
}
EntropyState::EntropyState(PrefService* local_state)
: … { … }
constexpr int EntropyState::kLowEntropySourceNotSet;
void EntropyState::ClearPrefs(PrefService* local_state) { … }
void EntropyState::RegisterPrefs(PrefRegistrySimple* registry) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
void EntropyState::SetExternalPrefs(
PrefService* local_state,
int low_entropy_source,
int old_low_entropy_source,
int pseudo_low_entropy_source,
std::string_view limited_entropy_randomization_source) {
if (!g_entropy_source_has_been_set) {
g_entropy_source_has_been_set = true;
if (g_entropy_source_has_been_retrieved) {
LOG(ERROR) << "Entropy value was retrieved before they were updated";
}
DCHECK(!g_entropy_source_has_been_retrieved);
}
local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source);
local_state->SetInteger(prefs::kMetricsOldLowEntropySource,
old_low_entropy_source);
local_state->SetInteger(prefs::kMetricsPseudoLowEntropySource,
pseudo_low_entropy_source);
if (IsValidLimitedEntropyRandomizationSource(
limited_entropy_randomization_source)) {
local_state->SetString(prefs::kMetricsLimitedEntropyRandomizationSource,
limited_entropy_randomization_source);
}
}
#endif
std::string EntropyState::GetHighEntropySource(
const std::string& initial_client_id) { … }
int EntropyState::GetLowEntropySource() { … }
int EntropyState::GetPseudoLowEntropySource() { … }
int EntropyState::GetOldLowEntropySource() { … }
std::string EntropyState::GenerateLimitedEntropyRandomizationSource() { … }
std::string_view EntropyState::GetLimitedEntropyRandomizationSource() { … }
void EntropyState::UpdateLimitedEntropyRandomizationSource() { … }
void EntropyState::UpdateLowEntropySources() { … }
bool EntropyState::IsValidLowEntropySource(int value) { … }
bool EntropyState::IsValidLimitedEntropyRandomizationSource(
std::string_view value) { … }
}