Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Unified Diff: components/favicon/core/large_icon_service.cc

Issue 1092873002: [Icons NTP] Refactor large_icon_source to extract the logic shared between desktop and Android to f… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/favicon/core/large_icon_service.h ('k') | components/favicon_base/fallback_icon_style.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..702761c82d8adc1a3510a8deb612b157f406dc93
--- /dev/null
+++ b/components/favicon/core/large_icon_service.cc
@@ -0,0 +1,77 @@
+// 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()) {
+ // 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());
+ callback.Run(result);
+ return;
+ }
+
+ // 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
« no previous file with comments | « components/favicon/core/large_icon_service.h ('k') | components/favicon_base/fallback_icon_style.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698