| 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/media_router_action.h" |
| 14 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" |
| 13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 14 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 16 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 15 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
| 16 | 18 |
| 17 #if defined(ENABLE_MEDIA_ROUTER) | |
| 18 #include "chrome/browser/ui/toolbar/media_router_action.h" | |
| 19 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" | |
| 20 #endif | |
| 21 | |
| 22 // static | 19 // static |
| 23 const char ComponentToolbarActionsFactory::kCastBetaExtensionId[] = | 20 const char ComponentToolbarActionsFactory::kCastBetaExtensionId[] = |
| 24 "dliochdbjfkdbacpmhlcpmleaejidimm"; | 21 "dliochdbjfkdbacpmhlcpmleaejidimm"; |
| 25 const char ComponentToolbarActionsFactory::kCastExtensionId[] = | 22 const char ComponentToolbarActionsFactory::kCastExtensionId[] = |
| 26 "boadgeojelhgndaghljhdicfkmllpafd"; | 23 "boadgeojelhgndaghljhdicfkmllpafd"; |
| 27 const char ComponentToolbarActionsFactory::kMediaRouterActionId[] = | 24 const char ComponentToolbarActionsFactory::kMediaRouterActionId[] = |
| 28 "media_router_action"; | 25 "media_router_action"; |
| 29 | 26 |
| 30 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory(Profile* profile) | 27 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory(Profile* profile) |
| 31 : profile_(profile) { | 28 : profile_(profile) { |
| 32 #if defined(ENABLE_MEDIA_ROUTER) | |
| 33 if (media_router::MediaRouterEnabled(profile_) && | 29 if (media_router::MediaRouterEnabled(profile_) && |
| 34 MediaRouterActionController::IsActionShownByPolicy(profile_)) { | 30 MediaRouterActionController::IsActionShownByPolicy(profile_)) { |
| 35 initial_ids_.insert(kMediaRouterActionId); | 31 initial_ids_.insert(kMediaRouterActionId); |
| 36 } | 32 } |
| 37 #endif | |
| 38 } | 33 } |
| 39 | 34 |
| 40 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {} | 35 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {} |
| 41 | 36 |
| 42 std::set<std::string> ComponentToolbarActionsFactory::GetInitialComponentIds() { | 37 std::set<std::string> ComponentToolbarActionsFactory::GetInitialComponentIds() { |
| 43 return initial_ids_; | 38 return initial_ids_; |
| 44 } | 39 } |
| 45 | 40 |
| 46 void ComponentToolbarActionsFactory::OnAddComponentActionBeforeInit( | 41 void ComponentToolbarActionsFactory::OnAddComponentActionBeforeInit( |
| 47 const std::string& action_id) { | 42 const std::string& action_id) { |
| 48 initial_ids_.insert(action_id); | 43 initial_ids_.insert(action_id); |
| 49 } | 44 } |
| 50 | 45 |
| 51 void ComponentToolbarActionsFactory::OnRemoveComponentActionBeforeInit( | 46 void ComponentToolbarActionsFactory::OnRemoveComponentActionBeforeInit( |
| 52 const std::string& action_id) { | 47 const std::string& action_id) { |
| 53 initial_ids_.erase(action_id); | 48 initial_ids_.erase(action_id); |
| 54 } | 49 } |
| 55 | 50 |
| 56 std::unique_ptr<ToolbarActionViewController> | 51 std::unique_ptr<ToolbarActionViewController> |
| 57 ComponentToolbarActionsFactory::GetComponentToolbarActionForId( | 52 ComponentToolbarActionsFactory::GetComponentToolbarActionForId( |
| 58 const std::string& action_id, | 53 const std::string& action_id, |
| 59 Browser* browser, | 54 Browser* browser, |
| 60 ToolbarActionsBar* bar) { | 55 ToolbarActionsBar* bar) { |
| 61 // Add component toolbar actions here. | 56 // Add component toolbar actions here. |
| 62 // This current design means that the ComponentToolbarActionsFactory is aware | 57 // This current design means that the ComponentToolbarActionsFactory is aware |
| 63 // of all actions. Since we should *not* have an excessive amount of these | 58 // 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 | 59 // (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, | 60 // should be okay. If this changes, we should rethink this design to have, |
| 66 // e.g., RegisterChromeAction(). | 61 // e.g., RegisterChromeAction(). |
| 67 #if defined(ENABLE_MEDIA_ROUTER) | |
| 68 if (action_id == kMediaRouterActionId) | 62 if (action_id == kMediaRouterActionId) |
| 69 return std::unique_ptr<ToolbarActionViewController>( | 63 return std::unique_ptr<ToolbarActionViewController>( |
| 70 new MediaRouterAction(browser, bar)); | 64 new MediaRouterAction(browser, bar)); |
| 71 #endif // defined(ENABLE_MEDIA_ROUTER) | |
| 72 | 65 |
| 73 NOTREACHED(); | 66 NOTREACHED(); |
| 74 return std::unique_ptr<ToolbarActionViewController>(); | 67 return std::unique_ptr<ToolbarActionViewController>(); |
| 75 } | 68 } |
| 76 | 69 |
| 77 void ComponentToolbarActionsFactory::UnloadMigratedExtensions( | 70 void ComponentToolbarActionsFactory::UnloadMigratedExtensions( |
| 78 ExtensionService* service, | 71 ExtensionService* service, |
| 79 extensions::ExtensionRegistry* registry) { | 72 extensions::ExtensionRegistry* registry) { |
| 80 // TODO(takumif): Replace the unloading of Cast and Cast Beta extensions with | 73 // TODO(takumif): Replace the unloading of Cast and Cast Beta extensions with |
| 81 // uninstallation. | 74 // uninstallation. |
| 82 UnloadExtension(service, registry, kCastExtensionId); | 75 UnloadExtension(service, registry, kCastExtensionId); |
| 83 UnloadExtension(service, registry, kCastBetaExtensionId); | 76 UnloadExtension(service, registry, kCastBetaExtensionId); |
| 84 } | 77 } |
| 85 | 78 |
| 86 void ComponentToolbarActionsFactory::UnloadExtension( | 79 void ComponentToolbarActionsFactory::UnloadExtension( |
| 87 ExtensionService* service, | 80 ExtensionService* service, |
| 88 extensions::ExtensionRegistry* registry, | 81 extensions::ExtensionRegistry* registry, |
| 89 const std::string& extension_id) { | 82 const std::string& extension_id) { |
| 90 if (registry->enabled_extensions().Contains(extension_id)) { | 83 if (registry->enabled_extensions().Contains(extension_id)) { |
| 91 service->UnloadExtension( | 84 service->UnloadExtension( |
| 92 extension_id, | 85 extension_id, |
| 93 extensions::UnloadedExtensionInfo::REASON_MIGRATED_TO_COMPONENT); | 86 extensions::UnloadedExtensionInfo::REASON_MIGRATED_TO_COMPONENT); |
| 94 } | 87 } |
| 95 } | 88 } |
| OLD | NEW |