Home | History | Annotate | Download | only in common
      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 class CommandLine;
     13 
     14 namespace extensions {
     15 
     16 // A switch that can turn a feature on or off. Typically controlled via
     17 // command-line switches but can be overridden, e.g., for testing.
     18 class FeatureSwitch {
     19  public:
     20   static FeatureSwitch* easy_off_store_install();
     21   static FeatureSwitch* force_dev_mode_highlighting();
     22   static FeatureSwitch* global_commands();
     23   static FeatureSwitch* script_badges();
     24   static FeatureSwitch* script_bubble();
     25   static FeatureSwitch* prompt_for_external_extensions();
     26   static FeatureSwitch* error_console();
     27   static FeatureSwitch* enable_override_bookmarks_ui();
     28 
     29   enum DefaultValue {
     30     DEFAULT_ENABLED,
     31     DEFAULT_DISABLED
     32   };
     33 
     34   enum OverrideValue {
     35     OVERRIDE_NONE,
     36     OVERRIDE_ENABLED,
     37     OVERRIDE_DISABLED
     38   };
     39 
     40   // A temporary override for the switch value.
     41   class ScopedOverride {
     42    public:
     43     ScopedOverride(FeatureSwitch* feature, bool override_value);
     44     ~ScopedOverride();
     45    private:
     46     FeatureSwitch* feature_;
     47     FeatureSwitch::OverrideValue previous_value_;
     48     DISALLOW_COPY_AND_ASSIGN(ScopedOverride);
     49   };
     50 
     51   FeatureSwitch(const char* switch_name,
     52                 DefaultValue default_value);
     53   FeatureSwitch(const CommandLine* command_line,
     54                 const char* switch_name,
     55                 DefaultValue default_value);
     56 
     57   // Consider using ScopedOverride instead.
     58   void SetOverrideValue(OverrideValue value);
     59   OverrideValue GetOverrideValue() const;
     60 
     61   bool IsEnabled() const;
     62 
     63   std::string GetLegacyEnableFlag() const;
     64   std::string GetLegacyDisableFlag() const;
     65 
     66  private:
     67   void Init(const CommandLine* command_line,
     68             const char* switch_name,
     69             DefaultValue default_value);
     70 
     71   const CommandLine* command_line_;
     72   const char* switch_name_;
     73   bool default_value_;
     74   OverrideValue override_value_;
     75 
     76   DISALLOW_COPY_AND_ASSIGN(FeatureSwitch);
     77 };
     78 
     79 }  // namespace extensions
     80 
     81 #endif  // EXTENSIONS_COMMON_FEATURE_SWITCH_H_
     82