Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <components/ntp_snippets/snippet_provider_type.h> | |
|
Marc Treib
2016/06/13 13:08:17
Remove this line
Philipp Keck
2016/06/13 14:13:14
Done.
| |
| 9 #include <memory> | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/time/time.h" | |
| 15 #include "components/ntp_snippets/snippet_category.h" | |
| 16 #include "components/ntp_snippets/snippet_provider_type.h" | |
| 17 #include "url/gurl.h" | |
| 18 | |
| 19 namespace ntp_snippets { | |
| 20 | |
| 21 // A snippet for the new tab page, which can be an article, an offline page or | |
| 22 // a snippet from another source. | |
| 23 class Snippet { | |
| 24 public: | |
| 25 using PtrVector = std::vector<std::unique_ptr<Snippet>>; | |
| 26 | |
| 27 // Creates a new snippet with the given |id|. | |
| 28 Snippet(const std::string& id, | |
| 29 const SnippetProviderType provider, | |
| 30 const SnippetCategory category); | |
| 31 | |
| 32 ~Snippet(); | |
| 33 | |
| 34 // An ID for identifying the snippet. The ID is unique among all snippets | |
| 35 // from the same provider, so to determine a globally unique identifier, | |
| 36 // combine this ID with the provider type. | |
| 37 const std::string& id() const { return id_; } | |
| 38 | |
| 39 // The provider that created this snippet. | |
| 40 SnippetProviderType provider() const { return provider_; } | |
| 41 | |
| 42 // The category that this snippet belongs to. | |
| 43 SnippetCategory category() const { return category_; } | |
| 44 void set_category(const SnippetCategory category) { category_ = category; } | |
| 45 | |
| 46 // The normal content URL where the content referenced by the snippet can be | |
| 47 // accessed. | |
| 48 const GURL& url() const { return url_; } | |
| 49 void set_url(const GURL& url) { url_ = url; } | |
| 50 | |
| 51 // If available, this contains an URL to an AMP version of the same content. | |
| 52 // Otherwise, this is an empty GURL(). | |
| 53 const GURL& amp_url() const { return amp_url_; } | |
| 54 void set_amp_url(const GURL& amp_url) { amp_url_ = amp_url; } | |
| 55 | |
| 56 // Title of the snippet. | |
| 57 const std::string& title() const { return title_; } | |
| 58 void set_title(const std::string& title) { title_ = title; } | |
| 59 | |
| 60 // Summary or relevant extract from the content. | |
| 61 const std::string& text_extract() const { return text_extract_; } | |
| 62 void set_text_extract(const std::string& text_extract) { | |
| 63 text_extract_ = text_extract; | |
| 64 } | |
| 65 | |
| 66 // Link to an image representative of the content. Do not fetch this image | |
| 67 // directly. | |
|
Marc Treib
2016/06/13 13:08:17
Hm, does the UI need to know about the image URL?
Philipp Keck
2016/06/13 14:13:14
That's right. If we leave it up to the providers t
Marc Treib
2016/06/13 15:11:10
Acknowledged.
| |
| 68 const GURL& salient_image_url() const { return salient_image_url_; } | |
| 69 void set_salient_image_url(const GURL& salient_image_url) { | |
| 70 salient_image_url_ = salient_image_url; | |
| 71 } | |
| 72 | |
| 73 // When the page pointed by this text_extract was published. | |
|
Marc Treib
2016/06/13 13:08:17
Er, what? How is this related to the text extract?
Philipp Keck
2016/06/13 14:13:14
Done.
| |
| 74 const base::Time& publish_date() const { return publish_date_; } | |
| 75 void set_publish_date(const base::Time& publish_date) { | |
| 76 publish_date_ = publish_date; | |
| 77 } | |
| 78 | |
| 79 const std::string& publisher_name() const { return publisher_name_; } | |
| 80 void set_publisher_name(const std::string& publisher_name) { | |
| 81 publisher_name_ = publisher_name; | |
| 82 } | |
| 83 | |
| 84 // TODO(pke) Remove the score from the Snippet class. The UI only uses | |
| 85 // it to track user clicks (histogram data). Instead, the providers should | |
| 86 // be informed about clicks and do appropriate logging themselves. | |
| 87 // IMPORTANT: The score may simply be 0 for text_extracts from providers which | |
|
Marc Treib
2016/06/13 13:08:17
Also here: Why text_extract?
Philipp Keck
2016/06/13 14:13:14
Done.
| |
| 88 // cannot provide score values. | |
| 89 float score() const { return score_; } | |
| 90 void set_score(float score) { score_ = score; } | |
| 91 | |
| 92 private: | |
| 93 std::string id_; | |
| 94 SnippetProviderType provider_; | |
| 95 SnippetCategory category_; | |
| 96 GURL url_; | |
| 97 GURL amp_url_; | |
| 98 std::string title_; | |
| 99 std::string text_extract_; | |
| 100 GURL salient_image_url_; | |
| 101 base::Time publish_date_; | |
| 102 std::string publisher_name_; | |
| 103 float score_; | |
| 104 | |
| 105 DISALLOW_COPY_AND_ASSIGN(Snippet); | |
| 106 }; | |
| 107 | |
| 108 } // namespace ntp_snippets | |
| 109 | |
| 110 #endif // COMPONENTS_NTP_SNIPPETS_SNIPPET_H_ | |
| OLD | NEW |