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

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
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..67370b2315ba13bde9656138599a192a901d263e
--- /dev/null
+++ b/components/favicon/core/large_icon_service.cc
@@ -0,0 +1,68 @@
+// 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/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) {
+ favicon_base::SetDominantColorAsBackground(bitmap_result.bitmap_data,
+ &result.fallback_icon_style);
+ } else {
+ // The bitmap is the right size, use it.
+ result.bitmap = bitmap_result;
+ }
+
+ callback.Run(result);
+}
+
+} // namespace favicon

Powered by Google App Engine
This is Rietveld 408576698