Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / extensions / common / feature_switch.h
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.
4
5 #ifndef EXTENSIONS_COMMON_FEATURE_SWITCH_H_
6 #define EXTENSIONS_COMMON_FEATURE_SWITCH_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11
12 namespace base {
13 class CommandLine;
14 }
15
16 namespace extensions {
17
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 class FeatureSwitch {
21  public:
22   static FeatureSwitch* easy_off_store_install();
23   static FeatureSwitch* force_dev_mode_highlighting();
24   static FeatureSwitch* prompt_for_external_extensions();
25   static FeatureSwitch* error_console();
26   static FeatureSwitch* enable_override_bookmarks_ui();
27   static FeatureSwitch* extension_action_redesign();
28   static FeatureSwitch* scripts_require_action();
29   static FeatureSwitch* embedded_extension_options();
30
31   enum DefaultValue {
32     DEFAULT_ENABLED,
33     DEFAULT_DISABLED
34   };
35
36   enum OverrideValue {
37     OVERRIDE_NONE,
38     OVERRIDE_ENABLED,
39     OVERRIDE_DISABLED
40   };
41
42   // A temporary override for the switch value.
43   class ScopedOverride {
44    public:
45     ScopedOverride(FeatureSwitch* feature, bool override_value);
46     ~ScopedOverride();
47    private:
48     FeatureSwitch* feature_;
49     FeatureSwitch::OverrideValue previous_value_;
50     DISALLOW_COPY_AND_ASSIGN(ScopedOverride);
51   };
52
53   // |switch_name| can be NULL, in which case the feature is controlled solely
54   // by the default and override values.
55   FeatureSwitch(const char* switch_name,
56                 DefaultValue default_value);
57   FeatureSwitch(const base::CommandLine* command_line,
58                 const char* switch_name,
59                 DefaultValue default_value);
60
61   // Consider using ScopedOverride instead.
62   void SetOverrideValue(OverrideValue value);
63   OverrideValue GetOverrideValue() const;
64
65   bool IsEnabled() const;
66
67  private:
68   void Init(const base::CommandLine* command_line,
69             const char* switch_name,
70             DefaultValue default_value);
71
72   std::string GetLegacyEnableFlag() const;
73   std::string GetLegacyDisableFlag() const;
74
75   const base::CommandLine* command_line_;
76   const char* switch_name_;
77   bool default_value_;
78   OverrideValue override_value_;
79
80   DISALLOW_COPY_AND_ASSIGN(FeatureSwitch);
81 };
82
83 }  // namespace extensions
84
85 #endif  // EXTENSIONS_COMMON_FEATURE_SWITCH_H_