Index: base/feature_list.h |
diff --git a/base/feature_list.h b/base/feature_list.h |
index 6e4ad5859c4211bed7be3f2ef8ffa07943f01905..377869e27c1e868221006f8480bcacac3dad93c6 100644 |
--- a/base/feature_list.h |
+++ b/base/feature_list.h |
@@ -7,6 +7,7 @@ |
#include <map> |
#include <string> |
+#include <utility> |
#include "base/base_export.h" |
#include "base/basictypes.h" |
@@ -16,6 +17,8 @@ |
namespace base { |
+class FieldTrial; |
+ |
// Specifies whether a given feature is enabled or disabled by default. |
enum FeatureState { |
FEATURE_DISABLED_BY_DEFAULT, |
@@ -83,6 +86,37 @@ class BASE_EXPORT FeatureList { |
void InitializeFromCommandLine(const std::string& enable_features, |
const std::string& disable_features); |
+ // Specifies whether a feature override enables or disables the feature. |
+ enum OverrideState { |
+ OVERRIDE_DISABLE_FEATURE, |
+ OVERRIDE_ENABLE_FEATURE, |
+ }; |
+ |
+ // Registers a field trial to override the enabled state of the specified |
+ // feature to |override_state|. Command-line overrides still take precedence |
+ // over field trials, so this will have no effect if the feature is being |
+ // overridden from the command-line. The associated field trial will be |
+ // activated when the feature state for this feature is queried. This should |
+ // be called during registration, after InitializeFromCommandLine() has been |
+ // called but before the instance is registered via SetInstance(). |
+ void RegisterFieldTrialOverride(const std::string& feature_name, |
+ OverrideState override_state, |
+ FieldTrial* field_trial); |
+ |
+ // Creates and associates a field trial for reporting purposes corresponding |
+ // to the command-line setting the feature state to |for_overridden_state|. |
+ // This is a no-op and returns null if the specified feature is not being |
+ // affected by a command-line override to the given state. Otherwise, it |
+ // creates a field trial with name |field_trial_name| and a single group named |
+ // |group_name| and returns it. The trial will be activated when the state of |
+ // the feature is queried. This should be called during registration, after |
+ // InitializeFromCommandLine() has been called but before the instance is |
+ // registered via SetInstance(). |
+ FieldTrial* AssociateReportingFieldTrial(const std::string& feature_name, |
+ OverrideState for_overridden_state, |
+ const std::string& field_trial_name, |
+ const std::string& group_name); |
+ |
// Returns whether the given |feature| is enabled. Must only be called after |
// the singleton instance has been registered via SetInstance(). Additionally, |
// a feature with a given name must only have a single corresponding Feature |
@@ -103,10 +137,18 @@ class BASE_EXPORT FeatureList { |
private: |
FRIEND_TEST_ALL_PREFIXES(FeatureListTest, CheckFeatureIdentity); |
- // Specifies whether a feature override enables or disables the feature. |
- enum OverrideState { |
- OVERRIDE_DISABLE_FEATURE, |
- OVERRIDE_ENABLE_FEATURE, |
+ struct OverrideEntry { |
+ // The overridden enable (on/off) state of the feature. |
+ const OverrideState overridden_state; |
+ |
+ // An optional associated field trial, which will be activated when the |
+ // state of the feature is queried for the first time. Weak pointer to the |
+ // FieldTrial object that is owned by the FieldTrialList singleton. |
+ base::FieldTrial* field_trial; |
+ |
+ // TODO(asvitkine): Expand this as more support is added. |
+ |
+ OverrideEntry(OverrideState overridden_state, FieldTrial* field_trial); |
}; |
// Finalizes the initialization state of the FeatureList, so that no further |
@@ -121,9 +163,17 @@ class BASE_EXPORT FeatureList { |
// Registers an override for feature |feature_name|. The override specifies |
// whether the feature should be on or off (via |overridden_state|), which |
- // will take precedence over the feature's default state. |
- void RegisterOverride(const std::string& feature_name, |
- OverrideState overridden_state); |
+ // will take precedence over the feature's default state. If |field_trial| is |
+ // not null, registers the specified field trial object to be associated with |
+ // the feature, which will activate the field trial when the feature state is |
+ // queried. If an override is already registered for the given feature, it |
+ // will not be changed. Returns a pair<entry, bool>, where the bool indicates |
+ // whether the override was registered and entry is the entry in the map - |
+ // either the existing one or the one that was inserted. |
+ std::pair<const FeatureList::OverrideEntry&, bool> RegisterOverride( |
+ const std::string& feature_name, |
+ OverrideState overridden_state, |
+ FieldTrial* field_trial); |
// Verifies that there's only a single definition of a Feature struct for a |
// given feature name. Keeps track of the first seen Feature struct for each |
@@ -132,14 +182,6 @@ class BASE_EXPORT FeatureList { |
// DCHECKs and tests. |
bool CheckFeatureIdentity(const Feature& feature); |
- struct OverrideEntry { |
- // The overridden enable (on/off) state of the feature. |
- const OverrideState overridden_state; |
- |
- // TODO(asvitkine): Expand this as more support is added. |
- |
- explicit OverrideEntry(OverrideState overridden_state); |
- }; |
// Map from feature name to an OverrideEntry struct for the feature, if it |
// exists. |
std::map<std::string, OverrideEntry> overrides_; |