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

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

Issue 2736653002: Suggested Articles can be dismissed (Closed)
Patch Set: Address comments Created 3 years, 9 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"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 (ContentSuggestionsSectionInformation*)sectionInfo; 126 (ContentSuggestionsSectionInformation*)sectionInfo;
127 127
128 @end 128 @end
129 129
130 @implementation ContentSuggestionsMediator 130 @implementation ContentSuggestionsMediator
131 131
132 @synthesize contentService = _contentService; 132 @synthesize contentService = _contentService;
133 @synthesize dataSink = _dataSink; 133 @synthesize dataSink = _dataSink;
134 @synthesize sectionInformationByCategory = _sectionInformationByCategory; 134 @synthesize sectionInformationByCategory = _sectionInformationByCategory;
135 135
136 #pragma mark - Public
137
136 - (instancetype)initWithContentService: 138 - (instancetype)initWithContentService:
137 (ntp_snippets::ContentSuggestionsService*)contentService { 139 (ntp_snippets::ContentSuggestionsService*)contentService {
138 self = [super init]; 140 self = [super init];
139 if (self) { 141 if (self) {
140 _suggestionBridge = 142 _suggestionBridge =
141 base::MakeUnique<ContentSuggestionsServiceBridge>(self, contentService); 143 base::MakeUnique<ContentSuggestionsServiceBridge>(self, contentService);
142 _contentService = contentService; 144 _contentService = contentService;
143 _sectionInformationByCategory = [[NSMutableDictionary alloc] init]; 145 _sectionInformationByCategory = [[NSMutableDictionary alloc] init];
144 } 146 }
145 return self; 147 return self;
146 } 148 }
147 149
150 - (void)dismissSuggestion:(ContentSuggestionIdentifier*)suggestionIdentifier {
151 ContentSuggestionsCategoryWrapper* categoryWrapper =
152 [self categoryWrapperForSectionInfo:suggestionIdentifier.sectionInfo];
153 ntp_snippets::ContentSuggestion::ID suggestion_id =
154 ntp_snippets::ContentSuggestion::ID([categoryWrapper category],
155 suggestionIdentifier.IDInSection);
156
157 self.contentService->DismissSuggestion(suggestion_id);
158 }
159
148 #pragma mark - ContentSuggestionsDataSource 160 #pragma mark - ContentSuggestionsDataSource
149 161
150 - (NSArray<ContentSuggestion*>*)allSuggestions { 162 - (NSArray<ContentSuggestion*>*)allSuggestions {
151 std::vector<ntp_snippets::Category> categories = 163 std::vector<ntp_snippets::Category> categories =
152 self.contentService->GetCategories(); 164 self.contentService->GetCategories();
153 NSMutableArray<ContentSuggestion*>* dataHolders = [NSMutableArray array]; 165 NSMutableArray<ContentSuggestion*>* dataHolders = [NSMutableArray array];
154 for (auto& category : categories) { 166 for (auto& category : categories) {
155 if (self.contentService->GetCategoryStatus(category) != 167 if (self.contentService->GetCategoryStatus(category) !=
156 ntp_snippets::CategoryStatus::AVAILABLE) { 168 ntp_snippets::CategoryStatus::AVAILABLE) {
157 continue; 169 continue;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 wrapperWithCategory:category]] = sectionInfo; 254 wrapperWithCategory:category]] = sectionInfo;
243 } 255 }
244 256
245 - (ContentSuggestionsCategoryWrapper*)categoryWrapperForSectionInfo: 257 - (ContentSuggestionsCategoryWrapper*)categoryWrapperForSectionInfo:
246 (ContentSuggestionsSectionInformation*)sectionInfo { 258 (ContentSuggestionsSectionInformation*)sectionInfo {
247 return [[self.sectionInformationByCategory allKeysForObject:sectionInfo] 259 return [[self.sectionInformationByCategory allKeysForObject:sectionInfo]
248 firstObject]; 260 firstObject];
249 } 261 }
250 262
251 @end 263 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698