Chromium Code Reviews| Index: ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm |
| diff --git a/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm b/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm |
| index c1400696c409c0d1348e2ac8e14eb81a2bccf11b..c9429b9bd21661bf865aa62d4dc4a5771b4dd5bf 100644 |
| --- a/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm |
| +++ b/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm |
| @@ -276,14 +276,7 @@ SectionIdentifier SectionIdentifierForInfo( |
| } |
| case ContentSuggestionTypeReadingList: { |
| ContentSuggestionsReadingListItem* readingListItem = |
| - [[ContentSuggestionsReadingListItem alloc] |
| - initWithType:ItemTypeReadingList |
| - url:suggestion.url |
| - distillationState:suggestion.readingListExtra.status]; |
| - readingListItem.title = suggestion.title; |
| - readingListItem.subtitle = suggestion.publisher; |
| - |
| - readingListItem.suggestionIdentifier = suggestion.suggestionIdentifier; |
| + [self readingListItemForSuggestion:suggestion]; |
| NSIndexPath* addedIndexPath = [self addItem:readingListItem |
| toSectionWithIdentifier:sectionIdentifier]; |
| @@ -467,25 +460,64 @@ SectionIdentifier SectionIdentifierForInfo( |
| articleItem.suggestionIdentifier = suggestion.suggestionIdentifier; |
| - __weak ContentSuggestionsCollectionUpdater* weakSelf = self; |
| __weak ContentSuggestionsArticleItem* weakItem = articleItem; |
| + [self fetchFaviconForItem:articleItem |
| + withURL:articleItem.articleURL |
| + callback:^void(FaviconAttributes* attributes) { |
| + weakItem.attributes = attributes; |
| + }]; |
| + |
| + return articleItem; |
| +} |
| + |
| +// Returns a reading list item build with the |suggestion|. |
|
lpromero
2017/04/05 13:14:14
*built
gambard
2017/04/06 11:17:47
Done.
|
| +- (ContentSuggestionsReadingListItem*)readingListItemForSuggestion: |
| + (ContentSuggestion*)suggestion { |
| + ContentSuggestionsReadingListItem* readingListItem = |
| + [[ContentSuggestionsReadingListItem alloc] |
| + initWithType:ItemTypeReadingList |
| + url:suggestion.url |
| + distillationState:suggestion.readingListExtra.status]; |
| + |
| + readingListItem.title = suggestion.title; |
| + readingListItem.subtitle = suggestion.publisher; |
| + |
| + readingListItem.suggestionIdentifier = suggestion.suggestionIdentifier; |
| + |
| + __weak ContentSuggestionsReadingListItem* weakItem = readingListItem; |
| + [self fetchFaviconForItem:readingListItem |
| + withURL:readingListItem.url |
| + callback:^void(FaviconAttributes* attributes) { |
| + weakItem.attributes = attributes; |
| + }]; |
| + |
| + return readingListItem; |
| +} |
| + |
| +// Fetches the favicon associated with the |URL|, call the |callback| with the |
| +// attributes then reconfigure the |item|. |
| +- (void)fetchFaviconForItem:(CSCollectionViewItem*)item |
| + withURL:(const GURL&)URL |
| + callback:(void (^)(FaviconAttributes*))callback { |
| + if (!callback) |
| + return; |
| + |
| + __weak ContentSuggestionsCollectionUpdater* weakSelf = self; |
| + __weak CSCollectionViewItem* weakItem = item; |
| void (^completionBlock)(FaviconAttributes* attributes) = |
| ^(FaviconAttributes* attributes) { |
| - ContentSuggestionsArticleItem* strongItem = weakItem; |
| + CSCollectionViewItem* strongItem = weakItem; |
| ContentSuggestionsCollectionUpdater* strongSelf = weakSelf; |
| if (!strongSelf || !strongItem) { |
| return; |
| } |
| - strongItem.attributes = attributes; |
| + callback(attributes); |
| [strongSelf reconfigure:strongItem]; |
| }; |
| - [self.dataSource fetchFaviconAttributesForURL:articleItem.articleURL |
| - completion:completionBlock]; |
| - |
| - return articleItem; |
| + [self.dataSource fetchFaviconAttributesForURL:URL completion:completionBlock]; |
| } |
| // Adds |item| to |sectionIdentifier| section of the model of the |