OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/variations/variations_seed_processor.h" | 5 #include "components/variations/variations_seed_processor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // Registers feature overrides for the chosen experiment in the specified study. | 100 // Registers feature overrides for the chosen experiment in the specified study. |
101 void RegisterFeatureOverrides(const ProcessedStudy& processed_study, | 101 void RegisterFeatureOverrides(const ProcessedStudy& processed_study, |
102 base::FieldTrial* trial, | 102 base::FieldTrial* trial, |
103 base::FeatureList* feature_list) { | 103 base::FeatureList* feature_list) { |
104 const std::string& group_name = trial->GetGroupNameWithoutActivation(); | 104 const std::string& group_name = trial->GetGroupNameWithoutActivation(); |
105 int experiment_index = processed_study.GetExperimentIndexByName(group_name); | 105 int experiment_index = processed_study.GetExperimentIndexByName(group_name); |
106 // The field trial was defined from |study|, so the active experiment's name | 106 // The field trial was defined from |study|, so the active experiment's name |
107 // must be in the |study|. | 107 // must be in the |study|. |
108 DCHECK_NE(-1, experiment_index); | 108 DCHECK_NE(-1, experiment_index); |
109 | 109 |
110 const Study_Experiment& experiment = | 110 const Study& study = *processed_study.study(); |
111 processed_study.study()->experiment(experiment_index); | 111 const Study_Experiment& experiment = study.experiment(experiment_index); |
112 | 112 |
113 // Process all the features to enable. | 113 // Process all the features to enable. |
114 int feature_count = experiment.feature_association().enable_feature_size(); | 114 int feature_count = experiment.feature_association().enable_feature_size(); |
115 for (int i = 0; i < feature_count; ++i) { | 115 for (int i = 0; i < feature_count; ++i) { |
116 feature_list->RegisterFieldTrialOverride( | 116 feature_list->RegisterFieldTrialOverride( |
117 experiment.feature_association().enable_feature(i), | 117 experiment.feature_association().enable_feature(i), |
118 base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial); | 118 base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial); |
119 } | 119 } |
120 | 120 |
121 // Process all the features to disable. | 121 // Process all the features to disable. |
122 feature_count = experiment.feature_association().disable_feature_size(); | 122 feature_count = experiment.feature_association().disable_feature_size(); |
123 for (int i = 0; i < feature_count; ++i) { | 123 for (int i = 0; i < feature_count; ++i) { |
124 feature_list->RegisterFieldTrialOverride( | 124 feature_list->RegisterFieldTrialOverride( |
125 experiment.feature_association().disable_feature(i), | 125 experiment.feature_association().disable_feature(i), |
126 base::FeatureList::OVERRIDE_DISABLE_FEATURE, trial); | 126 base::FeatureList::OVERRIDE_DISABLE_FEATURE, trial); |
127 } | 127 } |
| 128 |
| 129 // Check if this study enables/disables a single feature and uses explicit |
| 130 // activation (i.e. the trial should be activated when queried). If so, ensure |
| 131 // that groups that don't explicitly enable/disable that feature are still |
| 132 // associated with it (i.e. so "Default" group gets reported). |
| 133 // |
| 134 // Note: This checks for ACTIVATION_EXPLICIT, since there is no reason to |
| 135 // have this association with ACTIVATION_AUTO (where the trial starts active), |
| 136 // as well as allowing flexibility to disable this behavior in the future from |
| 137 // the server by introducing a new activation type. |
| 138 if (!processed_study.single_feature_name().empty() && |
| 139 study.activation_type() == Study_ActivationType_ACTIVATION_EXPLICIT && |
| 140 !experiment.has_feature_association()) { |
| 141 feature_list->RegisterFieldTrialOverride( |
| 142 processed_study.single_feature_name(), |
| 143 base::FeatureList::OVERRIDE_USE_DEFAULT, trial); |
| 144 } |
128 } | 145 } |
129 | 146 |
130 // Checks if |experiment| is associated with a forcing flag or feature and if it | 147 // Checks if |experiment| is associated with a forcing flag or feature and if it |
131 // is, returns whether it should be forced enabled based on the |command_line| | 148 // is, returns whether it should be forced enabled based on the |command_line| |
132 // or |feature_list| state. | 149 // or |feature_list| state. |
133 bool ShouldForceExperiment(const Study_Experiment& experiment, | 150 bool ShouldForceExperiment(const Study_Experiment& experiment, |
134 const base::CommandLine& command_line, | 151 const base::CommandLine& command_line, |
135 const base::FeatureList& feature_list) { | 152 const base::FeatureList& feature_list) { |
136 if (experiment.feature_association().has_forcing_feature_on()) { | 153 if (experiment.feature_association().has_forcing_feature_on()) { |
137 return feature_list.IsFeatureOverriddenFromCommandLine( | 154 return feature_list.IsFeatureOverriddenFromCommandLine( |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 // The field trial was defined from |study|, so the active experiment's name | 301 // The field trial was defined from |study|, so the active experiment's name |
285 // must be in the |study|. | 302 // must be in the |study|. |
286 DCHECK_NE(-1, experiment_index); | 303 DCHECK_NE(-1, experiment_index); |
287 | 304 |
288 ApplyUIStringOverrides(study.experiment(experiment_index), | 305 ApplyUIStringOverrides(study.experiment(experiment_index), |
289 override_callback); | 306 override_callback); |
290 } | 307 } |
291 } | 308 } |
292 | 309 |
293 } // namespace variations | 310 } // namespace variations |
OLD | NEW |