| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/feature_list.h" | 5 #include "base/feature_list.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 // static | 134 // static |
| 135 bool FeatureList::IsEnabled(const Feature& feature) { | 135 bool FeatureList::IsEnabled(const Feature& feature) { |
| 136 return GetInstance()->IsFeatureEnabled(feature); | 136 return GetInstance()->IsFeatureEnabled(feature); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // static | 139 // static |
| 140 FieldTrial* FeatureList::GetFieldTrial(const Feature& feature) { |
| 141 return GetInstance()->GetAssociatedFieldTrial(feature); |
| 142 } |
| 143 |
| 144 // static |
| 140 std::vector<std::string> FeatureList::SplitFeatureListString( | 145 std::vector<std::string> FeatureList::SplitFeatureListString( |
| 141 const std::string& input) { | 146 const std::string& input) { |
| 142 return SplitString(input, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); | 147 return SplitString(input, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); |
| 143 } | 148 } |
| 144 | 149 |
| 145 // static | 150 // static |
| 146 bool FeatureList::InitializeInstance(const std::string& enable_features, | 151 bool FeatureList::InitializeInstance(const std::string& enable_features, |
| 147 const std::string& disable_features) { | 152 const std::string& disable_features) { |
| 148 // We want to initialize a new instance here to support command-line features | 153 // We want to initialize a new instance here to support command-line features |
| 149 // in testing better. For example, we initialize a dummy instance in | 154 // in testing better. For example, we initialize a dummy instance in |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // TODO(asvitkine) Expand this section as more support is added. | 215 // TODO(asvitkine) Expand this section as more support is added. |
| 211 | 216 |
| 212 // If marked as OVERRIDE_USE_DEFAULT, simply return the default state below. | 217 // If marked as OVERRIDE_USE_DEFAULT, simply return the default state below. |
| 213 if (entry.overridden_state != OVERRIDE_USE_DEFAULT) | 218 if (entry.overridden_state != OVERRIDE_USE_DEFAULT) |
| 214 return entry.overridden_state == OVERRIDE_ENABLE_FEATURE; | 219 return entry.overridden_state == OVERRIDE_ENABLE_FEATURE; |
| 215 } | 220 } |
| 216 // Otherwise, return the default state. | 221 // Otherwise, return the default state. |
| 217 return feature.default_state == FEATURE_ENABLED_BY_DEFAULT; | 222 return feature.default_state == FEATURE_ENABLED_BY_DEFAULT; |
| 218 } | 223 } |
| 219 | 224 |
| 225 FieldTrial* FeatureList::GetAssociatedFieldTrial(const Feature& feature) { |
| 226 DCHECK(initialized_); |
| 227 DCHECK(IsValidFeatureOrFieldTrialName(feature.name)) << feature.name; |
| 228 DCHECK(CheckFeatureIdentity(feature)) << feature.name; |
| 229 |
| 230 auto it = overrides_.find(feature.name); |
| 231 if (it != overrides_.end()) { |
| 232 const OverrideEntry& entry = it->second; |
| 233 return entry.field_trial; |
| 234 } |
| 235 |
| 236 return nullptr; |
| 237 } |
| 238 |
| 220 void FeatureList::RegisterOverridesFromCommandLine( | 239 void FeatureList::RegisterOverridesFromCommandLine( |
| 221 const std::string& feature_list, | 240 const std::string& feature_list, |
| 222 OverrideState overridden_state) { | 241 OverrideState overridden_state) { |
| 223 for (const auto& value : SplitFeatureListString(feature_list)) { | 242 for (const auto& value : SplitFeatureListString(feature_list)) { |
| 224 StringPiece feature_name(value); | 243 StringPiece feature_name(value); |
| 225 base::FieldTrial* trial = nullptr; | 244 base::FieldTrial* trial = nullptr; |
| 226 | 245 |
| 227 // The entry may be of the form FeatureName<FieldTrialName - in which case, | 246 // The entry may be of the form FeatureName<FieldTrialName - in which case, |
| 228 // this splits off the field trial name and associates it with the override. | 247 // this splits off the field trial name and associates it with the override. |
| 229 std::string::size_type pos = feature_name.find('<'); | 248 std::string::size_type pos = feature_name.find('<'); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 return it->second == &feature; | 288 return it->second == &feature; |
| 270 } | 289 } |
| 271 | 290 |
| 272 FeatureList::OverrideEntry::OverrideEntry(OverrideState overridden_state, | 291 FeatureList::OverrideEntry::OverrideEntry(OverrideState overridden_state, |
| 273 FieldTrial* field_trial) | 292 FieldTrial* field_trial) |
| 274 : overridden_state(overridden_state), | 293 : overridden_state(overridden_state), |
| 275 field_trial(field_trial), | 294 field_trial(field_trial), |
| 276 overridden_by_field_trial(field_trial != nullptr) {} | 295 overridden_by_field_trial(field_trial != nullptr) {} |
| 277 | 296 |
| 278 } // namespace base | 297 } // namespace base |
| OLD | NEW |