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

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

Issue 2708623002: Add an ID to the ContentSuggestion (Closed)
Patch Set: Add tests Created 3 years, 10 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 | « no previous file | ios/chrome/browser/ui/content_suggestions/BUILD.gn » ('j') | 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 "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 #include "components/ntp_snippets/category.h" 11 #include "components/ntp_snippets/category.h"
12 #include "components/ntp_snippets/content_suggestion.h" 12 #include "components/ntp_snippets/content_suggestion.h"
13 #import "ios/chrome/browser/content_suggestions/content_suggestions_category_wra pper.h" 13 #import "ios/chrome/browser/content_suggestions/content_suggestions_category_wra pper.h"
14 #import "ios/chrome/browser/content_suggestions/content_suggestions_service_brid ge_observer.h" 14 #import "ios/chrome/browser/content_suggestions/content_suggestions_service_brid ge_observer.h"
15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" 15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion_identifier .h"
16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h" 17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h"
17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_i nformation.h" 18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_i nformation.h"
18 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
19 20
20 #if !defined(__has_feature) || !__has_feature(objc_arc) 21 #if !defined(__has_feature) || !__has_feature(objc_arc)
21 #error "This file requires ARC support." 22 #error "This file requires ARC support."
22 #endif 23 #endif
23 24
24 namespace { 25 namespace {
25 26
(...skipping 19 matching lines...) Expand all
45 ntp_snippets::ContentSuggestionsCardLayout layout) { 46 ntp_snippets::ContentSuggestionsCardLayout layout) {
46 // For now, only cards are relevant. 47 // For now, only cards are relevant.
47 return ContentSuggestionsSectionLayoutCard; 48 return ContentSuggestionsSectionLayoutCard;
48 } 49 }
49 50
50 // Converts a ntp_snippets::ContentSuggestion to an Objective-C 51 // Converts a ntp_snippets::ContentSuggestion to an Objective-C
51 // ContentSuggestion. 52 // ContentSuggestion.
52 ContentSuggestion* ConvertContentSuggestion( 53 ContentSuggestion* ConvertContentSuggestion(
53 const ntp_snippets::ContentSuggestion& contentSuggestion) { 54 const ntp_snippets::ContentSuggestion& contentSuggestion) {
54 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init]; 55 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init];
56
55 suggestion.title = base::SysUTF16ToNSString(contentSuggestion.title()); 57 suggestion.title = base::SysUTF16ToNSString(contentSuggestion.title());
56 suggestion.text = base::SysUTF16ToNSString(contentSuggestion.snippet_text()); 58 suggestion.text = base::SysUTF16ToNSString(contentSuggestion.snippet_text());
57 suggestion.url = contentSuggestion.url(); 59 suggestion.url = contentSuggestion.url();
60
58 suggestion.publisher = 61 suggestion.publisher =
59 base::SysUTF16ToNSString(contentSuggestion.publisher_name()); 62 base::SysUTF16ToNSString(contentSuggestion.publisher_name());
60 suggestion.publishDate = contentSuggestion.publish_date(); 63 suggestion.publishDate = contentSuggestion.publish_date();
61 64
65 suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init];
66 suggestion.suggestionIdentifier.IDInSection =
67 contentSuggestion.id().id_within_category();
68
62 return suggestion; 69 return suggestion;
63 } 70 }
64 71
65 // Returns a SectionInformation for a |category|, filled with the 72 // Returns a SectionInformation for a |category|, filled with the
66 // |categoryInfo|. 73 // |categoryInfo|.
67 ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo( 74 ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo(
68 const base::Optional<ntp_snippets::CategoryInfo>& categoryInfo, 75 const base::Optional<ntp_snippets::CategoryInfo>& categoryInfo,
69 const ntp_snippets::Category& category) { 76 const ntp_snippets::Category& category) {
70 ContentSuggestionsSectionInformation* sectionInfo = 77 ContentSuggestionsSectionInformation* sectionInfo =
71 [[ContentSuggestionsSectionInformation alloc] 78 [[ContentSuggestionsSectionInformation alloc]
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 187
181 - (void)addContentInCategory:(ntp_snippets::Category&)category 188 - (void)addContentInCategory:(ntp_snippets::Category&)category
182 toArray:(NSMutableArray<ContentSuggestion*>*)contentArray { 189 toArray:(NSMutableArray<ContentSuggestion*>*)contentArray {
183 const std::vector<ntp_snippets::ContentSuggestion>& suggestions = 190 const std::vector<ntp_snippets::ContentSuggestion>& suggestions =
184 self.contentService->GetSuggestionsForCategory(category); 191 self.contentService->GetSuggestionsForCategory(category);
185 ContentSuggestionsCategoryWrapper* categoryWrapper = 192 ContentSuggestionsCategoryWrapper* categoryWrapper =
186 [[ContentSuggestionsCategoryWrapper alloc] initWithCategory:category]; 193 [[ContentSuggestionsCategoryWrapper alloc] initWithCategory:category];
187 for (auto& contentSuggestion : suggestions) { 194 for (auto& contentSuggestion : suggestions) {
188 ContentSuggestion* suggestion = ConvertContentSuggestion(contentSuggestion); 195 ContentSuggestion* suggestion = ConvertContentSuggestion(contentSuggestion);
189 suggestion.type = TypeForCategory(category); 196 suggestion.type = TypeForCategory(category);
190 suggestion.section = self.sectionInformationByCategory[categoryWrapper]; 197 suggestion.suggestionIdentifier.sectionInfo =
198 self.sectionInformationByCategory[categoryWrapper];
191 199
192 // TODO(crbug.com/686728): fetch the image. 200 // TODO(crbug.com/686728): fetch the image.
193 201
194 [contentArray addObject:suggestion]; 202 [contentArray addObject:suggestion];
195 } 203 }
196 } 204 }
197 205
198 - (void)addSectionInformationForCategory:(ntp_snippets::Category)category { 206 - (void)addSectionInformationForCategory:(ntp_snippets::Category)category {
199 base::Optional<ntp_snippets::CategoryInfo> categoryInfo = 207 base::Optional<ntp_snippets::CategoryInfo> categoryInfo =
200 self.contentService->GetCategoryInfo(category); 208 self.contentService->GetCategoryInfo(category);
201 209
202 ContentSuggestionsSectionInformation* sectionInfo = 210 ContentSuggestionsSectionInformation* sectionInfo =
203 SectionInformationFromCategoryInfo(categoryInfo, category); 211 SectionInformationFromCategoryInfo(categoryInfo, category);
204 212
205 self.sectionInformationByCategory[[ContentSuggestionsCategoryWrapper 213 self.sectionInformationByCategory[[ContentSuggestionsCategoryWrapper
206 wrapperWithCategory:category]] = sectionInfo; 214 wrapperWithCategory:category]] = sectionInfo;
207 } 215 }
208 216
209 @end 217 @end
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/browser/ui/content_suggestions/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698