| Index: chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
|
| diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
|
| index 465ef44ed504299fef3decf335f1ca363171376d..8908e859722dc188a200fdb9ecb512073f1da768 100644
|
| --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
|
| +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
|
| @@ -5,6 +5,7 @@
|
| #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
|
|
|
| #include "ash/multi_profile_uma.h"
|
| +#include "ash/public/cpp/remote_shelf_item_delegate.h"
|
| #include "ash/public/cpp/shelf_item.h"
|
| #include "ash/public/interfaces/constants.mojom.h"
|
| #include "ash/resources/grit/ash_resources.h"
|
| @@ -20,6 +21,7 @@
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| #include "chrome/browser/chromeos/arc/arc_util.h"
|
| +#include "chrome/browser/chromeos/ash_config.h"
|
| #include "chrome/browser/extensions/chrome_app_icon_loader.h"
|
| #include "chrome/browser/extensions/extension_util.h"
|
| #include "chrome/browser/prefs/pref_service_syncable_util.h"
|
| @@ -279,6 +281,9 @@ void ChromeLauncherController::Init() {
|
| ash::mojom::ShelfObserverAssociatedPtrInfo ptr_info;
|
| observer_binding_.Bind(mojo::MakeRequest(&ptr_info));
|
| shelf_controller_->AddObserver(std::move(ptr_info));
|
| + // ShelfModel's constructor should have initialized the app list item.
|
| + DCHECK_EQ(1, model_->item_count());
|
| + DCHECK_EQ(ash::kAppListId, model_->items()[0].id.app_id);
|
| }
|
|
|
| CreateBrowserShortcutLauncherItem();
|
| @@ -1268,12 +1273,92 @@ void ChromeLauncherController::OnAutoHideBehaviorChanged(
|
| SetShelfAutoHideBehaviorPref(profile_->GetPrefs(), display_id, auto_hide);
|
| }
|
|
|
| +void ChromeLauncherController::OnShelfItemAdded(int32_t index,
|
| + const ash::ShelfItem& item) {
|
| + DCHECK(ash_util::IsRunningInMash()) << "Unexpected model synchronization";
|
| + DCHECK(!applying_remote_shelf_model_changes_) << "Unexpected model change";
|
| +
|
| + // Ignore notifications of adding the AppList item; it should already exist.
|
| + if (item.id.app_id == ash::kAppListId) {
|
| + DCHECK_EQ(0, model_->ItemIndexByID(item.id));
|
| + return;
|
| + }
|
| +
|
| + DCHECK_LE(index, model_->item_count()) << "Index out of bounds";
|
| + DCHECK_GT(index, 0) << "Items can not preceed the AppList";
|
| + index = std::min(std::max(index, 1), model_->item_count());
|
| + base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true);
|
| + model_->AddAt(index, item);
|
| +}
|
| +
|
| +void ChromeLauncherController::OnShelfItemRemoved(const ash::ShelfID& id) {
|
| + DCHECK(ash_util::IsRunningInMash()) << "Unexpected model synchronization";
|
| + DCHECK(!applying_remote_shelf_model_changes_) << "Unexpected model change";
|
| + const int index = model_->ItemIndexByID(id);
|
| + DCHECK_GE(index, 0) << "Item not found";
|
| + DCHECK_NE(index, 0) << "The AppList shelf item cannot be removed";
|
| + if (index <= 0)
|
| + return;
|
| + base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true);
|
| + model_->RemoveItemAt(index);
|
| +}
|
| +
|
| +void ChromeLauncherController::OnShelfItemMoved(const ash::ShelfID& id,
|
| + int32_t index) {
|
| + DCHECK(ash_util::IsRunningInMash()) << "Unexpected model synchronization";
|
| + DCHECK(!applying_remote_shelf_model_changes_) << "Unexpected model change";
|
| + const int current_index = model_->ItemIndexByID(id);
|
| + DCHECK_GE(current_index, 0) << "No item found with the given id";
|
| + DCHECK_NE(current_index, 0) << "The AppList shelf item cannot be moved";
|
| + if (current_index <= 0)
|
| + return;
|
| + DCHECK_GT(index, 0) << "Items can not preceed the AppList";
|
| + DCHECK_LT(index, model_->item_count()) << "Index out of bounds";
|
| + index = std::min(std::max(index, 1), model_->item_count() - 1);
|
| + DCHECK_NE(current_index, index) << "The item is already at the given index";
|
| + if (current_index == index)
|
| + return;
|
| + base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true);
|
| + model_->Move(current_index, index);
|
| +}
|
| +
|
| +void ChromeLauncherController::OnShelfItemUpdated(const ash::ShelfItem& item) {
|
| + DCHECK(ash_util::IsRunningInMash()) << "Unexpected model synchronization";
|
| + DCHECK(!applying_remote_shelf_model_changes_) << "Unexpected model change";
|
| + const int index = model_->ItemIndexByID(item.id);
|
| + DCHECK_GE(index, 0) << "No item found with the given id";
|
| + if (index < 0)
|
| + return;
|
| + base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true);
|
| + model_->Set(index, item);
|
| +}
|
| +
|
| +void ChromeLauncherController::OnShelfItemDelegateChanged(
|
| + const ash::ShelfID& id,
|
| + ash::mojom::ShelfItemDelegatePtr delegate) {
|
| + DCHECK(ash_util::IsRunningInMash()) << "Unexpected model synchronization";
|
| + DCHECK(!applying_remote_shelf_model_changes_) << "Unexpected model change";
|
| + base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true);
|
| + if (delegate.is_bound()) {
|
| + model_->SetShelfItemDelegate(id,
|
| + base::MakeUnique<ash::RemoteShelfItemDelegate>(
|
| + id, std::move(delegate)));
|
| + } else {
|
| + model_->SetShelfItemDelegate(id, nullptr);
|
| + }
|
| +}
|
| +
|
| ///////////////////////////////////////////////////////////////////////////////
|
| // ash::ShelfModelObserver:
|
|
|
| void ChromeLauncherController::ShelfItemAdded(int index) {
|
| - // Update the pin position preference as needed.
|
| ash::ShelfItem item = model_->items()[index];
|
| + if (shelf_controller_ && !applying_remote_shelf_model_changes_ &&
|
| + chromeos::GetAshConfig() == ash::Config::MASH) {
|
| + shelf_controller_->AddShelfItem(index, item);
|
| + }
|
| +
|
| + // Update the pin position preference as needed.
|
| if (ItemTypeIsPinned(item) && should_sync_pin_changes_)
|
| SyncPinPosition(item.id);
|
|
|
| @@ -1301,12 +1386,17 @@ void ChromeLauncherController::ShelfItemAdded(int index) {
|
| needs_update = true;
|
| item.status = status;
|
| }
|
| - if (needs_update)
|
| + if (needs_update) {
|
| + // Ensure these changes are reported back to Ash.
|
| + base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, false);
|
| model_->Set(index, item);
|
| + }
|
| }
|
|
|
| // Construct a ShelfItemDelegate for the item if one does not yet exist.
|
| if (!model_->GetShelfItemDelegate(item.id)) {
|
| + // Ensure these changes are reported back to Ash.
|
| + base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, false);
|
| model_->SetShelfItemDelegate(
|
| item.id, AppShortcutLauncherItemController::Create(item.id));
|
| }
|
| @@ -1315,6 +1405,11 @@ void ChromeLauncherController::ShelfItemAdded(int index) {
|
| void ChromeLauncherController::ShelfItemRemoved(
|
| int index,
|
| const ash::ShelfItem& old_item) {
|
| + if (shelf_controller_ && !applying_remote_shelf_model_changes_ &&
|
| + chromeos::GetAshConfig() == ash::Config::MASH) {
|
| + shelf_controller_->RemoveShelfItem(old_item.id);
|
| + }
|
| +
|
| // Remove the pin position from preferences as needed.
|
| if (ItemTypeIsPinned(old_item) && should_sync_pin_changes_)
|
| RemovePinPosition(profile(), old_item.id);
|
| @@ -1326,8 +1421,13 @@ void ChromeLauncherController::ShelfItemRemoved(
|
|
|
| void ChromeLauncherController::ShelfItemMoved(int start_index,
|
| int target_index) {
|
| - // Update the pin position preference as needed.
|
| const ash::ShelfItem& item = model_->items()[target_index];
|
| + if (shelf_controller_ && !applying_remote_shelf_model_changes_ &&
|
| + chromeos::GetAshConfig() == ash::Config::MASH) {
|
| + shelf_controller_->MoveShelfItem(item.id, target_index);
|
| + }
|
| +
|
| + // Update the pin position preference as needed.
|
| DCHECK_NE(ash::TYPE_APP_LIST, item.type);
|
| if (ItemTypeIsPinned(item) && should_sync_pin_changes_)
|
| SyncPinPosition(item.id);
|
| @@ -1336,10 +1436,15 @@ void ChromeLauncherController::ShelfItemMoved(int start_index,
|
| void ChromeLauncherController::ShelfItemChanged(
|
| int index,
|
| const ash::ShelfItem& old_item) {
|
| + const ash::ShelfItem& item = model_->items()[index];
|
| + if (shelf_controller_ && !applying_remote_shelf_model_changes_ &&
|
| + chromeos::GetAshConfig() == ash::Config::MASH) {
|
| + shelf_controller_->UpdateShelfItem(item);
|
| + }
|
| +
|
| if (!should_sync_pin_changes_)
|
| return;
|
|
|
| - const ash::ShelfItem& item = model_->items()[index];
|
| // Add or remove the pin position from preferences as needed.
|
| if (!ItemTypeIsPinned(old_item) && ItemTypeIsPinned(item))
|
| SyncPinPosition(item.id);
|
| @@ -1347,6 +1452,17 @@ void ChromeLauncherController::ShelfItemChanged(
|
| RemovePinPosition(profile(), old_item.id);
|
| }
|
|
|
| +void ChromeLauncherController::ShelfItemDelegateChanged(
|
| + const ash::ShelfID& id,
|
| + ash::ShelfItemDelegate* delegate) {
|
| + if (shelf_controller_ && !applying_remote_shelf_model_changes_ &&
|
| + chromeos::GetAshConfig() == ash::Config::MASH) {
|
| + shelf_controller_->SetShelfItemDelegate(
|
| + id, delegate ? delegate->CreateInterfacePtrAndBind()
|
| + : ash::mojom::ShelfItemDelegatePtr());
|
| + }
|
| +}
|
| +
|
| ///////////////////////////////////////////////////////////////////////////////
|
| // ash::WindowTreeHostManager::Observer:
|
|
|
|
|