OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 EXTENSIONS_COMMON_FEATURE_SWITCH_H_ | 5 #ifndef EXTENSIONS_COMMON_FEATURE_SWITCH_H_ |
6 #define EXTENSIONS_COMMON_FEATURE_SWITCH_H_ | 6 #define EXTENSIONS_COMMON_FEATURE_SWITCH_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 | 12 |
12 namespace base { | 13 namespace base { |
13 class CommandLine; | 14 class CommandLine; |
14 } | 15 } |
15 | 16 |
16 namespace extensions { | 17 namespace extensions { |
17 | 18 |
18 // A switch that can turn a feature on or off. Typically controlled via | 19 // A switch that can turn a feature on or off. Typically controlled via |
19 // command-line switches but can be overridden, e.g., for testing. | 20 // command-line switches but can be overridden, e.g., for testing. |
20 // Can also integrate with Finch's field trials. | 21 // Can also integrate with Finch's field trials. |
21 // A note about priority: | 22 // A note about priority: |
22 // 1. If an override is present, the override state will be used. | 23 // 1. If an override is present, the override state will be used. |
23 // 2. If there is no switch name, the default value will be used. This is | 24 // 2. If there is no switch name, the default value will be used. This is |
24 // because certain features are specifically designed *not* to be able to | 25 // because certain features are specifically designed *not* to be able to |
25 // be turned off via command-line, so we can't consult it (or, by extension, | 26 // be turned off via command-line, so we can't consult it (or, by extension, |
26 // the finch config). | 27 // the finch config). |
27 // 3. If there is a switch name, and the switch is present in the command line, | 28 // 3. If there is a switch name, and the switch is present in the command line, |
28 // the command line value will be used. | 29 // the command line value will be used. |
29 // 4. If there is a finch experiment associated and applicable to the machine, | 30 // 4. If there are field trials associated with the feature, and the machine |
30 // the finch value will be used. | 31 // is in the "Enabled" group for all field trials, then the feature is |
| 32 // enabled. If the machine is in the "Disabled" group for any field trials, |
| 33 // the feature is disabled. |
31 // 5. Otherwise, the default value is used. | 34 // 5. Otherwise, the default value is used. |
32 class FeatureSwitch { | 35 class FeatureSwitch { |
33 public: | 36 public: |
34 static FeatureSwitch* easy_off_store_install(); | 37 static FeatureSwitch* easy_off_store_install(); |
35 static FeatureSwitch* force_dev_mode_highlighting(); | 38 static FeatureSwitch* force_dev_mode_highlighting(); |
36 static FeatureSwitch* prompt_for_external_extensions(); | 39 static FeatureSwitch* prompt_for_external_extensions(); |
37 static FeatureSwitch* error_console(); | 40 static FeatureSwitch* error_console(); |
38 static FeatureSwitch* enable_override_bookmarks_ui(); | 41 static FeatureSwitch* enable_override_bookmarks_ui(); |
39 static FeatureSwitch* extension_action_redesign(); | 42 static FeatureSwitch* extension_action_redesign(); |
40 static FeatureSwitch* scripts_require_action(); | 43 static FeatureSwitch* scripts_require_action(); |
(...skipping 24 matching lines...) Expand all Loading... |
65 DISALLOW_COPY_AND_ASSIGN(ScopedOverride); | 68 DISALLOW_COPY_AND_ASSIGN(ScopedOverride); |
66 }; | 69 }; |
67 | 70 |
68 // |switch_name| can be null, in which case the feature is controlled solely | 71 // |switch_name| can be null, in which case the feature is controlled solely |
69 // by the default and override values. | 72 // by the default and override values. |
70 FeatureSwitch(const char* switch_name, | 73 FeatureSwitch(const char* switch_name, |
71 DefaultValue default_value); | 74 DefaultValue default_value); |
72 FeatureSwitch(const char* switch_name, | 75 FeatureSwitch(const char* switch_name, |
73 const char* field_trial_name, | 76 const char* field_trial_name, |
74 DefaultValue default_value); | 77 DefaultValue default_value); |
| 78 FeatureSwitch(const char* switch_name, |
| 79 const std::vector<std::string>& required_field_trials, |
| 80 DefaultValue default_value); |
75 FeatureSwitch(const base::CommandLine* command_line, | 81 FeatureSwitch(const base::CommandLine* command_line, |
76 const char* switch_name, | 82 const char* switch_name, |
77 DefaultValue default_value); | 83 DefaultValue default_value); |
78 FeatureSwitch(const base::CommandLine* command_line, | 84 FeatureSwitch(const base::CommandLine* command_line, |
79 const char* switch_name, | 85 const char* switch_name, |
80 const char* field_trial_name, | 86 const std::vector<std::string>& required_field_trials, |
81 DefaultValue default_value); | 87 DefaultValue default_value); |
| 88 ~FeatureSwitch(); |
82 | 89 |
83 // Consider using ScopedOverride instead. | 90 // Consider using ScopedOverride instead. |
84 void SetOverrideValue(OverrideValue value); | 91 void SetOverrideValue(OverrideValue value); |
85 OverrideValue GetOverrideValue() const; | 92 OverrideValue GetOverrideValue() const; |
86 | 93 |
87 bool IsEnabled() const; | 94 bool IsEnabled() const; |
88 | 95 |
89 private: | 96 private: |
90 std::string GetLegacyEnableFlag() const; | 97 std::string GetLegacyEnableFlag() const; |
91 std::string GetLegacyDisableFlag() const; | 98 std::string GetLegacyDisableFlag() const; |
92 | 99 |
93 const base::CommandLine* command_line_; | 100 const base::CommandLine* command_line_; |
94 const char* switch_name_; | 101 const char* switch_name_; |
95 const char* field_trial_name_; | 102 std::vector<std::string> required_field_trials_; |
96 bool default_value_; | 103 bool default_value_; |
97 OverrideValue override_value_; | 104 OverrideValue override_value_; |
98 | 105 |
99 DISALLOW_COPY_AND_ASSIGN(FeatureSwitch); | 106 DISALLOW_COPY_AND_ASSIGN(FeatureSwitch); |
100 }; | 107 }; |
101 | 108 |
102 } // namespace extensions | 109 } // namespace extensions |
103 | 110 |
104 #endif // EXTENSIONS_COMMON_FEATURE_SWITCH_H_ | 111 #endif // EXTENSIONS_COMMON_FEATURE_SWITCH_H_ |
OLD | NEW |