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/remote/remote_suggestion.h" | 5 #include "components/ntp_snippets/remote/remote_suggestion.h" |
6 | 6 |
7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 const base::ListValue* corpus_infos_list = nullptr; | 112 const base::ListValue* corpus_infos_list = nullptr; |
113 if (!content->GetList("sourceCorpusInfo", &corpus_infos_list)) { | 113 if (!content->GetList("sourceCorpusInfo", &corpus_infos_list)) { |
114 DLOG(WARNING) << "No sources found for article " << primary_id; | 114 DLOG(WARNING) << "No sources found for article " << primary_id; |
115 return nullptr; | 115 return nullptr; |
116 } | 116 } |
117 | 117 |
118 std::vector<std::string> ids(1, primary_id); | 118 std::vector<std::string> ids(1, primary_id); |
119 std::vector<SnippetSource> sources; | 119 std::vector<SnippetSource> sources; |
120 for (const auto& value : *corpus_infos_list) { | 120 for (const auto& value : *corpus_infos_list) { |
121 const base::DictionaryValue* dict_value = nullptr; | 121 const base::DictionaryValue* dict_value = nullptr; |
122 if (!value->GetAsDictionary(&dict_value)) { | 122 if (!value.GetAsDictionary(&dict_value)) { |
123 DLOG(WARNING) << "Invalid source info for article " << primary_id; | 123 DLOG(WARNING) << "Invalid source info for article " << primary_id; |
124 continue; | 124 continue; |
125 } | 125 } |
126 | 126 |
127 std::string corpus_id_str; | 127 std::string corpus_id_str; |
128 GURL corpus_id; | 128 GURL corpus_id; |
129 if (dict_value->GetString("corpusId", &corpus_id_str)) { | 129 if (dict_value->GetString("corpusId", &corpus_id_str)) { |
130 corpus_id = GURL(corpus_id_str); | 130 corpus_id = GURL(corpus_id_str); |
131 } | 131 } |
132 | 132 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 const base::DictionaryValue& dict, | 221 const base::DictionaryValue& dict, |
222 int remote_category_id, | 222 int remote_category_id, |
223 const base::Time& fetch_date) { | 223 const base::Time& fetch_date) { |
224 const base::ListValue* ids; | 224 const base::ListValue* ids; |
225 if (!dict.GetList("ids", &ids)) { | 225 if (!dict.GetList("ids", &ids)) { |
226 return nullptr; | 226 return nullptr; |
227 } | 227 } |
228 std::vector<std::string> parsed_ids; | 228 std::vector<std::string> parsed_ids; |
229 for (const auto& value : *ids) { | 229 for (const auto& value : *ids) { |
230 std::string id; | 230 std::string id; |
231 if (!value->GetAsString(&id)) { | 231 if (!value.GetAsString(&id)) { |
232 return nullptr; | 232 return nullptr; |
233 } | 233 } |
234 parsed_ids.push_back(id); | 234 parsed_ids.push_back(id); |
235 } | 235 } |
236 | 236 |
237 if (parsed_ids.empty()) { | 237 if (parsed_ids.empty()) { |
238 return nullptr; | 238 return nullptr; |
239 } | 239 } |
240 auto snippet = MakeUnique(parsed_ids, remote_category_id); | 240 auto snippet = MakeUnique(parsed_ids, remote_category_id); |
241 snippet->fetch_date_ = fetch_date; | 241 snippet->fetch_date_ = fetch_date; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 } | 428 } |
429 | 429 |
430 // static | 430 // static |
431 std::unique_ptr<RemoteSuggestion> RemoteSuggestion::MakeUnique( | 431 std::unique_ptr<RemoteSuggestion> RemoteSuggestion::MakeUnique( |
432 const std::vector<std::string>& ids, | 432 const std::vector<std::string>& ids, |
433 int remote_category_id) { | 433 int remote_category_id) { |
434 return base::WrapUnique(new RemoteSuggestion(ids, remote_category_id)); | 434 return base::WrapUnique(new RemoteSuggestion(ids, remote_category_id)); |
435 } | 435 } |
436 | 436 |
437 } // namespace ntp_snippets | 437 } // namespace ntp_snippets |
OLD | NEW |