OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/common/shelf/shelf_model.h" | 5 #include "ash/common/shelf/shelf_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/common/shelf/shelf_item_delegate.h" | 9 #include "ash/common/shelf/shelf_item_delegate.h" |
10 #include "ash/common/shelf/shelf_model_observer.h" | 10 #include "ash/common/shelf/shelf_model_observer.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 return; | 83 return; |
84 // TODO: this needs to enforce valid ranges. | 84 // TODO: this needs to enforce valid ranges. |
85 ShelfItem item(items_[index]); | 85 ShelfItem item(items_[index]); |
86 items_.erase(items_.begin() + index); | 86 items_.erase(items_.begin() + index); |
87 items_.insert(items_.begin() + target_index, item); | 87 items_.insert(items_.begin() + target_index, item); |
88 for (auto& observer : observers_) | 88 for (auto& observer : observers_) |
89 observer.ShelfItemMoved(index, target_index); | 89 observer.ShelfItemMoved(index, target_index); |
90 } | 90 } |
91 | 91 |
92 void ShelfModel::Set(int index, const ShelfItem& item) { | 92 void ShelfModel::Set(int index, const ShelfItem& item) { |
93 DCHECK(index >= 0 && index < item_count()); | 93 if (index < 0 || index >= item_count()) { |
| 94 NOTREACHED(); |
| 95 return; |
| 96 } |
| 97 |
94 int new_index = item.type == items_[index].type | 98 int new_index = item.type == items_[index].type |
95 ? index | 99 ? index |
96 : ValidateInsertionIndex(item.type, index); | 100 : ValidateInsertionIndex(item.type, index); |
97 | 101 |
98 ShelfItem old_item(items_[index]); | 102 ShelfItem old_item(items_[index]); |
99 items_[index] = item; | 103 items_[index] = item; |
100 items_[index].id = old_item.id; | 104 items_[index].id = old_item.id; |
101 for (auto& observer : observers_) | 105 for (auto& observer : observers_) |
102 observer.ShelfItemChanged(index, old_item); | 106 observer.ShelfItemChanged(index, old_item); |
103 | 107 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 202 |
199 return index; | 203 return index; |
200 } | 204 } |
201 | 205 |
202 void ShelfModel::RemoveShelfItemDelegate(ShelfID id) { | 206 void ShelfModel::RemoveShelfItemDelegate(ShelfID id) { |
203 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) | 207 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) |
204 id_to_item_delegate_map_.erase(id); | 208 id_to_item_delegate_map_.erase(id); |
205 } | 209 } |
206 | 210 |
207 } // namespace ash | 211 } // namespace ash |
OLD | NEW |