1 // Copyright 2014 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 "chrome/browser/favicon/chrome_favicon_client.h"
7 #include "base/memory/singleton.h"
8 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
9 #include "chrome/common/url_constants.h"
10 #include "components/bookmarks/browser/bookmark_model.h"
11 #include "extensions/common/constants.h"
16 void RunFaviconCallbackIfNotCanceled(
17 const base::CancelableTaskTracker::IsCanceledCallback
& is_canceled_cb
,
18 const favicon_base::FaviconResultsCallback
& original_callback
,
19 const std::vector
<favicon_base::FaviconRawBitmapResult
>& results
) {
20 if (!is_canceled_cb
.Run()) {
21 original_callback
.Run(results
);
27 ChromeFaviconClient::ChromeFaviconClient(Profile
* profile
) : profile_(profile
) {
30 ChromeFaviconClient::~ChromeFaviconClient() {
33 bool ChromeFaviconClient::IsNativeApplicationURL(const GURL
& url
) {
34 return url
.SchemeIs(content::kChromeUIScheme
) ||
35 url
.SchemeIs(extensions::kExtensionScheme
);
38 base::CancelableTaskTracker::TaskId
39 ChromeFaviconClient::GetFaviconForNativeApplicationURL(
41 const std::vector
<int>& desired_sizes_in_pixel
,
42 const favicon_base::FaviconResultsCallback
& callback
,
43 base::CancelableTaskTracker
* tracker
) {
45 DCHECK(IsNativeApplicationURL(url
));
46 base::CancelableTaskTracker::IsCanceledCallback is_canceled_cb
;
47 base::CancelableTaskTracker::TaskId task_id
=
48 tracker
->NewTrackedTaskId(&is_canceled_cb
);
49 if (task_id
!= base::CancelableTaskTracker::kBadTaskId
) {
50 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL(
51 profile_
, url
, desired_sizes_in_pixel
,
52 base::Bind(&RunFaviconCallbackIfNotCanceled
, is_canceled_cb
, callback
));