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 12 matching lines...) Expand all Loading... |
23 | 23 |
24 ContentSuggestionsService::ContentSuggestionsService( | 24 ContentSuggestionsService::ContentSuggestionsService( |
25 State state, | 25 State state, |
26 SigninManagerBase* signin_manager, | 26 SigninManagerBase* signin_manager, |
27 history::HistoryService* history_service, | 27 history::HistoryService* history_service, |
28 PrefService* pref_service, | 28 PrefService* pref_service, |
29 std::unique_ptr<CategoryRanker> category_ranker) | 29 std::unique_ptr<CategoryRanker> category_ranker) |
30 : state_(state), | 30 : state_(state), |
31 signin_observer_(this), | 31 signin_observer_(this), |
32 history_service_observer_(this), | 32 history_service_observer_(this), |
33 ntp_snippets_service_(nullptr), | 33 remote_suggestions_provider_(nullptr), |
| 34 remote_suggestions_scheduler_(nullptr), |
34 pref_service_(pref_service), | 35 pref_service_(pref_service), |
35 user_classifier_(pref_service), | 36 user_classifier_(pref_service), |
36 category_ranker_(std::move(category_ranker)) { | 37 category_ranker_(std::move(category_ranker)) { |
37 // Can be null in tests. | 38 // Can be null in tests. |
38 if (signin_manager) { | 39 if (signin_manager) { |
39 signin_observer_.Add(signin_manager); | 40 signin_observer_.Add(signin_manager); |
40 } | 41 } |
41 | 42 |
42 if (history_service) { | 43 if (history_service) { |
43 history_service_observer_.Add(history_service); | 44 history_service_observer_.Add(history_service); |
44 } | 45 } |
45 | 46 |
46 RestoreDismissedCategoriesFromPrefs(); | 47 RestoreDismissedCategoriesFromPrefs(); |
47 } | 48 } |
48 | 49 |
49 ContentSuggestionsService::~ContentSuggestionsService() = default; | 50 ContentSuggestionsService::~ContentSuggestionsService() = default; |
50 | 51 |
51 void ContentSuggestionsService::Shutdown() { | 52 void ContentSuggestionsService::Shutdown() { |
52 ntp_snippets_service_ = nullptr; | 53 remote_suggestions_provider_ = nullptr; |
| 54 remote_suggestions_scheduler_ = nullptr; |
53 suggestions_by_category_.clear(); | 55 suggestions_by_category_.clear(); |
54 providers_by_category_.clear(); | 56 providers_by_category_.clear(); |
55 categories_.clear(); | 57 categories_.clear(); |
56 providers_.clear(); | 58 providers_.clear(); |
57 state_ = State::DISABLED; | 59 state_ = State::DISABLED; |
58 for (Observer& observer : observers_) { | 60 for (Observer& observer : observers_) { |
59 observer.ContentSuggestionsServiceShutdown(); | 61 observer.ContentSuggestionsServiceShutdown(); |
60 } | 62 } |
61 } | 63 } |
62 | 64 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 const std::set<std::string>& known_suggestion_ids, | 229 const std::set<std::string>& known_suggestion_ids, |
228 const FetchDoneCallback& callback) { | 230 const FetchDoneCallback& callback) { |
229 auto providers_it = providers_by_category_.find(category); | 231 auto providers_it = providers_by_category_.find(category); |
230 if (providers_it == providers_by_category_.end()) { | 232 if (providers_it == providers_by_category_.end()) { |
231 return; | 233 return; |
232 } | 234 } |
233 | 235 |
234 providers_it->second->Fetch(category, known_suggestion_ids, callback); | 236 providers_it->second->Fetch(category, known_suggestion_ids, callback); |
235 } | 237 } |
236 | 238 |
| 239 void ContentSuggestionsService::ReloadSuggestions() { |
| 240 for (const auto& provider : providers_) { |
| 241 provider->ReloadSuggestions(); |
| 242 } |
| 243 } |
| 244 |
237 //////////////////////////////////////////////////////////////////////////////// | 245 //////////////////////////////////////////////////////////////////////////////// |
238 // Private methods | 246 // Private methods |
239 | 247 |
240 void ContentSuggestionsService::OnNewSuggestions( | 248 void ContentSuggestionsService::OnNewSuggestions( |
241 ContentSuggestionsProvider* provider, | 249 ContentSuggestionsProvider* provider, |
242 Category category, | 250 Category category, |
243 std::vector<ContentSuggestion> suggestions) { | 251 std::vector<ContentSuggestion> suggestions) { |
244 // Providers shouldn't call this when they're in a non-available state. | 252 // Providers shouldn't call this when they're in a non-available state. |
245 DCHECK( | 253 DCHECK( |
246 IsCategoryStatusInitOrAvailable(provider->GetCategoryStatus(category))); | 254 IsCategoryStatusInitOrAvailable(provider->GetCategoryStatus(category))); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { | 504 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { |
497 base::ListValue list; | 505 base::ListValue list; |
498 for (const auto& category_provider_pair : dismissed_providers_by_category_) { | 506 for (const auto& category_provider_pair : dismissed_providers_by_category_) { |
499 list.AppendInteger(category_provider_pair.first.id()); | 507 list.AppendInteger(category_provider_pair.first.id()); |
500 } | 508 } |
501 | 509 |
502 pref_service_->Set(prefs::kDismissedCategories, list); | 510 pref_service_->Set(prefs::kDismissedCategories, list); |
503 } | 511 } |
504 | 512 |
505 } // namespace ntp_snippets | 513 } // namespace ntp_snippets |
OLD | NEW |