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

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

Issue 2782613004: Add FaviconAttributesProvider to ContentSuggestions (Closed)
Patch Set: Cleanup 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 "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 #include "components/favicon/core/large_icon_service.h"
11 #include "components/ntp_snippets/category.h" 12 #include "components/ntp_snippets/category.h"
12 #include "components/ntp_snippets/category_info.h" 13 #include "components/ntp_snippets/category_info.h"
13 #include "components/ntp_snippets/content_suggestion.h" 14 #include "components/ntp_snippets/content_suggestion.h"
14 #import "ios/chrome/browser/content_suggestions/content_suggestions_category_wra pper.h" 15 #import "ios/chrome/browser/content_suggestions/content_suggestions_category_wra pper.h"
15 #import "ios/chrome/browser/content_suggestions/content_suggestions_service_brid ge_observer.h" 16 #import "ios/chrome/browser/content_suggestions/content_suggestions_service_brid ge_observer.h"
17 #import "ios/chrome/browser/favicon/favicon_attributes_provider.h"
16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" 18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h" 19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h"
18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet cher.h" 20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet cher.h"
19 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h" 21 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h"
20 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion s_section_information.h" 22 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion s_section_information.h"
21 #include "ios/chrome/grit/ios_strings.h" 23 #include "ios/chrome/grit/ios_strings.h"
22 #include "ui/base/l10n/l10n_util_mac.h" 24 #include "ui/base/l10n/l10n_util_mac.h"
23 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
24 26
25 #if !defined(__has_feature) || !__has_feature(objc_arc) 27 #if !defined(__has_feature) || !__has_feature(objc_arc)
26 #error "This file requires ARC support." 28 #error "This file requires ARC support."
27 #endif 29 #endif
28 30
29 namespace { 31 namespace {
30 32
33 // Size of the favicon returned by the provider.
34 const CGFloat kDefaultFaviconSize = 16;
35
31 // TODO(crbug.com/701275): Once base::BindBlock supports the move semantics, 36 // TODO(crbug.com/701275): Once base::BindBlock supports the move semantics,
32 // remove this wrapper. 37 // remove this wrapper.
33 // Wraps a callback taking a const ref to a callback taking an object. 38 // Wraps a callback taking a const ref to a callback taking an object.
34 void BindWrapper( 39 void BindWrapper(
35 base::Callback<void(ntp_snippets::Status status_code, 40 base::Callback<void(ntp_snippets::Status status_code,
36 const std::vector<ntp_snippets::ContentSuggestion>& 41 const std::vector<ntp_snippets::ContentSuggestion>&
37 suggestions)> callback, 42 suggestions)> callback,
38 ntp_snippets::Status status_code, 43 ntp_snippets::Status status_code,
39 std::vector<ntp_snippets::ContentSuggestion> suggestions) { 44 std::vector<ntp_snippets::ContentSuggestion> suggestions) {
40 if (callback) { 45 if (callback) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 - (ContentSuggestionsCategoryWrapper*)categoryWrapperForSectionInfo: 153 - (ContentSuggestionsCategoryWrapper*)categoryWrapperForSectionInfo:
149 (ContentSuggestionsSectionInformation*)sectionInfo; 154 (ContentSuggestionsSectionInformation*)sectionInfo;
150 155
151 @end 156 @end
152 157
153 @implementation ContentSuggestionsMediator 158 @implementation ContentSuggestionsMediator
154 159
155 @synthesize contentService = _contentService; 160 @synthesize contentService = _contentService;
156 @synthesize dataSink = _dataSink; 161 @synthesize dataSink = _dataSink;
157 @synthesize sectionInformationByCategory = _sectionInformationByCategory; 162 @synthesize sectionInformationByCategory = _sectionInformationByCategory;
163 @synthesize attributesProvider = _attributesProvider;
158 164
159 #pragma mark - Public 165 #pragma mark - Public
160 166
161 - (instancetype)initWithContentService: 167 - (instancetype)
162 (ntp_snippets::ContentSuggestionsService*)contentService { 168 initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService
169 largeIconService:(favicon::LargeIconService*)largeIconService {
163 self = [super init]; 170 self = [super init];
164 if (self) { 171 if (self) {
165 _suggestionBridge = 172 _suggestionBridge =
166 base::MakeUnique<ContentSuggestionsServiceBridge>(self, contentService); 173 base::MakeUnique<ContentSuggestionsServiceBridge>(self, contentService);
167 _contentService = contentService; 174 _contentService = contentService;
168 _sectionInformationByCategory = [[NSMutableDictionary alloc] init]; 175 _sectionInformationByCategory = [[NSMutableDictionary alloc] init];
176 _attributesProvider = [[FaviconAttributesProvider alloc]
177 initWithFaviconSize:kDefaultFaviconSize
178 minFaviconSize:1
lpromero 2017/03/29 13:32:07 That's small, isn't it? Or why not 0?
gambard 2017/03/30 08:07:11 The idea is "the smallest possible if you have one
179 largeIconService:largeIconService];
169 } 180 }
170 return self; 181 return self;
171 } 182 }
172 183
173 - (void)dismissSuggestion:(ContentSuggestionIdentifier*)suggestionIdentifier { 184 - (void)dismissSuggestion:(ContentSuggestionIdentifier*)suggestionIdentifier {
174 ContentSuggestionsCategoryWrapper* categoryWrapper = 185 ContentSuggestionsCategoryWrapper* categoryWrapper =
175 [self categoryWrapperForSectionInfo:suggestionIdentifier.sectionInfo]; 186 [self categoryWrapperForSectionInfo:suggestionIdentifier.sectionInfo];
176 ntp_snippets::ContentSuggestion::ID suggestion_id = 187 ntp_snippets::ContentSuggestion::ID suggestion_id =
177 ntp_snippets::ContentSuggestion::ID([categoryWrapper category], 188 ntp_snippets::ContentSuggestion::ID([categoryWrapper category],
178 suggestionIdentifier.IDInSection); 189 suggestionIdentifier.IDInSection);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 [NSMutableArray array]; 388 [NSMutableArray array];
378 ntp_snippets::Category category = suggestions[0].id().category(); 389 ntp_snippets::Category category = suggestions[0].id().category();
379 [self addSuggestions:suggestions 390 [self addSuggestions:suggestions
380 fromCategory:category 391 fromCategory:category
381 toArray:contentSuggestions]; 392 toArray:contentSuggestions];
382 callback(contentSuggestions); 393 callback(contentSuggestions);
383 } 394 }
384 } 395 }
385 396
386 @end 397 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698