chromium/components/metrics/entropy_state.cc

// Copyright 2020 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/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  // BUILDFLAG(IS_ANDROID)

namespace metrics {

namespace {

#if BUILDFLAG(IS_CHROMEOS_LACROS)
// Needed for a check to see if we retrieved entropy values before we have
// transferred them from Ash.
bool g_entropy_source_has_been_retrieved = false;
bool g_entropy_source_has_been_set = false;
#endif

// Generates a new non-identifying entropy source used to seed persistent
// activities. Make it static so that the new low entropy source value will
// only be generated on first access. And thus, even though we may write the
// new low entropy source value to prefs multiple times, it stays the same
// value.
int GenerateLowEntropySource() {}

// Generates a new non-identifying low entropy source using the same method
// that's used for the actual low entropy source. This one, however, is only
// used for statistical validation, and *not* for randomization or experiment
// assignment.
int GeneratePseudoLowEntropySource() {}

}  // namespace

EntropyState::EntropyState(PrefService* local_state)
    :{}

// static
constexpr int EntropyState::kLowEntropySourceNotSet;

// static
void EntropyState::ClearPrefs(PrefService* local_state) {}

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

#if BUILDFLAG(IS_CHROMEOS_LACROS)
// static
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;
    // As an |EntropyState| object has an internal state, we need to make sure
    // that none gets read before the Ash values have been transferred.
    // This is usually taken care of by
    // `ChromeMetricsServicesManagerClient::GetMetricsStateManager` which first
    // sets the Ash values and then creates the `MetricsStateManager`.
    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() {}

// static
bool EntropyState::IsValidLowEntropySource(int value) {}

// static
bool EntropyState::IsValidLimitedEntropyRandomizationSource(
    std::string_view value) {}

}  // namespace metrics