1 // Copyright (c) 2012 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 CHROME_COMMON_EXTENSIONS_FEATURE_SWITCH_H_ 6 #define CHROME_COMMON_EXTENSIONS_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* script_badges(); 22 static FeatureSwitch* script_bubble(); 23 static FeatureSwitch* prompt_for_external_extensions(); 24 static FeatureSwitch* tab_capture(); 25 26 enum DefaultValue { 27 DEFAULT_ENABLED, 28 DEFAULT_DISABLED 29 }; 30 31 enum OverrideValue { 32 OVERRIDE_NONE, 33 OVERRIDE_ENABLED, 34 OVERRIDE_DISABLED 35 }; 36 37 // A temporary override for the switch value. 38 class ScopedOverride { 39 public: 40 ScopedOverride(FeatureSwitch* feature, bool override_value); 41 ~ScopedOverride(); 42 private: 43 FeatureSwitch* feature_; 44 FeatureSwitch::OverrideValue previous_value_; 45 DISALLOW_COPY_AND_ASSIGN(ScopedOverride); 46 }; 47 48 FeatureSwitch(const char* switch_name, 49 DefaultValue default_value); 50 FeatureSwitch(const CommandLine* command_line, 51 const char* switch_name, 52 DefaultValue default_value); 53 54 // Consider using ScopedOverride instead. 55 void SetOverrideValue(OverrideValue value); 56 OverrideValue GetOverrideValue() const; 57 58 bool IsEnabled() const; 59 60 std::string GetLegacyEnableFlag() const; 61 std::string GetLegacyDisableFlag() const; 62 63 private: 64 void Init(const CommandLine* command_line, 65 const char* switch_name, 66 DefaultValue default_value); 67 68 const CommandLine* command_line_; 69 const char* switch_name_; 70 bool default_value_; 71 OverrideValue override_value_; 72 73 DISALLOW_COPY_AND_ASSIGN(FeatureSwitch); 74 }; 75 76 } // namespace extensions 77 78 #endif // CHROME_COMMON_EXTENSIONS_FEATURE_SWITCH_H_ 79