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

Side by Side Diff: ui/app_list/app_list_model.cc

Issue 487853003: Add additional CHECKs to AppListModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + feedback Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ui/app_list/app_list_item_list_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/app_list/app_list_model.h" 5 #include "ui/app_list/app_list_model.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ui/app_list/app_list_folder_item.h" 9 #include "ui/app_list/app_list_folder_item.h"
10 #include "ui/app_list/app_list_item.h" 10 #include "ui/app_list/app_list_item.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 DCHECK(!item->IsInFolder()); 67 DCHECK(!item->IsInFolder());
68 DCHECK(!top_level_item_list()->FindItem(item->id())); 68 DCHECK(!top_level_item_list()->FindItem(item->id()));
69 return AddItemToItemListAndNotify(item.Pass()); 69 return AddItemToItemListAndNotify(item.Pass());
70 } 70 }
71 71
72 AppListItem* AppListModel::AddItemToFolder(scoped_ptr<AppListItem> item, 72 AppListItem* AppListModel::AddItemToFolder(scoped_ptr<AppListItem> item,
73 const std::string& folder_id) { 73 const std::string& folder_id) {
74 if (folder_id.empty()) 74 if (folder_id.empty())
75 return AddItem(item.Pass()); 75 return AddItem(item.Pass());
76 DVLOG(2) << "AddItemToFolder: " << item->id() << ": " << folder_id; 76 DVLOG(2) << "AddItemToFolder: " << item->id() << ": " << folder_id;
77 DCHECK(!item->IsInFolder() || item->folder_id() == folder_id); 77 CHECK_NE(folder_id, item->folder_id());
78 DCHECK(item->GetItemType() != AppListFolderItem::kItemType); 78 DCHECK_NE(AppListFolderItem::kItemType, item->GetItemType());
79 AppListFolderItem* dest_folder = FindOrCreateFolderItem(folder_id); 79 AppListFolderItem* dest_folder = FindOrCreateFolderItem(folder_id);
80 if (!dest_folder) 80 if (!dest_folder)
81 return NULL; 81 return NULL;
82 DCHECK(!dest_folder->item_list()->FindItem(item->id())) 82 DCHECK(!dest_folder->item_list()->FindItem(item->id()))
83 << "Already in folder: " << dest_folder->id(); 83 << "Already in folder: " << dest_folder->id();
84 return AddItemToFolderItemAndNotify(dest_folder, item.Pass()); 84 return AddItemToFolderItemAndNotify(dest_folder, item.Pass());
85 } 85 }
86 86
87 const std::string AppListModel::MergeItems(const std::string& target_item_id, 87 const std::string AppListModel::MergeItems(const std::string& target_item_id,
88 const std::string& source_item_id) { 88 const std::string& source_item_id) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 153
154 void AppListModel::MoveItemToFolder(AppListItem* item, 154 void AppListModel::MoveItemToFolder(AppListItem* item,
155 const std::string& folder_id) { 155 const std::string& folder_id) {
156 DVLOG(2) << "MoveItemToFolder: " << folder_id 156 DVLOG(2) << "MoveItemToFolder: " << folder_id
157 << " <- " << item->ToDebugString(); 157 << " <- " << item->ToDebugString();
158 if (item->folder_id() == folder_id) 158 if (item->folder_id() == folder_id)
159 return; 159 return;
160 AppListFolderItem* dest_folder = FindOrCreateFolderItem(folder_id); 160 AppListFolderItem* dest_folder = FindOrCreateFolderItem(folder_id);
161 scoped_ptr<AppListItem> item_ptr = RemoveItem(item); 161 scoped_ptr<AppListItem> item_ptr = RemoveItem(item);
162 if (dest_folder) 162 if (dest_folder) {
163 CHECK(!item->IsInFolder());
163 AddItemToFolderItemAndNotify(dest_folder, item_ptr.Pass()); 164 AddItemToFolderItemAndNotify(dest_folder, item_ptr.Pass());
164 else 165 } else {
165 AddItemToItemListAndNotifyUpdate(item_ptr.Pass()); 166 AddItemToItemListAndNotifyUpdate(item_ptr.Pass());
167 }
166 } 168 }
167 169
168 bool AppListModel::MoveItemToFolderAt(AppListItem* item, 170 bool AppListModel::MoveItemToFolderAt(AppListItem* item,
169 const std::string& folder_id, 171 const std::string& folder_id,
170 syncer::StringOrdinal position) { 172 syncer::StringOrdinal position) {
171 DVLOG(2) << "MoveItemToFolderAt: " << folder_id 173 DVLOG(2) << "MoveItemToFolderAt: " << folder_id
172 << "[" << position.ToDebugString() << "]" 174 << "[" << position.ToDebugString() << "]"
173 << " <- " << item->ToDebugString(); 175 << " <- " << item->ToDebugString();
174 if (item->folder_id() == folder_id) 176 if (item->folder_id() == folder_id)
175 return false; 177 return false;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 AppListItem* item = top_level_item_list_->AddItem(item_ptr.Pass()); 352 AppListItem* item = top_level_item_list_->AddItem(item_ptr.Pass());
351 FOR_EACH_OBSERVER(AppListModelObserver, 353 FOR_EACH_OBSERVER(AppListModelObserver,
352 observers_, 354 observers_,
353 OnAppListItemUpdated(item)); 355 OnAppListItemUpdated(item));
354 return item; 356 return item;
355 } 357 }
356 358
357 AppListItem* AppListModel::AddItemToFolderItemAndNotify( 359 AppListItem* AppListModel::AddItemToFolderItemAndNotify(
358 AppListFolderItem* folder, 360 AppListFolderItem* folder,
359 scoped_ptr<AppListItem> item_ptr) { 361 scoped_ptr<AppListItem> item_ptr) {
362 CHECK_NE(folder->id(), item_ptr->folder_id());
360 AppListItem* item = folder->item_list()->AddItem(item_ptr.Pass()); 363 AppListItem* item = folder->item_list()->AddItem(item_ptr.Pass());
361 item->set_folder_id(folder->id()); 364 item->set_folder_id(folder->id());
362 FOR_EACH_OBSERVER(AppListModelObserver, 365 FOR_EACH_OBSERVER(AppListModelObserver,
363 observers_, 366 observers_,
364 OnAppListItemUpdated(item)); 367 OnAppListItemUpdated(item));
365 return item; 368 return item;
366 } 369 }
367 370
368 scoped_ptr<AppListItem> AppListModel::RemoveItem(AppListItem* item) { 371 scoped_ptr<AppListItem> AppListModel::RemoveItem(AppListItem* item) {
369 if (!item->IsInFolder()) 372 if (!item->IsInFolder())
370 return top_level_item_list_->RemoveItem(item->id()); 373 return top_level_item_list_->RemoveItem(item->id());
371 374
372 AppListFolderItem* folder = FindFolderItem(item->folder_id()); 375 AppListFolderItem* folder = FindFolderItem(item->folder_id());
373 return RemoveItemFromFolder(folder, item); 376 return RemoveItemFromFolder(folder, item);
374 } 377 }
375 378
376 scoped_ptr<AppListItem> AppListModel::RemoveItemFromFolder( 379 scoped_ptr<AppListItem> AppListModel::RemoveItemFromFolder(
377 AppListFolderItem* folder, 380 AppListFolderItem* folder,
378 AppListItem* item) { 381 AppListItem* item) {
379 std::string folder_id = folder->id(); 382 std::string folder_id = folder->id();
380 DCHECK_EQ(item->folder_id(), folder_id); 383 CHECK_EQ(item->folder_id(), folder_id);
381 scoped_ptr<AppListItem> result = folder->item_list()->RemoveItem(item->id()); 384 scoped_ptr<AppListItem> result = folder->item_list()->RemoveItem(item->id());
382 result->set_folder_id(""); 385 result->set_folder_id("");
383 if (folder->item_list()->item_count() == 0) { 386 if (folder->item_list()->item_count() == 0) {
384 DVLOG(2) << "Deleting empty folder: " << folder->ToDebugString(); 387 DVLOG(2) << "Deleting empty folder: " << folder->ToDebugString();
385 DeleteItem(folder_id); 388 DeleteItem(folder_id);
386 } 389 }
387 return result.Pass(); 390 return result.Pass();
388 } 391 }
389 392
390 } // namespace app_list 393 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/app_list_item_list_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698