OLD | NEW |
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 #include "components/ntp_snippets/ntp_snippet.h" | 5 #include "components/ntp_snippets/ntp_snippet.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 namespace ntp_snippets { | 23 namespace ntp_snippets { |
24 | 24 |
25 NTPSnippet::NTPSnippet(const GURL& url) : url_(url) { | 25 NTPSnippet::NTPSnippet(const GURL& url) : url_(url) { |
26 DCHECK(url_.is_valid()); | 26 DCHECK(url_.is_valid()); |
27 } | 27 } |
28 | 28 |
29 NTPSnippet::~NTPSnippet() {} | 29 NTPSnippet::~NTPSnippet() {} |
30 | 30 |
31 // static | 31 // static |
32 scoped_ptr<NTPSnippet> NTPSnippet::CreateFromDictionary( | 32 std::unique_ptr<NTPSnippet> NTPSnippet::CreateFromDictionary( |
33 const base::DictionaryValue& dict) { | 33 const base::DictionaryValue& dict) { |
34 // Need at least the url. | 34 // Need at least the url. |
35 std::string url_str; | 35 std::string url_str; |
36 if (!dict.GetString("url", &url_str)) | 36 if (!dict.GetString("url", &url_str)) |
37 return nullptr; | 37 return nullptr; |
38 GURL url(url_str); | 38 GURL url(url_str); |
39 if (!url.is_valid()) | 39 if (!url.is_valid()) |
40 return nullptr; | 40 return nullptr; |
41 | 41 |
42 scoped_ptr<NTPSnippet> snippet(new NTPSnippet(url)); | 42 std::unique_ptr<NTPSnippet> snippet(new NTPSnippet(url)); |
43 | 43 |
44 std::string site_title; | 44 std::string site_title; |
45 if (dict.GetString(kSiteTitle, &site_title)) | 45 if (dict.GetString(kSiteTitle, &site_title)) |
46 snippet->set_site_title(site_title); | 46 snippet->set_site_title(site_title); |
47 std::string title; | 47 std::string title; |
48 if (dict.GetString(kTitle, &title)) | 48 if (dict.GetString(kTitle, &title)) |
49 snippet->set_title(title); | 49 snippet->set_title(title); |
50 std::string favicon_url; | 50 std::string favicon_url; |
51 if (dict.GetString(kFaviconUrl, &favicon_url)) | 51 if (dict.GetString(kFaviconUrl, &favicon_url)) |
52 snippet->set_favicon_url(GURL(favicon_url)); | 52 snippet->set_favicon_url(GURL(favicon_url)); |
(...skipping 23 matching lines...) Expand all Loading... |
76 // be written to the output var, so reset it | 76 // be written to the output var, so reset it |
77 expiry_timestamp = 0; | 77 expiry_timestamp = 0; |
78 } | 78 } |
79 snippet->set_expiry_date(base::Time::UnixEpoch() + | 79 snippet->set_expiry_date(base::Time::UnixEpoch() + |
80 base::TimeDelta::FromSeconds(expiry_timestamp)); | 80 base::TimeDelta::FromSeconds(expiry_timestamp)); |
81 } | 81 } |
82 | 82 |
83 return snippet; | 83 return snippet; |
84 } | 84 } |
85 | 85 |
86 scoped_ptr<base::DictionaryValue> NTPSnippet::ToDictionary() const { | 86 std::unique_ptr<base::DictionaryValue> NTPSnippet::ToDictionary() const { |
87 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 87 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
88 | 88 |
89 dict->SetString(kUrl, url_.spec()); | 89 dict->SetString(kUrl, url_.spec()); |
90 if (!site_title_.empty()) | 90 if (!site_title_.empty()) |
91 dict->SetString(kSiteTitle, site_title_); | 91 dict->SetString(kSiteTitle, site_title_); |
92 if (!title_.empty()) | 92 if (!title_.empty()) |
93 dict->SetString(kTitle, title_); | 93 dict->SetString(kTitle, title_); |
94 if (favicon_url_.is_valid()) | 94 if (favicon_url_.is_valid()) |
95 dict->SetString(kFaviconUrl, favicon_url_.spec()); | 95 dict->SetString(kFaviconUrl, favicon_url_.spec()); |
96 if (salient_image_url_.is_valid()) | 96 if (salient_image_url_.is_valid()) |
97 dict->SetString(kSalientImageUrl, salient_image_url_.spec()); | 97 dict->SetString(kSalientImageUrl, salient_image_url_.spec()); |
98 if (!snippet_.empty()) | 98 if (!snippet_.empty()) |
99 dict->SetString(kSnippet, snippet_); | 99 dict->SetString(kSnippet, snippet_); |
100 if (!publish_date_.is_null()) { | 100 if (!publish_date_.is_null()) { |
101 dict->SetString(kPublishDate, | 101 dict->SetString(kPublishDate, |
102 base::Int64ToString( | 102 base::Int64ToString( |
103 (publish_date_ - base::Time::UnixEpoch()).InSeconds())); | 103 (publish_date_ - base::Time::UnixEpoch()).InSeconds())); |
104 } | 104 } |
105 if (!expiry_date_.is_null()) { | 105 if (!expiry_date_.is_null()) { |
106 dict->SetString(kExpiryDate, | 106 dict->SetString(kExpiryDate, |
107 base::Int64ToString( | 107 base::Int64ToString( |
108 (expiry_date_ - base::Time::UnixEpoch()).InSeconds())); | 108 (expiry_date_ - base::Time::UnixEpoch()).InSeconds())); |
109 } | 109 } |
110 | 110 |
111 return dict; | 111 return dict; |
112 } | 112 } |
113 | 113 |
114 } // namespace ntp_snippets | 114 } // namespace ntp_snippets |
OLD | NEW |