Chromium Code Reviews| Index: components/favicon/core/large_icon_service.cc |
| diff --git a/components/favicon/core/large_icon_service.cc b/components/favicon/core/large_icon_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..427ffc03b1500a2f8f9def34274f0bf8d4b629a5 |
| --- /dev/null |
| +++ b/components/favicon/core/large_icon_service.cc |
| @@ -0,0 +1,76 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/favicon/core/large_icon_service.h" |
| + |
| +#include "components/favicon/core/favicon_service.h" |
| +#include "components/favicon_base/fallback_icon_style.h" |
| +#include "components/favicon_base/favicon_types.h" |
| + |
| +namespace favicon { |
| + |
| +LargeIconService::LargeIconService(FaviconService* favicon_service) |
| + : favicon_service_(favicon_service) { |
| + large_icon_types_.push_back(favicon_base::IconType::FAVICON); |
| + large_icon_types_.push_back(favicon_base::IconType::TOUCH_ICON); |
| + large_icon_types_.push_back(favicon_base::IconType::TOUCH_PRECOMPOSED_ICON); |
| +} |
| + |
| +LargeIconService::~LargeIconService() { |
| +} |
| + |
| +base::CancelableTaskTracker::TaskId |
| + LargeIconService::GetLargeIconOrFallbackStyle( |
| + const GURL& page_url, |
| + int desired_size_in_pixel, |
| + const favicon_base::LargeIconCallback& callback, |
| + base::CancelableTaskTracker* tracker) { |
| + // TODO(beaudoin): For now this is just a wrapper around |
| + // GetLargestRawFaviconForPageURL. Add the logic required to select the best |
| + // possible large icon. Also add logic to fetch-on-demand when the URL of |
| + // a large icon is known but its bitmap is not available. |
| + return favicon_service_->GetLargestRawFaviconForPageURL( |
| + page_url, |
| + large_icon_types_, |
| + desired_size_in_pixel, |
| + base::Bind(&LargeIconService::RunLargeIconCallback, |
| + base::Unretained(this), callback, desired_size_in_pixel), |
| + tracker); |
| +} |
| + |
| +void LargeIconService::RunLargeIconCallback( |
| + const favicon_base::LargeIconCallback& callback, |
| + int desired_size_in_pixel, |
| + const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
| + // If there are no bitmaps, return a result with an empty |bitmap| and a |
| + // default |fallback_icon_style|. |
| + favicon_base::LargeIconResult result; |
| + if (!bitmap_result.is_valid()) { |
| + callback.Run(result); |
| + return; |
| + } |
| + |
| + // If there is a bitmap but it's smaller than the requested size or |
| + // non-square, compute its dominant color and use it as background in |
| + // |fallback_icon_style|. |
| + if (bitmap_result.pixel_size.width() < desired_size_in_pixel || |
| + bitmap_result.pixel_size.height() < desired_size_in_pixel || |
| + bitmap_result.pixel_size.width() != bitmap_result.pixel_size.height()) { |
|
pkotwicz
2015/04/21 18:19:48
It is probably worth mentioning in the CL descript
beaudoin
2015/04/21 19:03:23
Good point. I think it was a blatant bug in the or
|
| + // TODO(beaudoin): Resize the icon if it's large enough. Alternatively, |
| + // return it and let the HTML resize it. |
| + result.fallback_icon_style.reset(new favicon_base::FallbackIconStyle()); |
| + favicon_base::SetDominantColorAsBackground( |
| + bitmap_result.bitmap_data, result.fallback_icon_style.get()); |
| + } else { |
| + // The bitmap is square and at least as large as the requested one, return |
| + // it. |
| + // TODO(beaudoin): Resize the icon if it's too large. Alternatively, return |
| + // it and let the HTML resize it. |
| + result.bitmap = bitmap_result; |
| + } |
| + |
| + callback.Run(result); |
| +} |
| + |
| +} // namespace favicon |