| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/content_suggestions/content_suggestions_mediator.h" | 5 #import "ios/chrome/browser/content_suggestions/content_suggestions_mediator.h" |
| 6 | 6 |
| 7 #include "base/mac/bind_objc_block.h" | 7 #include "base/mac/bind_objc_block.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/optional.h" | 9 #include "base/optional.h" |
| 10 #include "components/favicon/core/large_icon_service.h" | 10 #include "components/favicon/core/large_icon_service.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| 231 - (void)fetchFaviconAttributesForURL:(const GURL&)URL | 231 - (void)fetchFaviconAttributesForURL:(const GURL&)URL |
| 232 completion:(void (^)(FaviconAttributes*))completion { | 232 completion:(void (^)(FaviconAttributes*))completion { |
| 233 [self.attributesProvider fetchFaviconAttributesForURL:URL | 233 [self.attributesProvider fetchFaviconAttributesForURL:URL |
| 234 completion:completion]; | 234 completion:completion]; |
| 235 } | 235 } |
| 236 | 236 |
| 237 - (void)fetchFaviconImageForSuggestion:(ContentSuggestionIdentifier*)suggestion |
| 238 completion:(void (^)(UIImage*))completion { |
| 239 if (!completion) |
| 240 return; |
| 241 |
| 242 void (^imageCallback)(const gfx::Image&) = ^(const gfx::Image& image) { |
| 243 if (!image.IsEmpty()) { |
| 244 completion([image.ToUIImage() copy]); |
| 245 } |
| 246 }; |
| 247 |
| 248 ntp_snippets::ContentSuggestion::ID identifier = |
| 249 ntp_snippets::ContentSuggestion::ID( |
| 250 [[self categoryWrapperForSectionInfo:suggestion.sectionInfo] |
| 251 category], |
| 252 suggestion.IDInSection); |
| 253 self.contentService->FetchSuggestionFavicon( |
| 254 identifier, /* minimum_size_in_pixel = */ 1, kDefaultFaviconSize, |
| 255 base::BindBlockArc(imageCallback)); |
| 256 } |
| 257 |
| 237 #pragma mark - ContentSuggestionsServiceObserver | 258 #pragma mark - ContentSuggestionsServiceObserver |
| 238 | 259 |
| 239 - (void)contentSuggestionsService: | 260 - (void)contentSuggestionsService: |
| 240 (ntp_snippets::ContentSuggestionsService*)suggestionsService | 261 (ntp_snippets::ContentSuggestionsService*)suggestionsService |
| 241 newSuggestionsInCategory:(ntp_snippets::Category)category { | 262 newSuggestionsInCategory:(ntp_snippets::Category)category { |
| 242 ContentSuggestionsCategoryWrapper* wrapper = | 263 ContentSuggestionsCategoryWrapper* wrapper = |
| 243 [ContentSuggestionsCategoryWrapper wrapperWithCategory:category]; | 264 [ContentSuggestionsCategoryWrapper wrapperWithCategory:category]; |
| 244 if (!self.sectionInformationByCategory[wrapper]) { | 265 if (!self.sectionInformationByCategory[wrapper]) { |
| 245 [self addSectionInformationForCategory:category]; | 266 [self addSectionInformationForCategory:category]; |
| 246 } | 267 } |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } | 457 } |
| 437 | 458 |
| 438 // Returns whether the |sectionInfo| is associated with a category from the | 459 // Returns whether the |sectionInfo| is associated with a category from the |
| 439 // content suggestions service. | 460 // content suggestions service. |
| 440 - (BOOL)isRelatedToContentSuggestionsService: | 461 - (BOOL)isRelatedToContentSuggestionsService: |
| 441 (ContentSuggestionsSectionInformation*)sectionInfo { | 462 (ContentSuggestionsSectionInformation*)sectionInfo { |
| 442 return sectionInfo != self.mostVisitedSectionInfo; | 463 return sectionInfo != self.mostVisitedSectionInfo; |
| 443 } | 464 } |
| 444 | 465 |
| 445 @end | 466 @end |
| OLD | NEW |