Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(541)

Side by Side Diff: chrome/browser/ui/toolbar/component_toolbar_actions_factory.cc

Issue 1241063003: Support Component Actions in the toolbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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::kActionIdForTesting[] =
27 "mock_action";
28
23 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory() 29 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory()
24 : num_component_actions_(-1) {} 30 : num_component_actions_(-1) {}
25 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {} 31 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {}
26 32
27 // static 33 // static
28 ComponentToolbarActionsFactory* ComponentToolbarActionsFactory::GetInstance() { 34 ComponentToolbarActionsFactory* ComponentToolbarActionsFactory::GetInstance() {
29 return testing_factory_ ? testing_factory_ : &lazy_factory.Get(); 35 return testing_factory_ ? testing_factory_ : &lazy_factory.Get();
30 } 36 }
31 37
38 // static
39 scoped_ptr<std::vector<std::string>>
40 ComponentToolbarActionsFactory::GetComponentIds() {
Peter Kasting 2015/08/11 19:10:49 It looks like this only ever returns 0 or 1 elemen
apacible 2015/08/12 05:26:44 In the future, we'll be returning more than one el
Peter Kasting 2015/08/12 07:13:45 OK. I still think returning the vector by copy mi
apacible 2015/08/15 08:46:40 Acknowledged.
41 scoped_ptr<std::vector<std::string>> component_ids(
42 new std::vector<std::string>);
43
44 // This is currently behind the extension-action-redesign flag, as it is
45 // designed for the new toolbar
Peter Kasting 2015/08/11 19:10:49 Nit: Comments should have trailing periods.
apacible 2015/08/12 05:26:44 Done.
46 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled())
47 return component_ids.Pass();
48
49 if (testing_factory_) {
50 component_ids->push_back(
51 ComponentToolbarActionsFactory::kActionIdForTesting);
52 } else {
53 #if defined(ENABLE_MEDIA_ROUTER)
54 if (switches::MediaRouterEnabled()) {
55 component_ids->push_back(
56 ComponentToolbarActionsFactory::kMediaRouterActionId);
57 }
58 #endif // ENABLE_MEDIA_ROUTER
59 }
60
61 return component_ids.Pass();
62 }
63
32 ScopedVector<ToolbarActionViewController> 64 ScopedVector<ToolbarActionViewController>
33 ComponentToolbarActionsFactory::GetComponentToolbarActions(Browser* browser) { 65 ComponentToolbarActionsFactory::GetComponentToolbarActions(Browser* browser) {
34 ScopedVector<ToolbarActionViewController> component_actions; 66 ScopedVector<ToolbarActionViewController> component_actions;
35 67
36 // This is currently behind the extension-action-redesign flag, as it is 68 // This is currently behind the extension-action-redesign flag, as it is
37 // designed for the new toolbar. 69 // designed for the new toolbar.
38 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) 70 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled())
39 return component_actions.Pass(); 71 return component_actions.Pass();
40 72
41 // Add component toolbar actions here. 73 // Add component toolbar actions here.
42 // This current design means that the ComponentToolbarActionsFactory is aware 74 // This current design means that the ComponentToolbarActionsFactory is aware
43 // of all actions. Since we should *not* have an excessive amount of these 75 // 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 76 // (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, 77 // should be okay. If this changes, we should rethink this design to have,
46 // e.g., RegisterChromeAction(). 78 // e.g., RegisterChromeAction().
47 79
48 #if defined(ENABLE_MEDIA_ROUTER) 80 #if defined(ENABLE_MEDIA_ROUTER)
49 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 81 if (switches::MediaRouterEnabled())
50 ::switches::kEnableMediaRouter)) {
51 component_actions.push_back(new MediaRouterAction(browser)); 82 component_actions.push_back(new MediaRouterAction(browser));
52 }
53 #endif 83 #endif
54 84
55 return component_actions.Pass(); 85 return component_actions.Pass();
56 } 86 }
57 87
58 int ComponentToolbarActionsFactory::GetNumComponentActions(Browser* browser) { 88 int ComponentToolbarActionsFactory::GetNumComponentActions() {
59 if (num_component_actions_ == -1) 89 if (num_component_actions_ == -1)
Peter Kasting 2015/08/11 19:10:49 This member variable seems like over-optimization.
apacible 2015/08/12 05:26:44 Eliminated GetNumComponentActions().
60 num_component_actions_ = GetComponentToolbarActions(browser).size(); 90 num_component_actions_ = GetComponentIds()->size();
61 91
62 return num_component_actions_; 92 return num_component_actions_;
63 } 93 }
64 94
65 // static 95 // static
66 void ComponentToolbarActionsFactory::SetTestingFactory( 96 void ComponentToolbarActionsFactory::SetTestingFactory(
67 ComponentToolbarActionsFactory* factory) { 97 ComponentToolbarActionsFactory* factory) {
68 testing_factory_ = factory; 98 testing_factory_ = factory;
69 } 99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698