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 {
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
// Study_FormFactor.
Study::FormFactor GetCurrentFormFactor() {
......
......@@ -33,18 +33,7 @@ class VariationsFieldTrialCreator {
// empty if it is not available.
std::string GetLatestCountry() const;
// Creates field trials based on the variations seed loaded from local state.
// 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_; }
VariationsSeedStore* seed_store() { return &seed_store_; }
const VariationsSeedStore& seed_store() const { return seed_store_; }
bool create_trials_from_seed_called() const {
......@@ -96,36 +85,27 @@ class VariationsFieldTrialCreator {
// Records the time of the most recent successful fetch.
void RecordLastFetchTime();
// Loads the seed from the variations store into |seed|. If successfull,
// |seed| will contain the loaded data and true is returned. Set as virtual
// so that it can be overridden by tests.
// Loads the seed from the variations store into |seed|. If successful, |seed|
// will contain the loaded data and true is returned. Virtual for testing.
virtual bool LoadSeed(VariationsSeed* seed);
// Allow the platform that is used to filter the set of active trials
// to be overridden.
// Allow the platform that is used to filter the set of active trials to be
// overridden.
void OverrideVariationsPlatform(Study::Platform platform_override);
private:
PrefService* local_state() { return seed_store_.local_state(); }
const PrefService* local_state() const { return seed_store_.local_state(); }
// Set of different possible values to report for the
// Variations.LoadPermanentConsistencyCountryResult histogram. This enum must
// be kept consistent with its counterpart in histograms.xml.
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,
};
// Creates field trials based on the variations seed loaded from local state.
// 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);
VariationsServiceClient* client_;
......
......@@ -436,7 +436,7 @@ bool VariationsService::StoreSeed(const std::string& seed_data,
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
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,
is_delta_compressed, is_gzip_compressed, seed.get())) {
return false;
......@@ -499,14 +499,14 @@ bool VariationsService::DoFetchFromURL(const GURL& url) {
net::LOAD_DO_NOT_SAVE_COOKIES);
pending_seed_request_->SetRequestContext(client_->GetURLRequestContext());
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_) {
// Tell the server that delta-compressed seeds are supported.
enable_deltas = true;
// 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.
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) &&
base::FeatureList::IsEnabled(kHttpRetryFeature)) {
std::string encrypted_sn;
......@@ -666,7 +666,7 @@ void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
// Update the seed date value in local state (used for expiry check on
// next start up), since 304 is a successful response.
field_trial_creator_.seed_store().UpdateSeedDateAndLogDayChange(
field_trial_creator_.seed_store()->UpdateSeedDateAndLogDayChange(
response_date);
}
return;
......@@ -683,7 +683,7 @@ void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
&is_gzip_compressed)) {
// The header does not specify supported instance manipulations, unable to
// process data. Details of errors were logged by GetInstanceManipulations.
field_trial_creator_.seed_store().ReportUnsupportedSeedFormatError();
field_trial_creator_.seed_store()->ReportUnsupportedSeedFormatError();
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