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/component_migration_helper.h" | |
| 10 #include "chrome/browser/media/router/media_router_feature.h" | 9 #include "chrome/browser/media/router/media_router_feature.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 12 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 13 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | |
| 14 #include "extensions/common/feature_switch.h" | 14 #include "extensions/common/feature_switch.h" |
| 15 | 15 |
| 16 #if defined(ENABLE_MEDIA_ROUTER) | 16 #if defined(ENABLE_MEDIA_ROUTER) |
| 17 #include "chrome/browser/ui/toolbar/media_router_action.h" | 17 #include "chrome/browser/ui/toolbar/media_router_action.h" |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 ComponentToolbarActionsFactory* testing_factory_ = nullptr; | |
| 23 | |
| 24 base::LazyInstance<ComponentToolbarActionsFactory> lazy_factory = | |
| 25 LAZY_INSTANCE_INITIALIZER; | |
| 26 | |
| 27 const char kCastExtensionId[] = "boadgeojelhgndaghljhdicfkmllpafd"; | 22 const char kCastExtensionId[] = "boadgeojelhgndaghljhdicfkmllpafd"; |
| 28 const char kCastBetaExtensionId[] = "dliochdbjfkdbacpmhlcpmleaejidimm"; | 23 const char kCastBetaExtensionId[] = "dliochdbjfkdbacpmhlcpmleaejidimm"; |
| 29 | 24 |
| 30 } // namespace | 25 } // namespace |
| 31 | 26 |
| 32 // static | 27 // static |
| 33 const char ComponentToolbarActionsFactory::kMediaRouterActionId[] = | 28 const char ComponentToolbarActionsFactory::kMediaRouterActionId[] = |
| 34 "media_router_action"; | 29 "media_router_action"; |
| 35 | 30 |
| 36 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory() {} | 31 ComponentToolbarActionsFactory::ComponentToolbarActionsFactory( |
| 32 Profile* profile, | |
| 33 extensions::ComponentMigrationHelper::ComponentActionDelegate* | |
| 34 action_delegate) | |
| 35 : migration_helper_(profile, action_delegate), profile_(profile) {} | |
| 37 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {} | 36 ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {} |
| 38 | 37 |
| 39 // static | 38 std::set<std::string> ComponentToolbarActionsFactory::GetInitialComponentIds() { |
| 40 ComponentToolbarActionsFactory* ComponentToolbarActionsFactory::GetInstance() { | 39 return initial_ids_; |
| 41 return testing_factory_ ? testing_factory_ : &lazy_factory.Get(); | |
| 42 } | 40 } |
| 43 | 41 |
| 44 std::set<std::string> ComponentToolbarActionsFactory::GetInitialComponentIds( | 42 void ComponentToolbarActionsFactory::OnAddComponentActionBeforeInit( |
| 45 Profile* profile) { | 43 const std::string& action_id) { |
| 46 std::set<std::string> component_ids; | 44 initial_ids_.insert(action_id); |
| 47 return component_ids; | 45 } |
| 46 | |
| 47 void ComponentToolbarActionsFactory::OnRemoveComponentActionBeforeInit( | |
| 48 const std::string& action_id) { | |
| 49 initial_ids_.erase(action_id); | |
| 48 } | 50 } |
| 49 | 51 |
| 50 std::unique_ptr<ToolbarActionViewController> | 52 std::unique_ptr<ToolbarActionViewController> |
| 51 ComponentToolbarActionsFactory::GetComponentToolbarActionForId( | 53 ComponentToolbarActionsFactory::GetComponentToolbarActionForId( |
| 52 const std::string& id, | 54 const std::string& action_id, |
| 53 Browser* browser, | 55 Browser* browser, |
| 54 ToolbarActionsBar* bar) { | 56 ToolbarActionsBar* bar) { |
| 55 // This is currently behind the extension-action-redesign flag, as it is | 57 // This is currently behind the extension-action-redesign flag, as it is |
| 56 // designed for the new toolbar. | 58 // designed for the new toolbar. |
| 57 DCHECK(extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()); | 59 DCHECK(extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()); |
| 58 | 60 |
| 59 // Add component toolbar actions here. | 61 // Add component toolbar actions here. |
| 60 // This current design means that the ComponentToolbarActionsFactory is aware | 62 // This current design means that the ComponentToolbarActionsFactory is aware |
| 61 // of all actions. Since we should *not* have an excessive amount of these | 63 // of all actions. Since we should *not* have an excessive amount of these |
| 62 // (since each will have an action in the toolbar or overflow menu), this | 64 // (since each will have an action in the toolbar or overflow menu), this |
| 63 // should be okay. If this changes, we should rethink this design to have, | 65 // should be okay. If this changes, we should rethink this design to have, |
| 64 // e.g., RegisterChromeAction(). | 66 // e.g., RegisterChromeAction(). |
| 65 #if defined(ENABLE_MEDIA_ROUTER) | 67 #if defined(ENABLE_MEDIA_ROUTER) |
| 66 if (id == kMediaRouterActionId) | 68 if (action_id == kMediaRouterActionId) |
| 67 return std::unique_ptr<ToolbarActionViewController>( | 69 return std::unique_ptr<ToolbarActionViewController>( |
| 68 new MediaRouterAction(browser, bar)); | 70 new MediaRouterAction(browser, bar)); |
| 69 #endif // defined(ENABLE_MEDIA_ROUTER) | 71 #endif // defined(ENABLE_MEDIA_ROUTER) |
| 70 | 72 |
| 71 NOTREACHED(); | 73 NOTREACHED(); |
| 72 return std::unique_ptr<ToolbarActionViewController>(); | 74 return std::unique_ptr<ToolbarActionViewController>(); |
| 73 } | 75 } |
| 74 | 76 |
| 75 // static | 77 void ComponentToolbarActionsFactory::RegisterComponentMigrations() { |
| 76 void ComponentToolbarActionsFactory::SetTestingFactory( | 78 migration_helper_.Register(kMediaRouterActionId, kCastExtensionId); |
| 77 ComponentToolbarActionsFactory* factory) { | 79 migration_helper_.Register(kMediaRouterActionId, kCastBetaExtensionId); |
| 78 testing_factory_ = factory; | |
| 79 } | 80 } |
| 80 | 81 |
| 81 void ComponentToolbarActionsFactory::RegisterComponentMigrations( | 82 void ComponentToolbarActionsFactory::HandleComponentMigrations() { |
| 82 extensions::ComponentMigrationHelper* helper) const { | 83 if (media_router::MediaRouterEnabled(profile_)) { |
|
msw
2017/01/10 23:23:59
optional nit: curlies not needed
takumif
2017/02/17 03:22:51
Removed migration-related code.
| |
| 83 helper->Register(kMediaRouterActionId, kCastExtensionId); | 84 migration_helper_.OnFeatureEnabled(kMediaRouterActionId); |
| 84 helper->Register(kMediaRouterActionId, kCastBetaExtensionId); | |
| 85 } | |
| 86 | |
| 87 void ComponentToolbarActionsFactory::HandleComponentMigrations( | |
| 88 extensions::ComponentMigrationHelper* helper, | |
| 89 Profile* profile) const { | |
| 90 if (media_router::MediaRouterEnabled(profile)) { | |
| 91 helper->OnFeatureEnabled(kMediaRouterActionId); | |
| 92 } else { | 85 } else { |
| 93 helper->OnFeatureDisabled(kMediaRouterActionId); | 86 migration_helper_.OnFeatureDisabled(kMediaRouterActionId); |
| 94 } | 87 } |
| 95 } | 88 } |
| 96 | |
| OLD | NEW |