Chromium Code Reviews| 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/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) {} | |
| 40 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {} | 33 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {} |
| 41 | 34 |
| 42 // static | 35 std::set<std::string> ComponentToolbarActionsFactory::GetInitialComponentIds() { |
| 43 ComponentToolbarActionsFactory* ComponentToolbarActionsFactory::GetInstance() { | |
| 44 return testing_factory_ ? testing_factory_ : &lazy_factory.Get(); | |
| 45 } | |
| 46 | |
| 47 std::set<std::string> ComponentToolbarActionsFactory::GetInitialComponentIds( | |
| 48 Profile* profile) { | |
| 49 std::set<std::string> component_ids; | |
| 50 #if defined(ENABLE_MEDIA_ROUTER) | 36 #if defined(ENABLE_MEDIA_ROUTER) |
| 51 if (media_router::MediaRouterEnabled(profile) && | 37 if (media_router::MediaRouterEnabled(profile_) && |
| 52 MediaRouterActionController::IsActionShownByPolicy(profile)) { | 38 MediaRouterActionController::IsActionShownByPolicy(profile_)) { |
| 53 component_ids.insert(kMediaRouterActionId); | 39 initial_ids_.insert(kMediaRouterActionId); |
|
msw
2017/02/17 23:55:05
If this function is called multiple times, wouldn'
takumif
2017/02/18 01:04:16
I thought it'd be fine since it's a set, but yes,
| |
| 54 } | 40 } |
| 55 #endif | 41 #endif |
| 56 | 42 |
| 57 return component_ids; | 43 return initial_ids_; |
| 44 } | |
| 45 | |
| 46 void ComponentToolbarActionsFactory::OnAddComponentActionBeforeInit( | |
| 47 const std::string& action_id) { | |
| 48 initial_ids_.insert(action_id); | |
| 49 } | |
| 50 | |
| 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 } |
| OLD | NEW |