Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: base/feature_list.cc

Issue 2226063002: Add a ScopedFeatureList class for testing and start using it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix issue in previous patchset. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/feature_list.h ('k') | base/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « base/feature_list.h ('k') | base/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698