| Index: chrome/browser/ui/toolbar/toolbar_actions_model.cc
|
| diff --git a/chrome/browser/ui/toolbar/toolbar_actions_model.cc b/chrome/browser/ui/toolbar/toolbar_actions_model.cc
|
| index c508e3da00a90f4a52797388a3cff33a51493c33..6d85465f625434334ac992d8c4bf380ca05b3f39 100644
|
| --- a/chrome/browser/ui/toolbar/toolbar_actions_model.cc
|
| +++ b/chrome/browser/ui/toolbar/toolbar_actions_model.cc
|
| @@ -50,6 +50,8 @@ ToolbarActionsModel::ToolbarActionsModel(
|
| extension_registry_(extensions::ExtensionRegistry::Get(profile_)),
|
| extension_action_manager_(
|
| extensions::ExtensionActionManager::Get(profile_)),
|
| + component_actions_factory_(
|
| + base::MakeUnique<ComponentToolbarActionsFactory>(profile_)),
|
| actions_initialized_(false),
|
| use_redesign_(
|
| extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()),
|
| @@ -183,15 +185,15 @@ ToolbarActionsModel::CreateActionForItem(Browser* browser,
|
| DCHECK(extension);
|
|
|
| // Create and add an ExtensionActionViewController for the extension.
|
| - result.reset(new ExtensionActionViewController(
|
| + result = base::MakeUnique<ExtensionActionViewController>(
|
| extension, browser,
|
| - extension_action_manager_->GetExtensionAction(*extension), bar));
|
| + extension_action_manager_->GetExtensionAction(*extension), bar);
|
| break;
|
| }
|
| case COMPONENT_ACTION: {
|
| DCHECK(use_redesign_);
|
| - result = ComponentToolbarActionsFactory::GetInstance()
|
| - ->GetComponentToolbarActionForId(item.id, browser, bar);
|
| + result = component_actions_factory_->GetComponentToolbarActionForId(
|
| + item.id, browser, bar);
|
| break;
|
| }
|
| case UNKNOWN_ACTION:
|
| @@ -270,7 +272,7 @@ void ToolbarActionsModel::OnReady() {
|
| observer.OnToolbarModelInitialized();
|
|
|
| if (use_redesign_) {
|
| - ComponentToolbarActionsFactory::GetInstance()->UnloadMigratedExtensions(
|
| + component_actions_factory_->UnloadMigratedExtensions(
|
| extensions::ExtensionSystem::Get(profile_)->extension_service(),
|
| extension_registry_);
|
| }
|
| @@ -440,6 +442,11 @@ ToolbarActionsModel::GetExtensionMessageBubbleController(Browser* browser) {
|
| return controller;
|
| }
|
|
|
| +void ToolbarActionsModel::SetMockActionsFactoryForTest(
|
| + std::unique_ptr<ComponentToolbarActionsFactory> mock_factory) {
|
| + component_actions_factory_ = std::move(mock_factory);
|
| +}
|
| +
|
| void ToolbarActionsModel::RemoveExtension(
|
| const extensions::Extension* extension) {
|
| RemoveItem(ToolbarItem(extension->id(), EXTENSION_ACTION));
|
| @@ -493,8 +500,7 @@ void ToolbarActionsModel::Populate() {
|
|
|
| // Next, add the component action ids.
|
| std::set<std::string> component_ids =
|
| - ComponentToolbarActionsFactory::GetInstance()->GetInitialComponentIds(
|
| - profile_);
|
| + component_actions_factory_->GetInitialComponentIds();
|
| for (const std::string& id : component_ids)
|
| all_actions.push_back(ToolbarItem(id, COMPONENT_ACTION));
|
|
|
| @@ -624,12 +630,12 @@ bool ToolbarActionsModel::HasComponentAction(
|
| }
|
|
|
| void ToolbarActionsModel::AddComponentAction(const std::string& action_id) {
|
| + DCHECK(use_redesign_);
|
| if (!actions_initialized_) {
|
| - // TODO(crbug.com/660972): Add these component actions at initialization.
|
| + component_actions_factory_->OnAddComponentActionBeforeInit(action_id);
|
| return;
|
| }
|
|
|
| - DCHECK(use_redesign_);
|
| ToolbarItem component_item(action_id, COMPONENT_ACTION);
|
| DCHECK(!HasItem(component_item));
|
| AddItem(component_item);
|
| @@ -637,6 +643,10 @@ void ToolbarActionsModel::AddComponentAction(const std::string& action_id) {
|
|
|
| void ToolbarActionsModel::RemoveComponentAction(const std::string& action_id) {
|
| DCHECK(use_redesign_);
|
| + if (!actions_initialized_) {
|
| + component_actions_factory_->OnRemoveComponentActionBeforeInit(action_id);
|
| + return;
|
| + }
|
| // If the action was visible and there are overflowed actions, we reduce the
|
| // visible count so that we don't pop out a previously-hidden action.
|
| if (IsActionVisible(action_id) && !all_icons_visible())
|
| @@ -662,8 +672,7 @@ void ToolbarActionsModel::IncognitoPopulate() {
|
| visible_icon_count_ = 0;
|
|
|
| std::set<std::string> component_ids =
|
| - ComponentToolbarActionsFactory::GetInstance()->GetInitialComponentIds(
|
| - profile_);
|
| + component_actions_factory_->GetInitialComponentIds();
|
| for (std::vector<ToolbarItem>::const_iterator iter =
|
| original_model->toolbar_items_.begin();
|
| iter != original_model->toolbar_items_.end(); ++iter) {
|
|
|