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

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

Issue 2059203002: Add ContentSuggestion, ContentSuggestionCategory and ContentSuggestionProviderType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_NTP_SNIPPET_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_
6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_ 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "components/ntp_snippets/snippet.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 16
16 namespace base { 17 namespace base {
17 class DictionaryValue; 18 class DictionaryValue;
18 class ListValue; 19 class ListValue;
19 } 20 }
20 21
21 namespace ntp_snippets { 22 namespace ntp_snippets {
22 23
23 class SnippetProto; 24 class SnippetProto;
24 25
25 struct SnippetSource { 26 struct SnippetSource {
26 SnippetSource(const GURL& url, 27 SnippetSource(const GURL& url,
27 const std::string& publisher_name, 28 const std::string& publisher_name,
28 const GURL& amp_url) 29 const GURL& amp_url)
29 : url(url), publisher_name(publisher_name), amp_url(amp_url) {} 30 : url(url), publisher_name(publisher_name), amp_url(amp_url) {}
30 GURL url; 31 GURL url;
31 std::string publisher_name; 32 std::string publisher_name;
32 GURL amp_url; 33 GURL amp_url;
33 }; 34 };
34 35
36 // TODO IMPORTANT NOTE: This class will move to a sub-namespace and be renamed
Marc Treib 2016/06/13 13:08:17 TODOs should always have someone assigned, as in:
Philipp Keck 2016/06/13 14:13:14 Done.
Philipp Keck 2016/06/13 14:13:14 Ok. I don't need the TODO comment for myself becau
37 // ArticleSnippet. It will only be used for snippets from Chrome Reader.
38 // When accessing snippets for all usages towards the UI, use the new "Snippet"
39 // class through the "SnippetService" instead.
40
35 class NTPSnippet { 41 class NTPSnippet {
36 public: 42 public:
37 using PtrVector = std::vector<std::unique_ptr<NTPSnippet>>; 43 using PtrVector = std::vector<std::unique_ptr<NTPSnippet>>;
38 44
39 // Creates a new snippet with the given |id|. 45 // Creates a new snippet with the given |id|.
40 // Public for testing only - create snippets using the Create* methods below. 46 // Public for testing only - create snippets using the Create* methods below.
41 // TODO(treib): Make this private and add a CreateSnippetForTest? 47 // TODO(treib): Make this private and add a CreateSnippetForTest?
42 NTPSnippet(const std::string& id); 48 NTPSnippet(const std::string& id);
43 49
44 ~NTPSnippet(); 50 ~NTPSnippet();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 !publish_date().is_null() && !expiry_date().is_null() && 124 !publish_date().is_null() && !expiry_date().is_null() &&
119 !best_source().publisher_name.empty(); 125 !best_source().publisher_name.empty();
120 } 126 }
121 127
122 float score() const { return score_; } 128 float score() const { return score_; }
123 void set_score(float score) { score_ = score; } 129 void set_score(float score) { score_ = score; }
124 130
125 bool is_discarded() const { return is_discarded_; } 131 bool is_discarded() const { return is_discarded_; }
126 void set_discarded(bool discarded) { is_discarded_ = discarded; } 132 void set_discarded(bool discarded) { is_discarded_ = discarded; }
127 133
134 // TODO IMPORTANT NOTE This method is confusingly named because of upcoming
135 // changes to the names: NTPSnippet will become ArticleSnippet.
136 // TODO (pke) Instead of converting, ArticleSnippet might inherit Snippet?
Marc Treib 2016/06/13 13:08:17 Probably not :) But anyway, this is the kind of t
Philipp Keck 2016/06/13 14:13:14 Done.
137 std::unique_ptr<Snippet> ToSnippet() const;
138
128 // Public for testing. 139 // Public for testing.
129 static base::Time TimeFromJsonString(const std::string& timestamp_str); 140 static base::Time TimeFromJsonString(const std::string& timestamp_str);
130 static std::string TimeToJsonString(const base::Time& time); 141 static std::string TimeToJsonString(const base::Time& time);
131 142
132 private: 143 private:
133 void FindBestSource(); 144 void FindBestSource();
134 145
135 std::string id_; 146 std::string id_;
136 std::string title_; 147 std::string title_;
137 GURL salient_image_url_; 148 GURL salient_image_url_;
138 std::string snippet_; 149 std::string snippet_;
139 base::Time publish_date_; 150 base::Time publish_date_;
140 base::Time expiry_date_; 151 base::Time expiry_date_;
141 float score_; 152 float score_;
142 bool is_discarded_; 153 bool is_discarded_;
143 154
144 size_t best_source_index_; 155 size_t best_source_index_;
145 156
146 std::vector<SnippetSource> sources_; 157 std::vector<SnippetSource> sources_;
147 158
148 DISALLOW_COPY_AND_ASSIGN(NTPSnippet); 159 DISALLOW_COPY_AND_ASSIGN(NTPSnippet);
149 }; 160 };
150 161
151 } // namespace ntp_snippets 162 } // namespace ntp_snippets
152 163
153 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_ 164 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698