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

Side by Side Diff: components/ntp_snippets/snippet.h

Issue 2059203002: Add ContentSuggestion, ContentSuggestionCategory and ContentSuggestionProviderType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed comments and copyright headers in NTPSnippet, NTPSnippetsService and new Snippet classes, rem… Created 4 years, 6 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
(Empty)
1 // Copyright 2016 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 #ifndef COMPONENTS_NTP_SNIPPETS_SNIPPET_H_
6 #define COMPONENTS_NTP_SNIPPETS_SNIPPET_H_
7
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 #include "base/macros.h"
13 #include "base/time/time.h"
14 #include "components/ntp_snippets/snippet_category.h"
15 #include "components/ntp_snippets/snippet_provider_type.h"
16 #include "url/gurl.h"
17
18 namespace ntp_snippets {
19
20 // A snippet for the new tab page, which can be an article, an offline page or
21 // a snippet from another source.
Marc Treib 2016/06/13 15:11:10 nit: I wouldn't say "source", since that term is t
Philipp Keck 2016/06/13 15:27:50 Done.
22 class Snippet {
23 public:
24 using PtrVector = std::vector<std::unique_ptr<Snippet>>;
25
26 // Creates a new snippet with the given |id|.
27 Snippet(const std::string& id,
28 const SnippetProviderType provider,
29 const SnippetCategory category);
Marc Treib 2016/06/13 15:11:10 Is the idea here to pass in all strictly-required
Philipp Keck 2016/06/13 15:27:50 If the two enum values are not passed in, they nee
Marc Treib 2016/06/13 15:30:42 No, initializing to 0 doesn't seem like a good ide
Philipp Keck 2016/06/13 15:38:56 Maybe also the title, as it doesn't make much sens
Marc Treib 2016/06/13 15:54:35 text_extract will definitely be optional (since Of
Philipp Keck 2016/06/13 16:12:20 I will go by your previous suggestion. The constru
30
31 ~Snippet();
32
33 // An ID for identifying the snippet. The ID is unique among all snippets
34 // from the same provider, so to determine a globally unique identifier,
35 // combine this ID with the provider type.
36 const std::string& id() const { return id_; }
37
38 // The provider that created this snippet.
39 SnippetProviderType provider() const { return provider_; }
40
41 // The category that this snippet belongs to.
42 SnippetCategory category() const { return category_; }
43 void set_category(const SnippetCategory category) { category_ = category; }
Marc Treib 2016/06/13 15:11:10 I think this setter isn't required?
Philipp Keck 2016/06/13 15:27:50 Depends on decision above.
Philipp Keck 2016/06/13 16:12:20 Done.
44
45 // The normal content URL where the content referenced by the snippet can be
46 // accessed.
47 const GURL& url() const { return url_; }
48 void set_url(const GURL& url) { url_ = url; }
49
50 // If available, this contains an URL to an AMP version of the same content.
51 // Otherwise, this is an empty GURL().
52 const GURL& amp_url() const { return amp_url_; }
53 void set_amp_url(const GURL& amp_url) { amp_url_ = amp_url; }
54
55 // Title of the snippet.
56 const std::string& title() const { return title_; }
57 void set_title(const std::string& title) { title_ = title; }
58
59 // Summary or relevant extract from the content.
60 const std::string& text_extract() const { return text_extract_; }
61 void set_text_extract(const std::string& text_extract) {
62 text_extract_ = text_extract;
63 }
64
65 // The time when the content represented by this snippet was published.
66 const base::Time& publish_date() const { return publish_date_; }
67 void set_publish_date(const base::Time& publish_date) {
68 publish_date_ = publish_date;
69 }
70
71 // The name of the source/publisher of this snippet.
72 const std::string& publisher_name() const { return publisher_name_; }
73 void set_publisher_name(const std::string& publisher_name) {
74 publisher_name_ = publisher_name;
75 }
76
77 // TODO(pke) Remove the score from the Snippet class. The UI only uses
78 // it to track user clicks (histogram data). Instead, the providers should
79 // be informed about clicks and do appropriate logging themselves.
80 // IMPORTANT: The score may simply be 0 for snippets from providers which
81 // cannot provide score values.
82 float score() const { return score_; }
83 void set_score(float score) { score_ = score; }
84
85 private:
86 std::string id_;
87 SnippetProviderType provider_;
88 SnippetCategory category_;
89 GURL url_;
90 GURL amp_url_;
91 std::string title_;
92 std::string text_extract_;
93 GURL salient_image_url_;
94 base::Time publish_date_;
95 std::string publisher_name_;
96 float score_;
97
98 DISALLOW_COPY_AND_ASSIGN(Snippet);
99 };
100
101 } // namespace ntp_snippets
102
103 #endif // COMPONENTS_NTP_SNIPPETS_SNIPPET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698