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 #include "base/values.h" | 6 #include "base/values.h" |
7 | 7 |
8 namespace ntp_snippets { | 8 namespace ntp_snippets { |
9 | 9 |
10 NTPSnippet::NTPSnippet(const GURL& url) : url_(url) { | 10 NTPSnippet::NTPSnippet(const GURL& url) : url_(url) { |
11 DCHECK(url_.is_valid() && !url.is_empty()); | 11 DCHECK(url_.is_valid() && !url.is_empty()); |
12 } | 12 } |
13 | 13 |
14 NTPSnippet::~NTPSnippet() {} | 14 NTPSnippet::~NTPSnippet() {} |
15 | 15 |
16 // static | 16 // static |
17 std::unique_ptr<NTPSnippet> NTPSnippet::NTPSnippetFromDictionary( | 17 scoped_ptr<NTPSnippet> NTPSnippet::NTPSnippetFromDictionary( |
18 const base::DictionaryValue& dict) { | 18 const base::DictionaryValue& dict) { |
19 // Need at least the url. | 19 // Need at least the url. |
20 std::string url; | 20 std::string url; |
21 if (!dict.GetString("url", &url)) | 21 if (!dict.GetString("url", &url)) |
22 return nullptr; | 22 return nullptr; |
23 | 23 |
24 std::unique_ptr<NTPSnippet> snippet(new NTPSnippet(GURL(url))); | 24 scoped_ptr<NTPSnippet> snippet(new NTPSnippet(GURL(url))); |
25 | 25 |
26 std::string site_title; | 26 std::string site_title; |
27 if (dict.GetString("site_title", &site_title)) | 27 if (dict.GetString("site_title", &site_title)) |
28 snippet->set_site_title(site_title); | 28 snippet->set_site_title(site_title); |
29 std::string favicon_url; | 29 std::string favicon_url; |
30 if (dict.GetString("favicon_url", &favicon_url)) | 30 if (dict.GetString("favicon_url", &favicon_url)) |
31 snippet->set_favicon_url(GURL(favicon_url)); | 31 snippet->set_favicon_url(GURL(favicon_url)); |
32 std::string title; | 32 std::string title; |
33 if (dict.GetString("title", &title)) | 33 if (dict.GetString("title", &title)) |
34 snippet->set_title(title); | 34 snippet->set_title(title); |
35 std::string snippet_str; | 35 std::string snippet_str; |
36 if (dict.GetString("snippet", &snippet_str)) | 36 if (dict.GetString("snippet", &snippet_str)) |
37 snippet->set_snippet(snippet_str); | 37 snippet->set_snippet(snippet_str); |
38 std::string salient_image_url; | 38 std::string salient_image_url; |
39 if (dict.GetString("thumbnailUrl", &salient_image_url)) | 39 if (dict.GetString("thumbnailUrl", &salient_image_url)) |
40 snippet->set_salient_image_url(GURL(salient_image_url)); | 40 snippet->set_salient_image_url(GURL(salient_image_url)); |
41 int creation_timestamp; | 41 int creation_timestamp; |
42 if (dict.GetInteger("creationTimestampSec", &creation_timestamp)) { | 42 if (dict.GetInteger("creationTimestampSec", &creation_timestamp)) { |
43 snippet->set_publish_date(base::Time::UnixEpoch() + | 43 snippet->set_publish_date(base::Time::UnixEpoch() + |
44 base::TimeDelta::FromSeconds(creation_timestamp)); | 44 base::TimeDelta::FromSeconds(creation_timestamp)); |
45 } | 45 } |
46 // TODO: Dates in json? | 46 // TODO: Dates in json? |
47 | 47 |
48 return snippet; | 48 return snippet; |
49 } | 49 } |
50 | 50 |
51 } // namespace ntp_snippets | 51 } // namespace ntp_snippets |
OLD | NEW |