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 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 void ContentSuggestionsService::FetchSuggestionFavicon( | 137 void ContentSuggestionsService::FetchSuggestionFavicon( |
| 138 const ContentSuggestion::ID& suggestion_id, | 138 const ContentSuggestion::ID& suggestion_id, |
| 139 int minimum_size_in_pixel, | 139 int minimum_size_in_pixel, |
| 140 int desired_size_in_pixel, | 140 int desired_size_in_pixel, |
| 141 const ImageFetchedCallback& callback) { | 141 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 = | 142 std::vector<ContentSuggestion>* suggestions = |
| 145 &suggestions_by_category_[suggestion_id.category()]; | 143 &suggestions_by_category_[suggestion_id.category()]; |
| 146 auto position = | 144 auto position = |
| 147 std::find_if(suggestions->begin(), suggestions->end(), | 145 std::find_if(suggestions->begin(), suggestions->end(), |
| 148 [&suggestion_id](const ContentSuggestion& suggestion) { | 146 [&suggestion_id](const ContentSuggestion& suggestion) { |
| 149 return suggestion_id == suggestion.id(); | 147 return suggestion_id == suggestion.id(); |
| 150 }); | 148 }); |
| 151 if (position == suggestions->end() || !large_icon_service_) { | 149 if (position == suggestions->end() || !large_icon_service_) { |
| 152 base::ThreadTaskRunnerHandle::Get()->PostTask( | 150 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 153 FROM_HERE, base::Bind(callback, gfx::Image())); | 151 FROM_HERE, base::Bind(callback, gfx::Image())); |
| 154 return; | 152 return; |
| 155 } | 153 } |
| 156 | 154 |
| 157 const GURL& publisher_url = position->url().GetWithEmptyPath(); | 155 const GURL& publisher_url = |
|
Marc Treib
2017/04/12 11:48:00
s/publisher_url/url_with_favicon/ ?
jkrcal
2017/04/12 12:44:18
Done. Renamed to domain_with_favicon to make the t
| |
| 156 position->url_with_favicon().is_valid() | |
| 157 ? position->url_with_favicon().GetWithEmptyPath() | |
|
Marc Treib
2017/04/12 11:48:00
Hm, should the fallback logic live in ContentSugge
jkrcal
2017/04/12 12:44:19
I do not think so, because it is CSS who is using
Marc Treib
2017/04/12 12:50:18
I didn't mean the trimming, just the "url_with_fav
jkrcal
2017/04/12 12:58:17
Ah, fair enough. Done.
| |
| 158 : position->url().GetWithEmptyPath(); | |
| 158 | 159 |
| 159 // TODO(jkrcal): Create a general wrapper function in LargeIconService that | 160 // TODO(jkrcal): Create a general wrapper function in LargeIconService that |
| 160 // does handle the get-from-cache-and-fallback-to-google-server functionality | 161 // 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). | 162 // in one shot (for all clients that do not need to react in between). |
| 162 large_icon_service_->GetLargeIconImageOrFallbackStyle( | 163 large_icon_service_->GetLargeIconImageOrFallbackStyle( |
| 163 publisher_url, minimum_size_in_pixel, desired_size_in_pixel, | 164 publisher_url, minimum_size_in_pixel, desired_size_in_pixel, |
| 164 base::Bind(&ContentSuggestionsService::OnGetFaviconFromCacheFinished, | 165 base::Bind(&ContentSuggestionsService::OnGetFaviconFromCacheFinished, |
| 165 base::Unretained(this), publisher_url, minimum_size_in_pixel, | 166 base::Unretained(this), publisher_url, minimum_size_in_pixel, |
| 166 desired_size_in_pixel, callback, | 167 desired_size_in_pixel, callback, |
| 167 /*continue_to_google_server=*/true), | 168 /*continue_to_google_server=*/true), |
| 168 &favicons_task_tracker_); | 169 &favicons_task_tracker_); |
| 169 } | 170 } |
| 170 | 171 |
| 171 void ContentSuggestionsService::OnGetFaviconFromCacheFinished( | 172 void ContentSuggestionsService::OnGetFaviconFromCacheFinished( |
|
Marc Treib
2017/04/12 11:48:00
Orthogonal to this CL: We might want to extract th
jkrcal
2017/04/12 12:44:19
Good point, added a CL.
| |
| 172 const GURL& publisher_url, | 173 const GURL& publisher_url, |
| 173 int minimum_size_in_pixel, | 174 int minimum_size_in_pixel, |
| 174 int desired_size_in_pixel, | 175 int desired_size_in_pixel, |
| 175 const ImageFetchedCallback& callback, | 176 const ImageFetchedCallback& callback, |
| 176 bool continue_to_google_server, | 177 bool continue_to_google_server, |
| 177 const favicon_base::LargeIconImageResult& result) { | 178 const favicon_base::LargeIconImageResult& result) { |
| 178 if (!result.image.IsEmpty()) { | 179 if (!result.image.IsEmpty()) { |
| 179 callback.Run(result.image); | 180 callback.Run(result.image); |
| 180 return; | 181 return; |
| 181 } | 182 } |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { | 622 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { |
| 622 base::ListValue list; | 623 base::ListValue list; |
| 623 for (const auto& category_provider_pair : dismissed_providers_by_category_) { | 624 for (const auto& category_provider_pair : dismissed_providers_by_category_) { |
| 624 list.AppendInteger(category_provider_pair.first.id()); | 625 list.AppendInteger(category_provider_pair.first.id()); |
| 625 } | 626 } |
| 626 | 627 |
| 627 pref_service_->Set(prefs::kDismissedCategories, list); | 628 pref_service_->Set(prefs::kDismissedCategories, list); |
| 628 } | 629 } |
| 629 | 630 |
| 630 } // namespace ntp_snippets | 631 } // namespace ntp_snippets |
| OLD | NEW |