Chromium Code Reviews| Index: chrome/browser/ui/toolbar/component_toolbar_actions_factory.cc |
| diff --git a/chrome/browser/ui/toolbar/component_toolbar_actions_factory.cc b/chrome/browser/ui/toolbar/component_toolbar_actions_factory.cc |
| index 487a59a88d9ba57f538fb13f71c930c0a21db8ee..8a9ba0dc9e45c8faff64c55ee18e923a3466c34b 100644 |
| --- a/chrome/browser/ui/toolbar/component_toolbar_actions_factory.cc |
| +++ b/chrome/browser/ui/toolbar/component_toolbar_actions_factory.cc |
| @@ -6,11 +6,11 @@ |
| #include "base/command_line.h" |
| #include "base/lazy_instance.h" |
| -#include "chrome/browser/extensions/component_migration_helper.h" |
| #include "chrome/browser/media/router/media_router_feature.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| +#include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| #include "extensions/common/feature_switch.h" |
| #if defined(ENABLE_MEDIA_ROUTER) |
| @@ -19,11 +19,6 @@ |
| namespace { |
| -ComponentToolbarActionsFactory* testing_factory_ = nullptr; |
| - |
| -base::LazyInstance<ComponentToolbarActionsFactory> lazy_factory = |
| - LAZY_INSTANCE_INITIALIZER; |
| - |
| const char kCastExtensionId[] = "boadgeojelhgndaghljhdicfkmllpafd"; |
| const char kCastBetaExtensionId[] = "dliochdbjfkdbacpmhlcpmleaejidimm"; |
| @@ -33,23 +28,30 @@ const char kCastBetaExtensionId[] = "dliochdbjfkdbacpmhlcpmleaejidimm"; |
| const char ComponentToolbarActionsFactory::kMediaRouterActionId[] = |
| "media_router_action"; |
| -ComponentToolbarActionsFactory::ComponentToolbarActionsFactory() {} |
| +ComponentToolbarActionsFactory::ComponentToolbarActionsFactory( |
| + Profile* profile, |
| + extensions::ComponentMigrationHelper::ComponentActionDelegate* |
| + action_delegate) |
| + : migration_helper_(profile, action_delegate), profile_(profile) {} |
| ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {} |
| -// static |
| -ComponentToolbarActionsFactory* ComponentToolbarActionsFactory::GetInstance() { |
| - return testing_factory_ ? testing_factory_ : &lazy_factory.Get(); |
| +std::set<std::string> ComponentToolbarActionsFactory::GetInitialComponentIds() { |
| + return initial_ids_; |
| +} |
| + |
| +void ComponentToolbarActionsFactory::OnAddComponentActionBeforeInit( |
| + const std::string& action_id) { |
| + initial_ids_.insert(action_id); |
| } |
| -std::set<std::string> ComponentToolbarActionsFactory::GetInitialComponentIds( |
| - Profile* profile) { |
| - std::set<std::string> component_ids; |
| - return component_ids; |
| +void ComponentToolbarActionsFactory::OnRemoveComponentActionBeforeInit( |
| + const std::string& action_id) { |
| + initial_ids_.erase(action_id); |
| } |
| std::unique_ptr<ToolbarActionViewController> |
| ComponentToolbarActionsFactory::GetComponentToolbarActionForId( |
| - const std::string& id, |
| + const std::string& action_id, |
| Browser* browser, |
| ToolbarActionsBar* bar) { |
| // This is currently behind the extension-action-redesign flag, as it is |
| @@ -63,7 +65,7 @@ ComponentToolbarActionsFactory::GetComponentToolbarActionForId( |
| // should be okay. If this changes, we should rethink this design to have, |
| // e.g., RegisterChromeAction(). |
| #if defined(ENABLE_MEDIA_ROUTER) |
| - if (id == kMediaRouterActionId) |
| + if (action_id == kMediaRouterActionId) |
| return std::unique_ptr<ToolbarActionViewController>( |
| new MediaRouterAction(browser, bar)); |
| #endif // defined(ENABLE_MEDIA_ROUTER) |
| @@ -72,25 +74,15 @@ ComponentToolbarActionsFactory::GetComponentToolbarActionForId( |
| return std::unique_ptr<ToolbarActionViewController>(); |
| } |
| -// static |
| -void ComponentToolbarActionsFactory::SetTestingFactory( |
| - ComponentToolbarActionsFactory* factory) { |
| - testing_factory_ = factory; |
| -} |
| - |
| -void ComponentToolbarActionsFactory::RegisterComponentMigrations( |
| - extensions::ComponentMigrationHelper* helper) const { |
| - helper->Register(kMediaRouterActionId, kCastExtensionId); |
| - helper->Register(kMediaRouterActionId, kCastBetaExtensionId); |
| +void ComponentToolbarActionsFactory::RegisterComponentMigrations() { |
| + migration_helper_.Register(kMediaRouterActionId, kCastExtensionId); |
| + migration_helper_.Register(kMediaRouterActionId, kCastBetaExtensionId); |
| } |
| -void ComponentToolbarActionsFactory::HandleComponentMigrations( |
| - extensions::ComponentMigrationHelper* helper, |
| - Profile* profile) const { |
| - if (media_router::MediaRouterEnabled(profile)) { |
| - helper->OnFeatureEnabled(kMediaRouterActionId); |
| +void ComponentToolbarActionsFactory::HandleComponentMigrations() { |
| + 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.
|
| + migration_helper_.OnFeatureEnabled(kMediaRouterActionId); |
| } else { |
| - helper->OnFeatureDisabled(kMediaRouterActionId); |
| + migration_helper_.OnFeatureDisabled(kMediaRouterActionId); |
| } |
| } |
| - |