| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // Creates suggestions from dictionary values in |list| and adds them to | 118 // Creates suggestions from dictionary values in |list| and adds them to |
| 119 // |suggestions|. Returns true on success, false if anything went wrong. | 119 // |suggestions|. Returns true on success, false if anything went wrong. |
| 120 // |remote_category_id| is only used if |content_suggestions_api| is true. | 120 // |remote_category_id| is only used if |content_suggestions_api| is true. |
| 121 bool AddSuggestionsFromListValue(bool content_suggestions_api, | 121 bool AddSuggestionsFromListValue(bool content_suggestions_api, |
| 122 int remote_category_id, | 122 int remote_category_id, |
| 123 const base::ListValue& list, | 123 const base::ListValue& list, |
| 124 RemoteSuggestion::PtrVector* suggestions, | 124 RemoteSuggestion::PtrVector* suggestions, |
| 125 const base::Time& fetch_time) { | 125 const base::Time& fetch_time) { |
| 126 for (const auto& value : list) { | 126 for (const auto& value : list) { |
| 127 const base::DictionaryValue* dict = nullptr; | 127 const base::DictionaryValue* dict = nullptr; |
| 128 if (!value->GetAsDictionary(&dict)) { | 128 if (!value.GetAsDictionary(&dict)) { |
| 129 return false; | 129 return false; |
| 130 } | 130 } |
| 131 | 131 |
| 132 std::unique_ptr<RemoteSuggestion> suggestion; | 132 std::unique_ptr<RemoteSuggestion> suggestion; |
| 133 if (content_suggestions_api) { | 133 if (content_suggestions_api) { |
| 134 suggestion = RemoteSuggestion::CreateFromContentSuggestionsDictionary( | 134 suggestion = RemoteSuggestion::CreateFromContentSuggestionsDictionary( |
| 135 *dict, remote_category_id, fetch_time); | 135 *dict, remote_category_id, fetch_time); |
| 136 } else { | 136 } else { |
| 137 suggestion = | 137 suggestion = |
| 138 RemoteSuggestion::CreateFromChromeReaderDictionary(*dict, fetch_time); | 138 RemoteSuggestion::CreateFromChromeReaderDictionary(*dict, fetch_time); |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 case FetchAPI::CHROME_CONTENT_SUGGESTIONS_API: { | 508 case FetchAPI::CHROME_CONTENT_SUGGESTIONS_API: { |
| 509 const base::ListValue* categories_value = nullptr; | 509 const base::ListValue* categories_value = nullptr; |
| 510 if (!top_dict->GetList("categories", &categories_value)) { | 510 if (!top_dict->GetList("categories", &categories_value)) { |
| 511 return false; | 511 return false; |
| 512 } | 512 } |
| 513 | 513 |
| 514 for (const auto& v : *categories_value) { | 514 for (const auto& v : *categories_value) { |
| 515 std::string utf8_title; | 515 std::string utf8_title; |
| 516 int remote_category_id = -1; | 516 int remote_category_id = -1; |
| 517 const base::DictionaryValue* category_value = nullptr; | 517 const base::DictionaryValue* category_value = nullptr; |
| 518 if (!(v->GetAsDictionary(&category_value) && | 518 if (!(v.GetAsDictionary(&category_value) && |
| 519 category_value->GetString("localizedTitle", &utf8_title) && | 519 category_value->GetString("localizedTitle", &utf8_title) && |
| 520 category_value->GetInteger("id", &remote_category_id) && | 520 category_value->GetInteger("id", &remote_category_id) && |
| 521 (remote_category_id > 0))) { | 521 (remote_category_id > 0))) { |
| 522 return false; | 522 return false; |
| 523 } | 523 } |
| 524 | 524 |
| 525 RemoteSuggestion::PtrVector suggestions; | 525 RemoteSuggestion::PtrVector suggestions; |
| 526 const base::ListValue* suggestions_list = nullptr; | 526 const base::ListValue* suggestions_list = nullptr; |
| 527 // Absence of a list of suggestions is treated as an empty list, which | 527 // Absence of a list of suggestions is treated as an empty list, which |
| 528 // is permissible. | 528 // is permissible. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 551 categories->back().suggestions = std::move(suggestions); | 551 categories->back().suggestions = std::move(suggestions); |
| 552 } | 552 } |
| 553 return true; | 553 return true; |
| 554 } | 554 } |
| 555 } | 555 } |
| 556 NOTREACHED(); | 556 NOTREACHED(); |
| 557 return false; | 557 return false; |
| 558 } | 558 } |
| 559 | 559 |
| 560 } // namespace ntp_snippets | 560 } // namespace ntp_snippets |
| OLD | NEW |