OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_provider_impl.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 } | 1178 } |
1179 return &content_it->second; | 1179 return &content_it->second; |
1180 } | 1180 } |
1181 | 1181 |
1182 void RemoteSuggestionsProviderImpl::RestoreCategoriesFromPrefs() { | 1182 void RemoteSuggestionsProviderImpl::RestoreCategoriesFromPrefs() { |
1183 // This must only be called at startup, before there are any categories. | 1183 // This must only be called at startup, before there are any categories. |
1184 DCHECK(category_contents_.empty()); | 1184 DCHECK(category_contents_.empty()); |
1185 | 1185 |
1186 const base::ListValue* list = | 1186 const base::ListValue* list = |
1187 pref_service_->GetList(prefs::kRemoteSuggestionCategories); | 1187 pref_service_->GetList(prefs::kRemoteSuggestionCategories); |
1188 for (const std::unique_ptr<base::Value>& entry : *list) { | 1188 for (const base::Value& entry : *list) { |
1189 const base::DictionaryValue* dict = nullptr; | 1189 const base::DictionaryValue* dict = nullptr; |
1190 if (!entry->GetAsDictionary(&dict)) { | 1190 if (!entry.GetAsDictionary(&dict)) { |
1191 DLOG(WARNING) << "Invalid category pref value: " << *entry; | 1191 DLOG(WARNING) << "Invalid category pref value: " << entry; |
1192 continue; | 1192 continue; |
1193 } | 1193 } |
1194 int id = 0; | 1194 int id = 0; |
1195 if (!dict->GetInteger(kCategoryContentId, &id)) { | 1195 if (!dict->GetInteger(kCategoryContentId, &id)) { |
1196 DLOG(WARNING) << "Invalid category pref value, missing '" | 1196 DLOG(WARNING) << "Invalid category pref value, missing '" |
1197 << kCategoryContentId << "': " << *entry; | 1197 << kCategoryContentId << "': " << entry; |
1198 continue; | 1198 continue; |
1199 } | 1199 } |
1200 base::string16 title; | 1200 base::string16 title; |
1201 if (!dict->GetString(kCategoryContentTitle, &title)) { | 1201 if (!dict->GetString(kCategoryContentTitle, &title)) { |
1202 DLOG(WARNING) << "Invalid category pref value, missing '" | 1202 DLOG(WARNING) << "Invalid category pref value, missing '" |
1203 << kCategoryContentTitle << "': " << *entry; | 1203 << kCategoryContentTitle << "': " << entry; |
1204 continue; | 1204 continue; |
1205 } | 1205 } |
1206 bool included_in_last_server_response = false; | 1206 bool included_in_last_server_response = false; |
1207 if (!dict->GetBoolean(kCategoryContentProvidedByServer, | 1207 if (!dict->GetBoolean(kCategoryContentProvidedByServer, |
1208 &included_in_last_server_response)) { | 1208 &included_in_last_server_response)) { |
1209 DLOG(WARNING) << "Invalid category pref value, missing '" | 1209 DLOG(WARNING) << "Invalid category pref value, missing '" |
1210 << kCategoryContentProvidedByServer << "': " << *entry; | 1210 << kCategoryContentProvidedByServer << "': " << entry; |
1211 continue; | 1211 continue; |
1212 } | 1212 } |
1213 bool allow_fetching_more_results = false; | 1213 bool allow_fetching_more_results = false; |
1214 // This wasn't always around, so it's okay if it's missing. | 1214 // This wasn't always around, so it's okay if it's missing. |
1215 dict->GetBoolean(kCategoryContentAllowFetchingMore, | 1215 dict->GetBoolean(kCategoryContentAllowFetchingMore, |
1216 &allow_fetching_more_results); | 1216 &allow_fetching_more_results); |
1217 | 1217 |
1218 Category category = Category::FromIDValue(id); | 1218 Category category = Category::FromIDValue(id); |
1219 // The ranker may not persist the order of remote categories. | 1219 // The ranker may not persist the order of remote categories. |
1220 category_ranker_->AppendCategoryIfNecessary(category); | 1220 category_ranker_->AppendCategoryIfNecessary(category); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 RemoteSuggestionsProviderImpl::CategoryContent::CategoryContent( | 1271 RemoteSuggestionsProviderImpl::CategoryContent::CategoryContent( |
1272 CategoryContent&&) = default; | 1272 CategoryContent&&) = default; |
1273 | 1273 |
1274 RemoteSuggestionsProviderImpl::CategoryContent::~CategoryContent() = default; | 1274 RemoteSuggestionsProviderImpl::CategoryContent::~CategoryContent() = default; |
1275 | 1275 |
1276 RemoteSuggestionsProviderImpl::CategoryContent& | 1276 RemoteSuggestionsProviderImpl::CategoryContent& |
1277 RemoteSuggestionsProviderImpl::CategoryContent::operator=(CategoryContent&&) = | 1277 RemoteSuggestionsProviderImpl::CategoryContent::operator=(CategoryContent&&) = |
1278 default; | 1278 default; |
1279 | 1279 |
1280 } // namespace ntp_snippets | 1280 } // namespace ntp_snippets |
OLD | NEW |