Upstream version 10.39.225.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   static FeatureSwitch* app_view();
31   static FeatureSwitch* mime_handler_view();
32
33   enum DefaultValue {
34     DEFAULT_ENABLED,
35     DEFAULT_DISABLED
36   };
37
38   enum OverrideValue {
39     OVERRIDE_NONE,
40     OVERRIDE_ENABLED,
41     OVERRIDE_DISABLED
42   };
43
44   // A temporary override for the switch value.
45   class ScopedOverride {
46    public:
47     ScopedOverride(FeatureSwitch* feature, bool override_value);
48     ~ScopedOverride();
49    private:
50     FeatureSwitch* feature_;
51     FeatureSwitch::OverrideValue previous_value_;
52     DISALLOW_COPY_AND_ASSIGN(ScopedOverride);
53   };
54
55   // |switch_name| can be NULL, in which case the feature is controlled solely
56   // by the default and override values.
57   FeatureSwitch(const char* switch_name,
58                 DefaultValue default_value);
59   FeatureSwitch(const base::CommandLine* command_line,
60                 const char* switch_name,
61                 DefaultValue default_value);
62
63   // Consider using ScopedOverride instead.
64   void SetOverrideValue(OverrideValue value);
65   OverrideValue GetOverrideValue() const;
66
67   bool IsEnabled() const;
68
69  private:
70   void Init(const base::CommandLine* command_line,
71             const char* switch_name,
72             DefaultValue default_value);
73
74   std::string GetLegacyEnableFlag() const;
75   std::string GetLegacyDisableFlag() const;
76
77   const base::CommandLine* command_line_;
78   const char* switch_name_;
79   bool default_value_;
80   OverrideValue override_value_;
81
82   DISALLOW_COPY_AND_ASSIGN(FeatureSwitch);
83 };
84
85 }  // namespace extensions
86
87 #endif  // EXTENSIONS_COMMON_FEATURE_SWITCH_H_