OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/favicon/core/large_icon_service.h" | 5 #include "components/favicon/core/large_icon_service.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/task_runner.h" | 16 #include "base/task_runner.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
19 #include "components/data_use_measurement/core/data_use_user_data.h" | 19 #include "components/data_use_measurement/core/data_use_user_data.h" |
20 #include "components/favicon/core/favicon_service.h" | 20 #include "components/favicon/core/favicon_service.h" |
21 #include "components/favicon_base/fallback_icon_style.h" | 21 #include "components/favicon_base/fallback_icon_style.h" |
22 #include "components/favicon_base/favicon_types.h" | 22 #include "components/favicon_base/favicon_types.h" |
23 #include "components/favicon_base/favicon_util.h" | 23 #include "components/favicon_base/favicon_util.h" |
24 #include "components/image_fetcher/core/request_metadata.h" | |
24 #include "skia/ext/image_operations.h" | 25 #include "skia/ext/image_operations.h" |
25 #include "ui/gfx/codec/png_codec.h" | 26 #include "ui/gfx/codec/png_codec.h" |
26 #include "ui/gfx/geometry/size.h" | 27 #include "ui/gfx/geometry/size.h" |
27 #include "url/url_canon.h" | 28 #include "url/url_canon.h" |
28 | 29 |
29 namespace favicon { | 30 namespace favicon { |
30 namespace { | 31 namespace { |
31 | 32 |
32 const char kGoogleServerV2RequestFormat[] = | 33 const char kGoogleServerV2RequestFormat[] = |
33 "https://t0.gstatic.com/faviconV2?" | 34 "https://t0.gstatic.com/faviconV2?" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 return; | 214 return; |
214 } | 215 } |
215 image_callback_.Run( | 216 image_callback_.Run( |
216 favicon_base::LargeIconImageResult(fallback_icon_style_.release())); | 217 favicon_base::LargeIconImageResult(fallback_icon_style_.release())); |
217 } | 218 } |
218 | 219 |
219 void OnFetchIconFromGoogleServerComplete( | 220 void OnFetchIconFromGoogleServerComplete( |
220 FaviconService* favicon_service, | 221 FaviconService* favicon_service, |
221 const GURL& page_url, | 222 const GURL& page_url, |
222 const base::Callback<void(bool success)>& callback, | 223 const base::Callback<void(bool success)>& callback, |
223 const std::string& icon_url, | 224 const std::string& icon_url, |
pkotwicz
2017/04/10 15:12:42
Maybe rename |icon_url| to |server_request_url| he
jkrcal
2017/04/10 15:50:59
Done.
| |
224 const gfx::Image& image, | 225 const gfx::Image& image, |
225 const image_fetcher::RequestMetadata& metadata) { | 226 const image_fetcher::RequestMetadata& metadata) { |
226 if (image.IsEmpty()) { | 227 if (image.IsEmpty()) { |
227 DLOG(WARNING) << "large icon server fetch empty " << icon_url; | 228 DLOG(WARNING) << "large icon server fetch empty " << icon_url; |
228 favicon_service->UnableToDownloadFavicon(GURL(icon_url)); | 229 favicon_service->UnableToDownloadFavicon(GURL(icon_url)); |
229 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 230 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
230 base::Bind(callback, false)); | 231 base::Bind(callback, false)); |
231 return; | 232 return; |
232 } | 233 } |
233 | 234 |
234 // TODO(crbug.com/699542): Extract the original icon url from the response | 235 // Get the original favicon URL from Content-Location http header (if given). |
235 // headers if available and use it instead of |icon_url|. Possibly the type | 236 std::string original_icon_url = metadata.content_location_header; |
236 // too, because using TOUCH_ICON is a hacky way that allows us to not | 237 if (original_icon_url.empty()) { |
237 // interfere with sync. | 238 original_icon_url = icon_url; // Use the favicon server url as fallback. |
239 } | |
238 | 240 |
239 // Write fetched icons to FaviconService's cache, but only if no icon was | 241 // Write fetched icons to FaviconService's cache, but only if no icon was |
240 // available (clients are encouraged to do this in advance, but meanwhile | 242 // available (clients are encouraged to do this in advance, but meanwhile |
241 // something else could've been written). By marking the icons initially | 243 // something else could've been written). By marking the icons initially |
242 // expired (out-of-date), they will be refetched when we visit the original | 244 // expired (out-of-date), they will be refetched when we visit the original |
243 // page any time in the future. | 245 // page any time in the future. |
244 favicon_service->SetLastResortFavicons(page_url, GURL(icon_url), | 246 favicon_service->SetLastResortFavicons(page_url, GURL(original_icon_url), |
245 favicon_base::IconType::TOUCH_ICON, | 247 favicon_base::IconType::TOUCH_ICON, |
246 image, callback); | 248 image, callback); |
247 } | 249 } |
248 | 250 |
249 } // namespace | 251 } // namespace |
250 | 252 |
251 LargeIconService::LargeIconService( | 253 LargeIconService::LargeIconService( |
252 FaviconService* favicon_service, | 254 FaviconService* favicon_service, |
253 const scoped_refptr<base::TaskRunner>& background_task_runner, | 255 const scoped_refptr<base::TaskRunner>& background_task_runner, |
254 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher) | 256 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 // TODO(beaudoin): For now this is just a wrapper around | 335 // TODO(beaudoin): For now this is just a wrapper around |
334 // GetLargestRawFaviconForPageURL. Add the logic required to select the best | 336 // GetLargestRawFaviconForPageURL. Add the logic required to select the best |
335 // possible large icon. Also add logic to fetch-on-demand when the URL of | 337 // possible large icon. Also add logic to fetch-on-demand when the URL of |
336 // a large icon is known but its bitmap is not available. | 338 // a large icon is known but its bitmap is not available. |
337 return favicon_service_->GetLargestRawFaviconForPageURL( | 339 return favicon_service_->GetLargestRawFaviconForPageURL( |
338 page_url, large_icon_types_, min_source_size_in_pixel, | 340 page_url, large_icon_types_, min_source_size_in_pixel, |
339 base::Bind(&LargeIconWorker::OnIconLookupComplete, worker), tracker); | 341 base::Bind(&LargeIconWorker::OnIconLookupComplete, worker), tracker); |
340 } | 342 } |
341 | 343 |
342 } // namespace favicon | 344 } // namespace favicon |
OLD | NEW |