| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/ui/toolbar/component_toolbar_actions_factory.h" | 5 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.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 "chrome/browser/ui/toolbar/media_router_action.h" | 9 #include "chrome/browser/ui/toolbar/media_router_action.h" |
| 10 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 10 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "extensions/common/feature_switch.h" | 12 #include "extensions/common/feature_switch.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 ComponentToolbarActionsFactory* testing_factory_ = nullptr; | 16 ComponentToolbarActionsFactory* testing_factory_ = nullptr; |
| 17 | 17 |
| 18 base::LazyInstance<ComponentToolbarActionsFactory> lazy_factory = | 18 base::LazyInstance<ComponentToolbarActionsFactory> lazy_factory = |
| 19 LAZY_INSTANCE_INITIALIZER; | 19 LAZY_INSTANCE_INITIALIZER; |
| 20 | 20 |
| 21 } // namespace | 21 } // namespace |
| 22 | 22 |
| 23 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory() | 23 // static |
| 24 : num_component_actions_(-1) {} | 24 const char ComponentToolbarActionsFactory::kMediaRouterActionId[] = |
| 25 "media_router_action"; |
| 26 const char ComponentToolbarActionsFactory::kActionIdForTesting[] = |
| 27 "mock_action"; |
| 28 |
| 29 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory() {} |
| 25 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {} | 30 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {} |
| 26 | 31 |
| 27 // static | 32 // static |
| 28 ComponentToolbarActionsFactory* ComponentToolbarActionsFactory::GetInstance() { | 33 ComponentToolbarActionsFactory* ComponentToolbarActionsFactory::GetInstance() { |
| 29 return testing_factory_ ? testing_factory_ : &lazy_factory.Get(); | 34 return testing_factory_ ? testing_factory_ : &lazy_factory.Get(); |
| 30 } | 35 } |
| 31 | 36 |
| 37 // static |
| 38 std::vector<std::string> ComponentToolbarActionsFactory::GetComponentIds() { |
| 39 std::vector<std::string> component_ids; |
| 40 |
| 41 // This is currently behind the extension-action-redesign flag, as it is |
| 42 // designed for the new toolbar. |
| 43 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) |
| 44 return component_ids; |
| 45 |
| 46 if (testing_factory_) { |
| 47 component_ids.push_back( |
| 48 ComponentToolbarActionsFactory::kActionIdForTesting); |
| 49 } else if (switches::MediaRouterEnabled()) { |
| 50 component_ids.push_back( |
| 51 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 52 } |
| 53 |
| 54 return component_ids; |
| 55 } |
| 56 |
| 32 ScopedVector<ToolbarActionViewController> | 57 ScopedVector<ToolbarActionViewController> |
| 33 ComponentToolbarActionsFactory::GetComponentToolbarActions(Browser* browser) { | 58 ComponentToolbarActionsFactory::GetComponentToolbarActions(Browser* browser) { |
| 34 ScopedVector<ToolbarActionViewController> component_actions; | 59 ScopedVector<ToolbarActionViewController> component_actions; |
| 35 | 60 |
| 36 // This is currently behind the extension-action-redesign flag, as it is | 61 // This is currently behind the extension-action-redesign flag, as it is |
| 37 // designed for the new toolbar. | 62 // designed for the new toolbar. |
| 38 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) | 63 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) |
| 39 return component_actions.Pass(); | 64 return component_actions.Pass(); |
| 40 | 65 |
| 41 // Add component toolbar actions here. | 66 // Add component toolbar actions here. |
| 42 // This current design means that the ComponentToolbarActionsFactory is aware | 67 // This current design means that the ComponentToolbarActionsFactory is aware |
| 43 // of all actions. Since we should *not* have an excessive amount of these | 68 // of all actions. Since we should *not* have an excessive amount of these |
| 44 // (since each will have an action in the toolbar or overflow menu), this | 69 // (since each will have an action in the toolbar or overflow menu), this |
| 45 // should be okay. If this changes, we should rethink this design to have, | 70 // should be okay. If this changes, we should rethink this design to have, |
| 46 // e.g., RegisterChromeAction(). | 71 // e.g., RegisterChromeAction(). |
| 47 | 72 |
| 48 #if defined(ENABLE_MEDIA_ROUTER) | 73 if (switches::MediaRouterEnabled()) |
| 49 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 50 ::switches::kEnableMediaRouter)) { | |
| 51 component_actions.push_back(new MediaRouterAction(browser)); | 74 component_actions.push_back(new MediaRouterAction(browser)); |
| 52 } | |
| 53 #endif | |
| 54 | 75 |
| 55 return component_actions.Pass(); | 76 return component_actions.Pass(); |
| 56 } | 77 } |
| 57 | 78 |
| 58 int ComponentToolbarActionsFactory::GetNumComponentActions(Browser* browser) { | |
| 59 if (num_component_actions_ == -1) | |
| 60 num_component_actions_ = GetComponentToolbarActions(browser).size(); | |
| 61 | |
| 62 return num_component_actions_; | |
| 63 } | |
| 64 | |
| 65 // static | 79 // static |
| 66 void ComponentToolbarActionsFactory::SetTestingFactory( | 80 void ComponentToolbarActionsFactory::SetTestingFactory( |
| 67 ComponentToolbarActionsFactory* factory) { | 81 ComponentToolbarActionsFactory* factory) { |
| 68 testing_factory_ = factory; | 82 testing_factory_ = factory; |
| 69 } | 83 } |
| OLD | NEW |