| Index: ash/common/shelf/shelf_model.cc
|
| diff --git a/ash/common/shelf/shelf_model.cc b/ash/common/shelf/shelf_model.cc
|
| index acc2c10235b11c3835b4f25798c4d48db32aaa3f..640674ee66dee73a677e8067aab30557441963cf 100644
|
| --- a/ash/common/shelf/shelf_model.cc
|
| +++ b/ash/common/shelf/shelf_model.cc
|
| @@ -70,7 +70,10 @@
|
| DCHECK(index >= 0 && index < item_count());
|
| ShelfItem old_item(items_[index]);
|
| items_.erase(items_.begin() + index);
|
| - id_to_item_delegate_map_.erase(old_item.id);
|
| + RemoveShelfItemDelegate(old_item.id);
|
| + // TODO(jamescook): Fold this into ShelfItemRemoved in existing observers.
|
| + for (auto& observer : observers_)
|
| + observer.OnSetShelfItemDelegate(old_item.id, nullptr);
|
| for (auto& observer : observers_)
|
| observer.ShelfItemRemoved(index, old_item);
|
| }
|
| @@ -157,9 +160,14 @@
|
| void ShelfModel::SetShelfItemDelegate(
|
| ShelfID id,
|
| std::unique_ptr<ShelfItemDelegate> item_delegate) {
|
| - if (item_delegate)
|
| - item_delegate->set_shelf_id(id);
|
| - // This assignment replaces any ShelfItemDelegate already registered for |id|.
|
| + // If another ShelfItemDelegate is already registered for |id|, we assume
|
| + // that this request is replacing ShelfItemDelegate for |id| with
|
| + // |item_delegate|.
|
| + RemoveShelfItemDelegate(id);
|
| +
|
| + for (auto& observer : observers_)
|
| + observer.OnSetShelfItemDelegate(id, item_delegate.get());
|
| +
|
| id_to_item_delegate_map_[id] = std::move(item_delegate);
|
| }
|
|
|
| @@ -195,4 +203,9 @@
|
| return index;
|
| }
|
|
|
| +void ShelfModel::RemoveShelfItemDelegate(ShelfID id) {
|
| + if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end())
|
| + id_to_item_delegate_map_.erase(id);
|
| +}
|
| +
|
| } // namespace ash
|
|
|