Index: base/feature_list.cc |
diff --git a/base/feature_list.cc b/base/feature_list.cc |
index 61043ceb731fa7bf2c6891c67c95882121d5afa7..96b5af0e7568311ee04dc71c24f784836e6f68c7 100644 |
--- a/base/feature_list.cc |
+++ b/base/feature_list.cc |
@@ -25,6 +25,8 @@ namespace { |
// have more control over initialization timing. Leaky. |
FeatureList* g_instance = nullptr; |
+bool g_block_overriding_instances_for_testing = false; |
+ |
// Tracks whether the FeatureList instance was initialized via an accessor. |
bool g_initialized_from_accessor = false; |
@@ -280,6 +282,7 @@ void FeatureList::SetInstance(std::unique_ptr<FeatureList> instance) { |
// static |
std::unique_ptr<FeatureList> FeatureList::ClearInstanceForTesting() { |
+ DCHECK(!g_block_overriding_instances_for_testing); |
FeatureList* old_instance = g_instance; |
g_instance = nullptr; |
g_initialized_from_accessor = false; |
@@ -289,11 +292,17 @@ std::unique_ptr<FeatureList> FeatureList::ClearInstanceForTesting() { |
// static |
void FeatureList::RestoreInstanceForTesting( |
std::unique_ptr<FeatureList> instance) { |
+ DCHECK(!g_block_overriding_instances_for_testing); |
DCHECK(!g_instance); |
// Note: Intentional leak of global singleton. |
g_instance = instance.release(); |
} |
+// static |
+void FeatureList::BlockOverridingInstanceForTesting(bool block) { |
+ g_block_overriding_instances_for_testing = block; |
+} |
+ |
void FeatureList::FinalizeInitialization() { |
DCHECK(!initialized_); |
initialized_ = true; |