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

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

Issue 2751713002: Fetch Suggestions by category (Closed)
Patch Set: git cl web Created 3 years, 9 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 | ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 fe99bd5b3364ad2f1bb45fe5d4d3dfa691db5802..6ba0cfd0899811a0d1a7aadcbf308491c2215c7e 100644
--- a/ios/chrome/browser/content_suggestions/content_suggestions_mediator.mm
+++ b/ios/chrome/browser/content_suggestions/content_suggestions_mediator.mm
@@ -113,7 +113,7 @@ ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID(
sectionInformationByCategory;
// Converts the data in |category| to ContentSuggestion and adds them to the
-// |contentArray|.
+// |contentArray| if the category is available.
- (void)addContentInCategory:(ntp_snippets::Category&)category
toArray:(NSMutableArray<ContentSuggestion*>*)contentArray;
@@ -164,19 +164,21 @@ ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID(
self.contentService->GetCategories();
NSMutableArray<ContentSuggestion*>* dataHolders = [NSMutableArray array];
for (auto& category : categories) {
- if (self.contentService->GetCategoryStatus(category) !=
- ntp_snippets::CategoryStatus::AVAILABLE) {
- continue;
- }
- if (!self.sectionInformationByCategory[
- [ContentSuggestionsCategoryWrapper wrapperWithCategory:category]]) {
- [self addSectionInformationForCategory:category];
- }
[self addContentInCategory:category toArray:dataHolders];
}
return dataHolders;
}
+- (NSArray<ContentSuggestion*>*)suggestionsForSection:
+ (ContentSuggestionsSectionInformation*)sectionInfo {
+ ntp_snippets::Category category =
+ [[self categoryWrapperForSectionInfo:sectionInfo] category];
+
+ NSMutableArray* suggestions = [NSMutableArray array];
+ [self addContentInCategory:category toArray:suggestions];
+ return suggestions;
+}
+
- (id<ContentSuggestionsImageFetcher>)imageFetcher {
return self;
}
@@ -186,7 +188,13 @@ ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID(
- (void)contentSuggestionsService:
(ntp_snippets::ContentSuggestionsService*)suggestionsService
newSuggestionsInCategory:(ntp_snippets::Category)category {
- [self.dataSink dataAvailable];
+ ContentSuggestionsCategoryWrapper* wrapper =
+ [ContentSuggestionsCategoryWrapper wrapperWithCategory:category];
+ if (!self.sectionInformationByCategory[wrapper]) {
+ [self addSectionInformationForCategory:category];
+ }
+ [self.dataSink
+ dataAvailableForSection:self.sectionInformationByCategory[wrapper]];
}
- (void)contentSuggestionsService:
@@ -246,12 +254,22 @@ ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID(
- (void)addContentInCategory:(ntp_snippets::Category&)category
toArray:(NSMutableArray<ContentSuggestion*>*)contentArray {
+ if (self.contentService->GetCategoryStatus(category) !=
+ ntp_snippets::CategoryStatus::AVAILABLE) {
+ return;
+ }
+ ContentSuggestionsCategoryWrapper* categoryWrapper =
+ [ContentSuggestionsCategoryWrapper wrapperWithCategory:category];
+ if (!self.sectionInformationByCategory[categoryWrapper]) {
+ [self addSectionInformationForCategory:category];
+ }
+
const std::vector<ntp_snippets::ContentSuggestion>& suggestions =
self.contentService->GetSuggestionsForCategory(category);
- ContentSuggestionsCategoryWrapper* categoryWrapper =
- [[ContentSuggestionsCategoryWrapper alloc] initWithCategory:category];
+
for (auto& contentSuggestion : suggestions) {
ContentSuggestion* suggestion = ConvertContentSuggestion(contentSuggestion);
+
suggestion.type = TypeForCategory(category);
suggestion.suggestionIdentifier.sectionInfo =
self.sectionInformationByCategory[categoryWrapper];
« no previous file with comments | « no previous file | ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698