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/content_suggestions_service.h" | 5 #include "components/ntp_snippets/content_suggestions_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 } | 487 } |
488 } | 488 } |
489 | 489 |
490 void ContentSuggestionsService::RestoreDismissedCategoriesFromPrefs() { | 490 void ContentSuggestionsService::RestoreDismissedCategoriesFromPrefs() { |
491 // This must only be called at startup. | 491 // This must only be called at startup. |
492 DCHECK(dismissed_providers_by_category_.empty()); | 492 DCHECK(dismissed_providers_by_category_.empty()); |
493 DCHECK(providers_by_category_.empty()); | 493 DCHECK(providers_by_category_.empty()); |
494 | 494 |
495 const base::ListValue* list = | 495 const base::ListValue* list = |
496 pref_service_->GetList(prefs::kDismissedCategories); | 496 pref_service_->GetList(prefs::kDismissedCategories); |
497 for (const std::unique_ptr<base::Value>& entry : *list) { | 497 for (const base::Value& entry : *list) { |
498 int id = 0; | 498 int id = 0; |
499 if (!entry->GetAsInteger(&id)) { | 499 if (!entry.GetAsInteger(&id)) { |
500 DLOG(WARNING) << "Invalid category pref value: " << *entry; | 500 DLOG(WARNING) << "Invalid category pref value: " << entry; |
501 continue; | 501 continue; |
502 } | 502 } |
503 | 503 |
504 // When the provider is registered, it will be stored in this map. | 504 // When the provider is registered, it will be stored in this map. |
505 dismissed_providers_by_category_[Category::FromIDValue(id)] = nullptr; | 505 dismissed_providers_by_category_[Category::FromIDValue(id)] = nullptr; |
506 } | 506 } |
507 } | 507 } |
508 | 508 |
509 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { | 509 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { |
510 base::ListValue list; | 510 base::ListValue list; |
511 for (const auto& category_provider_pair : dismissed_providers_by_category_) { | 511 for (const auto& category_provider_pair : dismissed_providers_by_category_) { |
512 list.AppendInteger(category_provider_pair.first.id()); | 512 list.AppendInteger(category_provider_pair.first.id()); |
513 } | 513 } |
514 | 514 |
515 pref_service_->Set(prefs::kDismissedCategories, list); | 515 pref_service_->Set(prefs::kDismissedCategories, list); |
516 } | 516 } |
517 | 517 |
518 } // namespace ntp_snippets | 518 } // namespace ntp_snippets |
OLD | NEW |