| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } | 221 } |
| 222 return g_instance->IsFeatureEnabled(feature); | 222 return g_instance->IsFeatureEnabled(feature); |
| 223 } | 223 } |
| 224 | 224 |
| 225 // static | 225 // static |
| 226 FieldTrial* FeatureList::GetFieldTrial(const Feature& feature) { | 226 FieldTrial* FeatureList::GetFieldTrial(const Feature& feature) { |
| 227 return GetInstance()->GetAssociatedFieldTrial(feature); | 227 return GetInstance()->GetAssociatedFieldTrial(feature); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // static | 230 // static |
| 231 std::vector<std::string> FeatureList::SplitFeatureListString( | 231 std::vector<base::StringPiece> FeatureList::SplitFeatureListString( |
| 232 const std::string& input) { | 232 base::StringPiece input) { |
| 233 return SplitString(input, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); | 233 return SplitStringPiece(input, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); |
| 234 } | 234 } |
| 235 | 235 |
| 236 // static | 236 // static |
| 237 bool FeatureList::InitializeInstance(const std::string& enable_features, | 237 bool FeatureList::InitializeInstance(const std::string& enable_features, |
| 238 const std::string& disable_features) { | 238 const std::string& disable_features) { |
| 239 // We want to initialize a new instance here to support command-line features | 239 // We want to initialize a new instance here to support command-line features |
| 240 // in testing better. For example, we initialize a dummy instance in | 240 // in testing better. For example, we initialize a dummy instance in |
| 241 // base/test/test_suite.cc, and override it in content/browser/ | 241 // base/test/test_suite.cc, and override it in content/browser/ |
| 242 // browser_main_loop.cc. | 242 // browser_main_loop.cc. |
| 243 // On the other hand, we want to avoid re-initialization from command line. | 243 // On the other hand, we want to avoid re-initialization from command line. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 return entry.field_trial; | 333 return entry.field_trial; |
| 334 } | 334 } |
| 335 | 335 |
| 336 return nullptr; | 336 return nullptr; |
| 337 } | 337 } |
| 338 | 338 |
| 339 void FeatureList::RegisterOverridesFromCommandLine( | 339 void FeatureList::RegisterOverridesFromCommandLine( |
| 340 const std::string& feature_list, | 340 const std::string& feature_list, |
| 341 OverrideState overridden_state) { | 341 OverrideState overridden_state) { |
| 342 for (const auto& value : SplitFeatureListString(feature_list)) { | 342 for (const auto& value : SplitFeatureListString(feature_list)) { |
| 343 StringPiece feature_name(value); | 343 StringPiece feature_name = value; |
| 344 base::FieldTrial* trial = nullptr; | 344 base::FieldTrial* trial = nullptr; |
| 345 | 345 |
| 346 // The entry may be of the form FeatureName<FieldTrialName - in which case, | 346 // The entry may be of the form FeatureName<FieldTrialName - in which case, |
| 347 // this splits off the field trial name and associates it with the override. | 347 // this splits off the field trial name and associates it with the override. |
| 348 std::string::size_type pos = feature_name.find('<'); | 348 std::string::size_type pos = feature_name.find('<'); |
| 349 if (pos != std::string::npos) { | 349 if (pos != std::string::npos) { |
| 350 feature_name.set(value.data(), pos); | 350 feature_name.set(value.data(), pos); |
| 351 trial = base::FieldTrialList::Find(value.substr(pos + 1)); | 351 trial = base::FieldTrialList::Find(value.substr(pos + 1).as_string()); |
| 352 } | 352 } |
| 353 | 353 |
| 354 RegisterOverride(feature_name, overridden_state, trial); | 354 RegisterOverride(feature_name, overridden_state, trial); |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 | 357 |
| 358 void FeatureList::RegisterOverride(StringPiece feature_name, | 358 void FeatureList::RegisterOverride(StringPiece feature_name, |
| 359 OverrideState overridden_state, | 359 OverrideState overridden_state, |
| 360 FieldTrial* field_trial) { | 360 FieldTrial* field_trial) { |
| 361 DCHECK(!initialized_); | 361 DCHECK(!initialized_); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 388 return it->second == &feature; | 388 return it->second == &feature; |
| 389 } | 389 } |
| 390 | 390 |
| 391 FeatureList::OverrideEntry::OverrideEntry(OverrideState overridden_state, | 391 FeatureList::OverrideEntry::OverrideEntry(OverrideState overridden_state, |
| 392 FieldTrial* field_trial) | 392 FieldTrial* field_trial) |
| 393 : overridden_state(overridden_state), | 393 : overridden_state(overridden_state), |
| 394 field_trial(field_trial), | 394 field_trial(field_trial), |
| 395 overridden_by_field_trial(field_trial != nullptr) {} | 395 overridden_by_field_trial(field_trial != nullptr) {} |
| 396 | 396 |
| 397 } // namespace base | 397 } // namespace base |
| OLD | NEW |