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

Side by Side Diff: base/feature_list.h

Issue 2546653002: Store and retrieve features from shared memory (Closed)
Patch Set: asvitkine@ comments Created 4 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') | base/feature_list.cc » ('J')
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 <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/base_export.h" 13 #include "base/base_export.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/metrics/persistent_memory_allocator.h"
16 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
17 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
18 19
19 namespace base { 20 namespace base {
20 21
21 class FieldTrial; 22 class FieldTrial;
22 23
23 // Specifies whether a given feature is enabled or disabled by default. 24 // Specifies whether a given feature is enabled or disabled by default.
24 enum FeatureState { 25 enum FeatureState {
25 FEATURE_DISABLED_BY_DEFAULT, 26 FEATURE_DISABLED_BY_DEFAULT,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // it will be disabled. If a list entry has the format "FeatureName<TrialName" 86 // it will be disabled. If a list entry has the format "FeatureName<TrialName"
86 // then this initialization will also associate the feature state override 87 // then this initialization will also associate the feature state override
87 // with the named field trial, if it exists. If a feature name is prefixed 88 // with the named field trial, if it exists. If a feature name is prefixed
88 // with the '*' character, it will be created with OVERRIDE_USE_DEFAULT - 89 // with the '*' character, it will be created with OVERRIDE_USE_DEFAULT -
89 // which is useful for associating with a trial while using the default state. 90 // which is useful for associating with a trial while using the default state.
90 // Must only be invoked during the initialization phase (before 91 // Must only be invoked during the initialization phase (before
91 // FinalizeInitialization() has been called). 92 // FinalizeInitialization() has been called).
92 void InitializeFromCommandLine(const std::string& enable_features, 93 void InitializeFromCommandLine(const std::string& enable_features,
93 const std::string& disable_features); 94 const std::string& disable_features);
94 95
96 // Initializes feature overrides through the field trial allocator, which
97 // we're using to store the feature names, their override state, and the name
98 // of the associated field trial.
99 void InitializeFromSharedMemory(SharedPersistentMemoryAllocator* allocator);
bcwhite 2016/12/01 20:15:15 Better to accept the base PersistentMemoryAllocato
lawrencewu 2016/12/02 19:24:46 Done.
100
95 // Specifies whether a feature override enables or disables the feature. 101 // Specifies whether a feature override enables or disables the feature.
96 enum OverrideState { 102 enum OverrideState {
97 OVERRIDE_USE_DEFAULT, 103 OVERRIDE_USE_DEFAULT,
98 OVERRIDE_DISABLE_FEATURE, 104 OVERRIDE_DISABLE_FEATURE,
99 OVERRIDE_ENABLE_FEATURE, 105 OVERRIDE_ENABLE_FEATURE,
100 }; 106 };
101 107
102 // Returns true if the state of |feature_name| has been overridden via 108 // Returns true if the state of |feature_name| has been overridden via
103 // |InitializeFromCommandLine()|. 109 // |InitializeFromCommandLine()|.
104 bool IsFeatureOverriddenFromCommandLine(const std::string& feature_name, 110 bool IsFeatureOverriddenFromCommandLine(const std::string& feature_name,
(...skipping 12 matching lines...) Expand all
117 // feature to |override_state|. Command-line overrides still take precedence 123 // feature to |override_state|. Command-line overrides still take precedence
118 // over field trials, so this will have no effect if the feature is being 124 // over field trials, so this will have no effect if the feature is being
119 // overridden from the command-line. The associated field trial will be 125 // overridden from the command-line. The associated field trial will be
120 // activated when the feature state for this feature is queried. This should 126 // activated when the feature state for this feature is queried. This should
121 // be called during registration, after InitializeFromCommandLine() has been 127 // be called during registration, after InitializeFromCommandLine() has been
122 // called but before the instance is registered via SetInstance(). 128 // called but before the instance is registered via SetInstance().
123 void RegisterFieldTrialOverride(const std::string& feature_name, 129 void RegisterFieldTrialOverride(const std::string& feature_name,
124 OverrideState override_state, 130 OverrideState override_state,
125 FieldTrial* field_trial); 131 FieldTrial* field_trial);
126 132
133 // Loops through feature overrides and serializes them all into |allocator|.
134 void AddFeaturesToAllocator(SharedPersistentMemoryAllocator* allocator);
135
127 // Returns comma-separated lists of feature names (in the same format that is 136 // Returns comma-separated lists of feature names (in the same format that is
128 // accepted by InitializeFromCommandLine()) corresponding to features that 137 // accepted by InitializeFromCommandLine()) corresponding to features that
129 // have been overridden - either through command-line or via FieldTrials. For 138 // have been overridden - either through command-line or via FieldTrials. For
130 // those features that have an associated FieldTrial, the output entry will be 139 // those features that have an associated FieldTrial, the output entry will be
131 // of the format "FeatureName<TrialName", where "TrialName" is the name of the 140 // of the format "FeatureName<TrialName", where "TrialName" is the name of the
132 // FieldTrial. Features that have overrides with OVERRIDE_USE_DEFAULT will be 141 // FieldTrial. Features that have overrides with OVERRIDE_USE_DEFAULT will be
133 // added to |enable_overrides| with a '*' character prefix. Must be called 142 // added to |enable_overrides| with a '*' character prefix. Must be called
134 // only after the instance has been initialized and registered. 143 // only after the instance has been initialized and registered.
135 void GetFeatureOverrides(std::string* enable_overrides, 144 void GetFeatureOverrides(std::string* enable_overrides,
136 std::string* disable_overrides); 145 std::string* disable_overrides);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // base::test::ScopedFeatureList. 182 // base::test::ScopedFeatureList.
174 static std::unique_ptr<FeatureList> ClearInstanceForTesting(); 183 static std::unique_ptr<FeatureList> ClearInstanceForTesting();
175 184
176 // Sets a given (initialized) |instance| to be the singleton feature list, 185 // Sets a given (initialized) |instance| to be the singleton feature list,
177 // for testing. Existing instance must be null. This is primarily intended 186 // for testing. Existing instance must be null. This is primarily intended
178 // to support base::test::ScopedFeatureList helper class. 187 // to support base::test::ScopedFeatureList helper class.
179 static void RestoreInstanceForTesting(std::unique_ptr<FeatureList> instance); 188 static void RestoreInstanceForTesting(std::unique_ptr<FeatureList> instance);
180 189
181 private: 190 private:
182 FRIEND_TEST_ALL_PREFIXES(FeatureListTest, CheckFeatureIdentity); 191 FRIEND_TEST_ALL_PREFIXES(FeatureListTest, CheckFeatureIdentity);
192 FRIEND_TEST_ALL_PREFIXES(FeatureListTest,
193 StoreAndRetrieveFeaturesFromSharedMemory);
183 194
184 struct OverrideEntry { 195 struct OverrideEntry {
185 // The overridden enable (on/off) state of the feature. 196 // The overridden enable (on/off) state of the feature.
186 const OverrideState overridden_state; 197 const OverrideState overridden_state;
187 198
188 // An optional associated field trial, which will be activated when the 199 // An optional associated field trial, which will be activated when the
189 // state of the feature is queried for the first time. Weak pointer to the 200 // state of the feature is queried for the first time. Weak pointer to the
190 // FieldTrial object that is owned by the FieldTrialList singleton. 201 // FieldTrial object that is owned by the FieldTrialList singleton.
191 base::FieldTrial* field_trial; 202 base::FieldTrial* field_trial;
192 203
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 272
262 // Whether this object has been initialized from command line. 273 // Whether this object has been initialized from command line.
263 bool initialized_from_command_line_ = false; 274 bool initialized_from_command_line_ = false;
264 275
265 DISALLOW_COPY_AND_ASSIGN(FeatureList); 276 DISALLOW_COPY_AND_ASSIGN(FeatureList);
266 }; 277 };
267 278
268 } // namespace base 279 } // namespace base
269 280
270 #endif // BASE_FEATURE_LIST_H_ 281 #endif // BASE_FEATURE_LIST_H_
OLDNEW
« no previous file with comments | « no previous file | base/feature_list.cc » ('j') | base/feature_list.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698