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

Side by Side Diff: ios/chrome/browser/ui/history/history_collection_view_controller.mm

Issue 2589313002: [ios] Wait for sync query to return before displaying history (Closed)
Patch Set: Cleanup Created 4 years 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/history/history_service_facade.h » ('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 #include "ios/chrome/browser/ui/history/history_collection_view_controller.h" 5 #include "ios/chrome/browser/ui/history/history_collection_view_controller.h"
6 6
7 #import <MobileCoreServices/MobileCoreServices.h> 7 #import <MobileCoreServices/MobileCoreServices.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 - (void)fetchHistoryForQuery:(NSString*)query 100 - (void)fetchHistoryForQuery:(NSString*)query
101 priorToTime:(const base::Time&)time; 101 priorToTime:(const base::Time&)time;
102 // Updates header section to provide relevant information about the currently 102 // Updates header section to provide relevant information about the currently
103 // displayed history entries. 103 // displayed history entries.
104 - (void)updateEntriesStatusMessage; 104 - (void)updateEntriesStatusMessage;
105 // Removes selected items from the visible collection, but does not delete them 105 // Removes selected items from the visible collection, but does not delete them
106 // from browser history. 106 // from browser history.
107 - (void)removeSelectedItemsFromCollection; 107 - (void)removeSelectedItemsFromCollection;
108 // Removes all items in the collection that are not included in entries. 108 // Removes all items in the collection that are not included in entries.
109 - (void)filterForHistoryEntries:(NSArray*)entries; 109 - (void)filterForHistoryEntries:(NSArray*)entries;
110 // Adds loading indicator to the top of the history collection, if one is not
111 // already present.
112 - (void)addLoadingIndicator;
110 // Displays context menu on cell pressed with gestureRecognizer. 113 // Displays context menu on cell pressed with gestureRecognizer.
111 - (void)displayContextMenuInvokedByGestureRecognizer: 114 - (void)displayContextMenuInvokedByGestureRecognizer:
112 (UILongPressGestureRecognizer*)gestureRecognizer; 115 (UILongPressGestureRecognizer*)gestureRecognizer;
113 // Opens URL in the current tab and dismisses the history view. 116 // Opens URL in the current tab and dismisses the history view.
114 - (void)openURL:(const GURL&)URL; 117 - (void)openURL:(const GURL&)URL;
115 // Opens URL in a new non-incognito tab and dismisses the history view. 118 // Opens URL in a new non-incognito tab and dismisses the history view.
116 - (void)openURLInNewTab:(const GURL&)URL; 119 - (void)openURLInNewTab:(const GURL&)URL;
117 // Opens URL in a new incognito tab and dismisses the history view. 120 // Opens URL in a new incognito tab and dismisses the history view.
118 - (void)openURLInNewIncognitoTab:(const GURL&)URL; 121 - (void)openURLInNewIncognitoTab:(const GURL&)URL;
119 // Copies URL to the clipboard. 122 // Copies URL to the clipboard.
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 inSectionWithIdentifier: 311 inSectionWithIdentifier:
309 [self.entryInserter sectionIdentifierForTimestamp:item.timestamp]]; 312 [self.entryInserter sectionIdentifierForTimestamp:item.timestamp]];
310 } 313 }
311 } 314 }
312 315
313 #pragma mark - HistoryServiceFacadeDelegate 316 #pragma mark - HistoryServiceFacadeDelegate
314 317
315 - (void)historyServiceFacade:(HistoryServiceFacade*)facade 318 - (void)historyServiceFacade:(HistoryServiceFacade*)facade
316 didReceiveQueryResult:(HistoryServiceFacade::QueryResult)result { 319 didReceiveQueryResult:(HistoryServiceFacade::QueryResult)result {
317 self.loading = NO; 320 self.loading = NO;
318 // Remove loading indicator. 321 // If history sync is enabled and there hasn't been a response from synced
319 CollectionViewItem* headerItem = [self.collectionViewModel 322 // history, try fetching again.
320 itemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; 323 SyncSetupService* syncSetupService =
321 if ([headerItem.cellClass isSubclassOfClass:[ActivityIndicatorCell class]]) { 324 SyncSetupServiceFactory::GetForBrowserState(_browserState);
322 [self.collectionViewModel removeItemWithType:kItemTypeEnumZero 325 if (syncSetupService->IsSyncEnabled() &&
323 fromSectionWithIdentifier:kSectionIdentifierEnumZero]; 326 syncSetupService->IsDataTypeEnabled(syncer::HISTORY_DELETE_DIRECTIVES) &&
324 [self.collectionView 327 !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 🙃
325 deleteItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:0 328 [self showHistoryMatchingQuery:_currentQuery];
326 inSection:0] ]]; 329 return;
327 } 330 }
328 331
329 // If there are no results and no URLs have been loaded, report that no 332 // If there are no results and no URLs have been loaded, report that no
330 // history entries were found. 333 // history entries were found.
331 if (result.entries.empty() && !self.hasHistoryEntries) { 334 if (result.entries.empty() && !self.hasHistoryEntries) {
332 DCHECK(self.entriesType == NO_ENTRIES); 335 DCHECK(self.entriesType == NO_ENTRIES);
333 [self updateEntriesStatusMessage]; 336 [self updateEntriesStatusMessage];
334 [self.delegate historyCollectionViewControllerDidChangeEntries:self]; 337 [self.delegate historyCollectionViewControllerDidChangeEntries:self];
335 return; 338 return;
336 } 339 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 [self.collectionViewModel itemAtIndexPath:indexPath]); 522 [self.collectionViewModel itemAtIndexPath:indexPath]);
520 [self fetchHistoryForQuery:_currentQuery priorToTime:lastItem.timestamp]; 523 [self fetchHistoryForQuery:_currentQuery priorToTime:lastItem.timestamp];
521 } 524 }
522 } 525 }
523 526
524 #pragma mark - Private methods 527 #pragma mark - Private methods
525 528
526 - (void)fetchHistoryForQuery:(NSString*)query 529 - (void)fetchHistoryForQuery:(NSString*)query
527 priorToTime:(const base::Time&)time { 530 priorToTime:(const base::Time&)time {
528 self.loading = YES; 531 self.loading = YES;
529 // Add loading indicator if nothing else is shown. 532 // Add loading indicator if no items are shown.
530 if (!self.hasHistoryEntries && !self.isSearching) { 533 if (!self.hasHistoryEntries && !self.isSearching) {
531 [self.collectionView performBatchUpdates:^{ 534 [self addLoadingIndicator];
532 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
533 if ([self.collectionViewModel hasItemAtIndexPath:indexPath]) {
534 [self.collectionViewModel
535 removeItemWithType:kItemTypeEnumZero
536 fromSectionWithIdentifier:kSectionIdentifierEnumZero];
537 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]];
538 }
539 CollectionViewItem* loadingIndicatorItem = [[[CollectionViewItem alloc]
540 initWithType:kItemTypeEnumZero] autorelease];
541 loadingIndicatorItem.cellClass = [ActivityIndicatorCell class];
542 [self.collectionViewModel addItem:loadingIndicatorItem
543 toSectionWithIdentifier:kEntriesStatusSectionIdentifier];
544 [self.collectionView insertItemsAtIndexPaths:@[ indexPath ]];
545 }
546 completion:nil];
547 } 535 }
548 536
549 BOOL fetchAllHistory = !query || [query isEqualToString:@""]; 537 BOOL fetchAllHistory = !query || [query isEqualToString:@""];
550 base::string16 queryString = 538 base::string16 queryString =
551 fetchAllHistory ? base::string16() : base::SysNSStringToUTF16(query); 539 fetchAllHistory ? base::string16() : base::SysNSStringToUTF16(query);
552 history::QueryOptions options; 540 history::QueryOptions options;
553 options.end_time = time; 541 options.end_time = time;
554 options.duplicate_policy = 542 options.duplicate_policy =
555 fetchAllHistory ? history::QueryOptions::REMOVE_DUPLICATES_PER_DAY 543 fetchAllHistory ? history::QueryOptions::REMOVE_DUPLICATES_PER_DAY
556 : history::QueryOptions::REMOVE_ALL_DUPLICATES; 544 : history::QueryOptions::REMOVE_ALL_DUPLICATES;
557 options.max_count = kMaxFetchCount; 545 options.max_count = kMaxFetchCount;
558 options.matching_algorithm = 546 options.matching_algorithm =
559 query_parser::MatchingAlgorithm::ALWAYS_PREFIX_SEARCH; 547 query_parser::MatchingAlgorithm::ALWAYS_PREFIX_SEARCH;
560 _historyServiceFacade->QueryOtherFormsOfBrowsingHistory();
561 _historyServiceFacade->QueryHistory(queryString, options); 548 _historyServiceFacade->QueryHistory(queryString, options);
562 // Also determine whether notice regarding other forms of browsing history 549 // Also determine whether notice regarding other forms of browsing history
563 // should be shown. 550 // should be shown.
564 _historyServiceFacade->QueryOtherFormsOfBrowsingHistory(); 551 _historyServiceFacade->QueryOtherFormsOfBrowsingHistory();
565 } 552 }
566 553
567 - (void)updateEntriesStatusMessage { 554 - (void)updateEntriesStatusMessage {
568 CollectionViewItem* entriesStatusItem = nil; 555 CollectionViewItem* entriesStatusItem = nil;
569 if (!self.hasHistoryEntries) { 556 if (!self.hasHistoryEntries) {
570 CollectionViewTextItem* noResultsItem = [[[CollectionViewTextItem alloc] 557 CollectionViewTextItem* noResultsItem = [[[CollectionViewTextItem alloc]
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 selectItemAtIndexPath:indexPath 647 selectItemAtIndexPath:indexPath
661 animated:NO 648 animated:NO
662 scrollPosition:UICollectionViewScrollPositionNone]; 649 scrollPosition:UICollectionViewScrollPositionNone];
663 } 650 }
664 } 651 }
665 } 652 }
666 } 653 }
667 [self removeSelectedItemsFromCollection]; 654 [self removeSelectedItemsFromCollection];
668 } 655 }
669 656
657 - (void)addLoadingIndicator {
658 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
659 if ([self.collectionViewModel hasItemAtIndexPath:indexPath] &&
660 [[[self.collectionViewModel itemAtIndexPath:indexPath] cellClass]
661 isSubclassOfClass:[ActivityIndicatorCell class]]) {
662 // Do not add indicator a sectond time.
663 return;
664 }
665
666 [self.collectionView performBatchUpdates:^{
667 if ([self.collectionViewModel hasItemAtIndexPath:indexPath]) {
668 [self.collectionViewModel removeItemWithType:kItemTypeEnumZero
669 fromSectionWithIdentifier:kSectionIdentifierEnumZero];
670 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]];
671 }
672 CollectionViewItem* loadingIndicatorItem = [[[CollectionViewItem alloc]
673 initWithType:kItemTypeEnumZero] autorelease];
674 loadingIndicatorItem.cellClass = [ActivityIndicatorCell class];
675 [self.collectionViewModel addItem:loadingIndicatorItem
676 toSectionWithIdentifier:kEntriesStatusSectionIdentifier];
677 [self.collectionView insertItemsAtIndexPaths:@[ indexPath ]];
678 }
679 completion:nil];
680 }
681
670 #pragma mark Context Menu 682 #pragma mark Context Menu
671 683
672 - (void)displayContextMenuInvokedByGestureRecognizer: 684 - (void)displayContextMenuInvokedByGestureRecognizer:
673 (UILongPressGestureRecognizer*)gestureRecognizer { 685 (UILongPressGestureRecognizer*)gestureRecognizer {
674 if (gestureRecognizer.numberOfTouches != 1 || self.editing || 686 if (gestureRecognizer.numberOfTouches != 1 || self.editing ||
675 gestureRecognizer.state != UIGestureRecognizerStateBegan) { 687 gestureRecognizer.state != UIGestureRecognizerStateBegan) {
676 return; 688 return;
677 } 689 }
678 690
679 CGPoint touchLocation = 691 CGPoint touchLocation =
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 NSData* plainText = [base::SysUTF8ToNSString(URL.spec()) 794 NSData* plainText = [base::SysUTF8ToNSString(URL.spec())
783 dataUsingEncoding:NSUTF8StringEncoding]; 795 dataUsingEncoding:NSUTF8StringEncoding];
784 NSDictionary* copiedItem = @{ 796 NSDictionary* copiedItem = @{
785 (NSString*)kUTTypeURL : net::NSURLWithGURL(URL), 797 (NSString*)kUTTypeURL : net::NSURLWithGURL(URL),
786 (NSString*)kUTTypeUTF8PlainText : plainText, 798 (NSString*)kUTTypeUTF8PlainText : plainText,
787 }; 799 };
788 [[UIPasteboard generalPasteboard] setItems:@[ copiedItem ]]; 800 [[UIPasteboard generalPasteboard] setItems:@[ copiedItem ]];
789 } 801 }
790 802
791 @end 803 @end
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/browser/ui/history/history_service_facade.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698