Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / favicon / core / favicon_util.cc
blobb3a5c0929f9391cd30d927f3b26e1c8fef5bc4f7
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
3 // found in the LICENSE file.
5 #include "components/favicon/core/favicon_util.h"
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "components/favicon/core/favicon_service.h"
11 namespace favicon {
12 namespace {
14 // Adapter to convert a FaviconImageCallback into a FaviconRawBitmapCallback
15 // for GetFaviconImageForPageURL.
16 void RunCallbackWithImage(
17 const favicon_base::FaviconImageCallback& callback,
18 const favicon_base::FaviconRawBitmapResult& bitmap_result) {
19 favicon_base::FaviconImageResult result;
20 if (bitmap_result.is_valid()) {
21 result.image = gfx::Image::CreateFrom1xPNGBytes(
22 bitmap_result.bitmap_data->front(), bitmap_result.bitmap_data->size());
23 result.icon_url = bitmap_result.icon_url;
24 callback.Run(result);
25 return;
27 callback.Run(result);
30 } // namespace
32 base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL(
33 FaviconService* favicon_service,
34 const GURL& page_url,
35 favicon_base::IconType type,
36 const favicon_base::FaviconImageCallback& callback,
37 base::CancelableTaskTracker* tracker) {
38 if (!favicon_service)
39 return base::CancelableTaskTracker::kBadTaskId;
41 if (type == favicon_base::FAVICON) {
42 return favicon_service->GetFaviconImageForPageURL(page_url, callback,
43 tracker);
46 return favicon_service->GetRawFaviconForPageURL(
47 page_url, type, 0, base::Bind(&RunCallbackWithImage, callback), tracker);
50 } // namespace favicon