Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: ash/shelf/shelf_model.cc

Issue 2833173002: mash: Support ShelfModel access in Chrome. (Closed)
Patch Set: Cleanup; Fix an Arc test by use CLC, not Ash's ShelfModel. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/shelf/shelf_model.h" 5 #include "ash/shelf/shelf_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/public/cpp/shelf_item_delegate.h" 9 #include "ash/public/cpp/shelf_item_delegate.h"
10 #include "ash/shelf/shelf_model_observer.h" 10 #include "ash/shelf/shelf_model_observer.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // need early cleanup. 99 // need early cleanup.
100 id_to_item_delegate_map_.clear(); 100 id_to_item_delegate_map_.clear();
101 } 101 }
102 102
103 int ShelfModel::Add(const ShelfItem& item) { 103 int ShelfModel::Add(const ShelfItem& item) {
104 return AddAt(items_.size(), item); 104 return AddAt(items_.size(), item);
105 } 105 }
106 106
107 int ShelfModel::AddAt(int index, const ShelfItem& item) { 107 int ShelfModel::AddAt(int index, const ShelfItem& item) {
108 // Items should have unique non-empty ids to avoid undefined model behavior. 108 // Items should have unique non-empty ids to avoid undefined model behavior.
109 DCHECK(!item.id.IsNull()); 109 DCHECK(!item.id.IsNull()) << " The id is null.";
110 DCHECK_EQ(ItemIndexByID(item.id), -1); 110 DCHECK_EQ(ItemIndexByID(item.id), -1) << " The id is not unique: " << item.id;
111 index = ValidateInsertionIndex(item.type, index); 111 index = ValidateInsertionIndex(item.type, index);
112 items_.insert(items_.begin() + index, item); 112 items_.insert(items_.begin() + index, item);
113 for (auto& observer : observers_) 113 for (auto& observer : observers_)
114 observer.ShelfItemAdded(index); 114 observer.ShelfItemAdded(index);
115 return index; 115 return index;
116 } 116 }
117 117
118 void ShelfModel::RemoveItemAt(int index) { 118 void ShelfModel::RemoveItemAt(int index) {
119 DCHECK(index >= 0 && index < item_count()); 119 DCHECK(index >= 0 && index < item_count());
120 ShelfItem old_item(items_[index]); 120 ShelfItem old_item(items_[index]);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 items_.begin(); 203 items_.begin();
204 } 204 }
205 205
206 void ShelfModel::SetShelfItemDelegate( 206 void ShelfModel::SetShelfItemDelegate(
207 const ShelfID& shelf_id, 207 const ShelfID& shelf_id,
208 std::unique_ptr<ShelfItemDelegate> item_delegate) { 208 std::unique_ptr<ShelfItemDelegate> item_delegate) {
209 if (item_delegate) 209 if (item_delegate)
210 item_delegate->set_shelf_id(shelf_id); 210 item_delegate->set_shelf_id(shelf_id);
211 // This assignment replaces any ShelfItemDelegate already registered for |id|. 211 // This assignment replaces any ShelfItemDelegate already registered for |id|.
212 id_to_item_delegate_map_[shelf_id] = std::move(item_delegate); 212 id_to_item_delegate_map_[shelf_id] = std::move(item_delegate);
213 for (auto& observer : observers_) {
214 observer.ShelfItemDelegateChanged(shelf_id,
215 id_to_item_delegate_map_[shelf_id].get());
216 }
213 } 217 }
214 218
215 ShelfItemDelegate* ShelfModel::GetShelfItemDelegate(const ShelfID& shelf_id) { 219 ShelfItemDelegate* ShelfModel::GetShelfItemDelegate(const ShelfID& shelf_id) {
216 auto it = id_to_item_delegate_map_.find(shelf_id); 220 auto it = id_to_item_delegate_map_.find(shelf_id);
217 if (it != id_to_item_delegate_map_.end()) 221 if (it != id_to_item_delegate_map_.end())
218 return it->second.get(); 222 return it->second.get();
219 return nullptr; 223 return nullptr;
220 } 224 }
221 225
222 void ShelfModel::AddObserver(ShelfModelObserver* observer) { 226 void ShelfModel::AddObserver(ShelfModelObserver* observer) {
(...skipping 16 matching lines...) Expand all
239 static_cast<ShelfItems::difference_type>(index)); 243 static_cast<ShelfItems::difference_type>(index));
240 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, 244 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy,
241 CompareByWeight) - 245 CompareByWeight) -
242 items_.begin(), 246 items_.begin(),
243 static_cast<ShelfItems::difference_type>(index)); 247 static_cast<ShelfItems::difference_type>(index));
244 248
245 return index; 249 return index;
246 } 250 }
247 251
248 } // namespace ash 252 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698