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

Unified 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: Address comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/ntp_snippets/ntp_snippets_fetcher_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/ntp_snippets_fetcher.cc
diff --git a/components/ntp_snippets/ntp_snippets_fetcher.cc b/components/ntp_snippets/ntp_snippets_fetcher.cc
index c0018e7d816ad650ff06f25bdf664b5b64034e2e..27da5f8a3f758d516a58718a618f9ed61d1ed664 100644
--- a/components/ntp_snippets/ntp_snippets_fetcher.cc
+++ b/components/ntp_snippets/ntp_snippets_fetcher.cc
@@ -537,15 +537,19 @@ bool NTPSnippetsFetcher::JsonToSnippets(const base::Value& parsed,
for (const auto& v : *categories) {
int category_id = -1;
const base::DictionaryValue* category_value = nullptr;
- const base::ListValue* suggestions = nullptr;
if (!(v->GetAsDictionary(&category_value) &&
category_value->GetInteger("id", &category_id) &&
- (category_id > 0) &&
- category_value->GetList("suggestions", &suggestions))) {
+ (category_id > 0))) {
return false;
}
Category category = category_factory_->FromRemoteCategory(category_id);
+ const base::ListValue* suggestions = nullptr;
NTPSnippet::PtrVector* articles = &(*snippets)[category];
+ if (!category_value->GetList("suggestions", &suggestions)) {
+ // Absence of a list of suggestions is treated as an empty list, which
+ // is permissible.
+ continue;
+ }
if (!AddSnippetsFromListValue(
/* content_suggestions_api = */ true, *suggestions, articles)) {
return false;
« 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