Chromium Code Reviews| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 observer.ContentSuggestionsServiceShutdown(); | 59 observer.ContentSuggestionsServiceShutdown(); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 // static | 63 // static |
| 64 void ContentSuggestionsService::RegisterProfilePrefs( | 64 void ContentSuggestionsService::RegisterProfilePrefs( |
| 65 PrefRegistrySimple* registry) { | 65 PrefRegistrySimple* registry) { |
| 66 registry->RegisterListPref(prefs::kDismissedCategories); | 66 registry->RegisterListPref(prefs::kDismissedCategories); |
| 67 } | 67 } |
| 68 | 68 |
| 69 const std::vector<Category>& ContentSuggestionsService::GetCategories() { | |
| 70 SortCategories(); | |
| 71 return categories_; | |
| 72 } | |
| 73 | |
| 69 CategoryStatus ContentSuggestionsService::GetCategoryStatus( | 74 CategoryStatus ContentSuggestionsService::GetCategoryStatus( |
| 70 Category category) const { | 75 Category category) const { |
| 71 if (state_ == State::DISABLED) { | 76 if (state_ == State::DISABLED) { |
| 72 return CategoryStatus::ALL_SUGGESTIONS_EXPLICITLY_DISABLED; | 77 return CategoryStatus::ALL_SUGGESTIONS_EXPLICITLY_DISABLED; |
| 73 } | 78 } |
| 74 | 79 |
| 75 auto iterator = providers_by_category_.find(category); | 80 auto iterator = providers_by_category_.find(category); |
| 76 if (iterator == providers_by_category_.end()) { | 81 if (iterator == providers_by_category_.end()) { |
| 77 return CategoryStatus::NOT_PROVIDED; | 82 return CategoryStatus::NOT_PROVIDED; |
| 78 } | 83 } |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 } | 387 } |
| 383 | 388 |
| 384 void ContentSuggestionsService::RegisterCategory( | 389 void ContentSuggestionsService::RegisterCategory( |
| 385 Category category, | 390 Category category, |
| 386 ContentSuggestionsProvider* provider) { | 391 ContentSuggestionsProvider* provider) { |
| 387 DCHECK(!base::ContainsKey(providers_by_category_, category)); | 392 DCHECK(!base::ContainsKey(providers_by_category_, category)); |
| 388 DCHECK(!IsCategoryDismissed(category)); | 393 DCHECK(!IsCategoryDismissed(category)); |
| 389 | 394 |
| 390 providers_by_category_[category] = provider; | 395 providers_by_category_[category] = provider; |
| 391 categories_.push_back(category); | 396 categories_.push_back(category); |
| 392 SortCategories(); | 397 SortCategories(); |
|
Marc Treib
2016/12/19 13:22:46
I think this call isn't required anymore.
vitaliii
2016/12/19 15:28:59
Done.
| |
| 393 if (IsCategoryStatusAvailable(provider->GetCategoryStatus(category))) { | 398 if (IsCategoryStatusAvailable(provider->GetCategoryStatus(category))) { |
| 394 suggestions_by_category_.insert( | 399 suggestions_by_category_.insert( |
| 395 std::make_pair(category, std::vector<ContentSuggestion>())); | 400 std::make_pair(category, std::vector<ContentSuggestion>())); |
| 396 } | 401 } |
| 397 } | 402 } |
| 398 | 403 |
| 399 void ContentSuggestionsService::UnregisterCategory( | 404 void ContentSuggestionsService::UnregisterCategory( |
| 400 Category category, | 405 Category category, |
| 401 ContentSuggestionsProvider* provider) { | 406 ContentSuggestionsProvider* provider) { |
| 402 auto providers_it = providers_by_category_.find(category); | 407 auto providers_it = providers_by_category_.find(category); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { | 500 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { |
| 496 base::ListValue list; | 501 base::ListValue list; |
| 497 for (const auto& category_provider_pair : dismissed_providers_by_category_) { | 502 for (const auto& category_provider_pair : dismissed_providers_by_category_) { |
| 498 list.AppendInteger(category_provider_pair.first.id()); | 503 list.AppendInteger(category_provider_pair.first.id()); |
| 499 } | 504 } |
| 500 | 505 |
| 501 pref_service_->Set(prefs::kDismissedCategories, list); | 506 pref_service_->Set(prefs::kDismissedCategories, list); |
| 502 } | 507 } |
| 503 | 508 |
| 504 } // namespace ntp_snippets | 509 } // namespace ntp_snippets |
| OLD | NEW |