Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: components/ntp_snippets/ntp_snippets_fetcher.cc

Issue 2279483002: Allow category["suggestions"] to be absent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/ntp_snippets/ntp_snippets_fetcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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; 540 const base::ListValue* suggestions = nullptr;
Marc Treib 2016/08/25 09:14:02 nit: Move this down to where it's used.
sfiera 2016/08/25 10:24:29 Done.
541 if (!(v->GetAsDictionary(&category_value) && 541 if (!(v->GetAsDictionary(&category_value) &&
542 category_value->GetInteger("id", &category_id) && 542 category_value->GetInteger("id", &category_id) &&
543 (category_id > 0) && 543 (category_id > 0))) {
544 category_value->GetList("suggestions", &suggestions))) {
545 return false; 544 return false;
546 } 545 }
547 Category category = category_factory_->FromRemoteCategory(category_id); 546 Category category = category_factory_->FromRemoteCategory(category_id);
548 NTPSnippet::PtrVector* articles = &(*snippets)[category]; 547 NTPSnippet::PtrVector* articles = &(*snippets)[category];
548 if (!category_value->GetList("suggestions", &suggestions)) {
tschumann 2016/08/24 21:35:22 let's document this case, e.g., // Categories are
Marc Treib 2016/08/25 09:14:02 +1 for comment
sfiera 2016/08/25 10:24:29 Done.
549 continue;
550 }
549 if (!AddSnippetsFromListValue( 551 if (!AddSnippetsFromListValue(
550 /* content_suggestions_api = */ true, *suggestions, articles)) { 552 /* content_suggestions_api = */ true, *suggestions, articles)) {
551 return false; 553 return false;
552 } 554 }
553 } 555 }
554 return true; 556 return true;
555 } 557 }
556 } 558 }
557 NOTREACHED(); 559 NOTREACHED();
558 return false; 560 return false;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 } 596 }
595 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", 597 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult",
596 static_cast<int>(result), 598 static_cast<int>(result),
597 static_cast<int>(FetchResult::RESULT_MAX)); 599 static_cast<int>(FetchResult::RESULT_MAX));
598 600
599 if (!snippets_available_callback_.is_null()) 601 if (!snippets_available_callback_.is_null())
600 snippets_available_callback_.Run(std::move(snippets)); 602 snippets_available_callback_.Run(std::move(snippets));
601 } 603 }
602 604
603 } // namespace ntp_snippets 605 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/ntp_snippets_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698