Chromium Code Reviews| 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 ed03e0942834cd15862878b26d12ddfc38582a5b..62c3319e7cba35b0366c50b8cee005f7c9f1bc31 100644 |
| --- a/ios/chrome/browser/content_suggestions/content_suggestions_mediator.mm |
| +++ b/ios/chrome/browser/content_suggestions/content_suggestions_mediator.mm |
| @@ -8,6 +8,7 @@ |
| #include "base/memory/ptr_util.h" |
| #include "base/optional.h" |
| #include "base/strings/sys_string_conversions.h" |
| +#include "components/favicon/core/large_icon_service.h" |
| #include "components/ntp_snippets/category.h" |
| #include "components/ntp_snippets/category_info.h" |
| #include "components/ntp_snippets/content_suggestion.h" |
| @@ -18,6 +19,7 @@ |
| #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fetcher.h" |
| #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion_identifier.h" |
| #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestions_section_information.h" |
| +#import "ios/chrome/browser/ui/favicon/favicon_attributes_provider.h" |
| #include "ios/chrome/grit/ios_strings.h" |
| #include "ui/base/l10n/l10n_util_mac.h" |
| #include "ui/gfx/image/image.h" |
| @@ -28,6 +30,9 @@ |
| namespace { |
| +// Size of the favicon returned by the provider. |
| +const CGFloat kDefaultFaviconSize = 16; |
| + |
| // TODO(crbug.com/701275): Once base::BindBlock supports the move semantics, |
| // remove this wrapper. |
| // Wraps a callback taking a const ref to a callback taking an object. |
| @@ -132,6 +137,9 @@ ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID( |
| NSMutableDictionary<ContentSuggestionsCategoryWrapper*, |
| ContentSuggestionsSectionInformation*>* |
| sectionInformationByCategory; |
| +// FaviconAttributesProvider to fetch the favicon for the suggestions. |
| +@property(nonatomic, nullable, strong) |
|
lpromero
2017/03/31 08:30:26
Optional nit: Could be nonnull.
gambard
2017/04/03 12:34:34
Yes but I think it is ok as is.
|
| + FaviconAttributesProvider* attributesProvider; |
| // Converts the |suggestions| from |category| to ContentSuggestion and adds them |
| // to the |contentArray| if the category is available. |
| @@ -155,17 +163,23 @@ ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID( |
| @synthesize contentService = _contentService; |
| @synthesize dataSink = _dataSink; |
| @synthesize sectionInformationByCategory = _sectionInformationByCategory; |
| +@synthesize attributesProvider = _attributesProvider; |
| #pragma mark - Public |
| -- (instancetype)initWithContentService: |
| - (ntp_snippets::ContentSuggestionsService*)contentService { |
| +- (instancetype) |
| +initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService |
| + largeIconService:(favicon::LargeIconService*)largeIconService { |
| self = [super init]; |
| if (self) { |
| _suggestionBridge = |
| base::MakeUnique<ContentSuggestionsServiceBridge>(self, contentService); |
| _contentService = contentService; |
| _sectionInformationByCategory = [[NSMutableDictionary alloc] init]; |
| + _attributesProvider = [[FaviconAttributesProvider alloc] |
| + initWithFaviconSize:kDefaultFaviconSize |
| + minFaviconSize:1 |
| + largeIconService:largeIconService]; |
| } |
| return self; |
| } |
| @@ -242,6 +256,12 @@ ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID( |
| serviceCallback); |
| } |
| +- (void)fetchFaviconAttributesForURL:(const GURL&)URL |
| + completion:(void (^)(FaviconAttributes*))completion { |
| + [self.attributesProvider fetchFaviconAttributesForURL:URL |
| + completion:completion]; |
| +} |
| + |
| #pragma mark - ContentSuggestionsServiceObserver |
| - (void)contentSuggestionsService: |