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

Unified Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm

Issue 2803623002: Fetch favicon for ReadingListItem (Closed)
Patch Set: Address comment Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 581ec0b986ee96fb257b93d63527c99f75e77fbe..69b2d02c5c79ef22ff42d723c10b43d5ff27c3e9 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
@@ -264,14 +264,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];
@@ -439,7 +432,7 @@ SectionIdentifier SectionIdentifierForInfo(
return item;
}
-// Returns an article build with the |suggestion|.
+// Returns an article built with the |suggestion|.
- (ContentSuggestionsArticleItem*)articleItemForSuggestion:
(ContentSuggestion*)suggestion {
ContentSuggestionsArticleItem* articleItem =
@@ -455,25 +448,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 built with the |suggestion|.
+- (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698