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/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/toolbar/media_router_action.h"
12 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "extensions/common/feature_switch.h"
18 ComponentToolbarActionsFactory
* testing_factory_
= nullptr;
20 base::LazyInstance
<ComponentToolbarActionsFactory
> lazy_factory
=
21 LAZY_INSTANCE_INITIALIZER
;
26 const char ComponentToolbarActionsFactory::kMediaRouterActionId
[] =
27 "media_router_action";
28 const char ComponentToolbarActionsFactory::kActionIdForTesting
[] =
31 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory() {}
32 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {}
35 ComponentToolbarActionsFactory
* ComponentToolbarActionsFactory::GetInstance() {
36 return testing_factory_
? testing_factory_
: &lazy_factory
.Get();
40 std::vector
<std::string
> ComponentToolbarActionsFactory::GetComponentIds() {
41 std::vector
<std::string
> component_ids
;
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())
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
);
60 bool ComponentToolbarActionsFactory::EnabledIncognito(
61 const std::string
& action_id
) {
62 return action_id
!= kMediaRouterActionId
;
65 ScopedVector
<ToolbarActionViewController
>
66 ComponentToolbarActionsFactory::GetComponentToolbarActions(Browser
* browser
) {
67 ScopedVector
<ToolbarActionViewController
> component_actions
;
69 // This is currently behind the extension-action-redesign flag, as it is
70 // designed for the new toolbar.
71 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled())
72 return component_actions
.Pass();
74 // Add component toolbar actions here.
75 // This current design means that the ComponentToolbarActionsFactory is aware
76 // of all actions. Since we should *not* have an excessive amount of these
77 // (since each will have an action in the toolbar or overflow menu), this
78 // should be okay. If this changes, we should rethink this design to have,
79 // e.g., RegisterChromeAction().
81 if (switches::MediaRouterEnabled() && !browser
->profile()->IsOffTheRecord())
82 component_actions
.push_back(new MediaRouterAction(browser
));
84 return component_actions
.Pass();
88 void ComponentToolbarActionsFactory::SetTestingFactory(
89 ComponentToolbarActionsFactory
* factory
) {
90 testing_factory_
= factory
;