| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/extensions/feature_switch.h" | 5 #include "chrome/common/extensions/feature_switch.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "content/public/common/content_switches.h" |
| 11 | 12 |
| 12 namespace extensions { | 13 namespace extensions { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 class CommonSwitches { | 17 class CommonSwitches { |
| 17 public: | 18 public: |
| 18 CommonSwitches() | 19 CommonSwitches() |
| 19 : action_box( | 20 : action_box( |
| 20 switches::kActionBox, | 21 switches::kActionBox, |
| 21 FeatureSwitch::DEFAULT_ENABLED), | 22 FeatureSwitch::DEFAULT_ENABLED), |
| 22 easy_off_store_install( | 23 easy_off_store_install( |
| 23 switches::kEasyOffStoreExtensionInstall, | 24 switches::kEasyOffStoreExtensionInstall, |
| 24 FeatureSwitch::DEFAULT_DISABLED), | 25 FeatureSwitch::DEFAULT_DISABLED), |
| 25 extensions_in_action_box( | 26 extensions_in_action_box( |
| 26 switches::kExtensionsInActionBox, | 27 switches::kExtensionsInActionBox, |
| 27 FeatureSwitch::DEFAULT_DISABLED), | 28 FeatureSwitch::DEFAULT_DISABLED), |
| 28 script_badges( | 29 script_badges( |
| 29 switches::kScriptBadges, | 30 switches::kScriptBadges, |
| 30 FeatureSwitch::DEFAULT_DISABLED), | 31 FeatureSwitch::DEFAULT_DISABLED), |
| 31 script_bubble( | 32 script_bubble( |
| 32 switches::kScriptBubble, | 33 switches::kScriptBubble, |
| 33 FeatureSwitch::DEFAULT_DISABLED), | 34 FeatureSwitch::DEFAULT_DISABLED), |
| 34 prompt_for_external_extensions( | 35 prompt_for_external_extensions( |
| 35 switches::kPromptForExternalExtensions, | 36 switches::kPromptForExternalExtensions, |
| 36 FeatureSwitch::DEFAULT_ENABLED) | 37 FeatureSwitch::DEFAULT_ENABLED), |
| 38 tab_capture( |
| 39 switches::kEnableTabCapture, |
| 40 FeatureSwitch::DEFAULT_DISABLED) |
| 37 { | 41 { |
| 38 // Disabling easy off-store installation is not yet implemented for Aura. Not | 42 // Disabling easy off-store installation is not yet implemented for Aura. Not |
| 39 // sure what the Aura equivalent for this UI is. | 43 // sure what the Aura equivalent for this UI is. |
| 40 #if defined(USE_AURA) | 44 #if defined(USE_AURA) |
| 41 easy_off_store_install.SetOverrideValue(FeatureSwitch::OVERRIDE_ENABLED); | 45 easy_off_store_install.SetOverrideValue(FeatureSwitch::OVERRIDE_ENABLED); |
| 42 #endif | 46 #endif |
| 43 | 47 |
| 44 if (!action_box.IsEnabled()){ | 48 if (!action_box.IsEnabled()){ |
| 45 extensions_in_action_box.SetOverrideValue( | 49 extensions_in_action_box.SetOverrideValue( |
| 46 FeatureSwitch::OVERRIDE_DISABLED); | 50 FeatureSwitch::OVERRIDE_DISABLED); |
| 47 } | 51 } |
| 48 } | 52 } |
| 49 | 53 |
| 50 FeatureSwitch action_box; | 54 FeatureSwitch action_box; |
| 51 FeatureSwitch easy_off_store_install; | 55 FeatureSwitch easy_off_store_install; |
| 52 FeatureSwitch extensions_in_action_box; | 56 FeatureSwitch extensions_in_action_box; |
| 53 FeatureSwitch script_badges; | 57 FeatureSwitch script_badges; |
| 54 FeatureSwitch script_bubble; | 58 FeatureSwitch script_bubble; |
| 55 FeatureSwitch prompt_for_external_extensions; | 59 FeatureSwitch prompt_for_external_extensions; |
| 60 FeatureSwitch tab_capture; |
| 56 }; | 61 }; |
| 57 | 62 |
| 58 base::LazyInstance<CommonSwitches> g_common_switches = | 63 base::LazyInstance<CommonSwitches> g_common_switches = |
| 59 LAZY_INSTANCE_INITIALIZER; | 64 LAZY_INSTANCE_INITIALIZER; |
| 60 | 65 |
| 61 } // namespace | 66 } // namespace |
| 62 | 67 |
| 63 | 68 |
| 64 FeatureSwitch* FeatureSwitch::action_box() { | 69 FeatureSwitch* FeatureSwitch::action_box() { |
| 65 return &g_common_switches.Get().action_box; | 70 return &g_common_switches.Get().action_box; |
| 66 } | 71 } |
| 67 FeatureSwitch* FeatureSwitch::easy_off_store_install() { | 72 FeatureSwitch* FeatureSwitch::easy_off_store_install() { |
| 68 return &g_common_switches.Get().easy_off_store_install; | 73 return &g_common_switches.Get().easy_off_store_install; |
| 69 } | 74 } |
| 70 FeatureSwitch* FeatureSwitch::extensions_in_action_box() { | 75 FeatureSwitch* FeatureSwitch::extensions_in_action_box() { |
| 71 return &g_common_switches.Get().extensions_in_action_box; | 76 return &g_common_switches.Get().extensions_in_action_box; |
| 72 } | 77 } |
| 73 FeatureSwitch* FeatureSwitch::script_badges() { | 78 FeatureSwitch* FeatureSwitch::script_badges() { |
| 74 return &g_common_switches.Get().script_badges; | 79 return &g_common_switches.Get().script_badges; |
| 75 } | 80 } |
| 76 FeatureSwitch* FeatureSwitch::script_bubble() { | 81 FeatureSwitch* FeatureSwitch::script_bubble() { |
| 77 return &g_common_switches.Get().script_bubble; | 82 return &g_common_switches.Get().script_bubble; |
| 78 } | 83 } |
| 79 FeatureSwitch* FeatureSwitch::prompt_for_external_extensions() { | 84 FeatureSwitch* FeatureSwitch::prompt_for_external_extensions() { |
| 80 return &g_common_switches.Get().prompt_for_external_extensions; | 85 return &g_common_switches.Get().prompt_for_external_extensions; |
| 81 } | 86 } |
| 87 FeatureSwitch* FeatureSwitch::tab_capture() { |
| 88 return &g_common_switches.Get().tab_capture; |
| 89 } |
| 82 | 90 |
| 83 | 91 |
| 84 FeatureSwitch::ScopedOverride::ScopedOverride(FeatureSwitch* feature, | 92 FeatureSwitch::ScopedOverride::ScopedOverride(FeatureSwitch* feature, |
| 85 bool override_value) | 93 bool override_value) |
| 86 : feature_(feature), | 94 : feature_(feature), |
| 87 previous_value_(feature->GetOverrideValue()) { | 95 previous_value_(feature->GetOverrideValue()) { |
| 88 feature_->SetOverrideValue( | 96 feature_->SetOverrideValue( |
| 89 override_value ? OVERRIDE_ENABLED : OVERRIDE_DISABLED); | 97 override_value ? OVERRIDE_ENABLED : OVERRIDE_DISABLED); |
| 90 } | 98 } |
| 91 | 99 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 134 |
| 127 if (switch_value == "0") | 135 if (switch_value == "0") |
| 128 return false; | 136 return false; |
| 129 | 137 |
| 130 if (!default_value_ && command_line_->HasSwitch(GetLegacyEnableFlag())) | 138 if (!default_value_ && command_line_->HasSwitch(GetLegacyEnableFlag())) |
| 131 return true; | 139 return true; |
| 132 | 140 |
| 133 if (default_value_ && command_line_->HasSwitch(GetLegacyDisableFlag())) | 141 if (default_value_ && command_line_->HasSwitch(GetLegacyDisableFlag())) |
| 134 return false; | 142 return false; |
| 135 | 143 |
| 144 if (!default_value_ && command_line_->HasSwitch(switch_name_)) |
| 145 return true; |
| 146 |
| 136 return default_value_; | 147 return default_value_; |
| 137 } | 148 } |
| 138 | 149 |
| 139 std::string FeatureSwitch::GetLegacyEnableFlag() const { | 150 std::string FeatureSwitch::GetLegacyEnableFlag() const { |
| 140 return std::string("enable-") + switch_name_; | 151 return std::string("enable-") + switch_name_; |
| 141 } | 152 } |
| 142 | 153 |
| 143 std::string FeatureSwitch::GetLegacyDisableFlag() const { | 154 std::string FeatureSwitch::GetLegacyDisableFlag() const { |
| 144 return std::string("disable-") + switch_name_; | 155 return std::string("disable-") + switch_name_; |
| 145 } | 156 } |
| 146 | 157 |
| 147 void FeatureSwitch::SetOverrideValue(OverrideValue override_value) { | 158 void FeatureSwitch::SetOverrideValue(OverrideValue override_value) { |
| 148 override_value_ = override_value; | 159 override_value_ = override_value; |
| 149 } | 160 } |
| 150 | 161 |
| 151 FeatureSwitch::OverrideValue FeatureSwitch::GetOverrideValue() const { | 162 FeatureSwitch::OverrideValue FeatureSwitch::GetOverrideValue() const { |
| 152 return override_value_; | 163 return override_value_; |
| 153 } | 164 } |
| 154 | 165 |
| 155 } // namespace extensions | 166 } // namespace extensions |
| OLD | NEW |