diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 10:22:43 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 12:36:28 +0000 |
commit | 271a6c3487a14599023a9106329505597638d793 (patch) | |
tree | e040d58ffc86c1480b79ca8528020ca9ec919bf8 /chromium/components/variations | |
parent | 7b2ffa587235a47d4094787d72f38102089f402a (diff) | |
download | qtwebengine-chromium-271a6c3487a14599023a9106329505597638d793.tar.gz |
BASELINE: Update Chromium to 77.0.3865.59
Change-Id: I1e89a5f3b009a9519a6705102ad65c92fe736f21
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/components/variations')
29 files changed, 298 insertions, 316 deletions
diff --git a/chromium/components/variations/BUILD.gn b/chromium/components/variations/BUILD.gn index 6349f454f93..a11a63ec109 100644 --- a/chromium/components/variations/BUILD.gn +++ b/chromium/components/variations/BUILD.gn @@ -92,7 +92,6 @@ if (is_android) { "android/java/src/org/chromium/components/variations/VariationsAssociatedData.java", "android/java/src/org/chromium/components/variations/firstrun/VariationsSeedBridge.java", ] - jni_package = "variations" } android_library("load_seed_result_enum_java") { diff --git a/chromium/components/variations/OWNERS b/chromium/components/variations/OWNERS index 03a77ec2207..0b08a582fc0 100644 --- a/chromium/components/variations/OWNERS +++ b/chromium/components/variations/OWNERS @@ -1,3 +1,4 @@ file://base/metrics/OWNERS # COMPONENT: Internals>Metrics>Variations +# TEAM: chromium-dev@chromium.org diff --git a/chromium/components/variations/android/DEPS b/chromium/components/variations/android/DEPS index c80012b5621..fc3054bc170 100644 --- a/chromium/components/variations/android/DEPS +++ b/chromium/components/variations/android/DEPS @@ -1,3 +1,3 @@ include_rules = [ - "+jni", + "+components/variations/jni", ] diff --git a/chromium/components/variations/android/junit/src/org/chromium/components/variations/firstrun/VariationsSeedFetcherTest.java b/chromium/components/variations/android/junit/src/org/chromium/components/variations/firstrun/VariationsSeedFetcherTest.java index 4f9597b3b6b..ab94cd41348 100644 --- a/chromium/components/variations/android/junit/src/org/chromium/components/variations/firstrun/VariationsSeedFetcherTest.java +++ b/chromium/components/variations/android/junit/src/org/chromium/components/variations/firstrun/VariationsSeedFetcherTest.java @@ -61,7 +61,6 @@ public class VariationsSeedFetcherTest { .getServerConnection(VariationsSeedFetcher.VariationsPlatform.ANDROID, sRestrict, sMilestone, sChannel); mPrefs = ContextUtils.getAppSharedPreferences(); - mPrefs.edit().clear().apply(); } @After diff --git a/chromium/components/variations/android/variations_associated_data_android.cc b/chromium/components/variations/android/variations_associated_data_android.cc index 043ed0a739e..b4d14395db5 100644 --- a/chromium/components/variations/android/variations_associated_data_android.cc +++ b/chromium/components/variations/android/variations_associated_data_android.cc @@ -5,9 +5,9 @@ #include <string> #include "base/android/jni_string.h" +#include "components/variations/jni/VariationsAssociatedData_jni.h" #include "components/variations/variations_associated_data.h" #include "components/variations/variations_http_header_provider.h" -#include "jni/VariationsAssociatedData_jni.h" using base::android::ConvertJavaStringToUTF8; using base::android::ConvertUTF8ToJavaString; diff --git a/chromium/components/variations/android/variations_seed_bridge.cc b/chromium/components/variations/android/variations_seed_bridge.cc index e9a5ddc1056..c3c4a71f729 100644 --- a/chromium/components/variations/android/variations_seed_bridge.cc +++ b/chromium/components/variations/android/variations_seed_bridge.cc @@ -12,7 +12,7 @@ #include "base/android/jni_array.h" #include "base/android/jni_string.h" #include "base/android/jni_weak_ref.h" -#include "jni/VariationsSeedBridge_jni.h" +#include "components/variations/jni/VariationsSeedBridge_jni.h" using base::android::AttachCurrentThread; using base::android::ConvertJavaStringToUTF8; diff --git a/chromium/components/variations/child_process_field_trial_syncer.cc b/chromium/components/variations/child_process_field_trial_syncer.cc index 0694ccf8086..6825bdd2d14 100644 --- a/chromium/components/variations/child_process_field_trial_syncer.cc +++ b/chromium/components/variations/child_process_field_trial_syncer.cc @@ -41,7 +41,7 @@ void ChildProcessFieldTrialSyncer::InitFieldTrialObserving( base::FieldTrial::ActiveGroups current_active_trials; base::FieldTrialList::GetActiveFieldTrialGroups(¤t_active_trials); for (const auto& trial : current_active_trials) { - if (!base::ContainsKey(initially_active_trials_set, trial.trial_name)) + if (!base::Contains(initially_active_trials_set, trial.trial_name)) observer_->OnFieldTrialGroupFinalized(trial.trial_name, trial.group_name); } } diff --git a/chromium/components/variations/field_trial_config/field_trial_util.cc b/chromium/components/variations/field_trial_config/field_trial_util.cc index 43f914a4112..2c85d689ff1 100644 --- a/chromium/components/variations/field_trial_config/field_trial_util.cc +++ b/chromium/components/variations/field_trial_config/field_trial_util.cc @@ -15,12 +15,10 @@ #include "base/command_line.h" #include "base/feature_list.h" #include "base/metrics/field_trial.h" -#include "base/strings/string_split.h" -#include "base/strings/stringprintf.h" +#include "base/metrics/field_trial_params.h" #include "base/strings/utf_string_conversions.h" #include "base/system/sys_info.h" #include "components/variations/field_trial_config/fieldtrial_testing_config.h" -#include "components/variations/variations_associated_data.h" #include "components/variations/variations_seed_processor.h" #include "net/base/escape.h" #include "ui/base/device_form_factor.h" @@ -89,12 +87,12 @@ void AssociateParamsFromExperiment( const VariationsSeedProcessor::UIStringOverrideCallback& callback, base::FeatureList* feature_list) { if (experiment.params_size != 0) { - std::map<std::string, std::string> params; + base::FieldTrialParams params; for (size_t i = 0; i < experiment.params_size; ++i) { const FieldTrialTestingExperimentParams& param = experiment.params[i]; params[param.key] = param.value; } - AssociateVariationParams(study_name, experiment.name, params); + base::AssociateFieldTrialParams(study_name, experiment.name, params); } base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial(study_name, experiment.name); @@ -188,55 +186,8 @@ std::string EscapeValue(const std::string& value) { } bool AssociateParamsFromString(const std::string& varations_string) { - // Format: Trial1.Group1:k1/v1/k2/v2,Trial2.Group2:k1/v1/k2/v2 - std::set<std::pair<std::string, std::string>> trial_groups; - for (const base::StringPiece& experiment_group : base::SplitStringPiece( - varations_string, ",", - base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { - std::vector<base::StringPiece> experiment = base::SplitStringPiece( - experiment_group, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); - if (experiment.size() != 2) { - DLOG(ERROR) << "Experiment and params should be separated by ':'"; - return false; - } - - std::vector<std::string> group_parts = base::SplitString( - experiment[0], ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); - if (group_parts.size() != 2) { - DLOG(ERROR) << "Trial and group name should be separated by '.'"; - return false; - } - - std::vector<std::string> key_values = base::SplitString( - experiment[1], "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); - if (key_values.size() % 2 != 0) { - DLOG(ERROR) << "Param name and param value should be separated by '/'"; - return false; - } - std::string trial = UnescapeValue(group_parts[0]); - std::string group = UnescapeValue(group_parts[1]); - auto trial_group = std::make_pair(trial, group); - if (trial_groups.find(trial_group) != trial_groups.end()) { - DLOG(ERROR) << base::StringPrintf( - "A (trial, group) pair listed more than once. (%s, %s)", - trial.c_str(), group.c_str()); - return false; - } - trial_groups.insert(trial_group); - std::map<std::string, std::string> params; - for (size_t i = 0; i < key_values.size(); i += 2) { - std::string key = UnescapeValue(key_values[i]); - std::string value = UnescapeValue(key_values[i + 1]); - params[key] = value; - } - bool result = AssociateVariationParams(trial, group, params); - if (!result) { - DLOG(ERROR) << "Failed to associate variation params for group \"" - << group << "\" in trial \"" << trial << "\""; - return false; - } - } - return true; + return base::AssociateFieldTrialParamsFromString(varations_string, + &UnescapeValue); } void AssociateParamsFromFieldTrialConfig( diff --git a/chromium/components/variations/metrics.h b/chromium/components/variations/metrics.h index 5fe2b8cca20..660a4751f03 100644 --- a/chromium/components/variations/metrics.h +++ b/chromium/components/variations/metrics.h @@ -47,16 +47,21 @@ enum class StoreSeedResult { FAILED_PARSE, FAILED_SIGNATURE, FAILED_GZIP, - // DELTA_COUNT is not so much a result of the seed store, but rather counting - // the number of delta-compressed seeds the SeedStore() function saw. Kept in - // the same histogram for convenience of comparing against the other values. - DELTA_COUNT, + DELTA_COUNT_OBSOLETE, FAILED_DELTA_READ_SEED, FAILED_DELTA_APPLY, FAILED_DELTA_STORE, FAILED_UNGZIP, FAILED_EMPTY_GZIP_CONTENTS, FAILED_UNSUPPORTED_SEED_FORMAT, + // The following are not so much a result of the seed store, but rather + // counting the types of seeds the SeedStore() function saw. Kept in the same + // histogram for efficiency and convenience of comparing against the other + // values. + GZIP_DELTA_COUNT, + NON_GZIP_DELTA_COUNT, + GZIP_FULL_COUNT, + NON_GZIP_FULL_COUNT, ENUM_SIZE }; diff --git a/chromium/components/variations/net/variations_http_headers.cc b/chromium/components/variations/net/variations_http_headers.cc index 0a0ca468e4d..eeed1869976 100644 --- a/chromium/components/variations/net/variations_http_headers.cc +++ b/chromium/components/variations/net/variations_http_headers.cc @@ -157,14 +157,6 @@ bool AppendVariationsHeader(const GURL& url, .AppendHeaderIfNeeded(url, incognito); } -bool AppendVariationsHeader(const GURL& url, - InIncognito incognito, - SignedIn signed_in, - net::URLRequest* request) { - return VariationsHeaderHelper(request, signed_in) - .AppendHeaderIfNeeded(url, incognito); -} - bool AppendVariationsHeaderWithCustomValue(const GURL& url, InIncognito incognito, const std::string& variations_header, @@ -179,12 +171,6 @@ bool AppendVariationsHeaderUnknownSignedIn(const GURL& url, return VariationsHeaderHelper(request).AppendHeaderIfNeeded(url, incognito); } -bool AppendVariationsHeaderUnknownSignedIn(const GURL& url, - InIncognito incognito, - net::URLRequest* request) { - return VariationsHeaderHelper(request).AppendHeaderIfNeeded(url, incognito); -} - void RemoveVariationsHeaderIfNeeded( const net::RedirectInfo& redirect_info, const network::ResourceResponseHead& response_head, @@ -193,12 +179,6 @@ void RemoveVariationsHeaderIfNeeded( to_be_removed_headers->push_back(kClientDataHeader); } -void StripVariationsHeaderIfNeeded(const GURL& new_location, - net::URLRequest* request) { - if (!ShouldAppendVariationsHeader(new_location)) - request->RemoveRequestHeaderByName(kClientDataHeader); -} - std::unique_ptr<network::SimpleURLLoader> CreateSimpleURLLoaderWithVariationsHeader( std::unique_ptr<network::ResourceRequest> request, diff --git a/chromium/components/variations/net/variations_http_headers.h b/chromium/components/variations/net/variations_http_headers.h index a18c6eddb52..b41454900d0 100644 --- a/chromium/components/variations/net/variations_http_headers.h +++ b/chromium/components/variations/net/variations_http_headers.h @@ -15,7 +15,6 @@ namespace net { struct NetworkTrafficAnnotationTag; struct RedirectInfo; -class URLRequest; } namespace network { @@ -45,16 +44,8 @@ bool AppendVariationsHeader(const GURL& url, SignedIn signed_in, network::ResourceRequest* request); -// TODO(toyoshim): Remove this deprecated API that takes net::URLRequest* once -// all callers are removed after NetworkService being fully enabled, or migrated -// to use SimpleURLLoader. See, crbug.com/773295. -bool AppendVariationsHeader(const GURL& url, - InIncognito incognito, - SignedIn signed_in, - net::URLRequest* request); - -// Similar to functions above, but uses specified |variations_header| as the -// custom header value. You should not generally need to use this. +// Similar to AppendVariationsHeader, but uses specified |variations_header| as +// the custom header value. You should not generally need to use this. bool AppendVariationsHeaderWithCustomValue(const GURL& url, InIncognito incognito, const std::string& variations_header, @@ -66,13 +57,6 @@ bool AppendVariationsHeaderUnknownSignedIn(const GURL& url, InIncognito incognito, network::ResourceRequest* request); -// TODO(toyoshim): Remove this deprecated API that takes net::URLRequest* once -// all callers are removed after NetworkService being fully enabled, or migrated -// to use SimpleURLLoader. See, crbug.com/773295. -bool AppendVariationsHeaderUnknownSignedIn(const GURL& url, - InIncognito incognito, - net::URLRequest* request); - // Removes the variations header for requests when a redirect to a non-Google // URL occurs. void RemoveVariationsHeaderIfNeeded( @@ -80,12 +64,6 @@ void RemoveVariationsHeaderIfNeeded( const network::ResourceResponseHead& response_head, std::vector<std::string>* to_be_removed_headers); -// Strips the variations header if |new_location| does not point to a location -// that should receive it. This is being called by the ChromeNetworkDelegate. -// Components calling AppendVariationsHeader() don't need to take care of this. -void StripVariationsHeaderIfNeeded(const GURL& new_location, - net::URLRequest* request); - // Creates a SimpleURLLoader that will include the variations header for // requests to Google and ensures they're removed if a redirect to a non-Google // URL occurs. diff --git a/chromium/components/variations/pref_names.cc b/chromium/components/variations/pref_names.cc index 2c950993043..b75b75ac14e 100644 --- a/chromium/components/variations/pref_names.cc +++ b/chromium/components/variations/pref_names.cc @@ -33,6 +33,13 @@ const char kVariationsLastFetchTime[] = "variations_last_fetch_time"; const char kVariationsPermanentConsistencyCountry[] = "variations_permanent_consistency_country"; +// A country code string representing the country used for filtering permanent +// consistency studies and will not be updated on Chrome updated. It can be +// changed via chrome://translate-internals and is intended for +// testing / developer use. +const char kVariationsPermanentOverriddenCountry[] = + "variations_permanent_overridden_country"; + // String for the restrict parameter to be appended to the variations URL. const char kVariationsRestrictParameter[] = "variations_restrict_parameter"; diff --git a/chromium/components/variations/pref_names.h b/chromium/components/variations/pref_names.h index 2b86485e707..a1f2e1db94a 100644 --- a/chromium/components/variations/pref_names.h +++ b/chromium/components/variations/pref_names.h @@ -17,6 +17,7 @@ extern const char kVariationsCrashStreak[]; extern const char kVariationsFailedToFetchSeedStreak[]; extern const char kVariationsLastFetchTime[]; extern const char kVariationsPermanentConsistencyCountry[]; +extern const char kVariationsPermanentOverriddenCountry[]; extern const char kVariationsRestrictParameter[]; extern const char kVariationsSafeCompressedSeed[]; extern const char kVariationsSafeSeedDate[]; diff --git a/chromium/components/variations/service/BUILD.gn b/chromium/components/variations/service/BUILD.gn index 341c18e7744..8163600d519 100644 --- a/chromium/components/variations/service/BUILD.gn +++ b/chromium/components/variations/service/BUILD.gn @@ -32,6 +32,7 @@ static_library("service") { "variations_field_trial_creator.h", "variations_service.cc", "variations_service.h", + "variations_service_client.cc", "variations_service_client.h", ] diff --git a/chromium/components/variations/service/variations_field_trial_creator.cc b/chromium/components/variations/service/variations_field_trial_creator.cc index 7c6a2a7e733..5abe50de8a6 100644 --- a/chromium/components/variations/service/variations_field_trial_creator.cc +++ b/chromium/components/variations/service/variations_field_trial_creator.cc @@ -55,23 +55,6 @@ 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() { @@ -122,26 +105,9 @@ base::Version GetOSVersion() { return ret; } -// Wrapper around channel checking, used to enable channel mocking for -// testing. If a fake channel flag is provided, it will take precedence. -// Otherwise, this will return the current browser channel (which could be -// UNKNOWN). -Study::Channel GetChannelForVariations(version_info::Channel product_channel) { - const std::string forced_channel = - base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - switches::kFakeVariationsChannel); - if (!forced_channel.empty()) { - if (forced_channel == "stable") - return Study::STABLE; - if (forced_channel == "beta") - return Study::BETA; - if (forced_channel == "dev") - return Study::DEV; - if (forced_channel == "canary") - return Study::CANARY; - DVLOG(1) << "Invalid channel provided: " << forced_channel; - } - +// Just maps one set of enum values to another. Nothing to see here. +Study::Channel ConvertProductChannelToStudyChannel( + version_info::Channel product_channel) { switch (product_channel) { case version_info::Channel::CANARY: return Study::CANARY; @@ -274,7 +240,8 @@ VariationsFieldTrialCreator::GetClientFilterableStateForVersion( state->reference_date = GetReferenceDateForExpiryChecks(local_state()); state->version = version; state->os_version = GetOSVersion(); - state->channel = GetChannelForVariations(client_->GetChannel()); + state->channel = + ConvertProductChannelToStudyChannel(client_->GetChannelForVariations()); state->form_factor = GetCurrentFormFactor(); state->platform = GetPlatform(); state->hardware_class = GetShortHardwareClass(); @@ -303,6 +270,16 @@ std::string VariationsFieldTrialCreator::LoadPermanentConsistencyCountry( if (!override_country.empty()) return override_country; + const std::string permanent_overridden_country = + local_state()->GetString(prefs::kVariationsPermanentOverriddenCountry); + + if (!permanent_overridden_country.empty()) { + base::UmaHistogramEnumeration( + "Variations.LoadPermanentConsistencyCountryResult", + LOAD_COUNTRY_HAS_PERMANENT_OVERRIDDEN_COUNTRY, LOAD_COUNTRY_MAX); + return permanent_overridden_country; + } + const base::ListValue* list_value = local_state()->GetList(prefs::kVariationsPermanentConsistencyCountry); std::string stored_version_string; @@ -376,6 +353,12 @@ void VariationsFieldTrialCreator::StorePermanentCountry( new_list_value); } +void VariationsFieldTrialCreator::StoreVariationsOverriddenCountry( + const std::string& country) { + local_state()->SetString(prefs::kVariationsPermanentOverriddenCountry, + country); +} + void VariationsFieldTrialCreator::OverrideVariationsPlatform( Study::Platform platform_override) { has_platform_override_ = true; diff --git a/chromium/components/variations/service/variations_field_trial_creator.h b/chromium/components/variations/service/variations_field_trial_creator.h index def6af0ec27..5159583fc77 100644 --- a/chromium/components/variations/service/variations_field_trial_creator.h +++ b/chromium/components/variations/service/variations_field_trial_creator.h @@ -22,6 +22,21 @@ namespace variations { +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_HAS_PERMANENT_OVERRIDDEN_COUNTRY, + LOAD_COUNTRY_MAX, +}; + class PlatformFieldTrials; class SafeSeedManager; class VariationsServiceClient; @@ -87,6 +102,10 @@ class VariationsFieldTrialCreator { void StorePermanentCountry(const base::Version& version, const std::string& country); + // Sets the stored permanent variations overridden country pref for this + // client. + void StoreVariationsOverriddenCountry(const std::string& country); + // Records the time of the most recent successful fetch. void RecordLastFetchTime(); diff --git a/chromium/components/variations/service/variations_field_trial_creator_unittest.cc b/chromium/components/variations/service/variations_field_trial_creator_unittest.cc index 3910b35828c..8da72309ea6 100644 --- a/chromium/components/variations/service/variations_field_trial_creator_unittest.cc +++ b/chromium/components/variations/service/variations_field_trial_creator_unittest.cc @@ -177,9 +177,6 @@ class TestVariationsServiceClient : public VariationsServiceClient { network_time::NetworkTimeTracker* GetNetworkTimeTracker() override { return nullptr; } - version_info::Channel GetChannel() override { - return version_info::Channel::UNKNOWN; - } bool OverridesRestrictParameter(std::string* parameter) override { if (restrict_parameter_.empty()) return false; @@ -192,6 +189,11 @@ class TestVariationsServiceClient : public VariationsServiceClient { } private: + // VariationsServiceClient: + version_info::Channel GetChannel() override { + return version_info::Channel::UNKNOWN; + } + std::string restrict_parameter_; DISALLOW_COPY_AND_ASSIGN(TestVariationsServiceClient); diff --git a/chromium/components/variations/service/variations_service.cc b/chromium/components/variations/service/variations_service.cc index 2066c217372..6b6218855a1 100644 --- a/chromium/components/variations/service/variations_service.cc +++ b/chromium/components/variations/service/variations_service.cc @@ -296,8 +296,7 @@ VariationsService::VariationsService( MaybeImportFirstRunSeed(local_state), base::BindOnce(&OnInitialSeedStored)), ui_string_overrider), - last_request_was_http_retry_(false), - weak_ptr_factory_(this) { + last_request_was_http_retry_(false) { DCHECK(client_); DCHECK(resource_request_allowed_notifier_); } @@ -401,7 +400,7 @@ GURL VariationsService::GetVariationsServerURL(HttpOptions http_options) { GetPlatformString()); // Add channel to the request URL. - version_info::Channel channel = client_->GetChannel(); + version_info::Channel channel = client_->GetChannelForVariations(); if (channel != version_info::Channel::UNKNOWN) { server_url = net::AppendOrReplaceQueryParameter( server_url, "channel", version_info::GetChannelString(channel)); @@ -454,6 +453,10 @@ void VariationsService::RegisterPrefs(PrefRegistrySimple* registry) { // it according to a value stored in the User Policy. registry->RegisterStringPref(prefs::kVariationsRestrictParameter, std::string()); + // This preference is used to override the variations country code which is + // consistent across different chrome version. + registry->RegisterStringPref(prefs::kVariationsPermanentOverriddenCountry, + std::string()); // This preference keeps track of the country code used to filter // permanent-consistency studies. registry->RegisterListPref(prefs::kVariationsPermanentConsistencyCountry); @@ -925,7 +928,16 @@ void VariationsService::StartRepeatedVariationsSeedFetchForTesting() { return StartRepeatedVariationsSeedFetch(); } +std::string VariationsService::GetOverriddenPermanentCountry() { + return local_state_->GetString(prefs::kVariationsPermanentOverriddenCountry); +} + std::string VariationsService::GetStoredPermanentCountry() { + const std::string variations_overridden_country = + GetOverriddenPermanentCountry(); + if (!variations_overridden_country.empty()) + return variations_overridden_country; + const base::ListValue* list_value = local_state_->GetList(prefs::kVariationsPermanentConsistencyCountry); std::string stored_country; @@ -941,21 +953,13 @@ bool VariationsService::OverrideStoredPermanentCountry( const std::string& country_override) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - if (country_override.empty()) - return false; - - const base::ListValue* list_value = - local_state_->GetList(prefs::kVariationsPermanentConsistencyCountry); - - std::string stored_country; - const bool got_stored_country = - list_value->GetSize() == 2 && list_value->GetString(1, &stored_country); + const std::string stored_country = + local_state_->GetString(prefs::kVariationsPermanentOverriddenCountry); - if (got_stored_country && stored_country == country_override) + if (stored_country == country_override) return false; - base::Version version(version_info::GetVersionNumber()); - field_trial_creator_.StorePermanentCountry(version, country_override); + field_trial_creator_.StoreVariationsOverriddenCountry(country_override); return true; } diff --git a/chromium/components/variations/service/variations_service.h b/chromium/components/variations/service/variations_service.h index ebe1a83bfbf..9943cc501fc 100644 --- a/chromium/components/variations/service/variations_service.h +++ b/chromium/components/variations/service/variations_service.h @@ -120,6 +120,10 @@ class VariationsService // should happen in that case. GURL GetVariationsServerURL(HttpOptions http_options); + // Returns the permanent overridden country code stored for this client. This + // value will not be updated on Chrome updates. + std::string GetOverriddenPermanentCountry(); + // Returns the permanent country code stored for this client. Country code is // in the format of lowercase ISO 3166-1 alpha-2. Example: us, br, in std::string GetStoredPermanentCountry(); @@ -290,23 +294,6 @@ class VariationsService FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, DoNotRetryIfInsecureURLIsHTTPS); - // 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, - }; - void InitResourceRequestedAllowedNotifier(); // Calls FetchVariationsSeed once and repeats this periodically. See @@ -432,7 +419,7 @@ class VariationsService SEQUENCE_CHECKER(sequence_checker_); - base::WeakPtrFactory<VariationsService> weak_ptr_factory_; + base::WeakPtrFactory<VariationsService> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(VariationsService); }; diff --git a/chromium/components/variations/service/variations_service_client.cc b/chromium/components/variations/service/variations_service_client.cc new file mode 100644 index 00000000000..bda4511f546 --- /dev/null +++ b/chromium/components/variations/service/variations_service_client.cc @@ -0,0 +1,32 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/variations/service/variations_service_client.h" + +#include "base/command_line.h" +#include "components/variations/variations_switches.h" + +namespace variations { + +version_info::Channel VariationsServiceClient::GetChannelForVariations() { + const std::string forced_channel = + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kFakeVariationsChannel); + if (!forced_channel.empty()) { + if (forced_channel == "stable") + return version_info::Channel::STABLE; + if (forced_channel == "beta") + return version_info::Channel::BETA; + if (forced_channel == "dev") + return version_info::Channel::DEV; + if (forced_channel == "canary") + return version_info::Channel::CANARY; + DVLOG(1) << "Invalid channel provided: " << forced_channel; + } + + // Return the embedder-provided channel if no forced channel is specified. + return GetChannel(); +} + +} // namespace variations diff --git a/chromium/components/variations/service/variations_service_client.h b/chromium/components/variations/service/variations_service_client.h index 640aefb52f8..ceff2c541a8 100644 --- a/chromium/components/variations/service/variations_service_client.h +++ b/chromium/components/variations/service/variations_service_client.h @@ -39,13 +39,21 @@ class VariationsServiceClient { GetURLLoaderFactory() = 0; virtual network_time::NetworkTimeTracker* GetNetworkTimeTracker() = 0; - // Gets the channel of the embedder. - virtual version_info::Channel GetChannel() = 0; - // Returns whether the embedder overrides the value of the restrict parameter. // |parameter| is an out-param that will contain the value of the restrict // parameter if true is returned. virtual bool OverridesRestrictParameter(std::string* parameter) = 0; + + // Gets the channel to use for variations. The --fake-variations-channel + // override switch takes precedence over the embedder-provided channel. + // If that switch is not set, it will return the embedder-provided channel, + // (which could be UNKNOWN). + version_info::Channel GetChannelForVariations(); + + private: + // Gets the channel of the embedder. But all variations callers should use + // |GetChannelForVariations()| instead. + virtual version_info::Channel GetChannel() = 0; }; } // namespace variations diff --git a/chromium/components/variations/service/variations_service_unittest.cc b/chromium/components/variations/service/variations_service_unittest.cc index ace3b64bd14..a253b9b55f8 100644 --- a/chromium/components/variations/service/variations_service_unittest.cc +++ b/chromium/components/variations/service/variations_service_unittest.cc @@ -96,7 +96,6 @@ class TestVariationsServiceClient : public VariationsServiceClient { network_time::NetworkTimeTracker* GetNetworkTimeTracker() override { return nullptr; } - version_info::Channel GetChannel() override { return channel_; } bool OverridesRestrictParameter(std::string* parameter) override { if (restrict_parameter_.empty()) return false; @@ -115,6 +114,9 @@ class TestVariationsServiceClient : public VariationsServiceClient { } private: + // VariationsServiceClient: + version_info::Channel GetChannel() override { return channel_; } + std::string restrict_parameter_; version_info::Channel channel_ = version_info::Channel::UNKNOWN; network::TestURLLoaderFactory test_url_loader_factory_; @@ -428,7 +430,8 @@ TEST_F(VariationsServiceTest, VariationsURLHasParams) { } TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) { - net::test::MockNetworkChangeNotifier network_change_notifier; + std::unique_ptr<net::test::MockNetworkChangeNotifier> + network_change_notifier = net::test::MockNetworkChangeNotifier::Create(); // Pass ownership to TestVariationsService, but keep a weak pointer to // manipulate it for this test. std::unique_ptr<web_resource::TestRequestAllowedNotifier> test_notifier = @@ -649,55 +652,62 @@ TEST_F(VariationsServiceTest, Observer) { TEST_F(VariationsServiceTest, LoadPermanentConsistencyCountry) { struct { + const char* permanent_overridden_country_before; // Comma separated list, NULL if the pref isn't set initially. - const char* pref_value_before; + const char* permanent_consistency_country_before; const char* version; // NULL indicates that no latest country code is present. const char* latest_country_code; // Comma separated list. - const char* expected_pref_value_after; + const char* permanent_consistency_country_after; std::string expected_country; - VariationsService::LoadPermanentConsistencyCountryResult expected_result; + LoadPermanentConsistencyCountryResult expected_result; } test_cases[] = { + // Existing permanent overridden country. + {"ca", "20.0.0.0,us", "20.0.0.0", "us", "20.0.0.0,us", "ca", + LOAD_COUNTRY_HAS_PERMANENT_OVERRIDDEN_COUNTRY}, + {"us", "20.0.0.0,us", "20.0.0.0", "us", "20.0.0.0,us", "us", + LOAD_COUNTRY_HAS_PERMANENT_OVERRIDDEN_COUNTRY}, + {"ca", nullptr, "20.0.0.0", nullptr, nullptr, "ca", + LOAD_COUNTRY_HAS_PERMANENT_OVERRIDDEN_COUNTRY}, + // Existing pref value present for this version. - {"20.0.0.0,us", "20.0.0.0", "ca", "20.0.0.0,us", "us", - VariationsService::LOAD_COUNTRY_HAS_BOTH_VERSION_EQ_COUNTRY_NEQ}, - {"20.0.0.0,us", "20.0.0.0", "us", "20.0.0.0,us", "us", - VariationsService::LOAD_COUNTRY_HAS_BOTH_VERSION_EQ_COUNTRY_EQ}, - {"20.0.0.0,us", "20.0.0.0", nullptr, "20.0.0.0,us", "us", - VariationsService::LOAD_COUNTRY_HAS_PREF_NO_SEED_VERSION_EQ}, + {"", "20.0.0.0,us", "20.0.0.0", "ca", "20.0.0.0,us", "us", + LOAD_COUNTRY_HAS_BOTH_VERSION_EQ_COUNTRY_NEQ}, + {"", "20.0.0.0,us", "20.0.0.0", "us", "20.0.0.0,us", "us", + LOAD_COUNTRY_HAS_BOTH_VERSION_EQ_COUNTRY_EQ}, + {"", "20.0.0.0,us", "20.0.0.0", nullptr, "20.0.0.0,us", "us", + LOAD_COUNTRY_HAS_PREF_NO_SEED_VERSION_EQ}, // Existing pref value present for a different version. - {"19.0.0.0,ca", "20.0.0.0", "us", "20.0.0.0,us", "us", - VariationsService::LOAD_COUNTRY_HAS_BOTH_VERSION_NEQ_COUNTRY_NEQ}, - {"19.0.0.0,us", "20.0.0.0", "us", "20.0.0.0,us", "us", - VariationsService::LOAD_COUNTRY_HAS_BOTH_VERSION_NEQ_COUNTRY_EQ}, - {"19.0.0.0,ca", "20.0.0.0", nullptr, "19.0.0.0,ca", "", - VariationsService::LOAD_COUNTRY_HAS_PREF_NO_SEED_VERSION_NEQ}, + {"", "19.0.0.0,ca", "20.0.0.0", "us", "20.0.0.0,us", "us", + LOAD_COUNTRY_HAS_BOTH_VERSION_NEQ_COUNTRY_NEQ}, + {"", "19.0.0.0,us", "20.0.0.0", "us", "20.0.0.0,us", "us", + LOAD_COUNTRY_HAS_BOTH_VERSION_NEQ_COUNTRY_EQ}, + {"", "19.0.0.0,ca", "20.0.0.0", nullptr, "19.0.0.0,ca", "", + LOAD_COUNTRY_HAS_PREF_NO_SEED_VERSION_NEQ}, // No existing pref value present. - {nullptr, "20.0.0.0", "us", "20.0.0.0,us", "us", - VariationsService::LOAD_COUNTRY_NO_PREF_HAS_SEED}, - {nullptr, "20.0.0.0", nullptr, "", "", - VariationsService::LOAD_COUNTRY_NO_PREF_NO_SEED}, - {"", "20.0.0.0", "us", "20.0.0.0,us", "us", - VariationsService::LOAD_COUNTRY_NO_PREF_HAS_SEED}, - {"", "20.0.0.0", nullptr, "", "", - VariationsService::LOAD_COUNTRY_NO_PREF_NO_SEED}, + {"", nullptr, "20.0.0.0", "us", "20.0.0.0,us", "us", + LOAD_COUNTRY_NO_PREF_HAS_SEED}, + {"", nullptr, "20.0.0.0", nullptr, "", "", LOAD_COUNTRY_NO_PREF_NO_SEED}, + {"", "", "20.0.0.0", "us", "20.0.0.0,us", "us", + LOAD_COUNTRY_NO_PREF_HAS_SEED}, + {"", "", "20.0.0.0", nullptr, "", "", LOAD_COUNTRY_NO_PREF_NO_SEED}, // Invalid existing pref value. - {"20.0.0.0", "20.0.0.0", "us", "20.0.0.0,us", "us", - VariationsService::LOAD_COUNTRY_INVALID_PREF_HAS_SEED}, - {"20.0.0.0", "20.0.0.0", nullptr, "", "", - VariationsService::LOAD_COUNTRY_INVALID_PREF_NO_SEED}, - {"20.0.0.0,us,element3", "20.0.0.0", "us", "20.0.0.0,us", "us", - VariationsService::LOAD_COUNTRY_INVALID_PREF_HAS_SEED}, - {"20.0.0.0,us,element3", "20.0.0.0", nullptr, "", "", - VariationsService::LOAD_COUNTRY_INVALID_PREF_NO_SEED}, - {"badversion,ca", "20.0.0.0", "us", "20.0.0.0,us", "us", - VariationsService::LOAD_COUNTRY_INVALID_PREF_HAS_SEED}, - {"badversion,ca", "20.0.0.0", nullptr, "", "", - VariationsService::LOAD_COUNTRY_INVALID_PREF_NO_SEED}, + {"", "20.0.0.0", "20.0.0.0", "us", "20.0.0.0,us", "us", + LOAD_COUNTRY_INVALID_PREF_HAS_SEED}, + {"", "20.0.0.0", "20.0.0.0", nullptr, "", "", + LOAD_COUNTRY_INVALID_PREF_NO_SEED}, + {"", "20.0.0.0,us,element3", "20.0.0.0", "us", "20.0.0.0,us", "us", + LOAD_COUNTRY_INVALID_PREF_HAS_SEED}, + {"", "20.0.0.0,us,element3", "20.0.0.0", nullptr, "", "", + LOAD_COUNTRY_INVALID_PREF_NO_SEED}, + {"", "badversion,ca", "20.0.0.0", "us", "20.0.0.0,us", "us", + LOAD_COUNTRY_INVALID_PREF_HAS_SEED}, + {"", "badversion,ca", "20.0.0.0", nullptr, "", "", + LOAD_COUNTRY_INVALID_PREF_NO_SEED}, }; for (const auto& test : test_cases) { @@ -707,13 +717,20 @@ TEST_F(VariationsServiceTest, LoadPermanentConsistencyCountry) { &prefs_, network_tracker_), &prefs_, GetMetricsStateManager(), UIStringOverrider()); - if (!test.pref_value_before) { + if (!test.permanent_overridden_country_before) { + prefs_.ClearPref(prefs::kVariationsPermanentOverriddenCountry); + } else { + prefs_.SetString(prefs::kVariationsPermanentOverriddenCountry, + test.permanent_overridden_country_before); + } + + if (!test.permanent_consistency_country_before) { prefs_.ClearPref(prefs::kVariationsPermanentConsistencyCountry); } else { base::ListValue list_value; for (const std::string& component : - base::SplitString(test.pref_value_before, ",", base::TRIM_WHITESPACE, - base::SPLIT_WANT_ALL)) { + base::SplitString(test.permanent_consistency_country_before, ",", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { list_value.AppendString(component); } prefs_.Set(prefs::kVariationsPermanentConsistencyCountry, list_value); @@ -728,12 +745,12 @@ TEST_F(VariationsServiceTest, LoadPermanentConsistencyCountry) { EXPECT_EQ(test.expected_country, service.LoadPermanentConsistencyCountry( base::Version(test.version), latest_country)) - << test.pref_value_before << ", " << test.version << ", " - << test.latest_country_code; + << test.permanent_consistency_country_before << ", " << test.version + << ", " << test.latest_country_code; base::ListValue expected_list_value; for (const std::string& component : - base::SplitString(test.expected_pref_value_after, ",", + base::SplitString(test.permanent_consistency_country_after, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { expected_list_value.AppendString(component); } @@ -741,8 +758,8 @@ TEST_F(VariationsServiceTest, LoadPermanentConsistencyCountry) { prefs_.GetList(prefs::kVariationsPermanentConsistencyCountry); EXPECT_EQ(ListValueToString(expected_list_value), ListValueToString(*pref_value)) - << test.pref_value_before << ", " << test.version << ", " - << test.latest_country_code; + << test.permanent_consistency_country_before << ", " << test.version + << ", " << test.latest_country_code; histogram_tester.ExpectUniqueSample( "Variations.LoadPermanentConsistencyCountryResult", @@ -750,27 +767,70 @@ TEST_F(VariationsServiceTest, LoadPermanentConsistencyCountry) { } } +TEST_F(VariationsServiceTest, GetStoredPermanentCountry) { + struct { + // The old overridden country, empty string if the pref isn't set initially. + const std::string permanent_overridden_country_before; + // Comma separated list, NULL if the pref isn't set initially. + const std::string permanent_consistency_country_before; + const std::string expected_country; + } test_cases[] = { + {"", "20.0.0.0,us", "us"}, + {"us", "20.0.0.0,us", "us"}, + {"ca", "20.0.0.0,us", "ca"}, + {"ca", "", "ca"}, + }; + + for (const auto& test : test_cases) { + TestVariationsService service( + std::make_unique<web_resource::TestRequestAllowedNotifier>( + &prefs_, network_tracker_), + &prefs_, GetMetricsStateManager(), true); + + if (test.permanent_overridden_country_before.empty()) { + prefs_.ClearPref(prefs::kVariationsPermanentOverriddenCountry); + } else { + prefs_.SetString(prefs::kVariationsPermanentOverriddenCountry, + test.permanent_overridden_country_before); + } + + if (test.permanent_consistency_country_before.empty()) { + prefs_.ClearPref(prefs::kVariationsPermanentConsistencyCountry); + } else { + base::ListValue list_value; + for (const std::string& component : + base::SplitString(test.permanent_consistency_country_before, ",", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { + list_value.AppendString(component); + } + prefs_.Set(prefs::kVariationsPermanentConsistencyCountry, list_value); + } + + VariationsSeed seed(CreateTestSeed()); + + EXPECT_EQ(test.expected_country, service.GetStoredPermanentCountry()) + << test.permanent_overridden_country_before << ", " + << test.permanent_consistency_country_before; + } +} + TEST_F(VariationsServiceTest, OverrideStoredPermanentCountry) { - const std::string kTestVersion = version_info::GetVersionNumber(); - const std::string kPrefCa = version_info::GetVersionNumber() + ",ca"; - const std::string kPrefUs = version_info::GetVersionNumber() + ",us"; + const std::string kPrefCa = "ca"; + const std::string kPrefUs = "us"; struct { - // Comma separated list, empty string if the pref isn't set initially. + // The old overridden country, empty string if the pref isn't set initially. const std::string pref_value_before; const std::string country_code_override; - // Comma separated list. + // The expected override country. const std::string expected_pref_value_after; // Is the pref expected to be updated or not. const bool has_updated; } test_cases[] = { {kPrefUs, "ca", kPrefCa, true}, {kPrefUs, "us", kPrefUs, false}, - {kPrefUs, "", kPrefUs, false}, + {kPrefUs, "", "", true}, {"", "ca", kPrefCa, true}, - {"", "", "", false}, - {"19.0.0.0,us", "ca", kPrefCa, true}, - {"19.0.0.0,us", "us", "19.0.0.0,us", false}, }; for (const auto& test : test_cases) { @@ -780,15 +840,10 @@ TEST_F(VariationsServiceTest, OverrideStoredPermanentCountry) { &prefs_, GetMetricsStateManager(), true); if (test.pref_value_before.empty()) { - prefs_.ClearPref(prefs::kVariationsPermanentConsistencyCountry); + prefs_.ClearPref(prefs::kVariationsPermanentOverriddenCountry); } else { - base::ListValue list_value; - for (const std::string& component : - base::SplitString(test.pref_value_before, ",", base::TRIM_WHITESPACE, - base::SPLIT_WANT_ALL)) { - list_value.AppendString(component); - } - prefs_.Set(prefs::kVariationsPermanentConsistencyCountry, list_value); + prefs_.SetString(prefs::kVariationsPermanentOverriddenCountry, + test.pref_value_before); } VariationsSeed seed(CreateTestSeed()); @@ -797,16 +852,9 @@ TEST_F(VariationsServiceTest, OverrideStoredPermanentCountry) { test.country_code_override)) << test.pref_value_before << ", " << test.country_code_override; - base::ListValue expected_list_value; - for (const std::string& component : - base::SplitString(test.expected_pref_value_after, ",", - base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { - expected_list_value.AppendString(component); - } - const base::ListValue* pref_value = - prefs_.GetList(prefs::kVariationsPermanentConsistencyCountry); - EXPECT_EQ(ListValueToString(expected_list_value), - ListValueToString(*pref_value)) + const std::string pref_value = + prefs_.GetString(prefs::kVariationsPermanentOverriddenCountry); + EXPECT_EQ(test.expected_pref_value_after, pref_value) << test.pref_value_before << ", " << test.country_code_override; } } @@ -833,7 +881,8 @@ TEST_F(VariationsServiceTest, SafeMode_SuccessfulFetchClearsFailureStreaks) { VariationsService::EnableFetchForTesting(); - net::test::MockNetworkChangeNotifier network_change_notifier; + std::unique_ptr<net::test::MockNetworkChangeNotifier> + network_change_notifier = net::test::MockNetworkChangeNotifier::Create(); // Create a variations service and perform a successful fetch. TestVariationsService service( diff --git a/chromium/components/variations/study_filtering.cc b/chromium/components/variations/study_filtering.cc index 9c95beb1179..93f56b903b3 100644 --- a/chromium/components/variations/study_filtering.cc +++ b/chromium/components/variations/study_filtering.cc @@ -21,7 +21,7 @@ base::Time ConvertStudyDateToBaseTime(int64_t date_time) { return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(date_time); } -// Similar to base::ContainsValue(), but specifically for ASCII strings and +// Similar to base::Contains(), but specifically for ASCII strings and // case-insensitive comparison. template <typename Collection> bool ContainsStringIgnoreCaseASCII(const Collection& collection, @@ -59,10 +59,10 @@ bool CheckStudyFormFactor(const Study::Filter& filter, // ignored. We do not expect both to be present for Chrome due to server-side // checks. if (filter.form_factor_size() > 0) - return base::ContainsValue(filter.form_factor(), form_factor); + return base::Contains(filter.form_factor(), form_factor); // Omit if we match the blacklist. - return !base::ContainsValue(filter.exclude_form_factor(), form_factor); + return !base::Contains(filter.exclude_form_factor(), form_factor); } bool CheckStudyHardwareClass(const Study::Filter& filter, @@ -99,10 +99,10 @@ bool CheckStudyLocale(const Study::Filter& filter, const std::string& locale) { // that this means this overrides the exclude_locale in case that ever occurs // (which it shouldn't). if (filter.locale_size() > 0) - return base::ContainsValue(filter.locale(), locale); + return base::Contains(filter.locale(), locale); // Omit if matches any of the exclude entries. - return !base::ContainsValue(filter.exclude_locale(), locale); + return !base::Contains(filter.exclude_locale(), locale); } bool CheckStudyPlatform(const Study::Filter& filter, Study::Platform platform) { @@ -184,10 +184,10 @@ bool CheckStudyCountry(const Study::Filter& filter, // that this means this overrides the exclude_country in case that ever occurs // (which it shouldn't). if (filter.country_size() > 0) - return base::ContainsValue(filter.country(), country); + return base::Contains(filter.country(), country); // Omit if matches any of the exclude entries. - return !base::ContainsValue(filter.exclude_country(), country); + return !base::Contains(filter.exclude_country(), country); } const std::string& GetClientCountryForStudy( @@ -312,14 +312,14 @@ void FilterAndValidateStudies(const VariationsSeed& seed, if (internal::IsStudyExpired(study, client_state.reference_date)) { expired_studies.push_back(&study); - } else if (!base::ContainsKey(created_studies, study.name())) { + } else if (!base::Contains(created_studies, study.name())) { ProcessedStudy::ValidateAndAppendStudy(&study, false, filtered_studies); created_studies.insert(study.name()); } } for (size_t i = 0; i < expired_studies.size(); ++i) { - if (!base::ContainsKey(created_studies, expired_studies[i]->name())) { + if (!base::Contains(created_studies, expired_studies[i]->name())) { ProcessedStudy::ValidateAndAppendStudy(expired_studies[i], true, filtered_studies); } diff --git a/chromium/components/variations/synthetic_trial_registry_unittest.cc b/chromium/components/variations/synthetic_trial_registry_unittest.cc index 5e8f0f391e7..0ab93744fd2 100644 --- a/chromium/components/variations/synthetic_trial_registry_unittest.cc +++ b/chromium/components/variations/synthetic_trial_registry_unittest.cc @@ -175,11 +175,11 @@ TEST_F(SyntheticTrialRegistryTest, GetSyntheticFieldTrialActiveGroups) { std::string trial1_hash = base::StringPrintf("%x-%x", trial1.id.name, trial1.id.group); - EXPECT_TRUE(base::ContainsValue(output, trial1_hash)); + EXPECT_TRUE(base::Contains(output, trial1_hash)); std::string trial2_hash = base::StringPrintf("%x-%x", trial2.id.name, trial2.id.group); - EXPECT_TRUE(base::ContainsValue(output, trial2_hash)); + EXPECT_TRUE(base::Contains(output, trial2_hash)); } } // namespace variations diff --git a/chromium/components/variations/variations_crash_keys_unittest.cc b/chromium/components/variations/variations_crash_keys_unittest.cc index a28cc5a05df..633f2cd5611 100644 --- a/chromium/components/variations/variations_crash_keys_unittest.cc +++ b/chromium/components/variations/variations_crash_keys_unittest.cc @@ -32,7 +32,7 @@ class VariationsCrashKeysTest : public ::testing::Test { public: VariationsCrashKeysTest() : field_trial_list_(nullptr) { crash_reporter::ResetCrashKeysForTesting(); - crash_reporter::InitializeCrashKeys(); + crash_reporter::InitializeCrashKeysForTesting(); } ~VariationsCrashKeysTest() override { @@ -51,13 +51,7 @@ class VariationsCrashKeysTest : public ::testing::Test { } // namespace -// TODO(crbug.com/821162): Test fails on iOS. Re-enable after fixing. -#if defined(OS_IOS) -#define MAYBE_BasicFunctionality DISABLED_BasicFunctionality -#else -#define MAYBE_BasicFunctionality BasicFunctionality -#endif -TEST_F(VariationsCrashKeysTest, MAYBE_BasicFunctionality) { +TEST_F(VariationsCrashKeysTest, BasicFunctionality) { SyntheticTrialRegistry registry; registry.AddSyntheticTrialObserver( SyntheticTrialsActiveGroupIdProvider::GetInstance()); diff --git a/chromium/components/variations/variations_http_header_provider.cc b/chromium/components/variations/variations_http_header_provider.cc index 24c43fcca6b..afef2d08eb5 100644 --- a/chromium/components/variations/variations_http_header_provider.cc +++ b/chromium/components/variations/variations_http_header_provider.cc @@ -194,8 +194,6 @@ void VariationsHttpHeaderProvider::InitVariationIDsCacheIfNeeded() { DCHECK(base::ThreadTaskRunnerHandle::IsSet()); base::FieldTrialList::AddObserver(this); - base::TimeTicks before_time = base::TimeTicks::Now(); - base::FieldTrial::ActiveGroups initial_groups; base::FieldTrialList::GetActiveFieldTrialGroups(&initial_groups); @@ -209,11 +207,6 @@ void VariationsHttpHeaderProvider::InitVariationIDsCacheIfNeeded() { } UpdateVariationIDsHeaderValue(); - UMA_HISTOGRAM_CUSTOM_COUNTS( - "Variations.HeaderConstructionTime", - (base::TimeTicks::Now() - before_time).InMicroseconds(), 1, - base::TimeDelta::FromSeconds(1).InMicroseconds(), 50); - variation_ids_cache_initialized_ = true; } diff --git a/chromium/components/variations/variations_params_manager.h b/chromium/components/variations/variations_params_manager.h index 2c61c52b904..0d6342029c3 100644 --- a/chromium/components/variations/variations_params_manager.h +++ b/chromium/components/variations/variations_params_manager.h @@ -11,7 +11,6 @@ #include <string> #include "base/macros.h" -#include "base/metrics/field_trial.h" namespace base { class CommandLine; @@ -26,6 +25,10 @@ class ScopedFeatureList; namespace variations { namespace testing { +// NOTE: THIS CLASS IS DEPRECATED. Please use ScopedFeatureList instead, which +// provides equivalent functionality. +// TODO(asvitkine): Migrate callers and remove this class. +// // Use this class as a member in your test class to set variation params for // your tests. You can directly set the parameters in the constructor (if they // are used by other members upon construction). You can change them later diff --git a/chromium/components/variations/variations_seed_store.cc b/chromium/components/variations/variations_seed_store.cc index 152a47cf023..f9ae86caf5e 100644 --- a/chromium/components/variations/variations_seed_store.cc +++ b/chromium/components/variations/variations_seed_store.cc @@ -151,9 +151,18 @@ bool VariationsSeedStore::StoreSeedData( bool is_gzip_compressed, bool fetched_insecurely, VariationsSeed* parsed_seed) { - UMA_HISTOGRAM_BOOLEAN("Variations.StoreSeed.HasCountry", - !country_code.empty()); - + UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.DataSize", + data.length() / 1024); + + if (is_delta_compressed && is_gzip_compressed) { + RecordStoreSeedResult(StoreSeedResult::GZIP_DELTA_COUNT); + } else if (is_delta_compressed) { + RecordStoreSeedResult(StoreSeedResult::NON_GZIP_DELTA_COUNT); + } else if (is_gzip_compressed) { + RecordStoreSeedResult(StoreSeedResult::GZIP_FULL_COUNT); + } else { + RecordStoreSeedResult(StoreSeedResult::NON_GZIP_FULL_COUNT); + } // If the data is gzip compressed, first uncompress it. std::string ungzipped_data; if (is_gzip_compressed) { @@ -162,12 +171,6 @@ bool VariationsSeedStore::StoreSeedData( RecordStoreSeedResult(StoreSeedResult::FAILED_EMPTY_GZIP_CONTENTS); return false; } - - int size_reduction = ungzipped_data.length() - data.length(); - UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.GzipSize.ReductionPercent", - 100 * size_reduction / ungzipped_data.length()); - UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.GzipSize", - data.length() / 1024); } else { RecordStoreSeedResult(StoreSeedResult::FAILED_UNGZIP); return false; @@ -177,19 +180,12 @@ bool VariationsSeedStore::StoreSeedData( } if (!is_delta_compressed) { - const bool result = StoreSeedDataNoDelta( - ungzipped_data, base64_seed_signature, country_code, date_fetched, - fetched_insecurely, parsed_seed); - if (result) { - UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.Size", - ungzipped_data.length() / 1024); - } - return result; + return StoreSeedDataNoDelta(ungzipped_data, base64_seed_signature, + country_code, date_fetched, fetched_insecurely, + parsed_seed); } // If the data is delta compressed, first decode it. - RecordStoreSeedResult(StoreSeedResult::DELTA_COUNT); - std::string existing_seed_data; std::string updated_seed_data; LoadSeedResult read_result = @@ -207,17 +203,8 @@ bool VariationsSeedStore::StoreSeedData( const bool result = StoreSeedDataNoDelta( updated_seed_data, base64_seed_signature, country_code, date_fetched, fetched_insecurely, parsed_seed); - if (result) { - // Note: |updated_seed_data.length()| is guaranteed to be non-zero, else - // result would be false. - int size_reduction = updated_seed_data.length() - ungzipped_data.length(); - UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.DeltaSize.ReductionPercent", - 100 * size_reduction / updated_seed_data.length()); - UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.DeltaSize", - ungzipped_data.length() / 1024); - } else { + if (!result) RecordStoreSeedResult(StoreSeedResult::FAILED_DELTA_STORE); - } return result; } diff --git a/chromium/components/variations/variations_switches.cc b/chromium/components/variations/variations_switches.cc index 662e2d23dad..a17c2d47895 100644 --- a/chromium/components/variations/variations_switches.cc +++ b/chromium/components/variations/variations_switches.cc @@ -16,8 +16,7 @@ const char kEnableBenchmarking[] = "enable-benchmarking"; // Fakes the channel of the browser for purposes of Variations filtering. This // is to be used for testing only. Possible values are "stable", "beta", "dev" -// and "canary". Note that this only applies if the browser's reported channel -// is UNKNOWN. +// and "canary". This works for official builds as well. const char kFakeVariationsChannel[] = "fake-variations-channel"; // This option can be used to force parameters of field trials when testing |