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 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_IMPL_H_
6 #define COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_IMPL_H_
10 #include "base/macros.h"
11 #include "components/favicon/core/favicon_driver.h"
31 class FaviconDriverObserver
;
36 // FaviconDriverImpl is a partial implementation of FaviconDriver that allow
37 // sharing implementation between different embedder.
39 // FaviconDriverImpl works with FaviconHandlers to fetch the favicons. It
40 // fetches the given page's icons, requesting them from history backend. If the
41 // icon is not available or expired, the icon will be downloaded and saved in
42 // the history backend.
43 class FaviconDriverImpl
: public FaviconDriver
{
45 // Favicon download callback.
46 // Public for testing.
47 void DidDownloadFavicon(int id
,
49 const GURL
& image_url
,
50 const std::vector
<SkBitmap
>& bitmaps
,
51 const std::vector
<gfx::Size
>& original_bitmap_sizes
);
53 // FaviconDriver implementation.
54 void FetchFavicon(const GURL
& url
) override
;
55 bool IsBookmarked(const GURL
& url
) override
;
56 void OnFaviconAvailable(const gfx::Image
& image
,
58 bool is_active_favicon
) override
;
59 bool HasPendingTasksForTest() override
;
62 FaviconDriverImpl(FaviconService
* favicon_service
,
63 history::HistoryService
* history_service
,
64 bookmarks::BookmarkModel
* bookmark_model
);
65 ~FaviconDriverImpl() override
;
67 // Returns whether downloading favicon for |url| previously failed.
68 bool WasUnableToDownloadFavicon(const GURL
& url
);
70 // Informs FaviconService that the favicon for |url| is out of date. If
71 // |force_reload| is true, then discard information about favicon download
73 void SetFaviconOutOfDateForPage(const GURL
& url
, bool force_reload
);
75 // Broadcasts new favicon URL candidates to FaviconHandlers.
76 void OnUpdateFaviconURL(const std::vector
<FaviconURL
>& candidates
);
79 history::HistoryService
* history_service() { return history_service_
; }
81 FaviconService
* favicon_service() { return favicon_service_
; }
84 // KeyedServices used by FaviconDriverImpl. They may be null during testing,
85 // but if they are defined, they must outlive the FaviconDriverImpl.
86 FaviconService
* favicon_service_
;
87 history::HistoryService
* history_service_
;
88 bookmarks::BookmarkModel
* bookmark_model_
;
90 // FaviconHandlers used to download the different kind of favicons. Both
91 // |touch_icon_handler_| and |large_icon_handler_| may be null depending
92 // on the platform or variations.
93 scoped_ptr
<FaviconHandler
> favicon_handler_
;
94 scoped_ptr
<FaviconHandler
> touch_icon_handler_
;
95 scoped_ptr
<FaviconHandler
> large_icon_handler_
;
97 DISALLOW_COPY_AND_ASSIGN(FaviconDriverImpl
);
100 } // namespace favicon
102 #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_IMPL_H_