Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / common / feature_switch.h
blob4e058b525e6d882d4017b17d12046d9f85fe9225
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_
8 #include <string>
10 #include "base/basictypes.h"
12 namespace base {
13 class CommandLine;
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,
26 // the finch config).
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.
32 class FeatureSwitch {
33 public:
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();
44 enum DefaultValue {
45 DEFAULT_ENABLED,
46 DEFAULT_DISABLED
49 enum OverrideValue {
50 OVERRIDE_NONE,
51 OVERRIDE_ENABLED,
52 OVERRIDE_DISABLED
55 // A temporary override for the switch value.
56 class ScopedOverride {
57 public:
58 ScopedOverride(FeatureSwitch* feature, bool override_value);
59 ~ScopedOverride();
60 private:
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;
87 private:
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_;
94 bool default_value_;
95 OverrideValue override_value_;
97 DISALLOW_COPY_AND_ASSIGN(FeatureSwitch);
100 } // namespace extensions
102 #endif // EXTENSIONS_COMMON_FEATURE_SWITCH_H_