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

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: Address comments 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
« no previous file with comments | « ios/chrome/browser/content_suggestions/content_suggestions_mediator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "components/ntp_snippets/category.h" 11 #include "components/ntp_snippets/category.h"
12 #include "components/ntp_snippets/category_info.h" 12 #include "components/ntp_snippets/category_info.h"
13 #include "components/ntp_snippets/content_suggestion.h" 13 #include "components/ntp_snippets/content_suggestion.h"
14 #import "ios/chrome/browser/content_suggestions/content_suggestions_category_wra pper.h" 14 #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" 15 #import "ios/chrome/browser/content_suggestions/content_suggestions_service_brid ge_observer.h"
16 #import "ios/chrome/browser/content_suggestions/mediator_util.h" 16 #import "ios/chrome/browser/content_suggestions/mediator_util.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 "ui/gfx/image/image.h" 24 #include "ui/gfx/image/image.h"
24 25
25 #if !defined(__has_feature) || !__has_feature(objc_arc) 26 #if !defined(__has_feature) || !__has_feature(objc_arc)
26 #error "This file requires ARC support." 27 #error "This file requires ARC support."
27 #endif 28 #endif
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 (ContentSuggestionsSectionInformation*)sectionInfo; 66 (ContentSuggestionsSectionInformation*)sectionInfo;
66 67
67 @end 68 @end
68 69
69 @implementation ContentSuggestionsMediator 70 @implementation ContentSuggestionsMediator
70 71
71 @synthesize contentService = _contentService; 72 @synthesize contentService = _contentService;
72 @synthesize dataSink = _dataSink; 73 @synthesize dataSink = _dataSink;
73 @synthesize sectionInformationByCategory = _sectionInformationByCategory; 74 @synthesize sectionInformationByCategory = _sectionInformationByCategory;
74 @synthesize attributesProvider = _attributesProvider; 75 @synthesize attributesProvider = _attributesProvider;
76 @synthesize commandHandler = _commandHandler;
75 77
76 #pragma mark - Public 78 #pragma mark - Public
77 79
78 - (instancetype) 80 - (instancetype)
79 initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService 81 initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService
80 largeIconService:(favicon::LargeIconService*)largeIconService { 82 largeIconService:(favicon::LargeIconService*)largeIconService {
81 self = [super init]; 83 self = [super init];
82 if (self) { 84 if (self) {
83 _suggestionBridge = 85 _suggestionBridge =
84 base::MakeUnique<ContentSuggestionsServiceBridge>(self, contentService); 86 base::MakeUnique<ContentSuggestionsServiceBridge>(self, contentService);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 std::set<std::string> known_suggestion_ids; 144 std::set<std::string> known_suggestion_ids;
143 for (ContentSuggestionIdentifier* identifier in knownSuggestions) { 145 for (ContentSuggestionIdentifier* identifier in knownSuggestions) {
144 if (identifier.sectionInfo != sectionInfo) 146 if (identifier.sectionInfo != sectionInfo)
145 continue; 147 continue;
146 known_suggestion_ids.insert(identifier.IDInSection); 148 known_suggestion_ids.insert(identifier.IDInSection);
147 } 149 }
148 150
149 ContentSuggestionsCategoryWrapper* wrapper = 151 ContentSuggestionsCategoryWrapper* wrapper =
150 [self categoryWrapperForSectionInfo:sectionInfo]; 152 [self categoryWrapperForSectionInfo:sectionInfo];
151 153
152 __weak ContentSuggestionsMediator* weakSelf = self; 154 base::Optional<ntp_snippets::CategoryInfo> categoryInfo =
153 ntp_snippets::FetchDoneCallback serviceCallback = base::Bind( 155 self.contentService->GetCategoryInfo([wrapper category]);
154 &BindWrapper,
155 base::BindBlockArc(^void(
156 ntp_snippets::Status status,
157 const std::vector<ntp_snippets::ContentSuggestion>& suggestions) {
158 [weakSelf didFetchMoreSuggestions:suggestions
159 withStatusCode:status
160 callback:callback];
161 }));
162 156
163 self.contentService->Fetch([wrapper category], known_suggestion_ids, 157 if (!categoryInfo) {
164 serviceCallback); 158 return;
159 }
160 switch (categoryInfo->additional_action()) {
161 case ntp_snippets::ContentSuggestionsAdditionalAction::NONE:
162 return;
163
164 case ntp_snippets::ContentSuggestionsAdditionalAction::VIEW_ALL:
165 if ([wrapper category].IsKnownCategory(
166 ntp_snippets::KnownCategories::READING_LIST)) {
167 [self.commandHandler openReadingList];
168 }
169 break;
170
171 case ntp_snippets::ContentSuggestionsAdditionalAction::FETCH: {
172 __weak ContentSuggestionsMediator* weakSelf = self;
173 ntp_snippets::FetchDoneCallback serviceCallback = base::Bind(
174 &BindWrapper,
175 base::BindBlockArc(^void(
176 ntp_snippets::Status status,
177 const std::vector<ntp_snippets::ContentSuggestion>& suggestions) {
178 [weakSelf didFetchMoreSuggestions:suggestions
179 withStatusCode:status
180 callback:callback];
181 }));
182
183 self.contentService->Fetch([wrapper category], known_suggestion_ids,
184 serviceCallback);
185
186 break;
187 }
188 }
165 } 189 }
166 190
167 - (void)fetchFaviconAttributesForURL:(const GURL&)URL 191 - (void)fetchFaviconAttributesForURL:(const GURL&)URL
168 completion:(void (^)(FaviconAttributes*))completion { 192 completion:(void (^)(FaviconAttributes*))completion {
169 [self.attributesProvider fetchFaviconAttributesForURL:URL 193 [self.attributesProvider fetchFaviconAttributesForURL:URL
170 completion:completion]; 194 completion:completion];
171 } 195 }
172 196
173 #pragma mark - ContentSuggestionsServiceObserver 197 #pragma mark - ContentSuggestionsServiceObserver
174 198
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 [NSMutableArray array]; 335 [NSMutableArray array];
312 ntp_snippets::Category category = suggestions[0].id().category(); 336 ntp_snippets::Category category = suggestions[0].id().category();
313 [self addSuggestions:suggestions 337 [self addSuggestions:suggestions
314 fromCategory:category 338 fromCategory:category
315 toArray:contentSuggestions]; 339 toArray:contentSuggestions];
316 callback(contentSuggestions); 340 callback(contentSuggestions);
317 } 341 }
318 } 342 }
319 343
320 @end 344 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/content_suggestions/content_suggestions_mediator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698