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