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 <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 or an offline page, | |
| 21 // for example. | |
| 22 class Snippet { | |
|
Marc Treib
2016/06/14 09:29:44
Could you add a comment here saying that this isn'
Philipp Keck
2016/06/14 09:35:50
Done.
| |
| 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, | |
| 30 const GURL& url); | |
| 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 | |
| 45 // The normal content URL where the content referenced by the snippet can be | |
| 46 // accessed. | |
| 47 const GURL& url() const { return url_; } | |
| 48 | |
| 49 // If available, this contains an URL to an AMP version of the same content. | |
| 50 // Otherwise, this is an empty GURL(). | |
| 51 const GURL& amp_url() const { return amp_url_; } | |
| 52 void set_amp_url(const GURL& amp_url) { amp_url_ = amp_url; } | |
| 53 | |
| 54 // Title of the snippet. | |
| 55 const std::string& title() const { return title_; } | |
| 56 void set_title(const std::string& title) { title_ = title; } | |
| 57 | |
| 58 // Summary or relevant extract from the content. | |
| 59 const std::string& text_extract() const { return text_extract_; } | |
| 60 void set_text_extract(const std::string& text_extract) { | |
| 61 text_extract_ = text_extract; | |
| 62 } | |
| 63 | |
| 64 // The time when the content represented by this snippet was published. | |
| 65 const base::Time& publish_date() const { return publish_date_; } | |
| 66 void set_publish_date(const base::Time& publish_date) { | |
| 67 publish_date_ = publish_date; | |
| 68 } | |
| 69 | |
| 70 // The name of the source/publisher of this snippet. | |
| 71 const std::string& publisher_name() const { return publisher_name_; } | |
| 72 void set_publisher_name(const std::string& publisher_name) { | |
| 73 publisher_name_ = publisher_name; | |
| 74 } | |
| 75 | |
| 76 // TODO(pke) Remove the score from the Snippet class. The UI only uses | |
| 77 // it to track user clicks (histogram data). Instead, the providers should | |
| 78 // be informed about clicks and do appropriate logging themselves. | |
| 79 // IMPORTANT: The score may simply be 0 for snippets from providers which | |
| 80 // cannot provide score values. | |
| 81 float score() const { return score_; } | |
| 82 void set_score(float score) { score_ = score; } | |
| 83 | |
| 84 private: | |
| 85 std::string id_; | |
| 86 SnippetProviderType provider_; | |
| 87 SnippetCategory category_; | |
| 88 GURL url_; | |
| 89 GURL amp_url_; | |
| 90 std::string title_; | |
| 91 std::string text_extract_; | |
| 92 GURL salient_image_url_; | |
| 93 base::Time publish_date_; | |
| 94 std::string publisher_name_; | |
| 95 float score_; | |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(Snippet); | |
| 98 }; | |
| 99 | |
| 100 } // namespace ntp_snippets | |
| 101 | |
| 102 #endif // COMPONENTS_NTP_SNIPPETS_SNIPPET_H_ | |
| OLD | NEW |