Commit 55489777 authored by Ilya Sherman's avatar Ilya Sherman Committed by Commit Bot

[Cleanup] Clean up the VariationsFieldTrialCreator code.

* Dramatically simplifies the test code, plus tests the public API rather than
  an internal API method.
* Declares said internal API method with private visibility.
* Updates a non-const reference returned type to be a pointer instead.
* Tucks an enum into the anonymous namespace in the implementation file.
* Fixes up some comments: clearer phrasing, plus fixed typos and wrapping.

R=holte@chromium.org

Bug: 727984
Change-Id: I4c394d04cb4f4d24cdcc8a7baa2db54f4dc5c8f7
Reviewed-on: https://chromium-review.googlesource.com/826493Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Ilya Sherman <isherman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524276}
parent 0688f63e
...@@ -42,6 +42,23 @@ enum VariationsSeedExpiry { ...@@ -42,6 +42,23 @@ enum VariationsSeedExpiry {
VARIATIONS_SEED_EXPIRY_ENUM_SIZE, VARIATIONS_SEED_EXPIRY_ENUM_SIZE,
}; };
// Set of different possible values to report for the
// Variations.LoadPermanentConsistencyCountryResult histogram. Values are
// persisted to logs, and should therefore never be renumbered nor reused.
enum LoadPermanentConsistencyCountryResult {
LOAD_COUNTRY_NO_PREF_NO_SEED = 0,
LOAD_COUNTRY_NO_PREF_HAS_SEED,
LOAD_COUNTRY_INVALID_PREF_NO_SEED,
LOAD_COUNTRY_INVALID_PREF_HAS_SEED,
LOAD_COUNTRY_HAS_PREF_NO_SEED_VERSION_EQ,
LOAD_COUNTRY_HAS_PREF_NO_SEED_VERSION_NEQ,
LOAD_COUNTRY_HAS_BOTH_VERSION_EQ_COUNTRY_EQ,
LOAD_COUNTRY_HAS_BOTH_VERSION_EQ_COUNTRY_NEQ,
LOAD_COUNTRY_HAS_BOTH_VERSION_NEQ_COUNTRY_EQ,
LOAD_COUNTRY_HAS_BOTH_VERSION_NEQ_COUNTRY_NEQ,
LOAD_COUNTRY_MAX,
};
// Gets current form factor and converts it from enum DeviceFormFactor to enum // Gets current form factor and converts it from enum DeviceFormFactor to enum
// Study_FormFactor. // Study_FormFactor.
Study::FormFactor GetCurrentFormFactor() { Study::FormFactor GetCurrentFormFactor() {
......
...@@ -33,18 +33,7 @@ class VariationsFieldTrialCreator { ...@@ -33,18 +33,7 @@ class VariationsFieldTrialCreator {
// empty if it is not available. // empty if it is not available.
std::string GetLatestCountry() const; std::string GetLatestCountry() const;
// Creates field trials based on the variations seed loaded from local state. VariationsSeedStore* seed_store() { return &seed_store_; }
// If there is a problem loading the seed data, all trials specified by the
// seed may not be created. Some field trials are configured to override or
// associate with (for reporting) specific features. These associations are
// registered with |feature_list|.
bool CreateTrialsFromSeed(
std::unique_ptr<const base::FieldTrial::EntropyProvider>
low_entropy_provider,
base::FeatureList* feature_list);
VariationsSeedStore& seed_store() { return seed_store_; }
const VariationsSeedStore& seed_store() const { return seed_store_; } const VariationsSeedStore& seed_store() const { return seed_store_; }
bool create_trials_from_seed_called() const { bool create_trials_from_seed_called() const {
...@@ -96,36 +85,27 @@ class VariationsFieldTrialCreator { ...@@ -96,36 +85,27 @@ class VariationsFieldTrialCreator {
// Records the time of the most recent successful fetch. // Records the time of the most recent successful fetch.
void RecordLastFetchTime(); void RecordLastFetchTime();
// Loads the seed from the variations store into |seed|. If successfull, // Loads the seed from the variations store into |seed|. If successful, |seed|
// |seed| will contain the loaded data and true is returned. Set as virtual // will contain the loaded data and true is returned. Virtual for testing.
// so that it can be overridden by tests.
virtual bool LoadSeed(VariationsSeed* seed); virtual bool LoadSeed(VariationsSeed* seed);
// Allow the platform that is used to filter the set of active trials // Allow the platform that is used to filter the set of active trials to be
// to be overridden. // overridden.
void OverrideVariationsPlatform(Study::Platform platform_override); void OverrideVariationsPlatform(Study::Platform platform_override);
private: private:
PrefService* local_state() { return seed_store_.local_state(); } PrefService* local_state() { return seed_store_.local_state(); }
const PrefService* local_state() const { return seed_store_.local_state(); } const PrefService* local_state() const { return seed_store_.local_state(); }
// Set of different possible values to report for the // Creates field trials based on the variations seed loaded from local state.
// Variations.LoadPermanentConsistencyCountryResult histogram. This enum must // If there is a problem loading the seed data, all trials specified by the
// be kept consistent with its counterpart in histograms.xml. // seed may not be created. Some field trials are configured to override or
enum LoadPermanentConsistencyCountryResult { // associate with (for reporting) specific features. These associations are
LOAD_COUNTRY_NO_PREF_NO_SEED = 0, // registered with |feature_list|.
LOAD_COUNTRY_NO_PREF_HAS_SEED, bool CreateTrialsFromSeed(
LOAD_COUNTRY_INVALID_PREF_NO_SEED, std::unique_ptr<const base::FieldTrial::EntropyProvider>
LOAD_COUNTRY_INVALID_PREF_HAS_SEED, low_entropy_provider,
LOAD_COUNTRY_HAS_PREF_NO_SEED_VERSION_EQ, base::FeatureList* feature_list);
LOAD_COUNTRY_HAS_PREF_NO_SEED_VERSION_NEQ,
LOAD_COUNTRY_HAS_BOTH_VERSION_EQ_COUNTRY_EQ,
LOAD_COUNTRY_HAS_BOTH_VERSION_EQ_COUNTRY_NEQ,
LOAD_COUNTRY_HAS_BOTH_VERSION_NEQ_COUNTRY_EQ,
LOAD_COUNTRY_HAS_BOTH_VERSION_NEQ_COUNTRY_NEQ,
LOAD_COUNTRY_MAX,
};
VariationsServiceClient* client_; VariationsServiceClient* client_;
......
...@@ -436,7 +436,7 @@ bool VariationsService::StoreSeed(const std::string& seed_data, ...@@ -436,7 +436,7 @@ bool VariationsService::StoreSeed(const std::string& seed_data,
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::unique_ptr<VariationsSeed> seed(new VariationsSeed); std::unique_ptr<VariationsSeed> seed(new VariationsSeed);
if (!field_trial_creator_.seed_store().StoreSeedData( if (!field_trial_creator_.seed_store()->StoreSeedData(
seed_data, seed_signature, country_code, date_fetched, seed_data, seed_signature, country_code, date_fetched,
is_delta_compressed, is_gzip_compressed, seed.get())) { is_delta_compressed, is_gzip_compressed, seed.get())) {
return false; return false;
...@@ -499,14 +499,14 @@ bool VariationsService::DoFetchFromURL(const GURL& url) { ...@@ -499,14 +499,14 @@ bool VariationsService::DoFetchFromURL(const GURL& url) {
net::LOAD_DO_NOT_SAVE_COOKIES); net::LOAD_DO_NOT_SAVE_COOKIES);
pending_seed_request_->SetRequestContext(client_->GetURLRequestContext()); pending_seed_request_->SetRequestContext(client_->GetURLRequestContext());
bool enable_deltas = false; bool enable_deltas = false;
if (!field_trial_creator_.seed_store().variations_serial_number().empty() && if (!field_trial_creator_.seed_store()->variations_serial_number().empty() &&
!disable_deltas_for_next_request_) { !disable_deltas_for_next_request_) {
// Tell the server that delta-compressed seeds are supported. // Tell the server that delta-compressed seeds are supported.
enable_deltas = true; enable_deltas = true;
// Get the seed only if its serial number doesn't match what we have. // Get the seed only if its serial number doesn't match what we have.
// If the fetch is being done over HTTP, encrypt the If-None-Match header. // If the fetch is being done over HTTP, encrypt the If-None-Match header.
const std::string& original_sn = const std::string& original_sn =
field_trial_creator_.seed_store().variations_serial_number(); field_trial_creator_.seed_store()->variations_serial_number();
if (!url.SchemeIs(url::kHttpsScheme) && if (!url.SchemeIs(url::kHttpsScheme) &&
base::FeatureList::IsEnabled(kHttpRetryFeature)) { base::FeatureList::IsEnabled(kHttpRetryFeature)) {
std::string encrypted_sn; std::string encrypted_sn;
...@@ -666,7 +666,7 @@ void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { ...@@ -666,7 +666,7 @@ void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
// Update the seed date value in local state (used for expiry check on // Update the seed date value in local state (used for expiry check on
// next start up), since 304 is a successful response. // next start up), since 304 is a successful response.
field_trial_creator_.seed_store().UpdateSeedDateAndLogDayChange( field_trial_creator_.seed_store()->UpdateSeedDateAndLogDayChange(
response_date); response_date);
} }
return; return;
...@@ -683,7 +683,7 @@ void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { ...@@ -683,7 +683,7 @@ void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
&is_gzip_compressed)) { &is_gzip_compressed)) {
// The header does not specify supported instance manipulations, unable to // The header does not specify supported instance manipulations, unable to
// process data. Details of errors were logged by GetInstanceManipulations. // process data. Details of errors were logged by GetInstanceManipulations.
field_trial_creator_.seed_store().ReportUnsupportedSeedFormatError(); field_trial_creator_.seed_store()->ReportUnsupportedSeedFormatError();
return; return;
} }
......
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