| 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/ntp_snippets_fetcher.h" | 5 #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 | 530 |
| 531 case CHROME_CONTENT_SUGGESTIONS_API: { | 531 case CHROME_CONTENT_SUGGESTIONS_API: { |
| 532 const base::ListValue* categories = nullptr; | 532 const base::ListValue* categories = nullptr; |
| 533 if (!top_dict->GetList("categories", &categories)) { | 533 if (!top_dict->GetList("categories", &categories)) { |
| 534 return false; | 534 return false; |
| 535 } | 535 } |
| 536 | 536 |
| 537 for (const auto& v : *categories) { | 537 for (const auto& v : *categories) { |
| 538 int category_id = -1; | 538 int category_id = -1; |
| 539 const base::DictionaryValue* category_value = nullptr; | 539 const base::DictionaryValue* category_value = nullptr; |
| 540 const base::ListValue* suggestions = nullptr; | |
| 541 if (!(v->GetAsDictionary(&category_value) && | 540 if (!(v->GetAsDictionary(&category_value) && |
| 542 category_value->GetInteger("id", &category_id) && | 541 category_value->GetInteger("id", &category_id) && |
| 543 (category_id > 0) && | 542 (category_id > 0))) { |
| 544 category_value->GetList("suggestions", &suggestions))) { | |
| 545 return false; | 543 return false; |
| 546 } | 544 } |
| 547 Category category = category_factory_->FromRemoteCategory(category_id); | 545 Category category = category_factory_->FromRemoteCategory(category_id); |
| 546 const base::ListValue* suggestions = nullptr; |
| 548 NTPSnippet::PtrVector* articles = &(*snippets)[category]; | 547 NTPSnippet::PtrVector* articles = &(*snippets)[category]; |
| 548 if (!category_value->GetList("suggestions", &suggestions)) { |
| 549 // Absence of a list of suggestions is treated as an empty list, which |
| 550 // is permissible. |
| 551 continue; |
| 552 } |
| 549 if (!AddSnippetsFromListValue( | 553 if (!AddSnippetsFromListValue( |
| 550 /* content_suggestions_api = */ true, *suggestions, articles)) { | 554 /* content_suggestions_api = */ true, *suggestions, articles)) { |
| 551 return false; | 555 return false; |
| 552 } | 556 } |
| 553 } | 557 } |
| 554 return true; | 558 return true; |
| 555 } | 559 } |
| 556 } | 560 } |
| 557 NOTREACHED(); | 561 NOTREACHED(); |
| 558 return false; | 562 return false; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 } | 598 } |
| 595 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", | 599 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", |
| 596 static_cast<int>(result), | 600 static_cast<int>(result), |
| 597 static_cast<int>(FetchResult::RESULT_MAX)); | 601 static_cast<int>(FetchResult::RESULT_MAX)); |
| 598 | 602 |
| 599 if (!snippets_available_callback_.is_null()) | 603 if (!snippets_available_callback_.is_null()) |
| 600 snippets_available_callback_.Run(std::move(snippets)); | 604 snippets_available_callback_.Run(std::move(snippets)); |
| 601 } | 605 } |
| 602 | 606 |
| 603 } // namespace ntp_snippets | 607 } // namespace ntp_snippets |
| OLD | NEW |