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

Unified Diff: components/ntp_snippets/ntp_snippet.cc

Issue 1743333002: [NTP Snippets] Implement snippets expiry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippets_persist
Patch Set: review Created 4 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/ntp_snippet.cc
diff --git a/components/ntp_snippets/ntp_snippet.cc b/components/ntp_snippets/ntp_snippet.cc
index b120e7bd0edd62b2e7a6779fcdc09a92b454d198..80e2fb22daf4b00259e2756eb736185a1db2c9ae 100644
--- a/components/ntp_snippets/ntp_snippet.cc
+++ b/components/ntp_snippets/ntp_snippet.cc
@@ -31,13 +31,14 @@ NTPSnippet::~NTPSnippet() {}
scoped_ptr<NTPSnippet> NTPSnippet::CreateFromDictionary(
const base::DictionaryValue& dict) {
// Need at least the url.
- std::string url;
- if (!dict.GetString("url", &url))
+ std::string url_str;
+ if (!dict.GetString("url", &url_str))
+ return nullptr;
+ GURL url(url_str);
+ if (!url.is_valid())
return nullptr;
- // TODO(treib,noyau): Need to check that the URL is valid first, or remove
- // the DCHECK in the constructor.
- scoped_ptr<NTPSnippet> snippet(new NTPSnippet(GURL(url)));
+ scoped_ptr<NTPSnippet> snippet(new NTPSnippet(url));
std::string site_title;
if (dict.GetString(kSiteTitle, &site_title))
@@ -59,7 +60,11 @@ scoped_ptr<NTPSnippet> NTPSnippet::CreateFromDictionary(
snippet->set_publish_date(base::Time::UnixEpoch() +
base::TimeDelta::FromSeconds(creation_timestamp));
}
- // TODO: Dates in json?
+ int expiry_timestamp;
+ if (dict.GetInteger(kExpiryDate, &expiry_timestamp)) {
+ snippet->set_expiry_date(base::Time::UnixEpoch() +
+ base::TimeDelta::FromSeconds(expiry_timestamp));
+ }
return snippet;
}

Powered by Google App Engine
This is Rietveld 408576698