| 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 PrefService* pref_service) | 23 PrefService* pref_service) |
| 24 : state_(state), | 24 : state_(state), |
| 25 history_service_observer_(this), | 25 history_service_observer_(this), |
| 26 ntp_snippets_service_(nullptr), | 26 ntp_snippets_service_(nullptr), |
| 27 user_classifier_(pref_service) { | 27 user_classifier_(pref_service) { |
| 28 // Can be null in tests. | 28 // Can be null in tests. |
| 29 if (history_service) | 29 if (history_service) |
| 30 history_service_observer_.Add(history_service); | 30 history_service_observer_.Add(history_service); |
| 31 } | 31 } |
| 32 | 32 |
| 33 ContentSuggestionsService::~ContentSuggestionsService() {} | 33 ContentSuggestionsService::~ContentSuggestionsService() = default; |
| 34 | 34 |
| 35 void ContentSuggestionsService::Shutdown() { | 35 void ContentSuggestionsService::Shutdown() { |
| 36 ntp_snippets_service_ = nullptr; | 36 ntp_snippets_service_ = nullptr; |
| 37 suggestions_by_category_.clear(); | 37 suggestions_by_category_.clear(); |
| 38 providers_by_category_.clear(); | 38 providers_by_category_.clear(); |
| 39 categories_.clear(); | 39 categories_.clear(); |
| 40 providers_.clear(); | 40 providers_.clear(); |
| 41 state_ = State::DISABLED; | 41 state_ = State::DISABLED; |
| 42 FOR_EACH_OBSERVER(Observer, observers_, ContentSuggestionsServiceShutdown()); | 42 FOR_EACH_OBSERVER(Observer, observers_, ContentSuggestionsServiceShutdown()); |
| 43 } | 43 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 DCHECK(state_ == State::ENABLED); | 169 DCHECK(state_ == State::ENABLED); |
| 170 providers_.push_back(std::move(provider)); | 170 providers_.push_back(std::move(provider)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 //////////////////////////////////////////////////////////////////////////////// | 173 //////////////////////////////////////////////////////////////////////////////// |
| 174 // Private methods | 174 // Private methods |
| 175 | 175 |
| 176 void ContentSuggestionsService::OnNewSuggestions( | 176 void ContentSuggestionsService::OnNewSuggestions( |
| 177 ContentSuggestionsProvider* provider, | 177 ContentSuggestionsProvider* provider, |
| 178 Category category, | 178 Category category, |
| 179 std::vector<ContentSuggestion> new_suggestions) { | 179 std::vector<ContentSuggestion> suggestions) { |
| 180 if (RegisterCategoryIfRequired(provider, category)) | 180 if (RegisterCategoryIfRequired(provider, category)) |
| 181 NotifyCategoryStatusChanged(category); | 181 NotifyCategoryStatusChanged(category); |
| 182 | 182 |
| 183 if (!IsCategoryStatusAvailable(provider->GetCategoryStatus(category))) | 183 if (!IsCategoryStatusAvailable(provider->GetCategoryStatus(category))) |
| 184 return; | 184 return; |
| 185 | 185 |
| 186 suggestions_by_category_[category] = std::move(new_suggestions); | 186 suggestions_by_category_[category] = std::move(suggestions); |
| 187 | 187 |
| 188 // The positioning of the bookmarks category depends on whether it's empty. | 188 // The positioning of the bookmarks category depends on whether it's empty. |
| 189 // TODO(treib): Remove this temporary hack, crbug.com/640568. | 189 // TODO(treib): Remove this temporary hack, crbug.com/640568. |
| 190 if (category.IsKnownCategory(KnownCategories::BOOKMARKS)) | 190 if (category.IsKnownCategory(KnownCategories::BOOKMARKS)) |
| 191 SortCategories(); | 191 SortCategories(); |
| 192 | 192 |
| 193 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions(category)); | 193 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions(category)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void ContentSuggestionsService::OnCategoryStatusChanged( | 196 void ContentSuggestionsService::OnCategoryStatusChanged( |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 if (left.IsKnownCategory(KnownCategories::BOOKMARKS)) | 328 if (left.IsKnownCategory(KnownCategories::BOOKMARKS)) |
| 329 return false; | 329 return false; |
| 330 if (right.IsKnownCategory(KnownCategories::BOOKMARKS)) | 330 if (right.IsKnownCategory(KnownCategories::BOOKMARKS)) |
| 331 return true; | 331 return true; |
| 332 } | 332 } |
| 333 return category_factory_.CompareCategories(left, right); | 333 return category_factory_.CompareCategories(left, right); |
| 334 }); | 334 }); |
| 335 } | 335 } |
| 336 | 336 |
| 337 } // namespace ntp_snippets | 337 } // namespace ntp_snippets |
| OLD | NEW |