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

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

Issue 2613713005: Make ToolbarActionsModel own ComponentToolbarActionsFactory (Closed)
Patch Set: Address Mike's comments Created 3 years, 10 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/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/media/router/media_router_feature.h" 10 #include "chrome/browser/media/router/media_router_feature.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
14 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
14 #include "extensions/browser/extension_registry.h" 15 #include "extensions/browser/extension_registry.h"
15 #include "extensions/common/feature_switch.h" 16 #include "extensions/common/feature_switch.h"
16 17
17 #if defined(ENABLE_MEDIA_ROUTER) 18 #if defined(ENABLE_MEDIA_ROUTER)
18 #include "chrome/browser/ui/toolbar/media_router_action.h" 19 #include "chrome/browser/ui/toolbar/media_router_action.h"
19 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" 20 #include "chrome/browser/ui/toolbar/media_router_action_controller.h"
20 #endif 21 #endif
21 22
22 namespace {
23
24 ComponentToolbarActionsFactory* testing_factory_ = nullptr;
25
26 base::LazyInstance<ComponentToolbarActionsFactory> lazy_factory =
27 LAZY_INSTANCE_INITIALIZER;
28
29 } // namespace
30
31 // static 23 // static
32 const char ComponentToolbarActionsFactory::kCastBetaExtensionId[] = 24 const char ComponentToolbarActionsFactory::kCastBetaExtensionId[] =
33 "dliochdbjfkdbacpmhlcpmleaejidimm"; 25 "dliochdbjfkdbacpmhlcpmleaejidimm";
34 const char ComponentToolbarActionsFactory::kCastExtensionId[] = 26 const char ComponentToolbarActionsFactory::kCastExtensionId[] =
35 "boadgeojelhgndaghljhdicfkmllpafd"; 27 "boadgeojelhgndaghljhdicfkmllpafd";
36 const char ComponentToolbarActionsFactory::kMediaRouterActionId[] = 28 const char ComponentToolbarActionsFactory::kMediaRouterActionId[] =
37 "media_router_action"; 29 "media_router_action";
38 30
39 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory() {} 31 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory(Profile* profile)
32 : profile_(profile) {
33 #if defined(ENABLE_MEDIA_ROUTER)
34 if (media_router::MediaRouterEnabled(profile_) &&
35 MediaRouterActionController::IsActionShownByPolicy(profile_)) {
36 initial_ids_.insert(kMediaRouterActionId);
37 }
38 #endif
39 }
40 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {} 40 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {}
msw 2017/02/18 01:06:08 nit: add a blank line above
41 41
42 // static 42 std::set<std::string> ComponentToolbarActionsFactory::GetInitialComponentIds() {
43 ComponentToolbarActionsFactory* ComponentToolbarActionsFactory::GetInstance() { 43 return initial_ids_;
44 return testing_factory_ ? testing_factory_ : &lazy_factory.Get();
45 } 44 }
46 45
47 std::set<std::string> ComponentToolbarActionsFactory::GetInitialComponentIds( 46 void ComponentToolbarActionsFactory::OnAddComponentActionBeforeInit(
48 Profile* profile) { 47 const std::string& action_id) {
49 std::set<std::string> component_ids; 48 initial_ids_.insert(action_id);
50 #if defined(ENABLE_MEDIA_ROUTER) 49 }
51 if (media_router::MediaRouterEnabled(profile) &&
52 MediaRouterActionController::IsActionShownByPolicy(profile)) {
53 component_ids.insert(kMediaRouterActionId);
54 }
55 #endif
56 50
57 return component_ids; 51 void ComponentToolbarActionsFactory::OnRemoveComponentActionBeforeInit(
52 const std::string& action_id) {
53 initial_ids_.erase(action_id);
58 } 54 }
59 55
60 std::unique_ptr<ToolbarActionViewController> 56 std::unique_ptr<ToolbarActionViewController>
61 ComponentToolbarActionsFactory::GetComponentToolbarActionForId( 57 ComponentToolbarActionsFactory::GetComponentToolbarActionForId(
62 const std::string& id, 58 const std::string& action_id,
63 Browser* browser, 59 Browser* browser,
64 ToolbarActionsBar* bar) { 60 ToolbarActionsBar* bar) {
65 // This is currently behind the extension-action-redesign flag, as it is 61 // This is currently behind the extension-action-redesign flag, as it is
66 // designed for the new toolbar. 62 // designed for the new toolbar.
67 DCHECK(extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()); 63 DCHECK(extensions::FeatureSwitch::extension_action_redesign()->IsEnabled());
68 64
69 // Add component toolbar actions here. 65 // Add component toolbar actions here.
70 // This current design means that the ComponentToolbarActionsFactory is aware 66 // This current design means that the ComponentToolbarActionsFactory is aware
71 // of all actions. Since we should *not* have an excessive amount of these 67 // of all actions. Since we should *not* have an excessive amount of these
72 // (since each will have an action in the toolbar or overflow menu), this 68 // (since each will have an action in the toolbar or overflow menu), this
73 // should be okay. If this changes, we should rethink this design to have, 69 // should be okay. If this changes, we should rethink this design to have,
74 // e.g., RegisterChromeAction(). 70 // e.g., RegisterChromeAction().
75 #if defined(ENABLE_MEDIA_ROUTER) 71 #if defined(ENABLE_MEDIA_ROUTER)
76 if (id == kMediaRouterActionId) 72 if (action_id == kMediaRouterActionId)
77 return std::unique_ptr<ToolbarActionViewController>( 73 return std::unique_ptr<ToolbarActionViewController>(
78 new MediaRouterAction(browser, bar)); 74 new MediaRouterAction(browser, bar));
79 #endif // defined(ENABLE_MEDIA_ROUTER) 75 #endif // defined(ENABLE_MEDIA_ROUTER)
80 76
81 NOTREACHED(); 77 NOTREACHED();
82 return std::unique_ptr<ToolbarActionViewController>(); 78 return std::unique_ptr<ToolbarActionViewController>();
83 } 79 }
84 80
85 void ComponentToolbarActionsFactory::UnloadMigratedExtensions( 81 void ComponentToolbarActionsFactory::UnloadMigratedExtensions(
86 ExtensionService* service, 82 ExtensionService* service,
87 extensions::ExtensionRegistry* registry) { 83 extensions::ExtensionRegistry* registry) {
88 // TODO(takumif): Replace the unloading of Cast and Cast Beta extensions with 84 // TODO(takumif): Replace the unloading of Cast and Cast Beta extensions with
89 // uninstallation. 85 // uninstallation.
90 UnloadExtension(service, registry, kCastExtensionId); 86 UnloadExtension(service, registry, kCastExtensionId);
91 UnloadExtension(service, registry, kCastBetaExtensionId); 87 UnloadExtension(service, registry, kCastBetaExtensionId);
92 } 88 }
93 89
94 // static
95 void ComponentToolbarActionsFactory::SetTestingFactory(
96 ComponentToolbarActionsFactory* factory) {
97 testing_factory_ = factory;
98 }
99
100 void ComponentToolbarActionsFactory::UnloadExtension( 90 void ComponentToolbarActionsFactory::UnloadExtension(
101 ExtensionService* service, 91 ExtensionService* service,
102 extensions::ExtensionRegistry* registry, 92 extensions::ExtensionRegistry* registry,
103 const std::string& extension_id) { 93 const std::string& extension_id) {
104 if (registry->enabled_extensions().Contains(extension_id)) { 94 if (registry->enabled_extensions().Contains(extension_id)) {
105 service->UnloadExtension( 95 service->UnloadExtension(
106 extension_id, 96 extension_id,
107 extensions::UnloadedExtensionInfo::REASON_MIGRATED_TO_COMPONENT); 97 extensions::UnloadedExtensionInfo::REASON_MIGRATED_TO_COMPONENT);
108 } 98 }
109 } 99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698