| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Pointer to the FeatureList instance singleton that was set via | 18 // Pointer to the FeatureList instance singleton that was set via |
| 19 // FeatureList::SetInstance(). Does not use base/memory/singleton.h in order to | 19 // FeatureList::SetInstance(). Does not use base/memory/singleton.h in order to |
| 20 // have more control over initialization timing. Leaky. | 20 // have more control over initialization timing. Leaky. |
| 21 FeatureList* g_instance = nullptr; | 21 FeatureList* g_instance = nullptr; |
| 22 | 22 |
| 23 // Splits a comma-separated string containing feature names into a vector. | |
| 24 std::vector<std::string> SplitFeatureListString(const std::string& input) { | |
| 25 return SplitString(input, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); | |
| 26 } | |
| 27 | |
| 28 } // namespace | 23 } // namespace |
| 29 | 24 |
| 30 FeatureList::FeatureList() : initialized_(false) {} | 25 FeatureList::FeatureList() : initialized_(false) {} |
| 31 | 26 |
| 32 FeatureList::~FeatureList() {} | 27 FeatureList::~FeatureList() {} |
| 33 | 28 |
| 34 void FeatureList::InitializeFromCommandLine( | 29 void FeatureList::InitializeFromCommandLine( |
| 35 const std::string& enable_features, | 30 const std::string& enable_features, |
| 36 const std::string& disable_features) { | 31 const std::string& disable_features) { |
| 37 DCHECK(!initialized_); | 32 DCHECK(!initialized_); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 82 |
| 88 entry->field_trial = field_trial; | 83 entry->field_trial = field_trial; |
| 89 } | 84 } |
| 90 | 85 |
| 91 // static | 86 // static |
| 92 bool FeatureList::IsEnabled(const Feature& feature) { | 87 bool FeatureList::IsEnabled(const Feature& feature) { |
| 93 return GetInstance()->IsFeatureEnabled(feature); | 88 return GetInstance()->IsFeatureEnabled(feature); |
| 94 } | 89 } |
| 95 | 90 |
| 96 // static | 91 // static |
| 92 std::vector<std::string> FeatureList::SplitFeatureListString( |
| 93 const std::string& input) { |
| 94 return SplitString(input, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); |
| 95 } |
| 96 |
| 97 // static |
| 97 FeatureList* FeatureList::GetInstance() { | 98 FeatureList* FeatureList::GetInstance() { |
| 98 return g_instance; | 99 return g_instance; |
| 99 } | 100 } |
| 100 | 101 |
| 101 // static | 102 // static |
| 102 void FeatureList::SetInstance(scoped_ptr<FeatureList> instance) { | 103 void FeatureList::SetInstance(scoped_ptr<FeatureList> instance) { |
| 103 DCHECK(!g_instance); | 104 DCHECK(!g_instance); |
| 104 instance->FinalizeInitialization(); | 105 instance->FinalizeInitialization(); |
| 105 | 106 |
| 106 // Note: Intentional leak of global singleton. | 107 // Note: Intentional leak of global singleton. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 return it->second == &feature; | 162 return it->second == &feature; |
| 162 } | 163 } |
| 163 | 164 |
| 164 FeatureList::OverrideEntry::OverrideEntry(OverrideState overridden_state, | 165 FeatureList::OverrideEntry::OverrideEntry(OverrideState overridden_state, |
| 165 FieldTrial* field_trial) | 166 FieldTrial* field_trial) |
| 166 : overridden_state(overridden_state), | 167 : overridden_state(overridden_state), |
| 167 field_trial(field_trial), | 168 field_trial(field_trial), |
| 168 overridden_by_field_trial(field_trial != nullptr) {} | 169 overridden_by_field_trial(field_trial != nullptr) {} |
| 169 | 170 |
| 170 } // namespace base | 171 } // namespace base |
| OLD | NEW |