| OLD | NEW |
| (Empty) | |
| 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 #include "chrome/common/extensions/feature_switch.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" |
| 9 #include "base/string_util.h" |
| 10 #include "chrome/common/chrome_switches.h" |
| 11 |
| 12 namespace extensions { |
| 13 |
| 14 namespace { |
| 15 |
| 16 class CommonSwitches { |
| 17 public: |
| 18 CommonSwitches() |
| 19 : script_bubble(CommandLine::ForCurrentProcess(), |
| 20 switches::kScriptBubbleEnabled, |
| 21 FeatureSwitch::DEFAULT_DISABLED) { |
| 22 } |
| 23 FeatureSwitch script_bubble; |
| 24 }; |
| 25 |
| 26 base::LazyInstance<CommonSwitches> g_common_switches = |
| 27 LAZY_INSTANCE_INITIALIZER; |
| 28 |
| 29 } // namespace |
| 30 |
| 31 |
| 32 FeatureSwitch* FeatureSwitch::GetScriptBubble() { |
| 33 return &g_common_switches.Get().script_bubble; |
| 34 } |
| 35 |
| 36 FeatureSwitch::ScopedOverride::ScopedOverride(FeatureSwitch* feature, |
| 37 bool override_value) |
| 38 : feature_(feature) { |
| 39 feature_->SetOverrideValue( |
| 40 override_value ? OVERRIDE_ENABLED : OVERRIDE_DISABLED); |
| 41 } |
| 42 |
| 43 FeatureSwitch::ScopedOverride::~ScopedOverride() { |
| 44 feature_->SetOverrideValue(OVERRIDE_NONE); |
| 45 } |
| 46 |
| 47 FeatureSwitch::FeatureSwitch(const CommandLine* command_line, |
| 48 const char* switch_name, |
| 49 DefaultValue default_value) |
| 50 : command_line_(command_line), |
| 51 switch_name_(switch_name), |
| 52 default_value_(default_value == DEFAULT_ENABLED), |
| 53 override_value_(OVERRIDE_NONE) { |
| 54 } |
| 55 |
| 56 bool FeatureSwitch::IsEnabled() const { |
| 57 if (override_value_ != OVERRIDE_NONE) |
| 58 return override_value_ == OVERRIDE_ENABLED; |
| 59 |
| 60 // TODO(aa): Consider supporting other values. |
| 61 std::string temp = command_line_->GetSwitchValueASCII(switch_name_); |
| 62 std::string switch_value; |
| 63 TrimWhitespaceASCII(temp, TRIM_ALL, &switch_value); |
| 64 if (switch_value == "1") |
| 65 return true; |
| 66 if (switch_value == "0") |
| 67 return false; |
| 68 return default_value_; |
| 69 } |
| 70 |
| 71 void FeatureSwitch::SetOverrideValue(OverrideValue override_value) { |
| 72 if (override_value_ != OVERRIDE_NONE) |
| 73 CHECK_EQ(OVERRIDE_NONE, override_value); |
| 74 |
| 75 override_value_ = override_value; |
| 76 } |
| 77 |
| 78 } // namespace extensions |
| OLD | NEW |