chromium/components/variations/service/limited_entropy_synthetic_trial.cc

// Copyright 2023 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/variations/service/limited_entropy_synthetic_trial.h"

#include <cstdint>

#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/version_info/channel.h"
#include "components/prefs/pref_service.h"
#include "components/variations/pref_names.h"
#include "components/variations/synthetic_trials.h"

namespace variations {
namespace {

#if BUILDFLAG(IS_CHROMEOS)
// A flag that is used to make sure that if seed of the trial is sync'ed from
// Ash to Lacros, the trial should only be randomized after the seed is set.
bool g_trial_is_randomized = false;
#endif

// The percentage of population that is enabled in this trial. It can be either
// 100 or an integer within [0, 50]. `kStableEnabledPercentage` specifies this
// percentage in the stable channel, and `kNonStableEnabledPercentage` is for
// other channels including `Channel::UNKNOWN`.
constexpr uint64_t kStableEnabledPercentage =;
constexpr uint64_t kNonStableEnabledPercentage =;

uint64_t SelectEnabledPercentage(version_info::Channel channel) {}

bool IsValidTrialSeed(uint64_t seed) {}

uint64_t GenerateTrialSeed() {}

constexpr bool IsValidEnabledPercentage(uint64_t percentage) {}

std::string_view SelectGroup(PrefService* local_state,
                             version_info::Channel channel) {}

}  // namespace

LimitedEntropySyntheticTrial::LimitedEntropySyntheticTrial(
    PrefService* local_state,
    version_info::Channel channel)
    :{}

LimitedEntropySyntheticTrial::LimitedEntropySyntheticTrial(
    std::string_view group_name)
    :{}

LimitedEntropySyntheticTrial::~LimitedEntropySyntheticTrial() = default;

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

#if BUILDFLAG(IS_CHROMEOS)
// static
void LimitedEntropySyntheticTrial::SetSeedFromAsh(PrefService* local_state,
                                                  uint64_t seed) {
  // This CHECK is defense in depth and is not expected to happen since this
  // method will be called before the creation of
  // `metrics::MetricsStateManager`, which is a dependency of
  // `variations::VariationsService`. `VariationsService` will control the
  // randomization of this trial through calling its constructor.
  CHECK(!g_trial_is_randomized);

  // The trial seed is only expected to be invalid when there is a version skew,
  // in which the Ash Chrome's version is older at a point that it is not
  // sending the seed over. In this case, the mojo field will carry a zero
  // value, which is an invalid seed.
  bool is_valid_seed = IsValidTrialSeed(seed);
  base::UmaHistogramBoolean(kIsLimitedEntropySyntheticTrialSeedValidHistogram,
                            is_valid_seed);
  if (is_valid_seed) {
    local_state->SetUint64(prefs::kVariationsLimitedEntropySyntheticTrialSeed,
                           seed);
  }
}

uint64_t LimitedEntropySyntheticTrial::GetRandomizationSeed(
    PrefService* local_state) {
  return local_state->GetUint64(
      prefs::kVariationsLimitedEntropySyntheticTrialSeed);
}
#endif

bool LimitedEntropySyntheticTrial::IsEnabled() {}

std::string_view LimitedEntropySyntheticTrial::GetGroupName() {}

void LimitedEntropySyntheticTrial::Register(
    SyntheticTrialRegistry& synthetic_trial_registry) {}

}  // namespace variations