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

Side by Side Diff: ios/chrome/browser/ui/collection_view/collection_view_model.mm

Issue 2659593002: Can request CollectionViewModel itemAtIndexPath with nil (Closed)
Patch Set: Add test Created 3 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
« no previous file with comments | « no previous file | ios/chrome/browser/ui/collection_view/collection_view_model_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/collection_view/collection_view_model.h" 5 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 9 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
10 10
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 CollectionViewItem* item = [self itemAtIndexPath:indexPath]; 141 CollectionViewItem* item = [self itemAtIndexPath:indexPath];
142 NSUInteger indexInItemType = 142 NSUInteger indexInItemType =
143 [self indexInItemTypeForItem:item inSectionItems:items]; 143 [self indexInItemTypeForItem:item inSectionItems:items];
144 return indexInItemType; 144 return indexInItemType;
145 } 145 }
146 146
147 #pragma mark Query items from index paths 147 #pragma mark Query items from index paths
148 148
149 - (BOOL)hasItemAtIndexPath:(NSIndexPath*)indexPath { 149 - (BOOL)hasItemAtIndexPath:(NSIndexPath*)indexPath {
150 if (!indexPath)
151 return NO;
152
150 if (static_cast<NSUInteger>(indexPath.section) < [_sections count]) { 153 if (static_cast<NSUInteger>(indexPath.section) < [_sections count]) {
151 SectionItems* items = [_sections objectAtIndex:indexPath.section]; 154 SectionItems* items = [_sections objectAtIndex:indexPath.section];
152 return static_cast<NSUInteger>(indexPath.item) < [items count]; 155 return static_cast<NSUInteger>(indexPath.item) < [items count];
153 } 156 }
154 return NO; 157 return NO;
155 } 158 }
156 159
157 - (CollectionViewItem*)itemAtIndexPath:(NSIndexPath*)indexPath { 160 - (CollectionViewItem*)itemAtIndexPath:(NSIndexPath*)indexPath {
161 DCHECK(indexPath);
158 DCHECK_LT(static_cast<NSUInteger>(indexPath.section), [_sections count]); 162 DCHECK_LT(static_cast<NSUInteger>(indexPath.section), [_sections count]);
159 SectionItems* items = [_sections objectAtIndex:indexPath.section]; 163 SectionItems* items = [_sections objectAtIndex:indexPath.section];
160 164
161 DCHECK_LT(static_cast<NSUInteger>(indexPath.item), [items count]); 165 DCHECK_LT(static_cast<NSUInteger>(indexPath.item), [items count]);
162 return [items objectAtIndex:indexPath.item]; 166 return [items objectAtIndex:indexPath.item];
163 } 167 }
164 168
165 - (CollectionViewItem*)headerForSection:(NSInteger)section { 169 - (CollectionViewItem*)headerForSection:(NSInteger)section {
166 NSInteger sectionIdentifier = [self sectionIdentifierForSection:section]; 170 NSInteger sectionIdentifier = [self sectionIdentifierForSection:section];
167 NSNumber* key = [NSNumber numberWithInteger:sectionIdentifier]; 171 NSNumber* key = [NSNumber numberWithInteger:sectionIdentifier];
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 320 }
317 if (sectionItem.type == item.type) { 321 if (sectionItem.type == item.type) {
318 indexInItemType++; 322 indexInItemType++;
319 } 323 }
320 } 324 }
321 DCHECK(found); 325 DCHECK(found);
322 return indexInItemType; 326 return indexInItemType;
323 } 327 }
324 328
325 @end 329 @end
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/browser/ui/collection_view/collection_view_model_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698