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..49651fca7fad5bb0cb2f8320a6a6f9373b0bc186 |
--- /dev/null |
+++ b/components/favicon/core/large_icon_service.cc |
@@ -0,0 +1,69 @@ |
+// 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, 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) { |
+ 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 the right size, use it. |
+ result.bitmap = bitmap_result; |
huangs
2015/04/21 05:00:28
// FIXME: Resize the bitmap to be |desired_size_in
beaudoin
2015/04/21 15:11:11
Done.
|
+ } |
+ |
+ callback.Run(result); |
+} |
+ |
+} // namespace favicon |