Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / shelf / shelf_item_delegate_manager.cc
blobd5b3d04958e05565d8dd1af435bc17748117874a
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/shelf/shelf_item_delegate_manager.h"
7 #include "ash/shelf/shelf_item_delegate.h"
8 #include "ash/shelf/shelf_model.h"
9 #include "ash/shell.h"
10 #include "base/logging.h"
11 #include "base/stl_util.h"
13 namespace ash {
15 ShelfItemDelegateManager::ShelfItemDelegateManager(ShelfModel* model)
16 : model_(model) {
17 DCHECK(model_);
18 model_->AddObserver(this);
21 ShelfItemDelegateManager::~ShelfItemDelegateManager() {
22 model_->RemoveObserver(this);
23 STLDeleteContainerPairSecondPointers(id_to_item_delegate_map_.begin(),
24 id_to_item_delegate_map_.end());
27 void ShelfItemDelegateManager::SetShelfItemDelegate(
28 ShelfID id,
29 scoped_ptr<ShelfItemDelegate> item_delegate) {
30 // If another ShelfItemDelegate is already registered for |id|, we assume
31 // that this request is replacing ShelfItemDelegate for |id| with
32 // |item_delegate|.
33 RemoveShelfItemDelegate(id);
34 id_to_item_delegate_map_[id] = item_delegate.release();
37 ShelfItemDelegate* ShelfItemDelegateManager::GetShelfItemDelegate(ShelfID id) {
38 if (model_->ItemIndexByID(id) != -1) {
39 // Each ShelfItem has to have a ShelfItemDelegate.
40 DCHECK(id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end());
41 return id_to_item_delegate_map_[id];
43 return NULL;
46 void ShelfItemDelegateManager::ShelfItemAdded(int index) {
49 void ShelfItemDelegateManager::ShelfItemRemoved(int index, ShelfID id) {
50 RemoveShelfItemDelegate(id);
53 void ShelfItemDelegateManager::ShelfItemMoved(int start_index,
54 int target_index) {
57 void ShelfItemDelegateManager::ShelfItemChanged(int index,
58 const ShelfItem& old_item) {
61 void ShelfItemDelegateManager::ShelfStatusChanged() {
64 void ShelfItemDelegateManager::RemoveShelfItemDelegate(ShelfID id) {
65 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) {
66 delete id_to_item_delegate_map_[id];
67 id_to_item_delegate_map_.erase(id);
71 } // namespace ash