Index: components/variations/processed_study.cc |
diff --git a/components/variations/processed_study.cc b/components/variations/processed_study.cc |
index 5f065d8e1e88ac19a6034581eb49780a775d132e..8bf91e3b3ff0664a44f80a609b75e05cf5a1deca 100644 |
--- a/components/variations/processed_study.cc |
+++ b/components/variations/processed_study.cc |
@@ -19,7 +19,8 @@ namespace { |
bool ValidateStudyAndComputeTotalProbability( |
const Study& study, |
base::FieldTrial::Probability* total_probability, |
- bool* all_assignments_to_one_group) { |
+ bool* all_assignments_to_one_group, |
+ std::string* single_feature_name) { |
// At the moment, a missing default_experiment_name makes the study invalid. |
if (study.default_experiment_name().empty()) { |
DVLOG(1) << study.name() << " has no default experiment defined."; |
@@ -43,6 +44,9 @@ bool ValidateStudyAndComputeTotalProbability( |
bool multiple_assigned_groups = false; |
bool found_default_group = false; |
+ std::string single_feature_name_seen; |
+ bool has_multiple_features = false; |
+ |
std::set<std::string> experiment_names; |
for (int i = 0; i < study.experiment_size(); ++i) { |
const Study_Experiment& experiment = study.experiment(i); |
@@ -56,6 +60,28 @@ bool ValidateStudyAndComputeTotalProbability( |
return false; |
} |
+ if (!has_multiple_features) { |
+ const auto& features = experiment.feature_association(); |
+ for (int i = 0; i < features.enable_feature_size(); ++i) { |
+ const std::string& feature_name = features.enable_feature(i); |
+ if (single_feature_name_seen.empty()) { |
+ single_feature_name_seen = feature_name; |
+ } else if (feature_name != single_feature_name_seen) { |
+ has_multiple_features = true; |
+ break; |
+ } |
+ } |
+ for (int i = 0; i < features.disable_feature_size(); ++i) { |
+ const std::string& feature_name = features.disable_feature(i); |
+ if (single_feature_name_seen.empty()) { |
+ single_feature_name_seen = feature_name; |
+ } else if (feature_name != single_feature_name_seen) { |
+ has_multiple_features = true; |
+ break; |
+ } |
+ } |
+ } |
+ |
if (!experiment.has_forcing_flag() && experiment.probability_weight() > 0) { |
// If |divisor| is not 0, there was at least one prior non-zero group. |
if (divisor != 0) |
@@ -74,6 +100,11 @@ bool ValidateStudyAndComputeTotalProbability( |
return false; |
} |
+ if (!has_multiple_features && !single_feature_name_seen.empty()) |
+ single_feature_name->swap(single_feature_name_seen); |
+ else |
+ single_feature_name->clear(); |
+ |
*total_probability = divisor; |
*all_assignments_to_one_group = !multiple_assigned_groups; |
return true; |
@@ -95,8 +126,10 @@ ProcessedStudy::~ProcessedStudy() { |
bool ProcessedStudy::Init(const Study* study, bool is_expired) { |
base::FieldTrial::Probability total_probability = 0; |
bool all_assignments_to_one_group = false; |
+ std::string single_feature_name; |
if (!ValidateStudyAndComputeTotalProbability(*study, &total_probability, |
- &all_assignments_to_one_group)) { |
+ &all_assignments_to_one_group, |
+ &single_feature_name)) { |
return false; |
} |
@@ -104,6 +137,7 @@ bool ProcessedStudy::Init(const Study* study, bool is_expired) { |
is_expired_ = is_expired; |
total_probability_ = total_probability; |
all_assignments_to_one_group_ = all_assignments_to_one_group; |
+ single_feature_name_.swap(single_feature_name); |
return true; |
} |