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

Unified Diff: components/ntp_snippets/remote/remote_suggestion.cc

Issue 2686063003: [remote suggestions] Attach the fetch time to RemoteSnippets, ContentSnippets and SnippetArticle (Closed)
Patch Set: Update comments 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/remote/remote_suggestion.cc
diff --git a/components/ntp_snippets/remote/remote_suggestion.cc b/components/ntp_snippets/remote/remote_suggestion.cc
index f68b1806aa582b770cc14ef6ac6cf1c997ae984c..8e894327d2b7abfa8b205275f7fc7ec0c3305ad3 100644
--- a/components/ntp_snippets/remote/remote_suggestion.cc
+++ b/components/ntp_snippets/remote/remote_suggestion.cc
@@ -9,6 +9,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/time/time.h"
Marc Treib 2017/02/10 16:16:56 nit: not required, it's already included in the he
markusheintz_ 2017/02/13 09:59:55 Done.
#include "base/values.h"
#include "components/ntp_snippets/category.h"
#include "components/ntp_snippets/features.h"
@@ -96,7 +97,8 @@ RemoteSuggestion::~RemoteSuggestion() = default;
// static
std::unique_ptr<RemoteSuggestion>
RemoteSuggestion::CreateFromChromeReaderDictionary(
- const base::DictionaryValue& dict) {
+ const base::DictionaryValue& dict,
+ const base::Time& fetch_time) {
const base::DictionaryValue* content = nullptr;
if (!dict.GetDictionary("contentInfo", &content)) {
return nullptr;
@@ -167,6 +169,7 @@ RemoteSuggestion::CreateFromChromeReaderDictionary(
std::unique_ptr<RemoteSuggestion> snippet(
new RemoteSuggestion(ids, kArticlesRemoteId));
+ snippet->fetch_time_ = fetch_time;
std::string title;
if (content->GetString("title", &title)) {
@@ -217,7 +220,8 @@ RemoteSuggestion::CreateFromChromeReaderDictionary(
std::unique_ptr<RemoteSuggestion>
RemoteSuggestion::CreateFromContentSuggestionsDictionary(
const base::DictionaryValue& dict,
- int remote_category_id) {
+ int remote_category_id,
+ const base::Time& fetch_time) {
const base::ListValue* ids;
if (!dict.GetList("ids", &ids)) {
return nullptr;
@@ -235,6 +239,7 @@ RemoteSuggestion::CreateFromContentSuggestionsDictionary(
return nullptr;
}
auto snippet = MakeUnique(parsed_ids, remote_category_id);
+ snippet->fetch_time_ = fetch_time;
if (!(dict.GetString("title", &snippet->title_) &&
dict.GetString("snippet", &snippet->snippet_) &&
@@ -281,6 +286,7 @@ std::unique_ptr<RemoteSuggestion> RemoteSuggestion::CreateFromProto(
: kArticlesRemoteId;
std::vector<std::string> ids(proto.ids().begin(), proto.ids().end());
+
auto snippet = MakeUnique(ids, remote_category_id);
snippet->title_ = proto.title();
@@ -319,6 +325,10 @@ std::unique_ptr<RemoteSuggestion> RemoteSuggestion::CreateFromProto(
snippet->publisher_name_ = source.publisher_name;
snippet->amp_url_ = source.amp_url;
+ if (proto.has_fetch_time()) {
+ snippet->fetch_time_ = base::Time::FromInternalValue(proto.fetch_time());
+ }
+
return snippet;
}
@@ -329,6 +339,7 @@ std::unique_ptr<RemoteSuggestion> RemoteSuggestion::CreateForTesting(
const GURL& url,
const std::string& publisher_name,
const GURL& amp_url) {
+ // TODO(markusheintz):
jkrcal 2017/02/10 16:14:42 can you please fill in the todo?
Marc Treib 2017/02/10 16:16:56 ?
markusheintz_ 2017/02/13 09:59:55 sorry forgot to remove :-( Removed now.
auto snippet =
MakeUnique(std::vector<std::string>(1, id), remote_category_id);
snippet->url_ = url;
@@ -371,6 +382,9 @@ SnippetProto RemoteSuggestion::ToProto() const {
source_proto->set_amp_url(amp_url_.spec());
}
+ if (!fetch_time_.is_null()) {
+ result.set_fetch_time(fetch_time_.ToInternalValue());
+ }
return result;
}
@@ -393,6 +407,7 @@ ContentSuggestion RemoteSuggestion::ToContentSuggestion(
suggestion.set_notification_extra(
base::MakeUnique<NotificationExtra>(extra));
}
+ suggestion.set_fetch_time(fetch_time_);
return suggestion;
}

Powered by Google App Engine
This is Rietveld 408576698