| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_IMPL_H_ | 5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_IMPL_H_ |
| 6 #define COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_IMPL_H_ | 6 #define COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "components/favicon/core/favicon_driver.h" | 12 #include "components/favicon/core/favicon_driver.h" |
| 13 #include "components/favicon/core/favicon_handler.h" |
| 13 | 14 |
| 14 class GURL; | 15 class GURL; |
| 15 class SkBitmap; | |
| 16 | |
| 17 namespace bookmarks { | |
| 18 class BookmarkModel; | |
| 19 } | |
| 20 | |
| 21 namespace gfx { | |
| 22 class Size; | |
| 23 } | |
| 24 | 16 |
| 25 namespace history { | 17 namespace history { |
| 26 class HistoryService; | 18 class HistoryService; |
| 27 } | 19 } |
| 28 | 20 |
| 29 namespace favicon { | 21 namespace favicon { |
| 30 | 22 |
| 31 class FaviconHandler; | |
| 32 class FaviconService; | 23 class FaviconService; |
| 33 struct FaviconURL; | 24 struct FaviconURL; |
| 34 | 25 |
| 35 // FaviconDriverImpl is a partial implementation of FaviconDriver that allow | 26 // FaviconDriverImpl is a partial implementation of FaviconDriver that allow |
| 36 // sharing implementation between different embedder. | 27 // sharing implementation between different embedder. |
| 37 // | 28 // |
| 38 // FaviconDriverImpl works with FaviconHandlers to fetch the favicons. It | 29 // FaviconDriverImpl works with FaviconHandlers to fetch the favicons. It |
| 39 // fetches the given page's icons, requesting them from history backend. If the | 30 // fetches the given page's icons, requesting them from history backend. If the |
| 40 // icon is not available or expired, the icon will be downloaded and saved in | 31 // icon is not available or expired, the icon will be downloaded and saved in |
| 41 // the history backend. | 32 // the history backend. |
| 42 class FaviconDriverImpl : public FaviconDriver { | 33 class FaviconDriverImpl : public FaviconDriver { |
| 43 public: | 34 public: |
| 44 // Favicon download callback. | |
| 45 // Public for testing. | |
| 46 void DidDownloadFavicon(int id, | |
| 47 int http_status_code, | |
| 48 const GURL& image_url, | |
| 49 const std::vector<SkBitmap>& bitmaps, | |
| 50 const std::vector<gfx::Size>& original_bitmap_sizes); | |
| 51 | |
| 52 // FaviconDriver implementation. | 35 // FaviconDriver implementation. |
| 53 void FetchFavicon(const GURL& url) override; | 36 void FetchFavicon(const GURL& url) override; |
| 54 bool IsBookmarked(const GURL& url) override; | 37 |
| 55 bool HasPendingTasksForTest() override; | 38 // Returns whether the driver is waiting for a download to complete or for |
| 39 // data from the FaviconService. Reserved for testing. |
| 40 bool HasPendingTasksForTest(); |
| 56 | 41 |
| 57 protected: | 42 protected: |
| 58 FaviconDriverImpl(FaviconService* favicon_service, | 43 FaviconDriverImpl(FaviconService* favicon_service, |
| 59 history::HistoryService* history_service, | 44 history::HistoryService* history_service, |
| 60 bookmarks::BookmarkModel* bookmark_model); | 45 FaviconHandler::Delegate* delegate); |
| 61 ~FaviconDriverImpl() override; | 46 ~FaviconDriverImpl() override; |
| 62 | 47 |
| 63 // Returns whether downloading favicon for |url| previously failed. | 48 // Returns whether downloading favicon for |url| previously failed. |
| 64 bool WasUnableToDownloadFavicon(const GURL& url); | 49 bool WasUnableToDownloadFavicon(const GURL& url); |
| 65 | 50 |
| 66 // Informs FaviconService that the favicon for |url| is out of date. If | 51 // Informs FaviconService that the favicon for |url| is out of date. If |
| 67 // |force_reload| is true, then discard information about favicon download | 52 // |force_reload| is true, then discard information about favicon download |
| 68 // failures. | 53 // failures. |
| 69 void SetFaviconOutOfDateForPage(const GURL& url, bool force_reload); | 54 void SetFaviconOutOfDateForPage(const GURL& url, bool force_reload); |
| 70 | 55 |
| 71 // Broadcasts new favicon URL candidates to FaviconHandlers. | 56 // Broadcasts new favicon URL candidates to FaviconHandlers. |
| 72 void OnUpdateFaviconURL(const GURL& page_url, | 57 void OnUpdateFaviconURL(const GURL& page_url, |
| 73 const std::vector<FaviconURL>& candidates); | 58 const std::vector<FaviconURL>& candidates); |
| 74 | 59 |
| 75 protected: | 60 protected: |
| 76 history::HistoryService* history_service() { return history_service_; } | 61 history::HistoryService* history_service() { return history_service_; } |
| 77 | 62 |
| 78 FaviconService* favicon_service() { return favicon_service_; } | 63 FaviconService* favicon_service() { return favicon_service_; } |
| 79 | 64 |
| 80 private: | 65 private: |
| 81 // KeyedServices used by FaviconDriverImpl. They may be null during testing, | 66 // KeyedServices used by FaviconDriverImpl. They may be null during testing, |
| 82 // but if they are defined, they must outlive the FaviconDriverImpl. | 67 // but if they are defined, they must outlive the FaviconDriverImpl. |
| 83 FaviconService* favicon_service_; | 68 FaviconService* favicon_service_; |
| 84 history::HistoryService* history_service_; | 69 history::HistoryService* history_service_; |
| 85 bookmarks::BookmarkModel* bookmark_model_; | |
| 86 | 70 |
| 87 // FaviconHandlers used to download the different kind of favicons. | 71 // FaviconHandlers used to download the different kind of favicons. |
| 88 // |touch_icon_handler_| may be null depending on the platform and variations. | 72 // |touch_icon_handler_| may be null depending on the platform and variations. |
| 89 std::unique_ptr<FaviconHandler> favicon_handler_; | 73 std::unique_ptr<FaviconHandler> favicon_handler_; |
| 90 std::unique_ptr<FaviconHandler> touch_icon_handler_; | 74 std::unique_ptr<FaviconHandler> touch_icon_handler_; |
| 91 | 75 |
| 92 DISALLOW_COPY_AND_ASSIGN(FaviconDriverImpl); | 76 DISALLOW_COPY_AND_ASSIGN(FaviconDriverImpl); |
| 93 }; | 77 }; |
| 94 | 78 |
| 95 } // namespace favicon | 79 } // namespace favicon |
| 96 | 80 |
| 97 #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_IMPL_H_ | 81 #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_IMPL_H_ |
| OLD | NEW |