| 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 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 observers_.AddObserver(observer); | 145 observers_.AddObserver(observer); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void ContentSuggestionsService::RemoveObserver(Observer* observer) { | 148 void ContentSuggestionsService::RemoveObserver(Observer* observer) { |
| 149 observers_.RemoveObserver(observer); | 149 observers_.RemoveObserver(observer); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void ContentSuggestionsService::RegisterProvider( | 152 void ContentSuggestionsService::RegisterProvider( |
| 153 std::unique_ptr<ContentSuggestionsProvider> provider) { | 153 std::unique_ptr<ContentSuggestionsProvider> provider) { |
| 154 DCHECK(state_ == State::ENABLED); | 154 DCHECK(state_ == State::ENABLED); |
| 155 for (Category category : provider->GetProvidedCategories()) { | |
| 156 DCHECK_NE(CategoryStatus::NOT_PROVIDED, | |
| 157 provider->GetCategoryStatus(category)); | |
| 158 RegisterCategoryIfRequired(provider.get(), category); | |
| 159 NotifyCategoryStatusChanged(category); | |
| 160 } | |
| 161 providers_.push_back(std::move(provider)); | 155 providers_.push_back(std::move(provider)); |
| 162 } | 156 } |
| 163 | 157 |
| 164 //////////////////////////////////////////////////////////////////////////////// | 158 //////////////////////////////////////////////////////////////////////////////// |
| 165 // Private methods | 159 // Private methods |
| 166 | 160 |
| 167 void ContentSuggestionsService::OnNewSuggestions( | 161 void ContentSuggestionsService::OnNewSuggestions( |
| 168 ContentSuggestionsProvider* provider, | 162 ContentSuggestionsProvider* provider, |
| 169 Category category, | 163 Category category, |
| 170 std::vector<ContentSuggestion> new_suggestions) { | 164 std::vector<ContentSuggestion> new_suggestions) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 return true; | 254 return true; |
| 261 } | 255 } |
| 262 | 256 |
| 263 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { | 257 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { |
| 264 FOR_EACH_OBSERVER( | 258 FOR_EACH_OBSERVER( |
| 265 Observer, observers_, | 259 Observer, observers_, |
| 266 OnCategoryStatusChanged(category, GetCategoryStatus(category))); | 260 OnCategoryStatusChanged(category, GetCategoryStatus(category))); |
| 267 } | 261 } |
| 268 | 262 |
| 269 } // namespace ntp_snippets | 263 } // namespace ntp_snippets |
| OLD | NEW |