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

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

Issue 2798563002: Add MostVistedSites to ContentSuggestionsMediator (Closed)
Patch Set: Reviewable 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
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/mediator_util.h" 5 #import "ios/chrome/browser/content_suggestions/mediator_util.h"
6 6
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #include "components/ntp_snippets/category.h" 8 #include "components/ntp_snippets/category.h"
9 #include "components/ntp_tiles/metrics.h"
10 #include "components/rappor/rappor_service_impl.h"
11 #include "ios/chrome/browser/application_context.h"
9 #import "ios/chrome/browser/content_suggestions/content_suggestions_category_wra pper.h" 12 #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" 13 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h"
11 #include "ios/chrome/grit/ios_strings.h" 14 #include "ios/chrome/grit/ios_strings.h"
12 #include "ui/base/l10n/l10n_util_mac.h" 15 #include "ui/base/l10n/l10n_util_mac.h"
13 16
14 #if !defined(__has_feature) || !__has_feature(objc_arc) 17 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support." 18 #error "This file requires ARC support."
16 #endif 19 #endif
17 20
18 void BindWrapper( 21 void BindWrapper(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 sectionInfo.title = base::SysUTF16ToNSString(categoryInfo->title()); 94 sectionInfo.title = base::SysUTF16ToNSString(categoryInfo->title());
92 } 95 }
93 return sectionInfo; 96 return sectionInfo;
94 } 97 }
95 98
96 ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID( 99 ntp_snippets::ContentSuggestion::ID SuggestionIDForSectionID(
97 ContentSuggestionsCategoryWrapper* category, 100 ContentSuggestionsCategoryWrapper* category,
98 const std::string& id_in_category) { 101 const std::string& id_in_category) {
99 return ntp_snippets::ContentSuggestion::ID(category.category, id_in_category); 102 return ntp_snippets::ContentSuggestion::ID(category.category, id_in_category);
100 } 103 }
104
105 ContentSuggestion* EmptySuggestion() {
106 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init];
107 suggestion.type = ContentSuggestionTypeEmpty;
108 suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init];
109
110 return suggestion;
111 }
112
113 ContentSuggestionsSectionInformation* MostVisitedSectionInformation() {
114 ContentSuggestionsSectionInformation* sectionInfo =
115 [[ContentSuggestionsSectionInformation alloc]
116 initWithSectionID:ContentSuggestionsSectionMostVisited];
117 sectionInfo.title = nil;
118 sectionInfo.footerTitle = nil;
119 sectionInfo.showIfEmpty = NO;
120 sectionInfo.layout = ContentSuggestionsSectionLayoutCustom;
121
122 return sectionInfo;
123 }
124
125 void RecordPageImpression(const ntp_tiles::NTPTilesVector& mostVisited) {
126 std::vector<ntp_tiles::metrics::TileImpression> tiles;
127 for (const ntp_tiles::NTPTile& ntpTile : mostVisited) {
128 tiles.emplace_back(ntpTile.source, ntp_tiles::metrics::UNKNOWN_TILE_TYPE,
129 ntpTile.url);
130 }
131 ntp_tiles::metrics::RecordPageImpression(
132 tiles, GetApplicationContext()->GetRapporServiceImpl());
133 }
134
135 ContentSuggestion* ConvertNTPTile(const ntp_tiles::NTPTile& tile) {
136 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init];
137
138 suggestion.title = base::SysUTF16ToNSString(tile.title);
139 suggestion.url = tile.url;
140 suggestion.type = ContentSuggestionTypeMostVisited;
141
142 suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init];
143 suggestion.suggestionIdentifier.IDInSection = tile.url.spec();
144
145 return suggestion;
146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698