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

Side by Side Diff: ui/app_list/app_list_item_list.h

Issue 148403007: Protect AppListItemList Add/Remove and fix sync bugs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #ifndef UI_APP_LIST_APP_LIST_ITEM_LIST_H_ 5 #ifndef UI_APP_LIST_APP_LIST_ITEM_LIST_H_
6 #define UI_APP_LIST_APP_LIST_ITEM_LIST_H_ 6 #define UI_APP_LIST_APP_LIST_ITEM_LIST_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 19 matching lines...) Expand all
30 void RemoveObserver(AppListItemListObserver* observer); 30 void RemoveObserver(AppListItemListObserver* observer);
31 31
32 // Finds item matching |id|. NOTE: Requires a linear search. 32 // Finds item matching |id|. NOTE: Requires a linear search.
33 AppListItem* FindItem(const std::string& id); 33 AppListItem* FindItem(const std::string& id);
34 34
35 // Finds the |index| of the the item matching |id| in |app_list_items_|. 35 // Finds the |index| of the the item matching |id| in |app_list_items_|.
36 // Returns true if the matching item is found. 36 // Returns true if the matching item is found.
37 // Note: Requires a linear search. 37 // Note: Requires a linear search.
38 bool FindItemIndex(const std::string& id, size_t* index); 38 bool FindItemIndex(const std::string& id, size_t* index);
39 39
40 // Moves item at |from_index| to |to_index|.
41 // Triggers observers_.OnListItemMoved().
42 void MoveItem(size_t from_index, size_t to_index);
43
44 // Sets the position of |item| which is expected to be a member of
45 // |app_list_items_| and sorts the list accordingly.
46 void SetItemPosition(AppListItem* item,
47 const syncer::StringOrdinal& new_position);
48
49 AppListItem* item_at(size_t index) {
50 DCHECK_LT(index, app_list_items_.size());
51 return app_list_items_[index];
52 }
53 const AppListItem* item_at(size_t index) const {
54 DCHECK_LT(index, app_list_items_.size());
55 return app_list_items_[index];
56 }
57 size_t item_count() const { return app_list_items_.size(); }
58
59 private:
60 friend class AppListItemListTest;
61 friend class AppListModel;
62 friend class AppListModelTest; // TODO(stevenjb): Remove dependency
63
40 // Adds |item| to the end of |app_list_items_|. Takes ownership of |item|. 64 // Adds |item| to the end of |app_list_items_|. Takes ownership of |item|.
41 // Triggers observers_.OnListItemAdded(). Returns the index of the added item. 65 // Triggers observers_.OnListItemAdded(). Returns the index of the added item.
42 size_t AddItem(AppListItem* item); 66 size_t AddItem(AppListItem* item);
43 67
44 // Inserts |item| at the |index| into |app_list_items_|. Takes ownership of
45 // |item|. Triggers observers_.OnListItemAdded().
46 void InsertItemAt(AppListItem* item, size_t index);
47
48 // Finds item matching |id| in |app_list_items_| (linear search) and deletes 68 // Finds item matching |id| in |app_list_items_| (linear search) and deletes
49 // it. Triggers observers_.OnListItemRemoved() after removing the item from 69 // it. Triggers observers_.OnListItemRemoved() after removing the item from
50 // the list and before deleting it. 70 // the list and before deleting it.
51 void DeleteItem(const std::string& id); 71 void DeleteItem(const std::string& id);
52 72
53 // Deletes all items matching |type| which must be a statically defined
54 // type descriptor, e.g. AppListFolderItem::kItemType. If |type| is NULL,
55 // deletes all items. Triggers observers_.OnListItemRemoved() for each item
56 // as for DeleteItem.
57 void DeleteItemsByType(const char* type);
58
59 // Removes the item with matching |id| in |app_list_items_| without deleting 73 // Removes the item with matching |id| in |app_list_items_| without deleting
60 // it. Returns a scoped pointer containing the removed item. 74 // it. Returns a scoped pointer containing the removed item.
61 scoped_ptr<AppListItem> RemoveItem(const std::string& id); 75 scoped_ptr<AppListItem> RemoveItem(const std::string& id);
62 76
63 // Removes the item at |index| from |app_list_items_| without deleting it. 77 // Removes the item at |index| from |app_list_items_| without deleting it.
64 // Returns a scoped pointer containing the removed item. 78 // Returns a scoped pointer containing the removed item.
65 scoped_ptr<AppListItem> RemoveItemAt(size_t index); 79 scoped_ptr<AppListItem> RemoveItemAt(size_t index);
66 80
67 // Moves item at |from_index| to |to_index|.
68 // Triggers observers_.OnListItemMoved().
69 void MoveItem(size_t from_index, size_t to_index);
70
71 // Sets the position of |item| which is expected to be a member of
72 // |app_list_items_| and sorts the list accordingly.
73 void SetItemPosition(AppListItem* item,
74 const syncer::StringOrdinal& new_position);
75
76 AppListItem* item_at(size_t index) {
77 DCHECK_LT(index, app_list_items_.size());
78 return app_list_items_[index];
79 }
80 size_t item_count() const { return app_list_items_.size(); }
81
82 private:
83 // Deletes item at |index| and signals observers. 81 // Deletes item at |index| and signals observers.
84 void DeleteItemAt(size_t index); 82 void DeleteItemAt(size_t index);
85 83
86 // If |item|->position() is not a valid ordinal, sets |item|->position() 84 // If |item|->position() is not a valid ordinal, sets |item|->position()
87 // to a valid ordinal after the last item in the list. 85 // to a valid ordinal after the last item in the list.
88 void EnsureValidItemPosition(AppListItem* item); 86 void EnsureValidItemPosition(AppListItem* item);
89 87
90 // Returns the index at which to insert an item in |app_list_items_| based on 88 // Returns the index at which to insert an item in |app_list_items_| based on
91 // |position| (which must be valid) and |id| (if the positions are equal). 89 // |position| (which must be valid) and |id| (if the positions are equal).
92 size_t GetItemSortOrderIndex(const syncer::StringOrdinal& position, 90 size_t GetItemSortOrderIndex(const syncer::StringOrdinal& position,
93 const std::string& id); 91 const std::string& id);
94 92
95 ScopedVector<AppListItem> app_list_items_; 93 ScopedVector<AppListItem> app_list_items_;
96 ObserverList<AppListItemListObserver> observers_; 94 ObserverList<AppListItemListObserver> observers_;
97 95
98 DISALLOW_COPY_AND_ASSIGN(AppListItemList); 96 DISALLOW_COPY_AND_ASSIGN(AppListItemList);
99 }; 97 };
100 98
101 } // namespace app_list 99 } // namespace app_list
102 100
103 #endif // UI_APP_LIST_APP_LIST_ITEM_LIST_H_ 101 #endif // UI_APP_LIST_APP_LIST_ITEM_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698