| 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 // static |
| 24 const char ComponentToolbarActionsFactory::kMediaRouterActionId[] = |
| 25 "media_router_action"; |
| 26 const char ComponentToolbarActionsFactory::kActionIdForTest[] = "mock_action"; |
| 27 |
| 23 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory() | 28 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory() |
| 24 : num_component_actions_(-1) {} | 29 : num_component_actions_(-1) {} |
| 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 = new std::vector<std::string>; |
| 40 |
| 41 if (testing_factory_) { |
| 42 component_ids->push_back(ComponentToolbarActionsFactory::kActionIdForTest); |
| 43 } else { |
| 44 #if defined(ENABLE_MEDIA_ROUTER) |
| 45 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 46 ::switches::kEnableMediaRouter)) { |
| 47 component_ids->push_back( |
| 48 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 49 } |
| 50 #endif // ENABLE_MEDIA_ROUTER |
| 51 } |
| 52 |
| 53 return *component_ids; |
| 54 } |
| 55 |
| 32 ScopedVector<ToolbarActionViewController> | 56 ScopedVector<ToolbarActionViewController> |
| 33 ComponentToolbarActionsFactory::GetComponentToolbarActions(Browser* browser) { | 57 ComponentToolbarActionsFactory::GetComponentToolbarActions(Browser* browser) { |
| 34 ScopedVector<ToolbarActionViewController> component_actions; | 58 ScopedVector<ToolbarActionViewController> component_actions; |
| 35 | 59 |
| 36 // This is currently behind the extension-action-redesign flag, as it is | 60 // This is currently behind the extension-action-redesign flag, as it is |
| 37 // designed for the new toolbar. | 61 // designed for the new toolbar. |
| 38 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) | 62 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) |
| 39 return component_actions.Pass(); | 63 return component_actions.Pass(); |
| 40 | 64 |
| 41 // Add component toolbar actions here. | 65 // Add component toolbar actions here. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 60 num_component_actions_ = GetComponentToolbarActions(browser).size(); | 84 num_component_actions_ = GetComponentToolbarActions(browser).size(); |
| 61 | 85 |
| 62 return num_component_actions_; | 86 return num_component_actions_; |
| 63 } | 87 } |
| 64 | 88 |
| 65 // static | 89 // static |
| 66 void ComponentToolbarActionsFactory::SetTestingFactory( | 90 void ComponentToolbarActionsFactory::SetTestingFactory( |
| 67 ComponentToolbarActionsFactory* factory) { | 91 ComponentToolbarActionsFactory* factory) { |
| 68 testing_factory_ = factory; | 92 testing_factory_ = factory; |
| 69 } | 93 } |
| OLD | NEW |