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

Side by Side Diff: base/feature_list.h

Issue 1408783002: Support base::Feature entries in chrome://flags. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 2 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 | « no previous file | base/feature_list.cc » ('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 #ifndef BASE_FEATURE_LIST_H_ 5 #ifndef BASE_FEATURE_LIST_H_
6 #define BASE_FEATURE_LIST_H_ 6 #define BASE_FEATURE_LIST_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector>
10 11
11 #include "base/base_export.h" 12 #include "base/base_export.h"
12 #include "base/basictypes.h" 13 #include "base/basictypes.h"
13 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
16 17
17 namespace base { 18 namespace base {
18 19
19 class FieldTrial; 20 class FieldTrial;
(...skipping 17 matching lines...) Expand all
37 const FeatureState default_state; 38 const FeatureState default_state;
38 }; 39 };
39 40
40 // The FeatureList class is used to determine whether a given feature is on or 41 // The FeatureList class is used to determine whether a given feature is on or
41 // off. It provides an authoritative answer, taking into account command-line 42 // off. It provides an authoritative answer, taking into account command-line
42 // overrides and experimental control. 43 // overrides and experimental control.
43 // 44 //
44 // The basic use case is for any feature that can be toggled (e.g. through 45 // The basic use case is for any feature that can be toggled (e.g. through
45 // command-line or an experiment) to have a defined Feature struct, e.g.: 46 // command-line or an experiment) to have a defined Feature struct, e.g.:
46 // 47 //
47 // struct base::Feature kMyGreatFeature { 48 // const base::Feature kMyGreatFeature {
48 // "MyGreatFeature", base::FEATURE_ENABLED_BY_DEFAULT 49 // "MyGreatFeature", base::FEATURE_ENABLED_BY_DEFAULT
49 // }; 50 // };
50 // 51 //
51 // Then, client code that wishes to query the state of the feature would check: 52 // Then, client code that wishes to query the state of the feature would check:
52 // 53 //
53 // if (base::FeatureList::IsEnabled(kMyGreatFeature)) { 54 // if (base::FeatureList::IsEnabled(kMyGreatFeature)) {
54 // // Feature code goes here. 55 // // Feature code goes here.
55 // } 56 // }
56 // 57 //
57 // Behind the scenes, the above call would take into account any command-line 58 // Behind the scenes, the above call would take into account any command-line
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 void RegisterFieldTrialOverride(const std::string& feature_name, 116 void RegisterFieldTrialOverride(const std::string& feature_name,
116 OverrideState override_state, 117 OverrideState override_state,
117 FieldTrial* field_trial); 118 FieldTrial* field_trial);
118 119
119 // Returns whether the given |feature| is enabled. Must only be called after 120 // Returns whether the given |feature| is enabled. Must only be called after
120 // the singleton instance has been registered via SetInstance(). Additionally, 121 // the singleton instance has been registered via SetInstance(). Additionally,
121 // a feature with a given name must only have a single corresponding Feature 122 // a feature with a given name must only have a single corresponding Feature
122 // struct, which is checked in builds with DCHECKs enabled. 123 // struct, which is checked in builds with DCHECKs enabled.
123 static bool IsEnabled(const Feature& feature); 124 static bool IsEnabled(const Feature& feature);
124 125
126 // Splits a comma-separated string containing feature names into a vector.
127 static std::vector<std::string> SplitFeatureListString(
128 const std::string& input);
129
125 // Returns the singleton instance of FeatureList. Will return null until an 130 // Returns the singleton instance of FeatureList. Will return null until an
126 // instance is registered via SetInstance(). 131 // instance is registered via SetInstance().
127 static FeatureList* GetInstance(); 132 static FeatureList* GetInstance();
128 133
129 // Registers the given |instance| to be the singleton feature list for this 134 // Registers the given |instance| to be the singleton feature list for this
130 // process. This should only be called once and |instance| must not be null. 135 // process. This should only be called once and |instance| must not be null.
131 static void SetInstance(scoped_ptr<FeatureList> instance); 136 static void SetInstance(scoped_ptr<FeatureList> instance);
132 137
133 // Clears the previously-registered singleton instance for tests. 138 // Clears the previously-registered singleton instance for tests.
134 static void ClearInstanceForTesting(); 139 static void ClearInstanceForTesting();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // Whether this object has been fully initialized. This gets set to true as a 205 // Whether this object has been fully initialized. This gets set to true as a
201 // result of FinalizeInitialization(). 206 // result of FinalizeInitialization().
202 bool initialized_; 207 bool initialized_;
203 208
204 DISALLOW_COPY_AND_ASSIGN(FeatureList); 209 DISALLOW_COPY_AND_ASSIGN(FeatureList);
205 }; 210 };
206 211
207 } // namespace base 212 } // namespace base
208 213
209 #endif // BASE_FEATURE_LIST_H_ 214 #endif // BASE_FEATURE_LIST_H_
OLDNEW
« no previous file with comments | « no previous file | base/feature_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698