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

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

Issue 2708623002: Add an ID to the ContentSuggestion (Closed)
Patch Set: 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
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_id.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_item.h" 18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_item.h"
18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_i nformation.h" 19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_i nformation.h"
19 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
20 21
21 #if !defined(__has_feature) || !__has_feature(objc_arc) 22 #if !defined(__has_feature) || !__has_feature(objc_arc)
22 #error "This file requires ARC support." 23 #error "This file requires ARC support."
23 #endif 24 #endif
24 25
25 namespace { 26 namespace {
(...skipping 23 matching lines...) Expand all
49 } 50 }
50 51
51 // Converts a ntp_snippets::ContentSuggestion to an Objective-C 52 // Converts a ntp_snippets::ContentSuggestion to an Objective-C
52 // ContentSuggestion. 53 // ContentSuggestion.
53 ContentSuggestion* ConvertContentSuggestion( 54 ContentSuggestion* ConvertContentSuggestion(
54 const ntp_snippets::ContentSuggestion& contentSuggestion) { 55 const ntp_snippets::ContentSuggestion& contentSuggestion) {
55 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init]; 56 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init];
56 suggestion.title = base::SysUTF16ToNSString(contentSuggestion.title()); 57 suggestion.title = base::SysUTF16ToNSString(contentSuggestion.title());
57 suggestion.text = base::SysUTF16ToNSString(contentSuggestion.snippet_text()); 58 suggestion.text = base::SysUTF16ToNSString(contentSuggestion.snippet_text());
58 suggestion.url = contentSuggestion.url(); 59 suggestion.url = contentSuggestion.url();
60 suggestion.suggestionID = [[ContentSuggestionID alloc] init];
61 suggestion.suggestionID.IDInSection =
62 contentSuggestion.id().id_within_category();
lpromero 2017/02/21 10:33:34 Out of curiosity: Here the lingo goes from categor
gambard 2017/02/21 14:37:48 For me it makes sense because this class is making
59 63
60 return suggestion; 64 return suggestion;
61 } 65 }
62 66
63 // Returns a SectionInformation for a |category|, filled with the 67 // Returns a SectionInformation for a |category|, filled with the
64 // |categoryInfo|. 68 // |categoryInfo|.
65 ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo( 69 ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo(
66 const base::Optional<ntp_snippets::CategoryInfo>& categoryInfo, 70 const base::Optional<ntp_snippets::CategoryInfo>& categoryInfo,
67 const ntp_snippets::Category& category) { 71 const ntp_snippets::Category& category) {
68 ContentSuggestionsSectionInformation* sectionInfo = 72 ContentSuggestionsSectionInformation* sectionInfo =
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 182
179 - (void)addContentInCategory:(ntp_snippets::Category&)category 183 - (void)addContentInCategory:(ntp_snippets::Category&)category
180 toArray:(NSMutableArray<ContentSuggestion*>*)contentArray { 184 toArray:(NSMutableArray<ContentSuggestion*>*)contentArray {
181 const std::vector<ntp_snippets::ContentSuggestion>& suggestions = 185 const std::vector<ntp_snippets::ContentSuggestion>& suggestions =
182 self.contentService->GetSuggestionsForCategory(category); 186 self.contentService->GetSuggestionsForCategory(category);
183 ContentSuggestionsCategoryWrapper* categoryWrapper = 187 ContentSuggestionsCategoryWrapper* categoryWrapper =
184 [[ContentSuggestionsCategoryWrapper alloc] initWithCategory:category]; 188 [[ContentSuggestionsCategoryWrapper alloc] initWithCategory:category];
185 for (auto& contentSuggestion : suggestions) { 189 for (auto& contentSuggestion : suggestions) {
186 ContentSuggestion* suggestion = ConvertContentSuggestion(contentSuggestion); 190 ContentSuggestion* suggestion = ConvertContentSuggestion(contentSuggestion);
187 suggestion.type = TypeForCategory(category); 191 suggestion.type = TypeForCategory(category);
188 suggestion.section = self.sectionInformationByCategory[categoryWrapper]; 192 suggestion.suggestionID.sectionInfo =
193 self.sectionInformationByCategory[categoryWrapper];
189 194
190 // TODO(crbug.com/686728): fetch the image. 195 // TODO(crbug.com/686728): fetch the image.
191 196
192 [contentArray addObject:suggestion]; 197 [contentArray addObject:suggestion];
193 } 198 }
194 } 199 }
195 200
196 - (void)addSectionInformationForCategory:(ntp_snippets::Category)category { 201 - (void)addSectionInformationForCategory:(ntp_snippets::Category)category {
197 base::Optional<ntp_snippets::CategoryInfo> categoryInfo = 202 base::Optional<ntp_snippets::CategoryInfo> categoryInfo =
198 self.contentService->GetCategoryInfo(category); 203 self.contentService->GetCategoryInfo(category);
199 204
200 ContentSuggestionsSectionInformation* sectionInfo = 205 ContentSuggestionsSectionInformation* sectionInfo =
201 SectionInformationFromCategoryInfo(categoryInfo, category); 206 SectionInformationFromCategoryInfo(categoryInfo, category);
202 207
203 self.sectionInformationByCategory[[ContentSuggestionsCategoryWrapper 208 self.sectionInformationByCategory[[ContentSuggestionsCategoryWrapper
204 wrapperWithCategory:category]] = sectionInfo; 209 wrapperWithCategory:category]] = sectionInfo;
205 } 210 }
206 211
207 @end 212 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698