| 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> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 14 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Pointer to the FeatureList instance singleton that was set via | 22 // Pointer to the FeatureList instance singleton that was set via |
| 22 // FeatureList::SetInstance(). Does not use base/memory/singleton.h in order to | 23 // FeatureList::SetInstance(). Does not use base/memory/singleton.h in order to |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // static | 191 // static |
| 191 void FeatureList::SetInstance(std::unique_ptr<FeatureList> instance) { | 192 void FeatureList::SetInstance(std::unique_ptr<FeatureList> instance) { |
| 192 DCHECK(!g_instance); | 193 DCHECK(!g_instance); |
| 193 instance->FinalizeInitialization(); | 194 instance->FinalizeInitialization(); |
| 194 | 195 |
| 195 // Note: Intentional leak of global singleton. | 196 // Note: Intentional leak of global singleton. |
| 196 g_instance = instance.release(); | 197 g_instance = instance.release(); |
| 197 } | 198 } |
| 198 | 199 |
| 199 // static | 200 // static |
| 200 void FeatureList::ClearInstanceForTesting() { | 201 std::unique_ptr<FeatureList> FeatureList::ClearInstanceForTesting() { |
| 201 delete g_instance; | 202 FeatureList* old_instance = g_instance; |
| 202 g_instance = nullptr; | 203 g_instance = nullptr; |
| 203 g_initialized_from_accessor = false; | 204 g_initialized_from_accessor = false; |
| 205 return base::WrapUnique(old_instance); |
| 206 } |
| 207 |
| 208 // static |
| 209 void FeatureList::RestoreInstanceForTesting( |
| 210 std::unique_ptr<FeatureList> instance) { |
| 211 DCHECK(!g_instance); |
| 212 // Note: Intentional leak of global singleton. |
| 213 g_instance = instance.release(); |
| 204 } | 214 } |
| 205 | 215 |
| 206 void FeatureList::FinalizeInitialization() { | 216 void FeatureList::FinalizeInitialization() { |
| 207 DCHECK(!initialized_); | 217 DCHECK(!initialized_); |
| 208 initialized_ = true; | 218 initialized_ = true; |
| 209 } | 219 } |
| 210 | 220 |
| 211 bool FeatureList::IsFeatureEnabled(const Feature& feature) { | 221 bool FeatureList::IsFeatureEnabled(const Feature& feature) { |
| 212 DCHECK(initialized_); | 222 DCHECK(initialized_); |
| 213 DCHECK(IsValidFeatureOrFieldTrialName(feature.name)) << feature.name; | 223 DCHECK(IsValidFeatureOrFieldTrialName(feature.name)) << feature.name; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 return it->second == &feature; | 307 return it->second == &feature; |
| 298 } | 308 } |
| 299 | 309 |
| 300 FeatureList::OverrideEntry::OverrideEntry(OverrideState overridden_state, | 310 FeatureList::OverrideEntry::OverrideEntry(OverrideState overridden_state, |
| 301 FieldTrial* field_trial) | 311 FieldTrial* field_trial) |
| 302 : overridden_state(overridden_state), | 312 : overridden_state(overridden_state), |
| 303 field_trial(field_trial), | 313 field_trial(field_trial), |
| 304 overridden_by_field_trial(field_trial != nullptr) {} | 314 overridden_by_field_trial(field_trial != nullptr) {} |
| 305 | 315 |
| 306 } // namespace base | 316 } // namespace base |
| OLD | NEW |