| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 59 } |
| 60 | 60 |
| 61 const std::vector<ContentSuggestion>& | 61 const std::vector<ContentSuggestion>& |
| 62 ContentSuggestionsService::GetSuggestionsForCategory(Category category) const { | 62 ContentSuggestionsService::GetSuggestionsForCategory(Category category) const { |
| 63 auto iterator = suggestions_by_category_.find(category); | 63 auto iterator = suggestions_by_category_.find(category); |
| 64 if (iterator == suggestions_by_category_.end()) | 64 if (iterator == suggestions_by_category_.end()) |
| 65 return no_suggestions_; | 65 return no_suggestions_; |
| 66 return iterator->second; | 66 return iterator->second; |
| 67 } | 67 } |
| 68 | 68 |
| 69 void ContentSuggestionsService::FetchMoreSuggestions(Category category) { |
| 70 auto iterator = providers_by_category_.find(category); |
| 71 if (iterator != providers_by_category_.end()) |
| 72 iterator->second->FetchMoreSuggestions(category); |
| 73 } |
| 74 |
| 69 void ContentSuggestionsService::FetchSuggestionImage( | 75 void ContentSuggestionsService::FetchSuggestionImage( |
| 70 const std::string& suggestion_id, | 76 const std::string& suggestion_id, |
| 71 const ImageFetchedCallback& callback) { | 77 const ImageFetchedCallback& callback) { |
| 72 if (!id_category_map_.count(suggestion_id)) { | 78 if (!id_category_map_.count(suggestion_id)) { |
| 73 LOG(WARNING) << "Requested image for unknown suggestion " << suggestion_id; | 79 LOG(WARNING) << "Requested image for unknown suggestion " << suggestion_id; |
| 74 base::ThreadTaskRunnerHandle::Get()->PostTask( | 80 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 75 FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image())); | 81 FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image())); |
| 76 return; | 82 return; |
| 77 } | 83 } |
| 78 Category category = id_category_map_.at(suggestion_id); | 84 Category category = id_category_map_.at(suggestion_id); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 return true; | 254 return true; |
| 249 } | 255 } |
| 250 | 256 |
| 251 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { | 257 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { |
| 252 FOR_EACH_OBSERVER( | 258 FOR_EACH_OBSERVER( |
| 253 Observer, observers_, | 259 Observer, observers_, |
| 254 OnCategoryStatusChanged(category, GetCategoryStatus(category))); | 260 OnCategoryStatusChanged(category, GetCategoryStatus(category))); |
| 255 } | 261 } |
| 256 | 262 |
| 257 } // namespace ntp_snippets | 263 } // namespace ntp_snippets |
| OLD | NEW |