Miscellaneous changes to finish Media Router upstreaming.
[chromium-blink-merge.git] / chrome / browser / ui / toolbar / component_toolbar_actions_factory.cc
blobc50d1784a248e39c94ea6ab0abe18364f0a67d3a
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
7 #include "base/command_line.h"
8 #include "base/lazy_instance.h"
9 #include "chrome/browser/ui/toolbar/media_router_action.h"
10 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "extensions/common/feature_switch.h"
14 namespace {
16 ComponentToolbarActionsFactory* testing_factory_ = nullptr;
18 base::LazyInstance<ComponentToolbarActionsFactory> lazy_factory =
19 LAZY_INSTANCE_INITIALIZER;
21 } // namespace
23 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory()
24 : num_component_actions_(-1) {}
25 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {}
27 // static
28 ComponentToolbarActionsFactory* ComponentToolbarActionsFactory::GetInstance() {
29 return testing_factory_ ? testing_factory_ : &lazy_factory.Get();
32 ScopedVector<ToolbarActionViewController>
33 ComponentToolbarActionsFactory::GetComponentToolbarActions() {
34 ScopedVector<ToolbarActionViewController> component_actions;
36 // This is currently behind the extension-action-redesign flag, as it is
37 // designed for the new toolbar.
38 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled())
39 return component_actions.Pass();
41 // Add component toolbar actions here.
42 // This current design means that the ComponentToolbarActionsFactory is aware
43 // 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
45 // should be okay. If this changes, we should rethink this design to have,
46 // e.g., RegisterChromeAction().
48 #if defined(ENABLE_MEDIA_ROUTER)
49 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
50 ::switches::kEnableMediaRouter)) {
51 component_actions.push_back(new MediaRouterAction());
53 #endif
55 return component_actions.Pass();
58 int ComponentToolbarActionsFactory::GetNumComponentActions() {
59 if (num_component_actions_ == -1)
60 num_component_actions_ = GetComponentToolbarActions().size();
62 return num_component_actions_;
65 // static
66 void ComponentToolbarActionsFactory::SetTestingFactory(
67 ComponentToolbarActionsFactory* factory) {
68 testing_factory_ = factory;