| 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];
|
|
|