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 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 return CategoryStatus::ALL_SUGGESTIONS_EXPLICITLY_DISABLED; | 41 return CategoryStatus::ALL_SUGGESTIONS_EXPLICITLY_DISABLED; |
| 42 } | 42 } |
| 43 | 43 |
| 44 auto iterator = providers_by_category_.find(category); | 44 auto iterator = providers_by_category_.find(category); |
| 45 if (iterator == providers_by_category_.end()) | 45 if (iterator == providers_by_category_.end()) |
| 46 return CategoryStatus::NOT_PROVIDED; | 46 return CategoryStatus::NOT_PROVIDED; |
| 47 | 47 |
| 48 return iterator->second->GetCategoryStatus(category); | 48 return iterator->second->GetCategoryStatus(category); |
| 49 } | 49 } |
| 50 | 50 |
| 51 CategoryInfo ContentSuggestionsService::GetCategoryInfo( | |
| 52 Category category) const { | |
| 53 auto iterator = providers_by_category_.find(category); | |
| 54 if (iterator == providers_by_category_.end()) | |
| 55 return CategoryInfo(base::string16()); | |
|
tschumann
2016/08/04 08:59:39
it might be better to explicitly signal the lookup
Marc Treib
2016/08/04 09:46:30
Explicitly signaling the failure might be good, bu
Philipp Keck
2016/08/04 11:48:18
base::Optional sounds good. We could so something
tschumann
2016/08/04 11:51:24
While that's possible, it would be nice to not rel
Philipp Keck
2016/08/08 14:50:18
Done.
| |
| 56 | |
| 57 return iterator->second->GetCategoryInfo(category); | |
| 58 } | |
| 59 | |
| 51 const std::vector<ContentSuggestion>& | 60 const std::vector<ContentSuggestion>& |
| 52 ContentSuggestionsService::GetSuggestionsForCategory(Category category) const { | 61 ContentSuggestionsService::GetSuggestionsForCategory(Category category) const { |
| 53 auto iterator = suggestions_by_category_.find(category); | 62 auto iterator = suggestions_by_category_.find(category); |
| 54 if (iterator == suggestions_by_category_.end()) | 63 if (iterator == suggestions_by_category_.end()) |
| 55 return no_suggestions_; | 64 return no_suggestions_; |
| 56 return iterator->second; | 65 return iterator->second; |
| 57 } | 66 } |
| 58 | 67 |
| 59 void ContentSuggestionsService::FetchSuggestionImage( | 68 void ContentSuggestionsService::FetchSuggestionImage( |
| 60 const std::string& suggestion_id, | 69 const std::string& suggestion_id, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 return true; | 221 return true; |
| 213 } | 222 } |
| 214 | 223 |
| 215 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { | 224 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { |
| 216 FOR_EACH_OBSERVER( | 225 FOR_EACH_OBSERVER( |
| 217 Observer, observers_, | 226 Observer, observers_, |
| 218 OnCategoryStatusChanged(category, GetCategoryStatus(category))); | 227 OnCategoryStatusChanged(category, GetCategoryStatus(category))); |
| 219 } | 228 } |
| 220 | 229 |
| 221 } // namespace ntp_snippets | 230 } // namespace ntp_snippets |
| OLD | NEW |