Commit 4875d4b1 authored by msw's avatar msw Committed by Commit bot

Fix mash shelf id mapping and removal.

Add ShelfID to app_id mapping, to complement the inverse map.
(these are 1-to-1 mappings, but two maps eases usage)

Remove mappings when shelf items are removed.
Implement the ShelfDelegate interface mapping functions.

TODO: Add unit/shell testing of ShelfDelegateMus.

BUG=607271
TEST=|ShelfDelegaeMus::app_id_to_shelf_id_| shrinks as appropriate.
R=sadrul@chromium.org,sky@chromium.org

Review-Url: https://codereview.chromium.org/1932503002
Cr-Commit-Position: refs/heads/master@{#390289}
parent 8ff06aa4
......@@ -216,17 +216,18 @@ void ShelfDelegateMus::OnShelfAutoHideBehaviorChanged(Shelf* shelf) {
}
ShelfID ShelfDelegateMus::GetShelfIDForAppID(const std::string& app_id) {
NOTIMPLEMENTED();
if (app_id_to_shelf_id_.count(app_id))
return app_id_to_shelf_id_[app_id];
return 0;
}
bool ShelfDelegateMus::HasShelfIDToAppIDMapping(ShelfID id) const {
NOTIMPLEMENTED();
return false;
return shelf_id_to_app_id_.count(id) != 0;
}
const std::string& ShelfDelegateMus::GetAppIDForShelfID(ShelfID id) {
NOTIMPLEMENTED();
if (shelf_id_to_app_id_.count(id))
return shelf_id_to_app_id_[id];
return base::EmptyString();
}
......@@ -282,6 +283,7 @@ void ShelfDelegateMus::PinItem(
ShelfID shelf_id = model_->next_id();
app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id));
shelf_id_to_app_id_.insert(std::make_pair(shelf_id, app_id));
ShelfItem shelf_item;
shelf_item.type = TYPE_APP_SHORTCUT;
......@@ -304,8 +306,11 @@ void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) {
ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id);
DCHECK(item_delegate->pinned());
item_delegate->set_pinned(false);
if (item_delegate->window_id_to_title().empty())
if (item_delegate->window_id_to_title().empty()) {
model_->RemoveItemAt(model_->ItemIndexByID(shelf_id));
app_id_to_shelf_id_.erase(app_id.To<std::string>());
shelf_id_to_app_id_.erase(shelf_id);
}
}
void ShelfDelegateMus::OnUserWindowObserverAdded(
......@@ -334,6 +339,7 @@ void ShelfDelegateMus::OnUserWindowAdded(
window_id_to_shelf_id_.insert(
std::make_pair(user_window->window_id, shelf_id));
app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id));
shelf_id_to_app_id_.insert(std::make_pair(shelf_id, app_id));
ShelfItem item;
item.type = TYPE_PLATFORM_APP;
......@@ -355,8 +361,12 @@ void ShelfDelegateMus::OnUserWindowRemoved(uint32_t window_id) {
ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id);
item_delegate->RemoveWindow(window_id);
window_id_to_shelf_id_.erase(window_id);
if (item_delegate->window_id_to_title().empty() && !item_delegate->pinned())
if (item_delegate->window_id_to_title().empty() && !item_delegate->pinned()) {
model_->RemoveItemAt(model_->ItemIndexByID(shelf_id));
const std::string& app_id = shelf_id_to_app_id_[shelf_id];
app_id_to_shelf_id_.erase(app_id);
shelf_id_to_app_id_.erase(shelf_id);
}
}
void ShelfDelegateMus::OnUserWindowTitleChanged(
......
......@@ -75,6 +75,7 @@ class ShelfDelegateMus : public ShelfDelegate,
std::map<uint32_t, ShelfID> window_id_to_shelf_id_;
std::map<std::string, ShelfID> app_id_to_shelf_id_;
std::map<ShelfID, std::string> shelf_id_to_app_id_;
DISALLOW_COPY_AND_ASSIGN(ShelfDelegateMus);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment