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 "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
8 #include "chrome/common/url_constants.h"
9 #include "components/bookmarks/browser/bookmark_model.h"
10 #include "extensions/common/constants.h"
15 void RunFaviconCallbackIfNotCanceled(
16 const base::CancelableTaskTracker::IsCanceledCallback
& is_canceled_cb
,
17 const favicon_base::FaviconResultsCallback
& original_callback
,
18 const std::vector
<favicon_base::FaviconRawBitmapResult
>& results
) {
19 if (!is_canceled_cb
.Run()) {
20 original_callback
.Run(results
);
26 ChromeFaviconClient::ChromeFaviconClient(
28 bookmarks::BookmarkModel
* bookmark_model
)
29 : profile_(profile
), bookmark_model_(bookmark_model
) {
32 ChromeFaviconClient::~ChromeFaviconClient() {
35 bool ChromeFaviconClient::IsBookmarked(const GURL
& url
) {
36 return bookmark_model_
&& bookmark_model_
->IsBookmarked(url
);
39 bool ChromeFaviconClient::IsNativeApplicationURL(const GURL
& url
) {
40 return url
.SchemeIs(content::kChromeUIScheme
) ||
41 url
.SchemeIs(extensions::kExtensionScheme
);
44 base::CancelableTaskTracker::TaskId
45 ChromeFaviconClient::GetFaviconForNativeApplicationURL(
47 const std::vector
<int>& desired_sizes_in_pixel
,
48 const favicon_base::FaviconResultsCallback
& callback
,
49 base::CancelableTaskTracker
* tracker
) {
51 DCHECK(IsNativeApplicationURL(url
));
52 base::CancelableTaskTracker::IsCanceledCallback is_canceled_cb
;
53 base::CancelableTaskTracker::TaskId task_id
=
54 tracker
->NewTrackedTaskId(&is_canceled_cb
);
55 if (task_id
!= base::CancelableTaskTracker::kBadTaskId
) {
56 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL(
57 profile_
, url
, desired_sizes_in_pixel
,
58 base::Bind(&RunFaviconCallbackIfNotCanceled
, is_canceled_cb
, callback
));