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

Side by Side Diff: ios/chrome/browser/ui/bookmarks/bookmark_all_collection_view.mm

Issue 2617243002: Remove ScopedVector from ios/. (Closed)
Patch Set: rebase Created 3 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "ios/chrome/browser/ui/bookmarks/bookmark_all_collection_view.h" 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_all_collection_view.h"
6 6
7 #include <memory>
8 #include <vector>
9
7 #include "base/logging.h" 10 #include "base/logging.h"
8 #include "base/mac/objc_property_releaser.h" 11 #include "base/mac/objc_property_releaser.h"
9 #include "base/mac/scoped_nsobject.h" 12 #include "base/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
11 #include "components/bookmarks/browser/bookmark_model.h" 14 #include "components/bookmarks/browser/bookmark_model.h"
12 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" 15 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h"
13 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" 16 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h"
14 #include "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" 17 #include "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h"
15 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" 18 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
16 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
(...skipping 14 matching lines...) Expand all
31 // is done once and all other updates received during the same runloop event are 34 // is done once and all other updates received during the same runloop event are
32 // deferred to the next turn of the runloop (if everything is deferred this 35 // deferred to the next turn of the runloop (if everything is deferred this
33 // unfortunately triggers a bug in the UICollectionView sometimes). 36 // unfortunately triggers a bug in the UICollectionView sometimes).
34 // This enum tracks the state of the refresh. See -collectionViewNeedsUpdate 37 // This enum tracks the state of the refresh. See -collectionViewNeedsUpdate
35 // for the state machine. 38 // for the state machine.
36 typedef enum { kNoUpdate = 0, kOneUpdateDone, kUpdateScheduled } UpdateState; 39 typedef enum { kNoUpdate = 0, kOneUpdateDone, kUpdateScheduled } UpdateState;
37 } // namespace 40 } // namespace
38 41
39 @interface BookmarkAllCollectionView ()<BookmarkPromoCellDelegate> { 42 @interface BookmarkAllCollectionView ()<BookmarkPromoCellDelegate> {
40 // A vector of vectors. Url nodes are segregated by month of creation. 43 // A vector of vectors. Url nodes are segregated by month of creation.
41 ScopedVector<NodesSection> _nodesSectionVector; 44 std::vector<std::unique_ptr<NodesSection>> _nodesSectionVector;
42 // To avoid refreshing the internal model too often. 45 // To avoid refreshing the internal model too often.
43 UpdateState _updateScheduled; 46 UpdateState _updateScheduled;
44 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkAllCollectionView; 47 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkAllCollectionView;
45 } 48 }
46 49
47 // Keep a reference to the promo cell to deregister as delegate. 50 // Keep a reference to the promo cell to deregister as delegate.
48 @property(nonatomic, retain) BookmarkPromoCell* promoCell; 51 @property(nonatomic, retain) BookmarkPromoCell* promoCell;
49 52
50 // Triggers an update of the collection, but delayed in order to coallesce a lot 53 // Triggers an update of the collection, but delayed in order to coallesce a lot
51 // of events into one update. 54 // of events into one update.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 movedFromParent:(const BookmarkNode*)oldParent 173 movedFromParent:(const BookmarkNode*)oldParent
171 toParent:(const BookmarkNode*)newParent { 174 toParent:(const BookmarkNode*)newParent {
172 [self updateCollectionView]; 175 [self updateCollectionView];
173 } 176 }
174 177
175 - (void)bookmarkNodeDeleted:(const BookmarkNode*)node 178 - (void)bookmarkNodeDeleted:(const BookmarkNode*)node
176 fromFolder:(const BookmarkNode*)folder { 179 fromFolder:(const BookmarkNode*)folder {
177 // Only remove the node from the list of all nodes. Since we also receive a 180 // Only remove the node from the list of all nodes. Since we also receive a
178 // 'bookmarkNodeChildrenChanged' callback, the collection view will be updated 181 // 'bookmarkNodeChildrenChanged' callback, the collection view will be updated
179 // there. 182 // there.
180 for (NodesSection* nodesSection : _nodesSectionVector) { 183 for (const auto& nodesSection : _nodesSectionVector) {
181 NodeVector nodeVector = nodesSection->vector; 184 NodeVector nodeVector = nodesSection->vector;
182 // If the node was in _nodesSectionVector, it is now invalid. In that case, 185 // If the node was in _nodesSectionVector, it is now invalid. In that case,
183 // remove it from _nodesSectionVector. 186 // remove it from _nodesSectionVector.
184 auto it = std::find(nodeVector.begin(), nodeVector.end(), node); 187 auto it = std::find(nodeVector.begin(), nodeVector.end(), node);
185 if (it != nodeVector.end()) { 188 if (it != nodeVector.end()) {
186 nodeVector.erase(it); 189 nodeVector.erase(it);
187 nodesSection->vector = nodeVector; 190 nodesSection->vector = nodeVector;
188 break; 191 break;
189 } 192 }
190 } 193 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 return _nodesSectionVector[section]->vector[indexPath.row]; 288 return _nodesSectionVector[section]->vector[indexPath.row];
286 } 289 }
287 290
288 - (NSIndexPath*)indexPathForNode:(const BookmarkNode*)bookmarkNode { 291 - (NSIndexPath*)indexPathForNode:(const BookmarkNode*)bookmarkNode {
289 NSInteger section = 0; 292 NSInteger section = 0;
290 293
291 // When showing promo cell, bookmarks start with section 1. 294 // When showing promo cell, bookmarks start with section 1.
292 if ([self shouldShowPromoCell]) 295 if ([self shouldShowPromoCell])
293 section = 1; 296 section = 1;
294 297
295 for (NodesSection* nodesSection : _nodesSectionVector) { 298 for (const auto& nodesSection : _nodesSectionVector) {
296 NodeVector nodeVector = nodesSection->vector; 299 NodeVector nodeVector = nodesSection->vector;
297 NSInteger item = 0; 300 NSInteger item = 0;
298 for (const BookmarkNode* node : nodeVector) { 301 for (const BookmarkNode* node : nodeVector) {
299 if (bookmarkNode == node) { 302 if (bookmarkNode == node) {
300 return [NSIndexPath indexPathForItem:item inSection:section]; 303 return [NSIndexPath indexPathForItem:item inSection:section];
301 } 304 }
302 ++item; 305 ++item;
303 } 306 }
304 ++section; 307 ++section;
305 } 308 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 - (BOOL)isPromoActive { 408 - (BOOL)isPromoActive {
406 return [self.delegate bookmarkCollectionViewShouldShowPromoCell:self]; 409 return [self.delegate bookmarkCollectionViewShouldShowPromoCell:self];
407 } 410 }
408 411
409 - (BOOL)shouldShowPromoCell { 412 - (BOOL)shouldShowPromoCell {
410 // The promo cell is not shown in edit mode. 413 // The promo cell is not shown in edit mode.
411 return !self.editing && [self isPromoActive]; 414 return !self.editing && [self isPromoActive];
412 } 415 }
413 416
414 @end 417 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698