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 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 } | 1184 } |
1185 return &content_it->second; | 1185 return &content_it->second; |
1186 } | 1186 } |
1187 | 1187 |
1188 void RemoteSuggestionsProviderImpl::RestoreCategoriesFromPrefs() { | 1188 void RemoteSuggestionsProviderImpl::RestoreCategoriesFromPrefs() { |
1189 // This must only be called at startup, before there are any categories. | 1189 // This must only be called at startup, before there are any categories. |
1190 DCHECK(category_contents_.empty()); | 1190 DCHECK(category_contents_.empty()); |
1191 | 1191 |
1192 const base::ListValue* list = | 1192 const base::ListValue* list = |
1193 pref_service_->GetList(prefs::kRemoteSuggestionCategories); | 1193 pref_service_->GetList(prefs::kRemoteSuggestionCategories); |
1194 for (const base::Value& entry : *list) { | 1194 for (const std::unique_ptr<base::Value>& entry : *list) { |
1195 const base::DictionaryValue* dict = nullptr; | 1195 const base::DictionaryValue* dict = nullptr; |
1196 if (!entry.GetAsDictionary(&dict)) { | 1196 if (!entry->GetAsDictionary(&dict)) { |
1197 DLOG(WARNING) << "Invalid category pref value: " << entry; | 1197 DLOG(WARNING) << "Invalid category pref value: " << *entry; |
1198 continue; | 1198 continue; |
1199 } | 1199 } |
1200 int id = 0; | 1200 int id = 0; |
1201 if (!dict->GetInteger(kCategoryContentId, &id)) { | 1201 if (!dict->GetInteger(kCategoryContentId, &id)) { |
1202 DLOG(WARNING) << "Invalid category pref value, missing '" | 1202 DLOG(WARNING) << "Invalid category pref value, missing '" |
1203 << kCategoryContentId << "': " << entry; | 1203 << kCategoryContentId << "': " << *entry; |
1204 continue; | 1204 continue; |
1205 } | 1205 } |
1206 base::string16 title; | 1206 base::string16 title; |
1207 if (!dict->GetString(kCategoryContentTitle, &title)) { | 1207 if (!dict->GetString(kCategoryContentTitle, &title)) { |
1208 DLOG(WARNING) << "Invalid category pref value, missing '" | 1208 DLOG(WARNING) << "Invalid category pref value, missing '" |
1209 << kCategoryContentTitle << "': " << entry; | 1209 << kCategoryContentTitle << "': " << *entry; |
1210 continue; | 1210 continue; |
1211 } | 1211 } |
1212 bool included_in_last_server_response = false; | 1212 bool included_in_last_server_response = false; |
1213 if (!dict->GetBoolean(kCategoryContentProvidedByServer, | 1213 if (!dict->GetBoolean(kCategoryContentProvidedByServer, |
1214 &included_in_last_server_response)) { | 1214 &included_in_last_server_response)) { |
1215 DLOG(WARNING) << "Invalid category pref value, missing '" | 1215 DLOG(WARNING) << "Invalid category pref value, missing '" |
1216 << kCategoryContentProvidedByServer << "': " << entry; | 1216 << kCategoryContentProvidedByServer << "': " << *entry; |
1217 continue; | 1217 continue; |
1218 } | 1218 } |
1219 bool allow_fetching_more_results = false; | 1219 bool allow_fetching_more_results = false; |
1220 // This wasn't always around, so it's okay if it's missing. | 1220 // This wasn't always around, so it's okay if it's missing. |
1221 dict->GetBoolean(kCategoryContentAllowFetchingMore, | 1221 dict->GetBoolean(kCategoryContentAllowFetchingMore, |
1222 &allow_fetching_more_results); | 1222 &allow_fetching_more_results); |
1223 | 1223 |
1224 Category category = Category::FromIDValue(id); | 1224 Category category = Category::FromIDValue(id); |
1225 // The ranker may not persist the order of remote categories. | 1225 // The ranker may not persist the order of remote categories. |
1226 category_ranker_->AppendCategoryIfNecessary(category); | 1226 category_ranker_->AppendCategoryIfNecessary(category); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 RemoteSuggestionsProviderImpl::CategoryContent::CategoryContent( | 1277 RemoteSuggestionsProviderImpl::CategoryContent::CategoryContent( |
1278 CategoryContent&&) = default; | 1278 CategoryContent&&) = default; |
1279 | 1279 |
1280 RemoteSuggestionsProviderImpl::CategoryContent::~CategoryContent() = default; | 1280 RemoteSuggestionsProviderImpl::CategoryContent::~CategoryContent() = default; |
1281 | 1281 |
1282 RemoteSuggestionsProviderImpl::CategoryContent& | 1282 RemoteSuggestionsProviderImpl::CategoryContent& |
1283 RemoteSuggestionsProviderImpl::CategoryContent::operator=(CategoryContent&&) = | 1283 RemoteSuggestionsProviderImpl::CategoryContent::operator=(CategoryContent&&) = |
1284 default; | 1284 default; |
1285 | 1285 |
1286 } // namespace ntp_snippets | 1286 } // namespace ntp_snippets |
OLD | NEW |