OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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. | |
4 | |
5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_IMPL_H_ | |
6 #define COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_IMPL_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <memory> | |
11 #include <vector> | |
12 | |
13 #include "base/callback.h" | |
14 #include "base/containers/hash_tables.h" | |
15 #include "base/macros.h" | |
16 #include "base/memory/ref_counted.h" | |
17 #include "base/task/cancelable_task_tracker.h" | |
18 #include "components/favicon/core/favicon_service.h" | |
19 #include "components/favicon_base/favicon_callback.h" | |
20 #include "components/favicon_base/favicon_types.h" | |
21 #include "components/favicon_base/favicon_usage_data.h" | |
22 | |
23 class GURL; | |
24 | |
25 namespace history { | |
26 class HistoryService; | |
27 } | |
28 | |
29 namespace favicon { | |
30 | |
31 class FaviconClient; | |
32 | |
33 // The favicon service provides methods to access favicons. It calls the history | |
34 // backend behind the scenes. The callbacks are run asynchronously, even in the | |
35 // case of an error. | |
36 class FaviconServiceImpl : public FaviconService { | |
37 public: | |
38 // |history_service| most not be nullptr and must outlive this object. | |
39 FaviconServiceImpl(std::unique_ptr<FaviconClient> favicon_client, | |
40 history::HistoryService* history_service); | |
41 ~FaviconServiceImpl() override; | |
42 | |
43 // FaviconServiceInterface implementation. | |
pkotwicz
2017/02/16 04:07:27
Nit: "FaviconServiceInterface implementation." ->
mastiz
2017/02/16 09:46:25
Done, thx!
| |
44 base::CancelableTaskTracker::TaskId GetFaviconImage( | |
45 const GURL& icon_url, | |
46 const favicon_base::FaviconImageCallback& callback, | |
47 base::CancelableTaskTracker* tracker) override; | |
48 base::CancelableTaskTracker::TaskId GetRawFavicon( | |
49 const GURL& icon_url, | |
50 favicon_base::IconType icon_type, | |
51 int desired_size_in_pixel, | |
52 const favicon_base::FaviconRawBitmapCallback& callback, | |
53 base::CancelableTaskTracker* tracker) override; | |
54 base::CancelableTaskTracker::TaskId GetFavicon( | |
55 const GURL& icon_url, | |
56 favicon_base::IconType icon_type, | |
57 int desired_size_in_dip, | |
58 const favicon_base::FaviconResultsCallback& callback, | |
59 base::CancelableTaskTracker* tracker) override; | |
60 base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL( | |
61 const GURL& page_url, | |
62 const favicon_base::FaviconImageCallback& callback, | |
63 base::CancelableTaskTracker* tracker) override; | |
64 base::CancelableTaskTracker::TaskId GetRawFaviconForPageURL( | |
65 const GURL& page_url, | |
66 int icon_types, | |
67 int desired_size_in_pixel, | |
68 const favicon_base::FaviconRawBitmapCallback& callback, | |
69 base::CancelableTaskTracker* tracker) override; | |
70 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForPageURL( | |
71 const GURL& page_url, | |
72 const std::vector<int>& icon_types, | |
73 int minimum_size_in_pixels, | |
74 const favicon_base::FaviconRawBitmapCallback& callback, | |
75 base::CancelableTaskTracker* tracker) override; | |
76 base::CancelableTaskTracker::TaskId GetFaviconForPageURL( | |
77 const GURL& page_url, | |
78 int icon_types, | |
79 int desired_size_in_dip, | |
80 const favicon_base::FaviconResultsCallback& callback, | |
81 base::CancelableTaskTracker* tracker) override; | |
82 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( | |
83 const GURL& page_url, | |
84 const std::vector<GURL>& icon_urls, | |
85 int icon_types, | |
86 int desired_size_in_dip, | |
87 const favicon_base::FaviconResultsCallback& callback, | |
88 base::CancelableTaskTracker* tracker) override; | |
89 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForID( | |
90 favicon_base::FaviconID favicon_id, | |
91 const favicon_base::FaviconRawBitmapCallback& callback, | |
92 base::CancelableTaskTracker* tracker) override; | |
93 void SetFaviconOutOfDateForPage(const GURL& page_url) override; | |
94 void SetImportedFavicons( | |
95 const favicon_base::FaviconUsageDataList& favicon_usage) override; | |
96 void MergeFavicon(const GURL& page_url, | |
97 const GURL& icon_url, | |
98 favicon_base::IconType icon_type, | |
99 scoped_refptr<base::RefCountedMemory> bitmap_data, | |
100 const gfx::Size& pixel_size) override; | |
101 void SetFavicons(const GURL& page_url, | |
102 const GURL& icon_url, | |
103 favicon_base::IconType icon_type, | |
104 const gfx::Image& image) override; | |
105 void UnableToDownloadFavicon(const GURL& icon_url) override; | |
106 bool WasUnableToDownloadFavicon(const GURL& icon_url) const override; | |
107 void ClearUnableToDownloadFavicons() override; | |
108 | |
109 private: | |
110 typedef uint32_t MissingFaviconURLHash; | |
111 | |
112 // Helper function for GetFaviconImageForPageURL(), GetRawFaviconForPageURL() | |
113 // and GetFaviconForPageURL(). | |
114 base::CancelableTaskTracker::TaskId GetFaviconForPageURLImpl( | |
115 const GURL& page_url, | |
116 int icon_types, | |
117 const std::vector<int>& desired_sizes_in_pixel, | |
118 const favicon_base::FaviconResultsCallback& callback, | |
119 base::CancelableTaskTracker* tracker); | |
120 | |
121 // Intermediate callback for GetFaviconImage() and GetFaviconImageForPageURL() | |
122 // so that history service can deal solely with FaviconResultsCallback. | |
123 // Builds favicon_base::FaviconImageResult from |favicon_bitmap_results| and | |
124 // runs |callback|. | |
125 void RunFaviconImageCallbackWithBitmapResults( | |
126 const favicon_base::FaviconImageCallback& callback, | |
127 int desired_size_in_dip, | |
128 const std::vector<favicon_base::FaviconRawBitmapResult>& | |
129 favicon_bitmap_results); | |
130 | |
131 // Intermediate callback for GetRawFavicon() and GetRawFaviconForPageURL() | |
132 // so that history service can deal solely with FaviconResultsCallback. | |
133 // Resizes favicon_base::FaviconRawBitmapResult if necessary and runs | |
134 // |callback|. | |
135 void RunFaviconRawBitmapCallbackWithBitmapResults( | |
136 const favicon_base::FaviconRawBitmapCallback& callback, | |
137 int desired_size_in_pixel, | |
138 const std::vector<favicon_base::FaviconRawBitmapResult>& | |
139 favicon_bitmap_results); | |
140 | |
141 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; | |
142 std::unique_ptr<FaviconClient> favicon_client_; | |
143 history::HistoryService* history_service_; | |
144 | |
145 DISALLOW_COPY_AND_ASSIGN(FaviconServiceImpl); | |
146 }; | |
147 | |
148 } // namespace favicon | |
149 | |
150 #endif // COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_IMPL_H_ | |
OLD | NEW |