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

Side by Side Diff: base/feature_list.h

Issue 1484483002: Plumb base::Feature field trial association to renderers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ownz
Patch Set: Address nits. Created 5 years 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 #include <vector>
11 11
12 #include "base/base_export.h" 12 #include "base/base_export.h"
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/strings/string_piece.h"
16 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
17 18
18 namespace base { 19 namespace base {
19 20
20 class FieldTrial; 21 class FieldTrial;
21 22
22 // Specifies whether a given feature is enabled or disabled by default. 23 // Specifies whether a given feature is enabled or disabled by default.
23 enum FeatureState { 24 enum FeatureState {
24 FEATURE_DISABLED_BY_DEFAULT, 25 FEATURE_DISABLED_BY_DEFAULT,
25 FEATURE_ENABLED_BY_DEFAULT, 26 FEATURE_ENABLED_BY_DEFAULT,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // intended use is to create an instance of this class and fully initialize it, 75 // intended use is to create an instance of this class and fully initialize it,
75 // before setting it as the singleton for a process, via SetInstance(). 76 // before setting it as the singleton for a process, via SetInstance().
76 class BASE_EXPORT FeatureList { 77 class BASE_EXPORT FeatureList {
77 public: 78 public:
78 FeatureList(); 79 FeatureList();
79 ~FeatureList(); 80 ~FeatureList();
80 81
81 // Initializes feature overrides via command-line flags |enable_features| and 82 // Initializes feature overrides via command-line flags |enable_features| and
82 // |disable_features|, each of which is a comma-separated list of features to 83 // |disable_features|, each of which is a comma-separated list of features to
83 // enable or disable, respectively. If a feature appears on both lists, then 84 // enable or disable, respectively. If a feature appears on both lists, then
84 // it will be disabled. Must only be invoked during the initialization phase 85 // it will be disabled. If a list entry has the format "FeatureName<TrialName"
85 // (before FinalizeInitialization() has been called). 86 // then this initialization will also associate the feature state override
87 // with the named field trial, if it exists. Must only be invoked during the
88 // initialization phase (before FinalizeInitialization() has been called).
86 void InitializeFromCommandLine(const std::string& enable_features, 89 void InitializeFromCommandLine(const std::string& enable_features,
87 const std::string& disable_features); 90 const std::string& disable_features);
88 91
89 // Specifies whether a feature override enables or disables the feature. 92 // Specifies whether a feature override enables or disables the feature.
90 enum OverrideState { 93 enum OverrideState {
91 OVERRIDE_DISABLE_FEATURE, 94 OVERRIDE_DISABLE_FEATURE,
92 OVERRIDE_ENABLE_FEATURE, 95 OVERRIDE_ENABLE_FEATURE,
93 }; 96 };
94 97
95 // Returns true if the state of |feature_name| has been overridden via 98 // Returns true if the state of |feature_name| has been overridden via
(...skipping 16 matching lines...) Expand all
112 // overridden from the command-line. The associated field trial will be 115 // overridden from the command-line. The associated field trial will be
113 // activated when the feature state for this feature is queried. This should 116 // activated when the feature state for this feature is queried. This should
114 // be called during registration, after InitializeFromCommandLine() has been 117 // be called during registration, after InitializeFromCommandLine() has been
115 // called but before the instance is registered via SetInstance(). 118 // called but before the instance is registered via SetInstance().
116 void RegisterFieldTrialOverride(const std::string& feature_name, 119 void RegisterFieldTrialOverride(const std::string& feature_name,
117 OverrideState override_state, 120 OverrideState override_state,
118 FieldTrial* field_trial); 121 FieldTrial* field_trial);
119 122
120 // Returns comma-separated lists of feature names (in the same format that is 123 // Returns comma-separated lists of feature names (in the same format that is
121 // accepted by InitializeFromCommandLine()) corresponding to features that 124 // accepted by InitializeFromCommandLine()) corresponding to features that
122 // have been overridden - either through command-line or via FieldTrials. 125 // have been overridden - either through command-line or via FieldTrials. For
123 // Must be called only after the instance has been initialized and registered. 126 // those features that have an associated FieldTrial, the output entry will be
127 // of the format "FeatureName<TrialName", where "TrialName" is the name of the
128 // FieldTrial. Must be called only after the instance has been initialized and
129 // registered.
124 void GetFeatureOverrides(std::string* enable_overrides, 130 void GetFeatureOverrides(std::string* enable_overrides,
125 std::string* disable_overrides); 131 std::string* disable_overrides);
126 132
127 // Returns whether the given |feature| is enabled. Must only be called after 133 // Returns whether the given |feature| is enabled. Must only be called after
128 // the singleton instance has been registered via SetInstance(). Additionally, 134 // the singleton instance has been registered via SetInstance(). Additionally,
129 // a feature with a given name must only have a single corresponding Feature 135 // a feature with a given name must only have a single corresponding Feature
130 // struct, which is checked in builds with DCHECKs enabled. 136 // struct, which is checked in builds with DCHECKs enabled.
131 static bool IsEnabled(const Feature& feature); 137 static bool IsEnabled(const Feature& feature);
132 138
133 // Splits a comma-separated string containing feature names into a vector. 139 // Splits a comma-separated string containing feature names into a vector.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // Finalizes the initialization state of the FeatureList, so that no further 184 // Finalizes the initialization state of the FeatureList, so that no further
179 // overrides can be registered. This is called by SetInstance() on the 185 // overrides can be registered. This is called by SetInstance() on the
180 // singleton feature list that is being registered. 186 // singleton feature list that is being registered.
181 void FinalizeInitialization(); 187 void FinalizeInitialization();
182 188
183 // Returns whether the given |feature| is enabled. This is invoked by the 189 // Returns whether the given |feature| is enabled. This is invoked by the
184 // public FeatureList::IsEnabled() static function on the global singleton. 190 // public FeatureList::IsEnabled() static function on the global singleton.
185 // Requires the FeatureList to have already been fully initialized. 191 // Requires the FeatureList to have already been fully initialized.
186 bool IsFeatureEnabled(const Feature& feature); 192 bool IsFeatureEnabled(const Feature& feature);
187 193
194 // For each feature name in comma-separated list of strings |feature_list|,
195 // registers an override with the specified |overridden_state|. Also, will
196 // associate an optional named field trial if the entry is of the format
197 // "FeatureName<TrialName".
198 void RegisterOverridesFromCommandLine(const std::string& feature_list,
199 OverrideState overridden_state);
200
188 // Registers an override for feature |feature_name|. The override specifies 201 // Registers an override for feature |feature_name|. The override specifies
189 // whether the feature should be on or off (via |overridden_state|), which 202 // whether the feature should be on or off (via |overridden_state|), which
190 // will take precedence over the feature's default state. If |field_trial| is 203 // will take precedence over the feature's default state. If |field_trial| is
191 // not null, registers the specified field trial object to be associated with 204 // not null, registers the specified field trial object to be associated with
192 // the feature, which will activate the field trial when the feature state is 205 // the feature, which will activate the field trial when the feature state is
193 // queried. If an override is already registered for the given feature, it 206 // queried. If an override is already registered for the given feature, it
194 // will not be changed. 207 // will not be changed.
195 void RegisterOverride(const std::string& feature_name, 208 void RegisterOverride(StringPiece feature_name,
196 OverrideState overridden_state, 209 OverrideState overridden_state,
197 FieldTrial* field_trial); 210 FieldTrial* field_trial);
198 211
199 // Verifies that there's only a single definition of a Feature struct for a 212 // Verifies that there's only a single definition of a Feature struct for a
200 // given feature name. Keeps track of the first seen Feature struct for each 213 // given feature name. Keeps track of the first seen Feature struct for each
201 // feature. Returns false when called on a Feature struct with a different 214 // feature. Returns false when called on a Feature struct with a different
202 // address than the first one it saw for that feature name. Used only from 215 // address than the first one it saw for that feature name. Used only from
203 // DCHECKs and tests. 216 // DCHECKs and tests.
204 bool CheckFeatureIdentity(const Feature& feature); 217 bool CheckFeatureIdentity(const Feature& feature);
205 218
(...skipping 10 matching lines...) Expand all
216 // Whether this object has been fully initialized. This gets set to true as a 229 // Whether this object has been fully initialized. This gets set to true as a
217 // result of FinalizeInitialization(). 230 // result of FinalizeInitialization().
218 bool initialized_; 231 bool initialized_;
219 232
220 DISALLOW_COPY_AND_ASSIGN(FeatureList); 233 DISALLOW_COPY_AND_ASSIGN(FeatureList);
221 }; 234 };
222 235
223 } // namespace base 236 } // namespace base
224 237
225 #endif // BASE_FEATURE_LIST_H_ 238 #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