Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / favicon / chrome_favicon_client.cc
blobce0882e4a556997b84ec444dbb6cd7b1d014b6ea
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"
11 #include "url/gurl.h"
13 namespace {
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);
24 } // namespace
26 ChromeFaviconClient::ChromeFaviconClient(
27 Profile* profile,
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(
46 const GURL& url,
47 const std::vector<int>& desired_sizes_in_pixel,
48 const favicon_base::FaviconResultsCallback& callback,
49 base::CancelableTaskTracker* tracker) {
50 DCHECK(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));
60 return task_id;