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

Unified Diff: ios/chrome/browser/content_suggestions/content_suggestions_mediator.mm

Issue 2701833003: Fetch images for ContentSuggestions (Closed)
Patch Set: Reviewable 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/content_suggestions/content_suggestions_mediator.mm
diff --git a/ios/chrome/browser/content_suggestions/content_suggestions_mediator.mm b/ios/chrome/browser/content_suggestions/content_suggestions_mediator.mm
index 791619f6ef82103cbacc5cda9c4329ee71766b27..c2f67f7a863e6887ad9aeb4bb3d4f7b3b0f8f84b 100644
--- a/ios/chrome/browser/content_suggestions/content_suggestions_mediator.mm
+++ b/ios/chrome/browser/content_suggestions/content_suggestions_mediator.mm
@@ -15,6 +15,7 @@
#import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestion_id.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink.h"
+#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fetcher.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_item.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_information.h"
#include "ui/gfx/image/image.h"
@@ -83,9 +84,18 @@ ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo(
return sectionInfo;
}
+// Returns a ntp_snippets::ID based on a Objective-C Category and the ID in the
+// category.
+ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID(
marq (ping after 24h) 2017/02/21 11:27:08 Should this be a method on ContentSuggestionsCateg
gambard 2017/02/21 15:07:53 Maybe. As they are only used in this file, I am no
+ ContentSuggestionsCategoryWrapper* category,
+ const std::string& id_in_category) {
+ return ntp_snippets::ContentSuggestion::ID(category.category, id_in_category);
+}
+
} // namespace
-@interface ContentSuggestionsMediator ()<ContentSuggestionsServiceObserver> {
+@interface ContentSuggestionsMediator ()<ContentSuggestionsImageFetcher,
+ ContentSuggestionsServiceObserver> {
// Bridge for this class to become an observer of a ContentSuggestionsService.
std::unique_ptr<ContentSuggestionsServiceBridge> _suggestionBridge;
}
@@ -106,6 +116,10 @@ ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo(
// self.sectionInformationByCategory.
- (void)addSectionInformationForCategory:(ntp_snippets::Category)category;
+// Returns a CategoryWrapper acting as a key for this section info.
+- (ContentSuggestionsCategoryWrapper*)categoryWrapperForSectionInfo:
+ (ContentSuggestionsSectionInformation*)sectionInfo;
+
@end
@implementation ContentSuggestionsMediator
@@ -146,6 +160,10 @@ ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo(
return dataHolders;
}
+- (id<ContentSuggestionsImageFetcher>)imageFetcher {
+ return self;
+}
+
#pragma mark - ContentSuggestionsServiceObserver
- (void)contentSuggestionsService:
@@ -178,6 +196,17 @@ ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo(
// Update dataSink.
}
+#pragma mark - ContentSuggestionsImageFetcher
+
+- (void)fetchImageForSuggestion:(ContentSuggestionID*)suggestionID
+ callback:(void (^)(const gfx::Image&))callback {
+ self.contentService->FetchSuggestionImage(
+ SuggestionIDForSectionID(
+ [self categoryWrapperForSectionInfo:suggestionID.sectionInfo],
+ suggestionID.IDInSection),
+ base::BindBlockArc(callback));
+}
+
#pragma mark - Private
- (void)addContentInCategory:(ntp_snippets::Category&)category
@@ -192,8 +221,6 @@ ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo(
suggestion.suggestionID.sectionInfo =
self.sectionInformationByCategory[categoryWrapper];
- // TODO(crbug.com/686728): fetch the image.
-
[contentArray addObject:suggestion];
}
}
@@ -209,4 +236,10 @@ ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo(
wrapperWithCategory:category]] = sectionInfo;
}
+- (ContentSuggestionsCategoryWrapper*)categoryWrapperForSectionInfo:
+ (ContentSuggestionsSectionInformation*)sectionInfo {
+ return [[self.sectionInformationByCategory allKeysForObject:sectionInfo]
+ firstObject];
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698