Commit 4fd7b3b4 authored by Karthika Pai's avatar Karthika Pai Committed by Commit Bot

Propagate entropy value to VariationsIdsProvider

The values are passed from the VariationsService to the
VariationsIdsProvider. This is needed to include the
low_entropy_source_value in the X-Client-Data header.

Change-Id: I81141eb22396c31c05101229b900631bd0a9a5b8
Bug: 1134444
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2444137Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: Karthika Pai <karthikapai@google.com>
Cr-Commit-Position: refs/heads/master@{#814975}
parent cb629a99
......@@ -216,14 +216,16 @@ void AwFeatureListCreator::SetUpFieldTrials() {
// Populate FieldTrialList. Since low_entropy_provider is null, it will fall
// back to the provider we previously gave to FieldTrialList, which is a low
// entropy provider.
// entropy provider. The X-Client-Data header is not reported on WebView, so
// we pass an empty object as the |low_entropy_source_value|.
variations_field_trial_creator_->SetupFieldTrials(
cc::switches::kEnableGpuBenchmarking, switches::kEnableFeatures,
switches::kDisableFeatures, std::vector<std::string>(),
content::GetSwitchDependentFeatureOverrides(
*base::CommandLine::ForCurrentProcess()),
/*low_entropy_provider=*/nullptr, std::make_unique<base::FeatureList>(),
aw_field_trials_.get(), &ignored_safe_seed_manager);
aw_field_trials_.get(), &ignored_safe_seed_manager,
/*low_entropy_source_value=*/base::nullopt);
}
void AwFeatureListCreator::CreateLocalState() {
......
......@@ -216,6 +216,10 @@ int64_t MetricsStateManager::GetInstallDate() const {
return ReadInstallDate(local_state_);
}
int MetricsStateManager::GetLowEntropySource() {
return entropy_state_.GetLowEntropySource();
}
void MetricsStateManager::ForceClientIdCreation() {
// TODO(asvitkine): Ideally, all tests would actually set up consent properly,
// so the command-line check wouldn't be needed here.
......@@ -375,10 +379,6 @@ std::string MetricsStateManager::GetHighEntropySource() {
return entropy_state_.GetHighEntropySource(initial_client_id_);
}
int MetricsStateManager::GetLowEntropySource() {
return entropy_state_.GetLowEntropySource();
}
int MetricsStateManager::GetOldLowEntropySource() {
return entropy_state_.GetOldLowEntropySource();
}
......
......@@ -57,6 +57,9 @@ class MetricsStateManager final {
// not opted in to metrics reporting.
const std::string& client_id() const { return client_id_; }
// Returns the low entropy source for this client.
int GetLowEntropySource();
// The CleanExitBeacon, used to determine whether the previous Chrome browser
// session terminated gracefully.
CleanExitBeacon* clean_exit_beacon() { return &clean_exit_beacon_; }
......@@ -153,9 +156,6 @@ class MetricsStateManager final {
// |provisional_client_id_| must be set before calling this.
std::string GetHighEntropySource();
// Returns the low entropy source for this client.
int GetLowEntropySource();
// Returns the old low entropy source for this client.
int GetOldLowEntropySource();
......
......@@ -432,7 +432,8 @@ bool VariationsFieldTrialCreator::SetupFieldTrials(
low_entropy_provider,
std::unique_ptr<base::FeatureList> feature_list,
PlatformFieldTrials* platform_field_trials,
SafeSeedManager* safe_seed_manager) {
SafeSeedManager* safe_seed_manager,
base::Optional<int> low_entropy_source_value) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kEnableBenchmarking) ||
......@@ -468,11 +469,13 @@ bool VariationsFieldTrialCreator::SetupFieldTrials(
VariationsIdsProvider* http_header_provider =
VariationsIdsProvider::GetInstance();
http_header_provider->SetLowEntropySourceValue(low_entropy_source_value);
// Force the variation ids selected in chrome://flags and/or specified using
// the command-line flag.
auto result = http_header_provider->ForceVariationIds(
variation_ids,
command_line->GetSwitchValueASCII(switches::kForceVariationIds));
switch (result) {
case VariationsIdsProvider::ForceIdsResult::INVALID_SWITCH_ENTRY:
ExitWithMessage(base::StringPrintf("Invalid --%s list specified.",
......
......@@ -70,6 +70,8 @@ class VariationsFieldTrialCreator {
// |safe_seed_manager| should be notified of the combined server and client
// state that was activated to create the field trials (only when the return
// value is true).
// |low_entropy_source_value| contains the low entropy source value that was
// used for client-side randomization of variations.
// |extra_overrides| gives a list of feature overrides that should be applied
// after the features explicitly disabled/enabled from the command line via
// --disable-features and --enable-features, but before field trials.
......@@ -88,7 +90,8 @@ class VariationsFieldTrialCreator {
low_entropy_provider,
std::unique_ptr<base::FeatureList> feature_list,
PlatformFieldTrials* platform_field_trials,
SafeSeedManager* safe_seed_manager);
SafeSeedManager* safe_seed_manager,
base::Optional<int> low_entropy_source_value);
// Returns all of the client state used for filtering studies.
// As a side-effect, may update the stored permanent consistency country.
......
......@@ -249,7 +249,7 @@ class TestVariationsFieldTrialCreator : public VariationsFieldTrialCreator {
"", "", "", std::vector<std::string>(),
std::vector<base::FeatureList::FeatureOverrideInfo>(), nullptr,
std::make_unique<base::FeatureList>(), &platform_field_trials,
safe_seed_manager_);
safe_seed_manager_, base::nullopt);
}
TestVariationsSeedStore* seed_store() { return &seed_store_; }
......@@ -500,7 +500,7 @@ TEST_F(FieldTrialCreatorTest, SetupFieldTrials_LoadsCountryOnFirstRun) {
"", "", "", std::vector<std::string>(),
std::vector<base::FeatureList::FeatureOverrideInfo>(), nullptr,
std::make_unique<base::FeatureList>(), &platform_field_trials,
&safe_seed_manager));
&safe_seed_manager, base::nullopt));
EXPECT_EQ(kTestSeedExperimentName,
base::FieldTrialList::FindFullName(kTestSeedStudyName));
......
......@@ -999,7 +999,8 @@ bool VariationsService::SetupFieldTrials(
return field_trial_creator_.SetupFieldTrials(
kEnableGpuBenchmarking, kEnableFeatures, kDisableFeatures, variation_ids,
extra_overrides, CreateLowEntropyProvider(), std::move(feature_list),
platform_field_trials, &safe_seed_manager_);
platform_field_trials, &safe_seed_manager_,
state_manager_->GetLowEntropySource());
}
void VariationsService::OverrideCachedUIStrings() {
......
......@@ -110,6 +110,18 @@ VariationsIdsProvider::GetVariationsVectorForWebPropertiesKeys() {
return GetVariationsVectorImpl(web_properties_keys);
}
void VariationsIdsProvider::SetLowEntropySourceValue(
base::Optional<int> low_entropy_source_value) {
// The low entropy source value is an integer that is between 0 and 7999,
// inclusive. See components/metrics/metrics_state_manager.cc for the logic to
// generate it.
if (low_entropy_source_value) {
DCHECK(low_entropy_source_value.value() >= 0 &&
low_entropy_source_value.value() <= 7999);
}
low_entropy_source_value_ = low_entropy_source_value;
}
VariationsIdsProvider::ForceIdsResult VariationsIdsProvider::ForceVariationIds(
const std::vector<std::string>& variation_ids,
const std::string& command_line_variation_ids) {
......
......@@ -96,6 +96,10 @@ class VariationsIdsProvider : public base::FieldTrialList::Observer,
// related keys.
std::vector<VariationID> GetVariationsVectorForWebPropertiesKeys();
// Sets low entropy source value that was used for client-side randomization
// of variations.
void SetLowEntropySourceValue(base::Optional<int> low_entropy_source_value);
// Result of ForceVariationIds() call.
enum class ForceIdsResult {
SUCCESS,
......@@ -218,6 +222,10 @@ class VariationsIdsProvider : public base::FieldTrialList::Observer,
// Guards access to variables below.
base::Lock lock_;
// Low entropy source value from client that was used for client-side
// randomization of variations.
base::Optional<int> low_entropy_source_value_;
// Whether or not we've initialized the caches.
bool variation_ids_cache_initialized_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment