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

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

Issue 2377663002: [NTP Snippets] Introduce ContentSuggestion::ID (Closed)
Patch Set: rebase Created 4 years, 2 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTION_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTION_H_
6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTION_H_ 6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTION_H_
7 7
8 #include <memory>
9 #include <string> 8 #include <string>
10 #include <vector>
11 9
12 #include "base/macros.h" 10 #include "base/macros.h"
13 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
14 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "components/ntp_snippets/category.h"
15 #include "url/gurl.h" 14 #include "url/gurl.h"
16 15
17 namespace ntp_snippets { 16 namespace ntp_snippets {
18 17
19 // A content suggestion for the new tab page, which can be an article or an 18 // A content suggestion for the new tab page, which can be an article or an
20 // offline page, for example. 19 // offline page, for example.
21 class ContentSuggestion { 20 class ContentSuggestion {
22 public: 21 public:
22 class ID {
23 public:
24 ID(Category category, const std::string& id_within_category)
25 : category_(category), id_within_category_(id_within_category) {}
26
27 Category category() const { return category_; }
28
29 const std::string& id_within_category() const {
30 return id_within_category_;
31 }
32
33 bool operator==(const ID& rhs) const;
34 bool operator!=(const ID& rhs) const;
35
36 private:
37 Category category_;
38 std::string id_within_category_;
39
40 // Allow copy and assignment.
41 };
42
23 // Creates a new ContentSuggestion. The caller must ensure that the |id| 43 // Creates a new ContentSuggestion. The caller must ensure that the |id|
24 // passed in here is unique application-wide. 44 // passed in here is unique application-wide.
25 ContentSuggestion(const std::string& id, 45 ContentSuggestion(ID id, const GURL& url);
46 ContentSuggestion(Category category,
47 const std::string& id_within_category,
26 const GURL& url); 48 const GURL& url);
27 ContentSuggestion(ContentSuggestion&&); 49 ContentSuggestion(ContentSuggestion&&);
28 ContentSuggestion& operator=(ContentSuggestion&&); 50 ContentSuggestion& operator=(ContentSuggestion&&);
29 51
30 ~ContentSuggestion(); 52 ~ContentSuggestion();
31 53
32 // An ID for identifying the suggestion. The ID is unique application-wide. 54 // An ID for identifying the suggestion. The ID is unique application-wide.
33 const std::string& id() const { return id_; } 55 const ID& id() const { return id_; }
34 56
35 // The normal content URL where the content referenced by the suggestion can 57 // The normal content URL where the content referenced by the suggestion can
36 // be accessed. 58 // be accessed.
37 const GURL& url() const { return url_; } 59 const GURL& url() const { return url_; }
38 60
39 // If available, this contains an URL to an AMP version of the same content. 61 // If available, this contains an URL to an AMP version of the same content.
40 // Otherwise, this is an empty GURL(). 62 // Otherwise, this is an empty GURL().
41 const GURL& amp_url() const { return amp_url_; } 63 const GURL& amp_url() const { return amp_url_; }
42 void set_amp_url(const GURL& amp_url) { amp_url_ = amp_url; } 64 void set_amp_url(const GURL& amp_url) { amp_url_ = amp_url; }
43 65
(...skipping 21 matching lines...) Expand all
65 87
66 // TODO(pke): Remove the score from the ContentSuggestion class. The UI only 88 // TODO(pke): Remove the score from the ContentSuggestion class. The UI only
67 // uses it to track user clicks (histogram data). Instead, the providers 89 // uses it to track user clicks (histogram data). Instead, the providers
68 // should be informed about clicks and do appropriate logging themselves. 90 // should be informed about clicks and do appropriate logging themselves.
69 // IMPORTANT: The score may simply be 0 for suggestions from providers which 91 // IMPORTANT: The score may simply be 0 for suggestions from providers which
70 // cannot provide score values. 92 // cannot provide score values.
71 float score() const { return score_; } 93 float score() const { return score_; }
72 void set_score(float score) { score_ = score; } 94 void set_score(float score) { score_ = score; }
73 95
74 private: 96 private:
75 std::string id_; 97 ID id_;
76 GURL url_; 98 GURL url_;
77 GURL amp_url_; 99 GURL amp_url_;
78 base::string16 title_; 100 base::string16 title_;
79 base::string16 snippet_text_; 101 base::string16 snippet_text_;
80 base::Time publish_date_; 102 base::Time publish_date_;
81 base::string16 publisher_name_; 103 base::string16 publisher_name_;
82 float score_; 104 float score_;
83 105
84 DISALLOW_COPY_AND_ASSIGN(ContentSuggestion); 106 DISALLOW_COPY_AND_ASSIGN(ContentSuggestion);
85 }; 107 };
86 108
109 std::ostream& operator<<(std::ostream& os, ContentSuggestion::ID id);
110
87 } // namespace ntp_snippets 111 } // namespace ntp_snippets
88 112
89 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTION_H_ 113 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTION_H_
OLDNEW
« no previous file with comments | « components/ntp_snippets/category_factory.cc ('k') | components/ntp_snippets/content_suggestion.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698