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