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

Side by Side Diff: components/ntp_snippets/remote/remote_suggestion.h

Issue 2686063003: [remote suggestions] Attach the fetch time to RemoteSnippets, ContentSnippets and SnippetArticle (Closed)
Patch Set: rebase Created 3 years, 10 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_REMOTE_REMOTE_SUGGESTION_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTION_H_
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTION_H_ 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTION_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 20 matching lines...) Expand all
31 public: 31 public:
32 using PtrVector = std::vector<std::unique_ptr<RemoteSuggestion>>; 32 using PtrVector = std::vector<std::unique_ptr<RemoteSuggestion>>;
33 33
34 ~RemoteSuggestion(); 34 ~RemoteSuggestion();
35 35
36 // Creates a RemoteSuggestion from a dictionary, as returned by Chrome Reader. 36 // Creates a RemoteSuggestion from a dictionary, as returned by Chrome Reader.
37 // Returns a null pointer if the dictionary doesn't correspond to a valid 37 // Returns a null pointer if the dictionary doesn't correspond to a valid
38 // suggestion. The keys in the dictionary are expected to be the same as the 38 // suggestion. The keys in the dictionary are expected to be the same as the
39 // property name, with exceptions documented in the property comment. 39 // property name, with exceptions documented in the property comment.
40 static std::unique_ptr<RemoteSuggestion> CreateFromChromeReaderDictionary( 40 static std::unique_ptr<RemoteSuggestion> CreateFromChromeReaderDictionary(
41 const base::DictionaryValue& dict); 41 const base::DictionaryValue& dict,
42 const base::Time& fetch_date);
42 43
43 // Creates a RemoteSuggestion from a dictionary, as returned by Chrome Content 44 // Creates a RemoteSuggestion from a dictionary, as returned by Chrome Content
44 // Suggestions. Returns a null pointer if the dictionary doesn't correspond to 45 // Suggestions. Returns a null pointer if the dictionary doesn't correspond to
45 // a valid suggestion. Maps field names to Chrome Reader field names. 46 // a valid suggestion. Maps field names to Chrome Reader field names.
46 static std::unique_ptr<RemoteSuggestion> 47 static std::unique_ptr<RemoteSuggestion>
47 CreateFromContentSuggestionsDictionary(const base::DictionaryValue& dict, 48 CreateFromContentSuggestionsDictionary(const base::DictionaryValue& dict,
48 int remote_category_id); 49 int remote_category_id,
50 const base::Time& fetch_date);
49 51
50 // Creates an RemoteSuggestion from a protocol buffer. Returns a null pointer 52 // Creates an RemoteSuggestion from a protocol buffer. Returns a null pointer
51 // if the protocol buffer doesn't correspond to a valid suggestion. 53 // if the protocol buffer doesn't correspond to a valid suggestion.
52 static std::unique_ptr<RemoteSuggestion> CreateFromProto( 54 static std::unique_ptr<RemoteSuggestion> CreateFromProto(
53 const SnippetProto& proto); 55 const SnippetProto& proto);
54 56
55 // TODO(treib): Make tests use the public interface and remove this. 57 // TODO(treib): Make tests use the public interface and remove this.
56 static std::unique_ptr<RemoteSuggestion> CreateForTesting( 58 static std::unique_ptr<RemoteSuggestion> CreateForTesting(
57 const std::string& id, 59 const std::string& id,
58 int remote_category_id, 60 int remote_category_id,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 bool should_notify() const { return should_notify_; } 115 bool should_notify() const { return should_notify_; }
114 base::Time notification_deadline() const { return notification_deadline_; } 116 base::Time notification_deadline() const { return notification_deadline_; }
115 117
116 bool is_dismissed() const { return is_dismissed_; } 118 bool is_dismissed() const { return is_dismissed_; }
117 void set_dismissed(bool dismissed) { is_dismissed_ = dismissed; } 119 void set_dismissed(bool dismissed) { is_dismissed_ = dismissed; }
118 120
119 // The ID of the remote category this suggestion belongs to, for use with 121 // The ID of the remote category this suggestion belongs to, for use with
120 // CategoryFactory::FromRemoteCategory. 122 // CategoryFactory::FromRemoteCategory.
121 int remote_category_id() const { return remote_category_id_; } 123 int remote_category_id() const { return remote_category_id_; }
122 124
125 base::Time fetch_date() const { return fetch_date_; }
126
123 // Public for testing. 127 // Public for testing.
124 static base::Time TimeFromJsonString(const std::string& timestamp_str); 128 static base::Time TimeFromJsonString(const std::string& timestamp_str);
125 static std::string TimeToJsonString(const base::Time& time); 129 static std::string TimeToJsonString(const base::Time& time);
126 130
127 private: 131 private:
128 RemoteSuggestion(const std::vector<std::string>& ids, int remote_category_id); 132 RemoteSuggestion(const std::vector<std::string>& ids, int remote_category_id);
129 133
130 // base::MakeUnique doesn't work if the ctor is private. 134 // base::MakeUnique doesn't work if the ctor is private.
131 static std::unique_ptr<RemoteSuggestion> MakeUnique( 135 static std::unique_ptr<RemoteSuggestion> MakeUnique(
132 const std::vector<std::string>& ids, 136 const std::vector<std::string>& ids,
(...skipping 12 matching lines...) Expand all
145 std::string snippet_; 149 std::string snippet_;
146 base::Time publish_date_; 150 base::Time publish_date_;
147 base::Time expiry_date_; 151 base::Time expiry_date_;
148 float score_; 152 float score_;
149 bool is_dismissed_; 153 bool is_dismissed_;
150 int remote_category_id_; 154 int remote_category_id_;
151 155
152 bool should_notify_; 156 bool should_notify_;
153 base::Time notification_deadline_; 157 base::Time notification_deadline_;
154 158
159 // The time when the remote suggestion was fetched from the server.
160 base::Time fetch_date_;
161
155 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestion); 162 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestion);
156 }; 163 };
157 164
158 } // namespace ntp_snippets 165 } // namespace ntp_snippets
159 166
160 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTION_H_ 167 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTION_H_
OLDNEW
« no previous file with comments | « components/ntp_snippets/remote/proto/ntp_snippets.proto ('k') | components/ntp_snippets/remote/remote_suggestion.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698