Ignore non-active fullscreen windows for shelf state.
[chromium-blink-merge.git] / extensions / common / feature_switch.cc
blob002446196c00fd4a20eab0f2f7099ad1e49cb160
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.
5 #include "extensions/common/feature_switch.h"
7 #include "base/command_line.h"
8 #include "base/lazy_instance.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string_util.h"
11 #include "extensions/common/switches.h"
13 namespace extensions {
15 namespace {
17 class CommonSwitches {
18 public:
19 CommonSwitches()
20 : easy_off_store_install(
21 switches::kEasyOffStoreExtensionInstall,
22 FeatureSwitch::DEFAULT_DISABLED),
23 global_commands(
24 switches::kGlobalCommands,
25 FeatureSwitch::DEFAULT_DISABLED),
26 script_badges(
27 switches::kScriptBadges,
28 FeatureSwitch::DEFAULT_DISABLED),
29 script_bubble(
30 switches::kScriptBubble,
31 FeatureSwitch::DEFAULT_DISABLED),
32 prompt_for_external_extensions(
33 switches::kPromptForExternalExtensions,
34 #if defined(OS_WIN)
35 FeatureSwitch::DEFAULT_ENABLED),
36 #else
37 FeatureSwitch::DEFAULT_DISABLED),
38 #endif
39 error_console(
40 switches::kErrorConsole,
41 FeatureSwitch::DEFAULT_DISABLED) {}
43 FeatureSwitch easy_off_store_install;
44 FeatureSwitch global_commands;
45 FeatureSwitch script_badges;
46 FeatureSwitch script_bubble;
47 FeatureSwitch prompt_for_external_extensions;
48 FeatureSwitch error_console;
51 base::LazyInstance<CommonSwitches> g_common_switches =
52 LAZY_INSTANCE_INITIALIZER;
54 } // namespace
56 FeatureSwitch* FeatureSwitch::easy_off_store_install() {
57 return &g_common_switches.Get().easy_off_store_install;
59 FeatureSwitch* FeatureSwitch::global_commands() {
60 return &g_common_switches.Get().global_commands;
62 FeatureSwitch* FeatureSwitch::script_badges() {
63 return &g_common_switches.Get().script_badges;
65 FeatureSwitch* FeatureSwitch::script_bubble() {
66 return &g_common_switches.Get().script_bubble;
68 FeatureSwitch* FeatureSwitch::prompt_for_external_extensions() {
69 return &g_common_switches.Get().prompt_for_external_extensions;
71 FeatureSwitch* FeatureSwitch::error_console() {
72 return &g_common_switches.Get().error_console;
75 FeatureSwitch::ScopedOverride::ScopedOverride(FeatureSwitch* feature,
76 bool override_value)
77 : feature_(feature),
78 previous_value_(feature->GetOverrideValue()) {
79 feature_->SetOverrideValue(
80 override_value ? OVERRIDE_ENABLED : OVERRIDE_DISABLED);
83 FeatureSwitch::ScopedOverride::~ScopedOverride() {
84 feature_->SetOverrideValue(previous_value_);
87 FeatureSwitch::FeatureSwitch(const char* switch_name,
88 DefaultValue default_value) {
89 Init(CommandLine::ForCurrentProcess(), switch_name, default_value);
92 FeatureSwitch::FeatureSwitch(const CommandLine* command_line,
93 const char* switch_name,
94 DefaultValue default_value) {
95 Init(command_line, switch_name, default_value);
98 void FeatureSwitch::Init(const CommandLine* command_line,
99 const char* switch_name,
100 DefaultValue default_value) {
101 command_line_ = command_line;
102 switch_name_ = switch_name;
103 default_value_ = default_value == DEFAULT_ENABLED;
104 override_value_ = OVERRIDE_NONE;
107 bool FeatureSwitch::IsEnabled() const {
108 if (override_value_ != OVERRIDE_NONE)
109 return override_value_ == OVERRIDE_ENABLED;
111 std::string temp = command_line_->GetSwitchValueASCII(switch_name_);
112 std::string switch_value;
113 TrimWhitespaceASCII(temp, TRIM_ALL, &switch_value);
115 if (switch_value == "1")
116 return true;
118 if (switch_value == "0")
119 return false;
121 if (!default_value_ && command_line_->HasSwitch(GetLegacyEnableFlag()))
122 return true;
124 if (default_value_ && command_line_->HasSwitch(GetLegacyDisableFlag()))
125 return false;
127 return default_value_;
130 std::string FeatureSwitch::GetLegacyEnableFlag() const {
131 return std::string("enable-") + switch_name_;
134 std::string FeatureSwitch::GetLegacyDisableFlag() const {
135 return std::string("disable-") + switch_name_;
138 void FeatureSwitch::SetOverrideValue(OverrideValue override_value) {
139 override_value_ = override_value;
142 FeatureSwitch::OverrideValue FeatureSwitch::GetOverrideValue() const {
143 return override_value_;
146 } // namespace extensions