Chromium Code Reviews| Index: ios/chrome/browser/ui/history/history_collection_view_controller.mm |
| diff --git a/ios/chrome/browser/ui/history/history_collection_view_controller.mm b/ios/chrome/browser/ui/history/history_collection_view_controller.mm |
| index c2c010360832627a6b280f0861faedca1db39484..fe83357656c502899d7d590d44fc44a0685eccf8 100644 |
| --- a/ios/chrome/browser/ui/history/history_collection_view_controller.mm |
| +++ b/ios/chrome/browser/ui/history/history_collection_view_controller.mm |
| @@ -107,6 +107,9 @@ const CGFloat kSeparatorInset = 10; |
| - (void)removeSelectedItemsFromCollection; |
| // Removes all items in the collection that are not included in entries. |
| - (void)filterForHistoryEntries:(NSArray*)entries; |
| +// Adds loading indicator to the top of the history collection, if one is not |
| +// already present. |
| +- (void)addLoadingIndicator; |
| // Displays context menu on cell pressed with gestureRecognizer. |
| - (void)displayContextMenuInvokedByGestureRecognizer: |
| (UILongPressGestureRecognizer*)gestureRecognizer; |
| @@ -315,15 +318,15 @@ const CGFloat kSeparatorInset = 10; |
| - (void)historyServiceFacade:(HistoryServiceFacade*)facade |
| didReceiveQueryResult:(HistoryServiceFacade::QueryResult)result { |
| self.loading = NO; |
| - // Remove loading indicator. |
| - CollectionViewItem* headerItem = [self.collectionViewModel |
| - itemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; |
| - if ([headerItem.cellClass isSubclassOfClass:[ActivityIndicatorCell class]]) { |
| - [self.collectionViewModel removeItemWithType:kItemTypeEnumZero |
| - fromSectionWithIdentifier:kSectionIdentifierEnumZero]; |
| - [self.collectionView |
| - deleteItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:0 |
| - inSection:0] ]]; |
| + // If history sync is enabled and there hasn't been a response from synced |
| + // history, try fetching again. |
| + SyncSetupService* syncSetupService = |
| + SyncSetupServiceFactory::GetForBrowserState(_browserState); |
| + if (syncSetupService->IsSyncEnabled() && |
| + syncSetupService->IsDataTypeEnabled(syncer::HISTORY_DELETE_DIRECTIVES) && |
| + !result.web_history_returned) { |
|
sczs
2016/12/20 22:49:48
Should this be !result.sync_returned ?!
Jackie Quinn
2016/12/20 23:12:04
Ah yes thanks. Last minute variable name change 🙃
|
| + [self showHistoryMatchingQuery:_currentQuery]; |
| + return; |
| } |
| // If there are no results and no URLs have been loaded, report that no |
| @@ -526,24 +529,9 @@ const CGFloat kSeparatorInset = 10; |
| - (void)fetchHistoryForQuery:(NSString*)query |
| priorToTime:(const base::Time&)time { |
| self.loading = YES; |
| - // Add loading indicator if nothing else is shown. |
| + // Add loading indicator if no items are shown. |
| if (!self.hasHistoryEntries && !self.isSearching) { |
| - [self.collectionView performBatchUpdates:^{ |
| - NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:0]; |
| - if ([self.collectionViewModel hasItemAtIndexPath:indexPath]) { |
| - [self.collectionViewModel |
| - removeItemWithType:kItemTypeEnumZero |
| - fromSectionWithIdentifier:kSectionIdentifierEnumZero]; |
| - [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]]; |
| - } |
| - CollectionViewItem* loadingIndicatorItem = [[[CollectionViewItem alloc] |
| - initWithType:kItemTypeEnumZero] autorelease]; |
| - loadingIndicatorItem.cellClass = [ActivityIndicatorCell class]; |
| - [self.collectionViewModel addItem:loadingIndicatorItem |
| - toSectionWithIdentifier:kEntriesStatusSectionIdentifier]; |
| - [self.collectionView insertItemsAtIndexPaths:@[ indexPath ]]; |
| - } |
| - completion:nil]; |
| + [self addLoadingIndicator]; |
| } |
| BOOL fetchAllHistory = !query || [query isEqualToString:@""]; |
| @@ -557,7 +545,6 @@ const CGFloat kSeparatorInset = 10; |
| options.max_count = kMaxFetchCount; |
| options.matching_algorithm = |
| query_parser::MatchingAlgorithm::ALWAYS_PREFIX_SEARCH; |
| - _historyServiceFacade->QueryOtherFormsOfBrowsingHistory(); |
| _historyServiceFacade->QueryHistory(queryString, options); |
| // Also determine whether notice regarding other forms of browsing history |
| // should be shown. |
| @@ -667,6 +654,31 @@ const CGFloat kSeparatorInset = 10; |
| [self removeSelectedItemsFromCollection]; |
| } |
| +- (void)addLoadingIndicator { |
| + NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:0]; |
|
sczs
2016/12/20 22:49:48
Could self.loading be used here instead of checkin
Jackie Quinn
2016/12/20 23:12:04
Not necessarily. Presence/absence of the loading i
|
| + if ([self.collectionViewModel hasItemAtIndexPath:indexPath] && |
| + [[[self.collectionViewModel itemAtIndexPath:indexPath] cellClass] |
| + isSubclassOfClass:[ActivityIndicatorCell class]]) { |
| + // Do not add indicator a sectond time. |
| + return; |
| + } |
| + |
| + [self.collectionView performBatchUpdates:^{ |
| + if ([self.collectionViewModel hasItemAtIndexPath:indexPath]) { |
| + [self.collectionViewModel removeItemWithType:kItemTypeEnumZero |
| + fromSectionWithIdentifier:kSectionIdentifierEnumZero]; |
| + [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]]; |
| + } |
| + CollectionViewItem* loadingIndicatorItem = [[[CollectionViewItem alloc] |
| + initWithType:kItemTypeEnumZero] autorelease]; |
| + loadingIndicatorItem.cellClass = [ActivityIndicatorCell class]; |
| + [self.collectionViewModel addItem:loadingIndicatorItem |
| + toSectionWithIdentifier:kEntriesStatusSectionIdentifier]; |
| + [self.collectionView insertItemsAtIndexPaths:@[ indexPath ]]; |
| + } |
| + completion:nil]; |
| +} |
| + |
| #pragma mark Context Menu |
| - (void)displayContextMenuInvokedByGestureRecognizer: |