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

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

Issue 2798883002: Open Reading List on tap on More (Closed)
Patch Set: 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/favicon/core/large_icon_service.h"
12 #include "components/ntp_snippets/category.h" 12 #include "components/ntp_snippets/category.h"
13 #include "components/ntp_snippets/category_info.h" 13 #include "components/ntp_snippets/category_info.h"
14 #include "components/ntp_snippets/content_suggestion.h" 14 #include "components/ntp_snippets/content_suggestion.h"
15 #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"
16 #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/ui/content_suggestions/content_suggestion.h" 17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands. h"
18 #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"
19 #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"
20 #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"
21 #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"
22 #import "ios/chrome/browser/ui/favicon/favicon_attributes_provider.h" 23 #import "ios/chrome/browser/ui/favicon/favicon_attributes_provider.h"
23 #include "ios/chrome/grit/ios_strings.h" 24 #include "ios/chrome/grit/ios_strings.h"
24 #include "ui/base/l10n/l10n_util_mac.h" 25 #include "ui/base/l10n/l10n_util_mac.h"
25 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
26 27
27 #if !defined(__has_feature) || !__has_feature(objc_arc) 28 #if !defined(__has_feature) || !__has_feature(objc_arc)
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 (ContentSuggestionsSectionInformation*)sectionInfo; 164 (ContentSuggestionsSectionInformation*)sectionInfo;
164 165
165 @end 166 @end
166 167
167 @implementation ContentSuggestionsMediator 168 @implementation ContentSuggestionsMediator
168 169
169 @synthesize contentService = _contentService; 170 @synthesize contentService = _contentService;
170 @synthesize dataSink = _dataSink; 171 @synthesize dataSink = _dataSink;
171 @synthesize sectionInformationByCategory = _sectionInformationByCategory; 172 @synthesize sectionInformationByCategory = _sectionInformationByCategory;
172 @synthesize attributesProvider = _attributesProvider; 173 @synthesize attributesProvider = _attributesProvider;
174 @synthesize commandHandler = _commandHandler;
173 175
174 #pragma mark - Public 176 #pragma mark - Public
175 177
176 - (instancetype) 178 - (instancetype)
177 initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService 179 initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService
178 largeIconService:(favicon::LargeIconService*)largeIconService { 180 largeIconService:(favicon::LargeIconService*)largeIconService {
179 self = [super init]; 181 self = [super init];
180 if (self) { 182 if (self) {
181 _suggestionBridge = 183 _suggestionBridge =
182 base::MakeUnique<ContentSuggestionsServiceBridge>(self, contentService); 184 base::MakeUnique<ContentSuggestionsServiceBridge>(self, contentService);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 std::set<std::string> known_suggestion_ids; 242 std::set<std::string> known_suggestion_ids;
241 for (ContentSuggestionIdentifier* identifier in knownSuggestions) { 243 for (ContentSuggestionIdentifier* identifier in knownSuggestions) {
242 if (identifier.sectionInfo != sectionInfo) 244 if (identifier.sectionInfo != sectionInfo)
243 continue; 245 continue;
244 known_suggestion_ids.insert(identifier.IDInSection); 246 known_suggestion_ids.insert(identifier.IDInSection);
245 } 247 }
246 248
247 ContentSuggestionsCategoryWrapper* wrapper = 249 ContentSuggestionsCategoryWrapper* wrapper =
248 [self categoryWrapperForSectionInfo:sectionInfo]; 250 [self categoryWrapperForSectionInfo:sectionInfo];
249 251
250 __weak ContentSuggestionsMediator* weakSelf = self; 252 base::Optional<ntp_snippets::CategoryInfo> categoryInfo =
251 ntp_snippets::FetchDoneCallback serviceCallback = base::Bind( 253 self.contentService->GetCategoryInfo([wrapper category]);
252 &BindWrapper,
253 base::BindBlockArc(^void(
254 ntp_snippets::Status status,
255 const std::vector<ntp_snippets::ContentSuggestion>& suggestions) {
256 [weakSelf didFetchMoreSuggestions:suggestions
257 withStatusCode:status
258 callback:callback];
259 }));
260 254
261 self.contentService->Fetch([wrapper category], known_suggestion_ids, 255 if (categoryInfo) {
stkhapugin 2017/04/05 13:06:02 nit: if (!categoryInfo) { return; } // to avoid id
gambard 2017/04/05 15:30:17 Done.
262 serviceCallback); 256 switch (categoryInfo->additional_action()) {
257 case ntp_snippets::ContentSuggestionsAdditionalAction::NONE:
258 return;
259
260 case ntp_snippets::ContentSuggestionsAdditionalAction::VIEW_ALL:
261 if ([wrapper category].IsKnownCategory(
262 ntp_snippets::KnownCategories::READING_LIST)) {
263 [self.commandHandler openReadingList];
264 }
265 break;
266
267 case ntp_snippets::ContentSuggestionsAdditionalAction::FETCH: {
268 __weak ContentSuggestionsMediator* weakSelf = self;
269 ntp_snippets::FetchDoneCallback serviceCallback =
270 base::Bind(&BindWrapper,
271 base::BindBlockArc(^void(
272 ntp_snippets::Status status,
273 const std::vector<ntp_snippets::ContentSuggestion>&
274 suggestions) {
275 [weakSelf didFetchMoreSuggestions:suggestions
276 withStatusCode:status
277 callback:callback];
278 }));
279
280 self.contentService->Fetch([wrapper category], known_suggestion_ids,
281 serviceCallback);
stkhapugin 2017/04/05 13:06:02 break;
gambard 2017/04/05 15:30:17 Done.
282 }
283 }
284 }
263 } 285 }
264 286
265 - (void)fetchFaviconAttributesForURL:(const GURL&)URL 287 - (void)fetchFaviconAttributesForURL:(const GURL&)URL
266 completion:(void (^)(FaviconAttributes*))completion { 288 completion:(void (^)(FaviconAttributes*))completion {
267 [self.attributesProvider fetchFaviconAttributesForURL:URL 289 [self.attributesProvider fetchFaviconAttributesForURL:URL
268 completion:completion]; 290 completion:completion];
269 } 291 }
270 292
271 #pragma mark - ContentSuggestionsServiceObserver 293 #pragma mark - ContentSuggestionsServiceObserver
272 294
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 [NSMutableArray array]; 431 [NSMutableArray array];
410 ntp_snippets::Category category = suggestions[0].id().category(); 432 ntp_snippets::Category category = suggestions[0].id().category();
411 [self addSuggestions:suggestions 433 [self addSuggestions:suggestions
412 fromCategory:category 434 fromCategory:category
413 toArray:contentSuggestions]; 435 toArray:contentSuggestions];
414 callback(contentSuggestions); 436 callback(contentSuggestions);
415 } 437 }
416 } 438 }
417 439
418 @end 440 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698