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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 void ContentSuggestionsService::RemoveObserver(Observer* observer) { | 189 void ContentSuggestionsService::RemoveObserver(Observer* observer) { |
190 observers_.RemoveObserver(observer); | 190 observers_.RemoveObserver(observer); |
191 } | 191 } |
192 | 192 |
193 void ContentSuggestionsService::RegisterProvider( | 193 void ContentSuggestionsService::RegisterProvider( |
194 std::unique_ptr<ContentSuggestionsProvider> provider) { | 194 std::unique_ptr<ContentSuggestionsProvider> provider) { |
195 DCHECK(state_ == State::ENABLED); | 195 DCHECK(state_ == State::ENABLED); |
196 providers_.push_back(std::move(provider)); | 196 providers_.push_back(std::move(provider)); |
197 } | 197 } |
198 | 198 |
| 199 void ContentSuggestionsService::Fetch( |
| 200 const Category& category, |
| 201 const std::set<std::string>& known_suggestion_ids, |
| 202 const FetchingCallback& callback) { |
| 203 auto providers_it = providers_by_category_.find(category); |
| 204 if (providers_it == providers_by_category_.end()) |
| 205 return; |
| 206 |
| 207 providers_it->second->Fetch(category, known_suggestion_ids, callback); |
| 208 } |
| 209 |
199 //////////////////////////////////////////////////////////////////////////////// | 210 //////////////////////////////////////////////////////////////////////////////// |
200 // Private methods | 211 // Private methods |
201 | 212 |
202 void ContentSuggestionsService::OnNewSuggestions( | 213 void ContentSuggestionsService::OnNewSuggestions( |
203 ContentSuggestionsProvider* provider, | 214 ContentSuggestionsProvider* provider, |
204 Category category, | 215 Category category, |
205 std::vector<ContentSuggestion> suggestions) { | 216 std::vector<ContentSuggestion> suggestions) { |
206 // Providers shouldn't call this when they're in a non-available state. | 217 // Providers shouldn't call this when they're in a non-available state. |
207 DCHECK( | 218 DCHECK( |
208 IsCategoryStatusInitOrAvailable(provider->GetCategoryStatus(category))); | 219 IsCategoryStatusInitOrAvailable(provider->GetCategoryStatus(category))); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { | 440 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { |
430 base::ListValue list; | 441 base::ListValue list; |
431 for (const auto& category_provider_pair : dismissed_providers_by_category_) { | 442 for (const auto& category_provider_pair : dismissed_providers_by_category_) { |
432 list.AppendInteger(category_provider_pair.first.id()); | 443 list.AppendInteger(category_provider_pair.first.id()); |
433 } | 444 } |
434 | 445 |
435 pref_service_->Set(prefs::kDismissedCategories, list); | 446 pref_service_->Set(prefs::kDismissedCategories, list); |
436 } | 447 } |
437 | 448 |
438 } // namespace ntp_snippets | 449 } // namespace ntp_snippets |
OLD | NEW |