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/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 std::string expiry_timestamp_str; | 64 std::string expiry_timestamp_str; |
65 if (content->GetString(kExpiryDate, &expiry_timestamp_str)) | 65 if (content->GetString(kExpiryDate, &expiry_timestamp_str)) |
66 snippet->set_expiry_date(TimeFromJsonString(expiry_timestamp_str)); | 66 snippet->set_expiry_date(TimeFromJsonString(expiry_timestamp_str)); |
67 | 67 |
68 const base::ListValue* corpus_infos_list = nullptr; | 68 const base::ListValue* corpus_infos_list = nullptr; |
69 if (!content->GetList(kSourceCorpusInfo, &corpus_infos_list)) { | 69 if (!content->GetList(kSourceCorpusInfo, &corpus_infos_list)) { |
70 DLOG(WARNING) << "No sources found for article " << title; | 70 DLOG(WARNING) << "No sources found for article " << title; |
71 return nullptr; | 71 return nullptr; |
72 } | 72 } |
73 | 73 |
74 for (base::Value* value : *corpus_infos_list) { | 74 for (const auto& value : *corpus_infos_list) { |
75 const base::DictionaryValue* dict_value = nullptr; | 75 const base::DictionaryValue* dict_value = nullptr; |
76 if (!value->GetAsDictionary(&dict_value)) { | 76 if (!value->GetAsDictionary(&dict_value)) { |
77 DLOG(WARNING) << "Invalid source info for article " << id; | 77 DLOG(WARNING) << "Invalid source info for article " << id; |
78 continue; | 78 continue; |
79 } | 79 } |
80 | 80 |
81 std::string corpus_id_str; | 81 std::string corpus_id_str; |
82 GURL corpus_id; | 82 GURL corpus_id; |
83 if (dict_value->GetString(kCorpusId, &corpus_id_str)) | 83 if (dict_value->GetString(kCorpusId, &corpus_id_str)) |
84 corpus_id = GURL(corpus_id_str); | 84 corpus_id = GURL(corpus_id_str); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 double score; | 142 double score; |
143 if (dict.GetDouble(kScore, &score)) | 143 if (dict.GetDouble(kScore, &score)) |
144 snippet->set_score(score); | 144 snippet->set_score(score); |
145 | 145 |
146 return snippet; | 146 return snippet; |
147 } | 147 } |
148 | 148 |
149 // static | 149 // static |
150 bool NTPSnippet::AddFromListValue(const base::ListValue& list, | 150 bool NTPSnippet::AddFromListValue(const base::ListValue& list, |
151 PtrVector* snippets) { | 151 PtrVector* snippets) { |
152 for (const base::Value* const value : list) { | 152 for (const auto& value : list) { |
153 const base::DictionaryValue* dict = nullptr; | 153 const base::DictionaryValue* dict = nullptr; |
154 if (!value->GetAsDictionary(&dict)) | 154 if (!value->GetAsDictionary(&dict)) |
155 return false; | 155 return false; |
156 | 156 |
157 std::unique_ptr<NTPSnippet> snippet = CreateFromDictionary(*dict); | 157 std::unique_ptr<NTPSnippet> snippet = CreateFromDictionary(*dict); |
158 if (!snippet) | 158 if (!snippet) |
159 return false; | 159 return false; |
160 | 160 |
161 snippets->push_back(std::move(snippet)); | 161 snippets->push_back(std::move(snippet)); |
162 } | 162 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 } | 214 } |
215 return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(timestamp); | 215 return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(timestamp); |
216 } | 216 } |
217 | 217 |
218 // static | 218 // static |
219 std::string NTPSnippet::TimeToJsonString(const base::Time& time) { | 219 std::string NTPSnippet::TimeToJsonString(const base::Time& time) { |
220 return base::Int64ToString((time - base::Time::UnixEpoch()).InSeconds()); | 220 return base::Int64ToString((time - base::Time::UnixEpoch()).InSeconds()); |
221 } | 221 } |
222 | 222 |
223 } // namespace ntp_snippets | 223 } // namespace ntp_snippets |
OLD | NEW |