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 COMPONENTS_FAVICON_CORE_BROWSER_FAVICON_HANDLER_H_ | 5 #ifndef COMPONENTS_FAVICON_CORE_BROWSER_FAVICON_HANDLER_H_ |
6 #define COMPONENTS_FAVICON_CORE_BROWSER_FAVICON_HANDLER_H_ | 6 #define COMPONENTS_FAVICON_CORE_BROWSER_FAVICON_HANDLER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 // | 69 // |
70 // When the renderer downloads favicons, it considers the entire list of | 70 // When the renderer downloads favicons, it considers the entire list of |
71 // favicon candidates, if |download_largest_favicon_| is true, the largest | 71 // favicon candidates, if |download_largest_favicon_| is true, the largest |
72 // favicon will be used, otherwise the one that best matches the preferred size | 72 // favicon will be used, otherwise the one that best matches the preferred size |
73 // is chosen (or the first one if there is no preferred size). Once the | 73 // is chosen (or the first one if there is no preferred size). Once the |
74 // matching favicon has been determined, SetFavicon is called which updates | 74 // matching favicon has been determined, SetFavicon is called which updates |
75 // the page's favicon and notifies the database to save the favicon. | 75 // the page's favicon and notifies the database to save the favicon. |
76 | 76 |
77 class FaviconHandler { | 77 class FaviconHandler { |
78 public: | 78 public: |
79 enum Type { FAVICON, TOUCH }; | 79 enum Type { FAVICON, TOUCH, LARGE }; |
80 | 80 |
81 FaviconHandler(FaviconService* service, | 81 FaviconHandler(FaviconService* service, |
82 FaviconClient* client, | 82 FaviconClient* client, |
83 FaviconDriver* driver, | 83 FaviconDriver* driver, |
84 Type icon_type, | 84 Type handler_type, |
85 bool download_largest_icon); | 85 bool download_largest_icon); |
86 virtual ~FaviconHandler(); | 86 virtual ~FaviconHandler(); |
87 | 87 |
88 // Returns the bit mask of favicon_base::IconType based on the handler's type. | |
89 static int GetIconTypesFromHandlerType(Type icon_type); | |
sky
2015/05/06 19:29:05
Why is this public?
huangs
2015/05/06 19:59:14
An oversight from my part. Move to private?
sky
2015/05/06 20:13:54
Yes please.
huangs
2015/05/06 20:33:55
Acknowledged.
| |
90 | |
88 // Initiates loading the favicon for the specified url. | 91 // Initiates loading the favicon for the specified url. |
89 void FetchFavicon(const GURL& url); | 92 void FetchFavicon(const GURL& url); |
90 | 93 |
91 // Message Handler. Must be public, because also called from | 94 // Message Handler. Must be public, because also called from |
92 // PrerenderContents. Collects the |image_urls| list. | 95 // PrerenderContents. Collects the |image_urls| list. |
93 void OnUpdateFaviconURL(const std::vector<favicon::FaviconURL>& candidates); | 96 void OnUpdateFaviconURL(const std::vector<favicon::FaviconURL>& candidates); |
94 | 97 |
95 // Processes the current image_irls_ entry, requesting the image from the | 98 // Processes the current image_urls_ entry, requesting the image from the |
96 // history / download service. | 99 // history / download service. |
97 void ProcessCurrentUrl(); | 100 void ProcessCurrentUrl(); |
98 | 101 |
99 // Message handler for ImageHostMsg_DidDownloadImage. Called when the image | 102 // Message handler for ImageHostMsg_DidDownloadImage. Called when the image |
100 // at |image_url| has been downloaded. | 103 // at |image_url| has been downloaded. |
101 // |bitmaps| is a list of all the frames of the image at |image_url|. | 104 // |bitmaps| is a list of all the frames of the image at |image_url|. |
102 // |original_bitmap_sizes| are the sizes of |bitmaps| before they were resized | 105 // |original_bitmap_sizes| are the sizes of |bitmaps| before they were resized |
103 // to the maximum bitmap size passed to DownloadFavicon(). | 106 // to the maximum bitmap size passed to DownloadFavicon(). |
104 void OnDidDownloadFavicon( | 107 void OnDidDownloadFavicon( |
105 int id, | 108 int id, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 } | 241 } |
239 | 242 |
240 // Returns whether the page's url changed since the favicon was requested. | 243 // Returns whether the page's url changed since the favicon was requested. |
241 bool PageChangedSinceFaviconWasRequested(); | 244 bool PageChangedSinceFaviconWasRequested(); |
242 | 245 |
243 // Returns the preferred size of the image. 0 means no preference (any size | 246 // Returns the preferred size of the image. 0 means no preference (any size |
244 // will do). | 247 // will do). |
245 int preferred_icon_size() const { | 248 int preferred_icon_size() const { |
246 if (download_largest_icon_) | 249 if (download_largest_icon_) |
247 return 0; | 250 return 0; |
248 return icon_types_ == favicon_base::FAVICON ? gfx::kFaviconSize : 0; | 251 return handler_type_ == FAVICON ? gfx::kFaviconSize : 0; |
249 } | 252 } |
250 | 253 |
251 // Sorts the entries in |image_urls_| by icon size in descending order. | 254 // Sorts the entries in |image_urls_| by icon size in descending order. |
252 // Additionally removes any entries whose sizes are all greater than the max | 255 // Additionally removes any entries whose sizes are all greater than the max |
253 // allowed size. | 256 // allowed size. |
254 void SortAndPruneImageUrls(); | 257 void SortAndPruneImageUrls(); |
255 | 258 |
256 // Used for FaviconService requests. | 259 // Used for FaviconService requests. |
257 base::CancelableTaskTracker cancelable_task_tracker_; | 260 base::CancelableTaskTracker cancelable_task_tracker_; |
258 | 261 |
259 // URL of the page we're requesting the favicon for. | 262 // URL of the page we're requesting the favicon for. |
260 GURL url_; | 263 GURL url_; |
261 | 264 |
262 // Whether we are waiting for data from the FaviconService. | 265 // Whether we are waiting for data from the FaviconService. |
263 bool waiting_for_favicon_service_data_; | 266 bool waiting_for_favicon_service_data_; |
264 | 267 |
265 // Whether we got data back for the initial request to the FaviconService. | 268 // Whether we got data back for the initial request to the FaviconService. |
266 bool got_favicon_from_history_; | 269 bool got_favicon_from_history_; |
267 | 270 |
268 // Whether the favicon is out of date or the favicon data in | 271 // Whether the favicon is out of date or the favicon data in |
269 // |history_results_| is known to be incomplete. If true, it means history | 272 // |history_results_| is known to be incomplete. If true, it means history |
270 // knows about the favicon, but we need to download the favicon because the | 273 // knows about the favicon, but we need to download the favicon because the |
271 // icon has expired or the data in the database is incomplete. | 274 // icon has expired or the data in the database is incomplete. |
272 bool favicon_expired_or_incomplete_; | 275 bool favicon_expired_or_incomplete_; |
273 | 276 |
274 // Requests to the renderer to download favicons. | 277 // Requests to the renderer to download favicons. |
275 typedef std::map<int, DownloadRequest> DownloadRequests; | 278 typedef std::map<int, DownloadRequest> DownloadRequests; |
276 DownloadRequests download_requests_; | 279 DownloadRequests download_requests_; |
277 | 280 |
281 // The type of the current handler. | |
282 const Type handler_type_; | |
283 | |
278 // The combination of the supported icon types. | 284 // The combination of the supported icon types. |
279 const int icon_types_; | 285 const int icon_types_; |
280 | 286 |
281 // Whether the largest icon should be downloaded. | 287 // Whether the largest icon should be downloaded. |
282 const bool download_largest_icon_; | 288 const bool download_largest_icon_; |
283 | 289 |
284 // The prioritized favicon candidates from the page back from the renderer. | 290 // The prioritized favicon candidates from the page back from the renderer. |
285 std::vector<favicon::FaviconURL> image_urls_; | 291 std::vector<favicon::FaviconURL> image_urls_; |
286 | 292 |
287 // The FaviconRawBitmapResults from history. | 293 // The FaviconRawBitmapResults from history. |
(...skipping 12 matching lines...) Expand all Loading... | |
300 // Best image we've seen so far. As images are downloaded from the page they | 306 // Best image we've seen so far. As images are downloaded from the page they |
301 // are stored here. When there is an exact match, or no more images are | 307 // are stored here. When there is an exact match, or no more images are |
302 // available the favicon service and the current page are updated (assuming | 308 // available the favicon service and the current page are updated (assuming |
303 // the image is for a favicon). | 309 // the image is for a favicon). |
304 FaviconCandidate best_favicon_candidate_; | 310 FaviconCandidate best_favicon_candidate_; |
305 | 311 |
306 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); | 312 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); |
307 }; | 313 }; |
308 | 314 |
309 #endif // COMPONENTS_FAVICON_CORE_BROWSER_FAVICON_HANDLER_H_ | 315 #endif // COMPONENTS_FAVICON_CORE_BROWSER_FAVICON_HANDLER_H_ |
OLD | NEW |