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

Side by Side Diff: ios/chrome/browser/content_suggestions/content_suggestions_mediator.mm

Issue 2818453002: Download favicon from server for suggested articles (Closed)
Patch Set: Reviewable Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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
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]);
lpromero 2017/04/14 13:19:40 Is the copy necessary? UIImage is immutable.
gambard 2017/04/14 13:28:10 It is a memory management thing. You can ask stkha
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, 1, kDefaultFaviconSize, base::BindBlockArc(imageCallback));
lpromero 2017/04/14 13:19:40 Optional nit: Can you add something like: "identif
gambard 2017/04/14 13:28:10 Done.
255 }
256
237 #pragma mark - ContentSuggestionsServiceObserver 257 #pragma mark - ContentSuggestionsServiceObserver
238 258
239 - (void)contentSuggestionsService: 259 - (void)contentSuggestionsService:
240 (ntp_snippets::ContentSuggestionsService*)suggestionsService 260 (ntp_snippets::ContentSuggestionsService*)suggestionsService
241 newSuggestionsInCategory:(ntp_snippets::Category)category { 261 newSuggestionsInCategory:(ntp_snippets::Category)category {
242 ContentSuggestionsCategoryWrapper* wrapper = 262 ContentSuggestionsCategoryWrapper* wrapper =
243 [ContentSuggestionsCategoryWrapper wrapperWithCategory:category]; 263 [ContentSuggestionsCategoryWrapper wrapperWithCategory:category];
244 if (!self.sectionInformationByCategory[wrapper]) { 264 if (!self.sectionInformationByCategory[wrapper]) {
245 [self addSectionInformationForCategory:category]; 265 [self addSectionInformationForCategory:category];
246 } 266 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 456 }
437 457
438 // Returns whether the |sectionInfo| is associated with a category from the 458 // Returns whether the |sectionInfo| is associated with a category from the
439 // content suggestions service. 459 // content suggestions service.
440 - (BOOL)isRelatedToContentSuggestionsService: 460 - (BOOL)isRelatedToContentSuggestionsService:
441 (ContentSuggestionsSectionInformation*)sectionInfo { 461 (ContentSuggestionsSectionInformation*)sectionInfo {
442 return sectionInfo != self.mostVisitedSectionInfo; 462 return sectionInfo != self.mostVisitedSectionInfo;
443 } 463 }
444 464
445 @end 465 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698