| 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 #include "components/favicon/core/favicon_handler.h" |
| 14 | 14 |
| 15 class GURL; | 15 class GURL; |
| 16 namespace bookmarks { | |
| 17 class BookmarkModel; | |
| 18 } | |
| 19 | |
| 20 | 16 |
| 21 namespace history { | 17 namespace history { |
| 22 class HistoryService; | 18 class HistoryService; |
| 23 } | 19 } |
| 24 | 20 |
| 25 namespace favicon { | 21 namespace favicon { |
| 26 | 22 |
| 27 class FaviconService; | 23 class FaviconService; |
| 28 struct FaviconURL; | 24 struct FaviconURL; |
| 29 | 25 |
| 30 // FaviconDriverImpl is a partial implementation of FaviconDriver that allow | 26 // FaviconDriverImpl is a partial implementation of FaviconDriver that allow |
| 31 // sharing implementation between different embedder. | 27 // sharing implementation between different embedder. |
| 32 // | 28 // |
| 33 // FaviconDriverImpl works with FaviconHandlers to fetch the favicons. It | 29 // FaviconDriverImpl works with FaviconHandlers to fetch the favicons. It |
| 34 // 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 |
| 35 // 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 |
| 36 // the history backend. | 32 // the history backend. |
| 37 class FaviconDriverImpl : public FaviconDriver, | 33 class FaviconDriverImpl : public FaviconDriver, |
| 38 public FaviconHandler::Delegate { | 34 public FaviconHandler::Delegate { |
| 39 public: | 35 public: |
| 40 // FaviconDriver implementation. | 36 // FaviconDriver implementation. |
| 41 void FetchFavicon(const GURL& page_url, bool is_same_document) override; | 37 void FetchFavicon(const GURL& page_url, bool is_same_document) override; |
| 42 | 38 |
| 43 // FaviconHandler::Delegate implementation. | |
| 44 bool IsBookmarked(const GURL& url) override; | |
| 45 | |
| 46 // Returns whether the driver is waiting for a download to complete or for | 39 // Returns whether the driver is waiting for a download to complete or for |
| 47 // data from the FaviconService. Reserved for testing. | 40 // data from the FaviconService. Reserved for testing. |
| 48 bool HasPendingTasksForTest(); | 41 bool HasPendingTasksForTest(); |
| 49 | 42 |
| 50 protected: | 43 protected: |
| 51 FaviconDriverImpl(FaviconService* favicon_service, | 44 FaviconDriverImpl(FaviconService* favicon_service, |
| 52 history::HistoryService* history_service, | 45 history::HistoryService* history_service); |
| 53 bookmarks::BookmarkModel* bookmark_model); | |
| 54 ~FaviconDriverImpl() override; | 46 ~FaviconDriverImpl() override; |
| 55 | 47 |
| 56 // Informs FaviconService that the favicon for |url| is out of date. If | 48 // Informs FaviconService that the favicon for |url| is out of date. If |
| 57 // |force_reload| is true, then discard information about favicon download | 49 // |force_reload| is true, then discard information about favicon download |
| 58 // failures. | 50 // failures. |
| 59 void SetFaviconOutOfDateForPage(const GURL& url, bool force_reload); | 51 void SetFaviconOutOfDateForPage(const GURL& url, bool force_reload); |
| 60 | 52 |
| 61 // Broadcasts new favicon URL candidates to FaviconHandlers. | 53 // Broadcasts new favicon URL candidates to FaviconHandlers. |
| 62 void OnUpdateCandidates(const GURL& page_url, | 54 void OnUpdateCandidates(const GURL& page_url, |
| 63 const std::vector<FaviconURL>& candidates, | 55 const std::vector<FaviconURL>& candidates, |
| 64 const GURL& manifest_url); | 56 const GURL& manifest_url); |
| 65 | 57 |
| 66 protected: | 58 protected: |
| 67 history::HistoryService* history_service() { return history_service_; } | 59 history::HistoryService* history_service() { return history_service_; } |
| 68 | 60 |
| 69 FaviconService* favicon_service() { return favicon_service_; } | 61 FaviconService* favicon_service() { return favicon_service_; } |
| 70 | 62 |
| 71 private: | 63 private: |
| 72 // KeyedServices used by FaviconDriverImpl. They may be null during testing, | 64 // KeyedServices used by FaviconDriverImpl. They may be null during testing, |
| 73 // but if they are defined, they must outlive the FaviconDriverImpl. | 65 // but if they are defined, they must outlive the FaviconDriverImpl. |
| 74 FaviconService* favicon_service_; | 66 FaviconService* favicon_service_; |
| 75 history::HistoryService* history_service_; | 67 history::HistoryService* history_service_; |
| 76 bookmarks::BookmarkModel* bookmark_model_; | |
| 77 | 68 |
| 78 // FaviconHandlers used to download the different kind of favicons. | 69 // FaviconHandlers used to download the different kind of favicons. |
| 79 std::vector<std::unique_ptr<FaviconHandler>> handlers_; | 70 std::vector<std::unique_ptr<FaviconHandler>> handlers_; |
| 80 | 71 |
| 81 DISALLOW_COPY_AND_ASSIGN(FaviconDriverImpl); | 72 DISALLOW_COPY_AND_ASSIGN(FaviconDriverImpl); |
| 82 }; | 73 }; |
| 83 | 74 |
| 84 } // namespace favicon | 75 } // namespace favicon |
| 85 | 76 |
| 86 #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_IMPL_H_ | 77 #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_IMPL_H_ |
| OLD | NEW |