Chromium Code Reviews| Index: chrome/common/variations/variations_util.cc |
| diff --git a/chrome/common/variations/variations_util.cc b/chrome/common/variations/variations_util.cc |
| index dc63a292ee7628202af49601b5cba56b518916c6..b3747b66f70714b619ee640a4d709aff1d419acd 100644 |
| --- a/chrome/common/variations/variations_util.cc |
| +++ b/chrome/common/variations/variations_util.cc |
| @@ -27,6 +27,39 @@ std::string EscapeValue(const std::string& value) { |
| net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS); |
| } |
| +void AssociateParamsFromGroup(const std::string& study_name, |
|
jwd
2016/08/22 21:54:08
Can you also switch to trial/group terminology in
robliao
2016/08/22 22:55:23
Done.
|
| + const FieldTrialTestingGroup& group, |
| + base::FeatureList* feature_list) { |
| + if (group.params_size != 0) { |
| + std::map<std::string, std::string> params; |
| + for (size_t i = 0; i < group.params_size; ++i) { |
| + const FieldTrialTestingGroupParams& param = group.params[i]; |
| + params[param.key] = param.value; |
| + } |
| + variations::AssociateVariationParams(study_name, group.name, params); |
| + } |
| + base::FieldTrial* trial = |
| + base::FieldTrialList::CreateFieldTrial(study_name, group.name); |
| + |
| + if (!trial) { |
| + DLOG(WARNING) << "Field trial config study skipped: " << study_name |
| + << "." << group.name |
| + << " (it is overridden from chrome://flags)"; |
| + return; |
| + } |
| + |
| + for (size_t i = 0; i < group.enable_features_size; ++i) { |
| + feature_list->RegisterFieldTrialOverride( |
| + group.enable_features[i], base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| + trial); |
| + } |
| + for (size_t i = 0; i < group.disable_features_size; ++i) { |
| + feature_list->RegisterFieldTrialOverride( |
| + group.disable_features[i], |
| + base::FeatureList::OVERRIDE_DISABLE_FEATURE, trial); |
| + } |
| +} |
| + |
| } // namespace |
| bool AssociateParamsFromString(const std::string& varations_string) { |
| @@ -78,36 +111,12 @@ bool AssociateParamsFromString(const std::string& varations_string) { |
| void AssociateParamsFromFieldTrialConfig(const FieldTrialTestingConfig& config, |
| base::FeatureList* feature_list) { |
| - for (size_t i = 0; i < config.groups_size; ++i) { |
| - const FieldTrialTestingGroup& group = config.groups[i]; |
| - if (group.params_size != 0) { |
| - std::map<std::string, std::string> params; |
| - for (size_t j = 0; j < group.params_size; ++j) { |
| - const FieldTrialGroupParams& param = group.params[j]; |
| - params[param.key] = param.value; |
| - } |
| - variations::AssociateVariationParams(group.study, group.group_name, |
| - params); |
| - } |
| - base::FieldTrial* trial = |
| - base::FieldTrialList::CreateFieldTrial(group.study, group.group_name); |
| - |
| - if (!trial) { |
| - DLOG(WARNING) << "Field trial config study skipped: " << group.study |
| - << "." << group.group_name |
| - << " (it is overridden from chrome://flags)"; |
| - continue; |
| - } |
| - |
| - for (size_t j = 0; j < group.enable_features_size; ++j) { |
| - feature_list->RegisterFieldTrialOverride( |
| - group.enable_features[j], base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| - trial); |
| - } |
| - for (size_t j = 0; j < group.disable_features_size; ++j) { |
| - feature_list->RegisterFieldTrialOverride( |
| - group.disable_features[j], |
| - base::FeatureList::OVERRIDE_DISABLE_FEATURE, trial); |
| + for (size_t i = 0; i < config.studies_size; ++i) { |
| + const FieldTrialTestingStudy& study = config.studies[i]; |
| + if (study.groups_size > 0) { |
| + AssociateParamsFromGroup(study.name, study.groups[0], feature_list); |
| + } else { |
| + DLOG(ERROR) << "Unexpected empty study: " << study.name; |
| } |
| } |
| } |