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. NOTE: This class is not yet in use, please use NTPSnippet for | |
| 22 // now (see ntp_snippet.h). | |
| 23 class Snippet { | |
| 24 public: | |
| 25 using PtrVector = std::vector<std::unique_ptr<Snippet>>; | |
| 26 | |
| 27 // Creates a new snippet with the given |id|. | |
|
Marc Treib
2016/06/14 12:57:28
nit: Not really correct, since it takes more than
Philipp Keck
2016/06/14 13:02:17
Done.
| |
| 28 Snippet(const std::string& id, | |
| 29 const SnippetProviderType provider, | |
| 30 const SnippetCategory category, | |
| 31 const GURL& url); | |
| 32 | |
| 33 ~Snippet(); | |
| 34 | |
| 35 // An ID for identifying the snippet. The ID is unique among all snippets | |
| 36 // from the same provider, so to determine a globally unique identifier, | |
| 37 // combine this ID with the provider type. | |
| 38 const std::string& id() const { return id_; } | |
| 39 | |
| 40 // The provider that created this snippet. | |
| 41 SnippetProviderType provider() const { return provider_; } | |
| 42 | |
| 43 // The category that this snippet belongs to. | |
| 44 SnippetCategory category() const { return 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 | |
| 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_ | |
| OLD | NEW |