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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_COMMON_FEATURE_SWITCH_H_
6 #define EXTENSIONS_COMMON_FEATURE_SWITCH_H_
10 #include "base/basictypes.h"
16 namespace extensions
{
18 // 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 // Can also integrate with Finch's field trials.
21 // A note about priority:
22 // 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 // 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,
27 // 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 // 4. If there is a finch experiment associated and applicable to the machine,
30 // the finch value will be used.
31 // 5. Otherwise, the default value is used.
34 static FeatureSwitch
* easy_off_store_install();
35 static FeatureSwitch
* force_dev_mode_highlighting();
36 static FeatureSwitch
* prompt_for_external_extensions();
37 static FeatureSwitch
* error_console();
38 static FeatureSwitch
* enable_override_bookmarks_ui();
39 static FeatureSwitch
* extension_action_redesign();
40 static FeatureSwitch
* scripts_require_action();
41 static FeatureSwitch
* embedded_extension_options();
42 static FeatureSwitch
* trace_app_source();
55 // A temporary override for the switch value.
56 class ScopedOverride
{
58 ScopedOverride(FeatureSwitch
* feature
, bool override_value
);
61 FeatureSwitch
* feature_
;
62 FeatureSwitch::OverrideValue previous_value_
;
63 DISALLOW_COPY_AND_ASSIGN(ScopedOverride
);
66 // |switch_name| can be null, in which case the feature is controlled solely
67 // by the default and override values.
68 FeatureSwitch(const char* switch_name
,
69 DefaultValue default_value
);
70 FeatureSwitch(const char* switch_name
,
71 const char* field_trial_name
,
72 DefaultValue default_value
);
73 FeatureSwitch(const base::CommandLine
* command_line
,
74 const char* switch_name
,
75 DefaultValue default_value
);
76 FeatureSwitch(const base::CommandLine
* command_line
,
77 const char* switch_name
,
78 const char* field_trial_name
,
79 DefaultValue default_value
);
81 // Consider using ScopedOverride instead.
82 void SetOverrideValue(OverrideValue value
);
83 OverrideValue
GetOverrideValue() const;
85 bool IsEnabled() const;
88 std::string
GetLegacyEnableFlag() const;
89 std::string
GetLegacyDisableFlag() const;
91 const base::CommandLine
* command_line_
;
92 const char* switch_name_
;
93 const char* field_trial_name_
;
95 OverrideValue override_value_
;
97 DISALLOW_COPY_AND_ASSIGN(FeatureSwitch
);
100 } // namespace extensions
102 #endif // EXTENSIONS_COMMON_FEATURE_SWITCH_H_