OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
6 #define CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 6 #define CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/task/cancelable_task_tracker.h" |
13 #include "chrome/browser/common/cancelable_request.h" | 14 #include "chrome/browser/common/cancelable_request.h" |
14 #include "chrome/common/cancelable_task_tracker.h" | |
15 #include "chrome/common/favicon/favicon_types.h" | 15 #include "chrome/common/favicon/favicon_types.h" |
16 #include "chrome/common/ref_counted_util.h" | 16 #include "chrome/common/ref_counted_util.h" |
17 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 17 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
18 #include "ui/base/layout.h" | 18 #include "ui/base/layout.h" |
19 | 19 |
20 class GURL; | 20 class GURL; |
21 class HistoryService; | 21 class HistoryService; |
22 struct ImportedFaviconUsage; | 22 struct ImportedFaviconUsage; |
23 class Profile; | 23 class Profile; |
24 | 24 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 const std::vector<chrome::FaviconBitmapResult>* results); | 88 const std::vector<chrome::FaviconBitmapResult>* results); |
89 | 89 |
90 // Requests the favicon at |icon_url| of |icon_type| whose size most closely | 90 // Requests the favicon at |icon_url| of |icon_type| whose size most closely |
91 // matches |desired_size_in_dip|. If |desired_size_in_dip| is 0, the largest | 91 // matches |desired_size_in_dip|. If |desired_size_in_dip| is 0, the largest |
92 // favicon bitmap at |icon_url| is returned. |consumer| is notified when the | 92 // favicon bitmap at |icon_url| is returned. |consumer| is notified when the |
93 // bits have been fetched. |icon_url| is the URL of the icon itself, e.g. | 93 // bits have been fetched. |icon_url| is the URL of the icon itself, e.g. |
94 // <http://www.google.com/favicon.ico>. | 94 // <http://www.google.com/favicon.ico>. |
95 // Each of the three methods below differs in the format of the callback and | 95 // Each of the three methods below differs in the format of the callback and |
96 // the requested scale factors. All of the scale factors supported by the | 96 // the requested scale factors. All of the scale factors supported by the |
97 // current platform (eg MacOS) are requested for GetFaviconImage(). | 97 // current platform (eg MacOS) are requested for GetFaviconImage(). |
98 CancelableTaskTracker::TaskId GetFaviconImage( | 98 base::CancelableTaskTracker::TaskId GetFaviconImage( |
99 const GURL& icon_url, | 99 const GURL& icon_url, |
100 chrome::IconType icon_type, | 100 chrome::IconType icon_type, |
101 int desired_size_in_dip, | 101 int desired_size_in_dip, |
102 const FaviconImageCallback& callback, | 102 const FaviconImageCallback& callback, |
103 CancelableTaskTracker* tracker); | 103 base::CancelableTaskTracker* tracker); |
104 | 104 |
105 CancelableTaskTracker::TaskId GetRawFavicon( | 105 base::CancelableTaskTracker::TaskId GetRawFavicon( |
106 const GURL& icon_url, | 106 const GURL& icon_url, |
107 chrome::IconType icon_type, | 107 chrome::IconType icon_type, |
108 int desired_size_in_dip, | 108 int desired_size_in_dip, |
109 ui::ScaleFactor desired_scale_factor, | 109 ui::ScaleFactor desired_scale_factor, |
110 const FaviconRawCallback& callback, | 110 const FaviconRawCallback& callback, |
111 CancelableTaskTracker* tracker); | 111 base::CancelableTaskTracker* tracker); |
112 | 112 |
113 CancelableTaskTracker::TaskId GetFavicon( | 113 base::CancelableTaskTracker::TaskId GetFavicon( |
114 const GURL& icon_url, | 114 const GURL& icon_url, |
115 chrome::IconType icon_type, | 115 chrome::IconType icon_type, |
116 int desired_size_in_dip, | 116 int desired_size_in_dip, |
117 const FaviconResultsCallback& callback, | 117 const FaviconResultsCallback& callback, |
118 CancelableTaskTracker* tracker); | 118 base::CancelableTaskTracker* tracker); |
119 | 119 |
120 // Set the favicon mappings to |page_url| for |icon_types| in the history | 120 // Set the favicon mappings to |page_url| for |icon_types| in the history |
121 // database. | 121 // database. |
122 // Sample |icon_urls|: | 122 // Sample |icon_urls|: |
123 // { ICON_URL1 -> TOUCH_ICON, known to the database, | 123 // { ICON_URL1 -> TOUCH_ICON, known to the database, |
124 // ICON_URL2 -> TOUCH_ICON, not known to the database, | 124 // ICON_URL2 -> TOUCH_ICON, not known to the database, |
125 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } | 125 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } |
126 // The new mappings are computed from |icon_urls| with these rules: | 126 // The new mappings are computed from |icon_urls| with these rules: |
127 // 1) Any urls in |icon_urls| which are not already known to the database are | 127 // 1) Any urls in |icon_urls| which are not already known to the database are |
128 // rejected. | 128 // rejected. |
129 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } | 129 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } |
130 // 2) If |icon_types| has multiple types, the mappings are only set for the | 130 // 2) If |icon_types| has multiple types, the mappings are only set for the |
131 // largest icon type. | 131 // largest icon type. |
132 // Sample new mappings to |page_url|: { ICON_URL3 } | 132 // Sample new mappings to |page_url|: { ICON_URL3 } |
133 // |icon_types| can only have multiple IconTypes if | 133 // |icon_types| can only have multiple IconTypes if |
134 // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. | 134 // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. |
135 // The favicon bitmaps which most closely match |desired_size_in_dip| | 135 // The favicon bitmaps which most closely match |desired_size_in_dip| |
136 // at the scale factors supported by the current platform (eg MacOS) in | 136 // at the scale factors supported by the current platform (eg MacOS) in |
137 // addition to 1x from the favicons which were just mapped to |page_url| are | 137 // addition to 1x from the favicons which were just mapped to |page_url| are |
138 // returned. If |desired_size_in_dip| is 0, the largest favicon bitmap is | 138 // returned. If |desired_size_in_dip| is 0, the largest favicon bitmap is |
139 // returned. | 139 // returned. |
140 CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( | 140 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( |
141 const GURL& page_url, | 141 const GURL& page_url, |
142 const std::vector<GURL>& icon_urls, | 142 const std::vector<GURL>& icon_urls, |
143 int icon_types, | 143 int icon_types, |
144 int desired_size_in_dip, | 144 int desired_size_in_dip, |
145 const FaviconResultsCallback& callback, | 145 const FaviconResultsCallback& callback, |
146 CancelableTaskTracker* tracker); | 146 base::CancelableTaskTracker* tracker); |
147 | 147 |
148 // Requests the favicons of any of |icon_types| whose pixel sizes most | 148 // Requests the favicons of any of |icon_types| whose pixel sizes most |
149 // closely match |desired_size_in_dip| and desired scale factors for a web | 149 // closely match |desired_size_in_dip| and desired scale factors for a web |
150 // page URL. If |desired_size_in_dip| is 0, the largest favicon for the web | 150 // page URL. If |desired_size_in_dip| is 0, the largest favicon for the web |
151 // page URL is returned. |callback| is run when the bits have been fetched. | 151 // page URL is returned. |callback| is run when the bits have been fetched. |
152 // |icon_types| can be any combination of IconType value, but only one icon | 152 // |icon_types| can be any combination of IconType value, but only one icon |
153 // will be returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON and | 153 // will be returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON and |
154 // FAVICON. Each of the three methods below differs in the format of the | 154 // FAVICON. Each of the three methods below differs in the format of the |
155 // callback and the requested scale factors. All of the scale factors | 155 // callback and the requested scale factors. All of the scale factors |
156 // supported by the current platform (eg MacOS) are requested for | 156 // supported by the current platform (eg MacOS) are requested for |
157 // GetFaviconImageForURL(). | 157 // GetFaviconImageForURL(). |
158 // Note. |callback| is always run asynchronously. | 158 // Note. |callback| is always run asynchronously. |
159 CancelableTaskTracker::TaskId GetFaviconImageForURL( | 159 base::CancelableTaskTracker::TaskId GetFaviconImageForURL( |
160 const FaviconForURLParams& params, | 160 const FaviconForURLParams& params, |
161 const FaviconImageCallback& callback, | 161 const FaviconImageCallback& callback, |
162 CancelableTaskTracker* tracker); | 162 base::CancelableTaskTracker* tracker); |
163 | 163 |
164 CancelableTaskTracker::TaskId GetRawFaviconForURL( | 164 base::CancelableTaskTracker::TaskId GetRawFaviconForURL( |
165 const FaviconForURLParams& params, | 165 const FaviconForURLParams& params, |
166 ui::ScaleFactor desired_scale_factor, | 166 ui::ScaleFactor desired_scale_factor, |
167 const FaviconRawCallback& callback, | 167 const FaviconRawCallback& callback, |
168 CancelableTaskTracker* tracker); | 168 base::CancelableTaskTracker* tracker); |
169 | 169 |
170 // See HistoryService::GetLargestFaviconForURL(). | 170 // See HistoryService::GetLargestFaviconForURL(). |
171 CancelableTaskTracker::TaskId GetLargestRawFaviconForURL( | 171 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForURL( |
172 Profile* profile, | 172 Profile* profile, |
173 const GURL& page_url, | 173 const GURL& page_url, |
174 const std::vector<int>& icon_types, | 174 const std::vector<int>& icon_types, |
175 int minimum_size_in_pixels, | 175 int minimum_size_in_pixels, |
176 const FaviconRawCallback& callback, | 176 const FaviconRawCallback& callback, |
177 CancelableTaskTracker* tracker); | 177 base::CancelableTaskTracker* tracker); |
178 | 178 |
179 CancelableTaskTracker::TaskId GetFaviconForURL( | 179 base::CancelableTaskTracker::TaskId GetFaviconForURL( |
180 const FaviconForURLParams& params, | 180 const FaviconForURLParams& params, |
181 const FaviconResultsCallback& callback, | 181 const FaviconResultsCallback& callback, |
182 CancelableTaskTracker* tracker); | 182 base::CancelableTaskTracker* tracker); |
183 | 183 |
184 // Used to request a bitmap for the favicon with |favicon_id| which is not | 184 // Used to request a bitmap for the favicon with |favicon_id| which is not |
185 // resized from the size it is stored at in the database. If there are | 185 // resized from the size it is stored at in the database. If there are |
186 // multiple favicon bitmaps for |favicon_id|, the largest favicon bitmap is | 186 // multiple favicon bitmaps for |favicon_id|, the largest favicon bitmap is |
187 // returned. | 187 // returned. |
188 CancelableTaskTracker::TaskId GetLargestRawFaviconForID( | 188 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForID( |
189 chrome::FaviconID favicon_id, | 189 chrome::FaviconID favicon_id, |
190 const FaviconRawCallback& callback, | 190 const FaviconRawCallback& callback, |
191 CancelableTaskTracker* tracker); | 191 base::CancelableTaskTracker* tracker); |
192 | 192 |
193 // Marks all types of favicon for the page as being out of date. | 193 // Marks all types of favicon for the page as being out of date. |
194 void SetFaviconOutOfDateForPage(const GURL& page_url); | 194 void SetFaviconOutOfDateForPage(const GURL& page_url); |
195 | 195 |
196 // Clones all icons from an existing page. This associates the icons from | 196 // Clones all icons from an existing page. This associates the icons from |
197 // |old_page_url| with |new_page_url|, provided |new_page_url| has no | 197 // |old_page_url| with |new_page_url|, provided |new_page_url| has no |
198 // recorded associations to any other icons. | 198 // recorded associations to any other icons. |
199 // Needed if you want to declare favicons (tentatively) in advance, before a | 199 // Needed if you want to declare favicons (tentatively) in advance, before a |
200 // page is ever visited. | 200 // page is ever visited. |
201 void CloneFavicon(const GURL& old_page_url, const GURL& new_page_url); | 201 void CloneFavicon(const GURL& old_page_url, const GURL& new_page_url); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 void ClearUnableToDownloadFavicons(); | 238 void ClearUnableToDownloadFavicons(); |
239 | 239 |
240 private: | 240 private: |
241 typedef uint32 MissingFaviconURLHash; | 241 typedef uint32 MissingFaviconURLHash; |
242 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; | 242 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; |
243 HistoryService* history_service_; | 243 HistoryService* history_service_; |
244 Profile* profile_; | 244 Profile* profile_; |
245 | 245 |
246 // Helper function for GetFaviconImageForURL(), GetRawFaviconForURL() and | 246 // Helper function for GetFaviconImageForURL(), GetRawFaviconForURL() and |
247 // GetFaviconForURL(). | 247 // GetFaviconForURL(). |
248 CancelableTaskTracker::TaskId GetFaviconForURLImpl( | 248 base::CancelableTaskTracker::TaskId GetFaviconForURLImpl( |
249 const FaviconForURLParams& params, | 249 const FaviconForURLParams& params, |
250 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 250 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
251 const FaviconResultsCallback& callback, | 251 const FaviconResultsCallback& callback, |
252 CancelableTaskTracker* tracker); | 252 base::CancelableTaskTracker* tracker); |
253 | 253 |
254 // Intermediate callback for GetFaviconImage() and GetFaviconImageForURL() | 254 // Intermediate callback for GetFaviconImage() and GetFaviconImageForURL() |
255 // so that history service can deal solely with FaviconResultsCallback. | 255 // so that history service can deal solely with FaviconResultsCallback. |
256 // Builds chrome::FaviconImageResult from |favicon_bitmap_results| and runs | 256 // Builds chrome::FaviconImageResult from |favicon_bitmap_results| and runs |
257 // |callback|. | 257 // |callback|. |
258 void RunFaviconImageCallbackWithBitmapResults( | 258 void RunFaviconImageCallbackWithBitmapResults( |
259 const FaviconImageCallback& callback, | 259 const FaviconImageCallback& callback, |
260 int desired_size_in_dip, | 260 int desired_size_in_dip, |
261 const std::vector<chrome::FaviconBitmapResult>& favicon_bitmap_results); | 261 const std::vector<chrome::FaviconBitmapResult>& favicon_bitmap_results); |
262 | 262 |
263 // Intermediate callback for GetRawFavicon() and GetRawFaviconForURL() | 263 // Intermediate callback for GetRawFavicon() and GetRawFaviconForURL() |
264 // so that history service can deal solely with FaviconResultsCallback. | 264 // so that history service can deal solely with FaviconResultsCallback. |
265 // Resizes chrome::FaviconBitmapResult if necessary and runs |callback|. | 265 // Resizes chrome::FaviconBitmapResult if necessary and runs |callback|. |
266 void RunFaviconRawCallbackWithBitmapResults( | 266 void RunFaviconRawCallbackWithBitmapResults( |
267 const FaviconRawCallback& callback, | 267 const FaviconRawCallback& callback, |
268 int desired_size_in_dip, | 268 int desired_size_in_dip, |
269 ui::ScaleFactor desired_scale_factor, | 269 ui::ScaleFactor desired_scale_factor, |
270 const std::vector<chrome::FaviconBitmapResult>& favicon_bitmap_results); | 270 const std::vector<chrome::FaviconBitmapResult>& favicon_bitmap_results); |
271 | 271 |
272 DISALLOW_COPY_AND_ASSIGN(FaviconService); | 272 DISALLOW_COPY_AND_ASSIGN(FaviconService); |
273 }; | 273 }; |
274 | 274 |
275 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 275 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
OLD | NEW |