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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 LOG(WARNING) << "Requested image for suggestion " << suggestion_id | 127 LOG(WARNING) << "Requested image for suggestion " << suggestion_id |
128 << " for unavailable category " << suggestion_id.category(); | 128 << " for unavailable category " << suggestion_id.category(); |
129 base::ThreadTaskRunnerHandle::Get()->PostTask( | 129 base::ThreadTaskRunnerHandle::Get()->PostTask( |
130 FROM_HERE, base::Bind(callback, gfx::Image())); | 130 FROM_HERE, base::Bind(callback, gfx::Image())); |
131 return; | 131 return; |
132 } | 132 } |
133 providers_by_category_[suggestion_id.category()]->FetchSuggestionImage( | 133 providers_by_category_[suggestion_id.category()]->FetchSuggestionImage( |
134 suggestion_id, callback); | 134 suggestion_id, callback); |
135 } | 135 } |
136 | 136 |
| 137 // TODO(jkrcal): Split the favicon fetching into a separate class. |
137 void ContentSuggestionsService::FetchSuggestionFavicon( | 138 void ContentSuggestionsService::FetchSuggestionFavicon( |
138 const ContentSuggestion::ID& suggestion_id, | 139 const ContentSuggestion::ID& suggestion_id, |
139 int minimum_size_in_pixel, | 140 int minimum_size_in_pixel, |
140 int desired_size_in_pixel, | 141 int desired_size_in_pixel, |
141 const ImageFetchedCallback& callback) { | 142 const ImageFetchedCallback& callback) { |
142 // TODO(jkrcal): Allow the provider to provide (or possibly override) the URL | |
143 // for looking up the favicon. | |
144 std::vector<ContentSuggestion>* suggestions = | 143 std::vector<ContentSuggestion>* suggestions = |
145 &suggestions_by_category_[suggestion_id.category()]; | 144 &suggestions_by_category_[suggestion_id.category()]; |
146 auto position = | 145 auto position = |
147 std::find_if(suggestions->begin(), suggestions->end(), | 146 std::find_if(suggestions->begin(), suggestions->end(), |
148 [&suggestion_id](const ContentSuggestion& suggestion) { | 147 [&suggestion_id](const ContentSuggestion& suggestion) { |
149 return suggestion_id == suggestion.id(); | 148 return suggestion_id == suggestion.id(); |
150 }); | 149 }); |
151 if (position == suggestions->end() || !large_icon_service_) { | 150 if (position == suggestions->end() || !large_icon_service_) { |
152 base::ThreadTaskRunnerHandle::Get()->PostTask( | 151 base::ThreadTaskRunnerHandle::Get()->PostTask( |
153 FROM_HERE, base::Bind(callback, gfx::Image())); | 152 FROM_HERE, base::Bind(callback, gfx::Image())); |
154 return; | 153 return; |
155 } | 154 } |
156 | 155 |
157 const GURL& publisher_url = position->url().GetWithEmptyPath(); | 156 const GURL& domain_with_favicon = |
| 157 position->url_with_favicon().GetWithEmptyPath(); |
158 | 158 |
159 // TODO(jkrcal): Create a general wrapper function in LargeIconService that | 159 // TODO(jkrcal): Create a general wrapper function in LargeIconService that |
160 // does handle the get-from-cache-and-fallback-to-google-server functionality | 160 // does handle the get-from-cache-and-fallback-to-google-server functionality |
161 // in one shot (for all clients that do not need to react in between). | 161 // in one shot (for all clients that do not need to react in between). |
162 large_icon_service_->GetLargeIconImageOrFallbackStyle( | 162 large_icon_service_->GetLargeIconImageOrFallbackStyle( |
163 publisher_url, minimum_size_in_pixel, desired_size_in_pixel, | 163 domain_with_favicon, minimum_size_in_pixel, desired_size_in_pixel, |
164 base::Bind(&ContentSuggestionsService::OnGetFaviconFromCacheFinished, | 164 base::Bind(&ContentSuggestionsService::OnGetFaviconFromCacheFinished, |
165 base::Unretained(this), publisher_url, minimum_size_in_pixel, | 165 base::Unretained(this), domain_with_favicon, |
166 desired_size_in_pixel, callback, | 166 minimum_size_in_pixel, desired_size_in_pixel, callback, |
167 /*continue_to_google_server=*/true), | 167 /*continue_to_google_server=*/true), |
168 &favicons_task_tracker_); | 168 &favicons_task_tracker_); |
169 } | 169 } |
170 | 170 |
171 void ContentSuggestionsService::OnGetFaviconFromCacheFinished( | 171 void ContentSuggestionsService::OnGetFaviconFromCacheFinished( |
172 const GURL& publisher_url, | 172 const GURL& publisher_url, |
173 int minimum_size_in_pixel, | 173 int minimum_size_in_pixel, |
174 int desired_size_in_pixel, | 174 int desired_size_in_pixel, |
175 const ImageFetchedCallback& callback, | 175 const ImageFetchedCallback& callback, |
176 bool continue_to_google_server, | 176 bool continue_to_google_server, |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { | 621 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { |
622 base::ListValue list; | 622 base::ListValue list; |
623 for (const auto& category_provider_pair : dismissed_providers_by_category_) { | 623 for (const auto& category_provider_pair : dismissed_providers_by_category_) { |
624 list.AppendInteger(category_provider_pair.first.id()); | 624 list.AppendInteger(category_provider_pair.first.id()); |
625 } | 625 } |
626 | 626 |
627 pref_service_->Set(prefs::kDismissedCategories, list); | 627 pref_service_->Set(prefs::kDismissedCategories, list); |
628 } | 628 } |
629 | 629 |
630 } // namespace ntp_snippets | 630 } // namespace ntp_snippets |
OLD | NEW |