OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_suggestions_fetcher.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // Creates suggestions from dictionary values in |list| and adds them to | 105 // Creates suggestions from dictionary values in |list| and adds them to |
106 // |suggestions|. Returns true on success, false if anything went wrong. | 106 // |suggestions|. Returns true on success, false if anything went wrong. |
107 // |remote_category_id| is only used if |content_suggestions_api| is true. | 107 // |remote_category_id| is only used if |content_suggestions_api| is true. |
108 bool AddSuggestionsFromListValue(bool content_suggestions_api, | 108 bool AddSuggestionsFromListValue(bool content_suggestions_api, |
109 int remote_category_id, | 109 int remote_category_id, |
110 const base::ListValue& list, | 110 const base::ListValue& list, |
111 RemoteSuggestion::PtrVector* suggestions, | 111 RemoteSuggestion::PtrVector* suggestions, |
112 const base::Time& fetch_time) { | 112 const base::Time& fetch_time) { |
113 for (const auto& value : list) { | 113 for (const auto& value : list) { |
114 const base::DictionaryValue* dict = nullptr; | 114 const base::DictionaryValue* dict = nullptr; |
115 if (!value->GetAsDictionary(&dict)) { | 115 if (!value.GetAsDictionary(&dict)) { |
116 return false; | 116 return false; |
117 } | 117 } |
118 | 118 |
119 std::unique_ptr<RemoteSuggestion> suggestion; | 119 std::unique_ptr<RemoteSuggestion> suggestion; |
120 if (content_suggestions_api) { | 120 if (content_suggestions_api) { |
121 suggestion = RemoteSuggestion::CreateFromContentSuggestionsDictionary( | 121 suggestion = RemoteSuggestion::CreateFromContentSuggestionsDictionary( |
122 *dict, remote_category_id, fetch_time); | 122 *dict, remote_category_id, fetch_time); |
123 } else { | 123 } else { |
124 suggestion = | 124 suggestion = |
125 RemoteSuggestion::CreateFromChromeReaderDictionary(*dict, fetch_time); | 125 RemoteSuggestion::CreateFromChromeReaderDictionary(*dict, fetch_time); |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 451 |
452 const base::ListValue* categories_value = nullptr; | 452 const base::ListValue* categories_value = nullptr; |
453 if (!top_dict->GetList("categories", &categories_value)) { | 453 if (!top_dict->GetList("categories", &categories_value)) { |
454 return false; | 454 return false; |
455 } | 455 } |
456 | 456 |
457 for (const auto& v : *categories_value) { | 457 for (const auto& v : *categories_value) { |
458 std::string utf8_title; | 458 std::string utf8_title; |
459 int remote_category_id = -1; | 459 int remote_category_id = -1; |
460 const base::DictionaryValue* category_value = nullptr; | 460 const base::DictionaryValue* category_value = nullptr; |
461 if (!(v->GetAsDictionary(&category_value) && | 461 if (!(v.GetAsDictionary(&category_value) && |
462 category_value->GetString("localizedTitle", &utf8_title) && | 462 category_value->GetString("localizedTitle", &utf8_title) && |
463 category_value->GetInteger("id", &remote_category_id) && | 463 category_value->GetInteger("id", &remote_category_id) && |
464 (remote_category_id > 0))) { | 464 (remote_category_id > 0))) { |
465 return false; | 465 return false; |
466 } | 466 } |
467 | 467 |
468 RemoteSuggestion::PtrVector suggestions; | 468 RemoteSuggestion::PtrVector suggestions; |
469 const base::ListValue* suggestions_list = nullptr; | 469 const base::ListValue* suggestions_list = nullptr; |
470 // Absence of a list of suggestions is treated as an empty list, which | 470 // Absence of a list of suggestions is treated as an empty list, which |
471 // is permissible. | 471 // is permissible. |
(...skipping 18 matching lines...) Expand all Loading... |
490 category, BuildRemoteCategoryInfo(base::UTF8ToUTF16(utf8_title), | 490 category, BuildRemoteCategoryInfo(base::UTF8ToUTF16(utf8_title), |
491 allow_fetching_more_results))); | 491 allow_fetching_more_results))); |
492 } | 492 } |
493 categories->back().suggestions = std::move(suggestions); | 493 categories->back().suggestions = std::move(suggestions); |
494 } | 494 } |
495 | 495 |
496 return true; | 496 return true; |
497 } | 497 } |
498 | 498 |
499 } // namespace ntp_snippets | 499 } // namespace ntp_snippets |
OLD | NEW |