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

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

Issue 2790363002: Move C functions out of ContentSuggestionsMediator (Closed)
Patch Set: Fix line break 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/mediator_util.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/content_suggestions/mediator_util.h"
6
7 #include "base/strings/sys_string_conversions.h"
8 #include "components/ntp_snippets/category.h"
9 #import "ios/chrome/browser/content_suggestions/content_suggestions_category_wra pper.h"
10 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h"
11 #include "ios/chrome/grit/ios_strings.h"
12 #include "ui/base/l10n/l10n_util_mac.h"
13
14 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support."
16 #endif
17
18 void BindWrapper(
19 base::Callback<void(ntp_snippets::Status status_code,
20 const std::vector<ntp_snippets::ContentSuggestion>&
21 suggestions)> callback,
22 ntp_snippets::Status status_code,
23 std::vector<ntp_snippets::ContentSuggestion> suggestions) {
24 if (callback) {
25 callback.Run(status_code, suggestions);
26 }
27 }
28
29 ContentSuggestionType TypeForCategory(ntp_snippets::Category category) {
30 if (category.IsKnownCategory(ntp_snippets::KnownCategories::ARTICLES))
31 return ContentSuggestionTypeArticle;
32 if (category.IsKnownCategory(ntp_snippets::KnownCategories::READING_LIST))
33 return ContentSuggestionTypeReadingList;
34
35 return ContentSuggestionTypeEmpty;
36 }
37
38 ContentSuggestionsSectionID SectionIDForCategory(
39 ntp_snippets::Category category) {
40 if (category.IsKnownCategory(ntp_snippets::KnownCategories::BOOKMARKS))
41 return ContentSuggestionsSectionBookmarks;
42 if (category.IsKnownCategory(ntp_snippets::KnownCategories::ARTICLES))
43 return ContentSuggestionsSectionArticles;
44 if (category.IsKnownCategory(ntp_snippets::KnownCategories::READING_LIST))
45 return ContentSuggestionsSectionReadingList;
46
47 return ContentSuggestionsSectionUnknown;
48 }
49
50 ContentSuggestionsSectionLayout SectionLayoutForLayout(
51 ntp_snippets::ContentSuggestionsCardLayout layout) {
52 // For now, only cards are relevant.
53 return ContentSuggestionsSectionLayoutCard;
54 }
55
56 ContentSuggestion* ConvertContentSuggestion(
57 const ntp_snippets::ContentSuggestion& contentSuggestion) {
58 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init];
59
60 suggestion.title = base::SysUTF16ToNSString(contentSuggestion.title());
61 suggestion.text = base::SysUTF16ToNSString(contentSuggestion.snippet_text());
62 suggestion.url = contentSuggestion.url();
63
64 suggestion.publisher =
65 base::SysUTF16ToNSString(contentSuggestion.publisher_name());
66 suggestion.publishDate = contentSuggestion.publish_date();
67
68 suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init];
69 suggestion.suggestionIdentifier.IDInSection =
70 contentSuggestion.id().id_within_category();
71
72 return suggestion;
73 }
74
75 ContentSuggestionsSectionInformation* SectionInformationFromCategoryInfo(
76 const base::Optional<ntp_snippets::CategoryInfo>& categoryInfo,
77 const ntp_snippets::Category& category) {
78 ContentSuggestionsSectionInformation* sectionInfo =
79 [[ContentSuggestionsSectionInformation alloc]
80 initWithSectionID:SectionIDForCategory(category)];
81 if (categoryInfo) {
82 sectionInfo.layout = SectionLayoutForLayout(categoryInfo->card_layout());
83 sectionInfo.showIfEmpty = categoryInfo->show_if_empty();
84 sectionInfo.emptyText =
85 base::SysUTF16ToNSString(categoryInfo->no_suggestions_message());
86 if (categoryInfo->additional_action() !=
87 ntp_snippets::ContentSuggestionsAdditionalAction::NONE) {
88 sectionInfo.footerTitle =
89 l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_FOOTER_TITLE);
90 }
91 sectionInfo.title = base::SysUTF16ToNSString(categoryInfo->title());
92 }
93 return sectionInfo;
94 }
95
96 ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID(
97 ContentSuggestionsCategoryWrapper* category,
98 const std::string& id_in_category) {
99 return ntp_snippets::ContentSuggestion::ID(category.category, id_in_category);
100 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/content_suggestions/mediator_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698