OLD | NEW |
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 Loading... |
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); |
| 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 Loading... |
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 270 |
262 // Whether this object has been initialized from command line. | 271 // Whether this object has been initialized from command line. |
263 bool initialized_from_command_line_ = false; | 272 bool initialized_from_command_line_ = false; |
264 | 273 |
265 DISALLOW_COPY_AND_ASSIGN(FeatureList); | 274 DISALLOW_COPY_AND_ASSIGN(FeatureList); |
266 }; | 275 }; |
267 | 276 |
268 } // namespace base | 277 } // namespace base |
269 | 278 |
270 #endif // BASE_FEATURE_LIST_H_ | 279 #endif // BASE_FEATURE_LIST_H_ |
OLD | NEW |