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 scoped_ptr<std::vector<std::string>> |
| 39 ComponentToolbarActionsFactory::GetComponentIds() { |
| 40 scoped_ptr<std::vector<std::string>> component_ids( |
| 41 new std::vector<std::string>); |
| 42 |
| 43 // This is currently behind the extension-action-redesign flag, as it is |
| 44 // designed for the new toolbar. |
| 45 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) |
| 46 return component_ids.Pass(); |
| 47 |
| 48 if (testing_factory_) { |
| 49 component_ids->push_back( |
| 50 ComponentToolbarActionsFactory::kActionIdForTesting); |
| 51 } else if (switches::MediaRouterEnabled()) { |
| 52 component_ids->push_back( |
| 53 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 54 } |
| 55 |
| 56 return component_ids.Pass(); |
| 57 } |
| 58 |
32 ScopedVector<ToolbarActionViewController> | 59 ScopedVector<ToolbarActionViewController> |
33 ComponentToolbarActionsFactory::GetComponentToolbarActions(Browser* browser) { | 60 ComponentToolbarActionsFactory::GetComponentToolbarActions(Browser* browser) { |
34 ScopedVector<ToolbarActionViewController> component_actions; | 61 ScopedVector<ToolbarActionViewController> component_actions; |
35 | 62 |
36 // This is currently behind the extension-action-redesign flag, as it is | 63 // This is currently behind the extension-action-redesign flag, as it is |
37 // designed for the new toolbar. | 64 // designed for the new toolbar. |
38 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) | 65 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) |
39 return component_actions.Pass(); | 66 return component_actions.Pass(); |
40 | 67 |
41 // Add component toolbar actions here. | 68 // Add component toolbar actions here. |
42 // This current design means that the ComponentToolbarActionsFactory is aware | 69 // This current design means that the ComponentToolbarActionsFactory is aware |
43 // of all actions. Since we should *not* have an excessive amount of these | 70 // 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 | 71 // (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, | 72 // should be okay. If this changes, we should rethink this design to have, |
46 // e.g., RegisterChromeAction(). | 73 // e.g., RegisterChromeAction(). |
47 | 74 |
48 #if defined(ENABLE_MEDIA_ROUTER) | 75 if (switches::MediaRouterEnabled()) |
49 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
50 ::switches::kEnableMediaRouter)) { | |
51 component_actions.push_back(new MediaRouterAction(browser)); | 76 component_actions.push_back(new MediaRouterAction(browser)); |
52 } | |
53 #endif | |
54 | 77 |
55 return component_actions.Pass(); | 78 return component_actions.Pass(); |
56 } | 79 } |
57 | 80 |
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 | 81 // static |
66 void ComponentToolbarActionsFactory::SetTestingFactory( | 82 void ComponentToolbarActionsFactory::SetTestingFactory( |
67 ComponentToolbarActionsFactory* factory) { | 83 ComponentToolbarActionsFactory* factory) { |
68 testing_factory_ = factory; | 84 testing_factory_ = factory; |
69 } | 85 } |
OLD | NEW |