1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTION_H_
#define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTION_H_
#include <memory>
#include <string>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "components/ntp_snippets/category.h"
#include "url/gurl.h"
namespace ntp_snippets {
// DownloadSuggestionExtra contains additional data which is only available for
// download suggestions.
struct DownloadSuggestionExtra {
DownloadSuggestionExtra();
DownloadSuggestionExtra(const DownloadSuggestionExtra&);
~DownloadSuggestionExtra();
// The GUID for the downloaded file.
std::string download_guid;
// The file path of the downloaded file once download completes.
base::FilePath target_file_path;
// The effective MIME type of downloaded content.
std::string mime_type;
// Underlying offline page identifier.
int64_t offline_page_id = 0;
// Whether or not the download suggestion is a downloaded asset.
// When this is true, |offline_page_id| is ignored, otherwise
// |target_file_path| and |mime_type| are ignored.
bool is_download_asset = false;
};
// Contains additional data which is only available for recent tab suggestions.
struct RecentTabSuggestionExtra {
// Corresponding tab identifier.
int tab_id;
// Underlying offline page identifier.
int64_t offline_page_id = 0;
};
// ReadingListSuggestionExtra contains additional data which is only available
// for Reading List suggestions.
struct ReadingListSuggestionExtra {
// State of the distillation of the suggestion.
bool distilled = false;
// URL of the page whose favicon should be displayed for this suggestion.
GURL favicon_page_url;
};
// Contains additional data for notification-worthy suggestions.
struct NotificationExtra {
// Deadline for showing notification. If the deadline is past, the
// notification is no longer fresh and no notification should be sent. If the
// deadline passes while a notification is up, it should be canceled.
base::Time deadline;
};
// A content suggestion for the new tab page, which can be an article or an
// offline page, for example.
class ContentSuggestion {
public:
class ID {
public:
ID(Category category, const std::string& id_within_category)
: category_(category), id_within_category_(id_within_category) {}
Category category() const { return category_; }
const std::string& id_within_category() const {
return id_within_category_;
}
bool operator==(const ID& rhs) const;
bool operator!=(const ID& rhs) const;
private:
Category category_;
std::string id_within_category_;
// Allow copy and assignment.
};
// Creates a new ContentSuggestion. The caller must ensure that the |id|
// passed in here is unique application-wide.
ContentSuggestion(const ID& id, const GURL& url);
ContentSuggestion(Category category,
const std::string& id_within_category,
const GURL& url);
ContentSuggestion(ContentSuggestion&&);
ContentSuggestion& operator=(ContentSuggestion&&);
~ContentSuggestion();
// An ID for identifying the suggestion. The ID is unique application-wide.
const ID& id() const { return id_; }
// The URL where the content referenced by the suggestion can be accessed.
// This may be an AMP URL.
const GURL& url() const { return url_; }
// The URL of the page that links to a favicon that represents the suggestion.
// Path is trimmed for the URL because the current favicon server backend
// prefers it this way.
GURL url_with_favicon() const {
return url_with_favicon_.is_valid() ? GetFaviconDomain(url_with_favicon_)
: GetFaviconDomain(url_);
}
void set_url_with_favicon(const GURL& url_with_favicon) {
url_with_favicon_ = url_with_favicon;
}
static GURL GetFaviconDomain(const GURL& favicon_url);
// Title of the suggestion.
const base::string16& title() const { return title_; }
void set_title(const base::string16& title) { title_ = title; }
// Summary or relevant textual extract from the content.
const base::string16& snippet_text() const { return snippet_text_; }
void set_snippet_text(const base::string16& snippet_text) {
snippet_text_ = snippet_text;
}
// The time when the content represented by this suggestion was published.
const base::Time& publish_date() const { return publish_date_; }
void set_publish_date(const base::Time& publish_date) {
publish_date_ = publish_date;
}
// The name of the source/publisher of this suggestion.
const base::string16& publisher_name() const { return publisher_name_; }
void set_publisher_name(const base::string16& publisher_name) {
publisher_name_ = publisher_name;
}
// TODO(pke): Remove the score from the ContentSuggestion class. The UI only
// uses it to track user clicks (histogram data). Instead, the providers
// should be informed about clicks and do appropriate logging themselves.
// IMPORTANT: The score may simply be 0 for suggestions from providers which
// cannot provide score values.
float score() const { return score_; }
void set_score(float score) { score_ = score; }
// Extra information for download suggestions. Only available for DOWNLOADS
// suggestions (i.e., if the associated category has the
// KnownCategories::DOWNLOADS id).
DownloadSuggestionExtra* download_suggestion_extra() const {
return download_suggestion_extra_.get();
}
void set_download_suggestion_extra(
std::unique_ptr<DownloadSuggestionExtra> download_suggestion_extra);
// Extra information for recent tab suggestions. Only available for
// KnownCategories::RECENT_TABS suggestions.
RecentTabSuggestionExtra* recent_tab_suggestion_extra() const {
return recent_tab_suggestion_extra_.get();
}
void set_recent_tab_suggestion_extra(
std::unique_ptr<RecentTabSuggestionExtra> recent_tab_suggestion_extra);
// Extra information for reading list suggestions. Only available for
// KnownCategories::READING_LIST suggestions.
ReadingListSuggestionExtra* reading_list_suggestion_extra() const {
return reading_list_suggestion_extra_.get();
}
void set_reading_list_suggestion_extra(
std::unique_ptr<ReadingListSuggestionExtra>
reading_list_suggestion_extra);
// Extra information for notifications. When absent, no notification should be
// sent for this suggestion. When present, a notification should be sent,
// unless other factors disallow it (examples: the extra parameters say to;
// notifications are disabled; Chrome is in the foreground).
NotificationExtra* notification_extra() const {
return notification_extra_.get();
}
void set_notification_extra(
std::unique_ptr<NotificationExtra> notification_extra);
const base::Time& fetch_date() const { return fetch_date_; }
void set_fetch_date(const base::Time& fetch_date) {
fetch_date_ = fetch_date;
}
private:
ID id_;
GURL url_;
GURL url_with_favicon_;
base::string16 title_;
base::string16 snippet_text_;
base::Time publish_date_;
base::string16 publisher_name_;
float score_;
std::unique_ptr<DownloadSuggestionExtra> download_suggestion_extra_;
std::unique_ptr<RecentTabSuggestionExtra> recent_tab_suggestion_extra_;
std::unique_ptr<ReadingListSuggestionExtra> reading_list_suggestion_extra_;
std::unique_ptr<NotificationExtra> notification_extra_;
// The time when the remote suggestion was fetched from the server. This field
// is only populated when the ContentSuggestion is created from a
// RemoteSuggestion.
base::Time fetch_date_;
DISALLOW_COPY_AND_ASSIGN(ContentSuggestion);
};
std::ostream& operator<<(std::ostream& os, const ContentSuggestion::ID& id);
} // namespace ntp_snippets
#endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTION_H_
|