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

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: Fix tests and indentation changes. 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 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() {
Devlin 2015/08/13 21:21:10 Wait, why is this a scoped_ptr?
apacible 2015/08/15 08:46:41 We switched it from returning a raw ptr to a scope
Devlin 2015/08/17 16:32:21 But why return a ptr at all? Why not just std::ve
apacible 2015/08/17 18:23:32 Talked offline, switched to vector.
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 {
52 if (switches::MediaRouterEnabled()) {
Devlin 2015/08/13 21:21:10 isn't this always the same as else if (switches::M
apacible 2015/08/15 08:46:41 Yes, updated.
53 component_ids->push_back(
54 ComponentToolbarActionsFactory::kMediaRouterActionId);
55 }
56 }
57
58 return component_ids.Pass();
59 }
60
32 ScopedVector<ToolbarActionViewController> 61 ScopedVector<ToolbarActionViewController>
33 ComponentToolbarActionsFactory::GetComponentToolbarActions(Browser* browser) { 62 ComponentToolbarActionsFactory::GetComponentToolbarActions(Browser* browser) {
34 ScopedVector<ToolbarActionViewController> component_actions; 63 ScopedVector<ToolbarActionViewController> component_actions;
35 64
36 // This is currently behind the extension-action-redesign flag, as it is 65 // This is currently behind the extension-action-redesign flag, as it is
37 // designed for the new toolbar. 66 // designed for the new toolbar.
38 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) 67 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled())
39 return component_actions.Pass(); 68 return component_actions.Pass();
40 69
41 // Add component toolbar actions here. 70 // Add component toolbar actions here.
42 // This current design means that the ComponentToolbarActionsFactory is aware 71 // This current design means that the ComponentToolbarActionsFactory is aware
43 // of all actions. Since we should *not* have an excessive amount of these 72 // 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 73 // (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, 74 // should be okay. If this changes, we should rethink this design to have,
46 // e.g., RegisterChromeAction(). 75 // e.g., RegisterChromeAction().
47 76
48 #if defined(ENABLE_MEDIA_ROUTER) 77 if (switches::MediaRouterEnabled())
Devlin 2015/08/13 21:21:10 Do we not need the #if defined blocks anymore? (F
apacible 2015/08/15 08:46:41 No, pkasting@ gave some good feedback about minimi
49 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
50 ::switches::kEnableMediaRouter)) {
51 component_actions.push_back(new MediaRouterAction(browser)); 78 component_actions.push_back(new MediaRouterAction(browser));
52 }
53 #endif
54 79
55 return component_actions.Pass(); 80 return component_actions.Pass();
56 } 81 }
57 82
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 83 // static
66 void ComponentToolbarActionsFactory::SetTestingFactory( 84 void ComponentToolbarActionsFactory::SetTestingFactory(
67 ComponentToolbarActionsFactory* factory) { 85 ComponentToolbarActionsFactory* factory) {
68 testing_factory_ = factory; 86 testing_factory_ = factory;
69 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698