Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Unified Diff: chrome/common/extensions/feature_switch.cc

Issue 11014009: Beginnings of the script bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More minor cleanup Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/feature_switch.cc
diff --git a/chrome/common/extensions/feature_switch.cc b/chrome/common/extensions/feature_switch.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ed6443e37fb48f4dab9f00db0e8f846bf14ed2bd
--- /dev/null
+++ b/chrome/common/extensions/feature_switch.cc
@@ -0,0 +1,83 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/extensions/feature_switch.h"
+
+#include "base/command_line.h"
+#include "base/lazy_instance.h"
+#include "base/string_util.h"
+#include "chrome/common/chrome_switches.h"
+
+namespace extensions {
+
+namespace {
+
+class CommonSwitches {
+ public:
+ CommonSwitches()
+ : script_bubble(CommandLine::ForCurrentProcess(),
+ switches::kScriptBubbleEnabled,
+ FeatureSwitch::DEFAULT_DISABLED) {
+ }
+ FeatureSwitch script_bubble;
+};
+
+base::LazyInstance<CommonSwitches> g_common_switches =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+
+FeatureSwitch* FeatureSwitch::GetScriptBubble() {
+ return &g_common_switches.Get().script_bubble;
+}
+
+FeatureSwitch::ScopedOverride::ScopedOverride(FeatureSwitch* feature,
+ bool override_value)
+ : feature_(feature) {
+ feature_->SetOverrideValue(
+ override_value ? OVERRIDE_ENABLED : OVERRIDE_DISABLED);
+}
+
+FeatureSwitch::ScopedOverride::~ScopedOverride() {
+ feature_->SetOverrideValue(OVERRIDE_NONE);
+}
+
+FeatureSwitch::FeatureSwitch(const CommandLine* command_line,
+ const char* switch_name,
+ DefaultValue default_value)
+ : command_line_(command_line),
+ switch_name_(switch_name),
+ default_value_(default_value == DEFAULT_ENABLED),
+ override_value_(OVERRIDE_NONE) {
+}
+
+bool FeatureSwitch::IsEnabled() const {
+ if (override_value_ != OVERRIDE_NONE)
+ return override_value_ == OVERRIDE_ENABLED;
+
+ // TODO(aa): Consider supporting other values.
+ std::string temp = command_line_->GetSwitchValueASCII(switch_name_);
+ std::string switch_value;
+ TrimWhitespaceASCII(temp, TRIM_ALL, &switch_value);
+ if (switch_value == "1")
+ return true;
+ if (switch_value == "0")
+ return false;
+ return default_value_;
+}
+
+FeatureSwitch::ScopedOverride FeatureSwitch::Override(
+ bool override_value) {
+ return ScopedOverride(this, override_value);
+}
+
+void FeatureSwitch::SetOverrideValue(OverrideValue override_value) {
+ if (override_value_ != OVERRIDE_NONE)
+ CHECK_EQ(OVERRIDE_NONE, override_value);
+
+ override_value_ = override_value;
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698