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