Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(786)

Side by Side Diff: components/favicon/core/favicon_handler.h

Issue 2738063004: Remove DownloadRequest registry from FaviconHandler (Closed)
Patch Set: Rebased. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/favicon/core/favicon_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_FAVICON_HANDLER_H_ 5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_
6 #define COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ 6 #define COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map>
11 #include <vector> 10 #include <vector>
12 11
13 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
13 #include "base/cancelable_callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/task/cancelable_task_tracker.h" 16 #include "base/task/cancelable_task_tracker.h"
18 #include "components/favicon/core/favicon_driver_observer.h" 17 #include "components/favicon/core/favicon_driver_observer.h"
19 #include "components/favicon/core/favicon_url.h" 18 #include "components/favicon/core/favicon_url.h"
20 #include "components/favicon_base/favicon_callback.h" 19 #include "components/favicon_base/favicon_callback.h"
21 #include "ui/gfx/favicon_size.h" 20 #include "ui/gfx/favicon_size.h"
22 #include "ui/gfx/image/image.h" 21 #include "ui/gfx/image/image.h"
23 #include "url/gurl.h" 22 #include "url/gurl.h"
24 23
25 class SkBitmap; 24 class SkBitmap;
26 25
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 136
138 // Returns whether the handler is waiting for a download to complete or for 137 // Returns whether the handler is waiting for a download to complete or for
139 // data from the FaviconService. Reserved for testing. 138 // data from the FaviconService. Reserved for testing.
140 bool HasPendingTasksForTest(); 139 bool HasPendingTasksForTest();
141 140
142 // Get the maximal icon size in pixels for a icon of type |icon_type| for the 141 // Get the maximal icon size in pixels for a icon of type |icon_type| for the
143 // current platform. 142 // current platform.
144 static int GetMaximalIconSize(favicon_base::IconType icon_type); 143 static int GetMaximalIconSize(favicon_base::IconType icon_type);
145 144
146 private: 145 private:
147 // Represents an in progress download of an image from the renderer.
148 struct DownloadRequest {
149 DownloadRequest();
150 ~DownloadRequest();
151
152 DownloadRequest(const GURL& image_url, favicon_base::IconType icon_type);
153
154 GURL image_url;
155 favicon_base::IconType icon_type;
156 };
157
158 // Used to track a candidate for the favicon. 146 // Used to track a candidate for the favicon.
159 struct FaviconCandidate { 147 struct FaviconCandidate {
160 FaviconCandidate(); 148 FaviconCandidate();
161 ~FaviconCandidate(); 149 ~FaviconCandidate();
162 150
163 FaviconCandidate(const GURL& image_url, 151 FaviconCandidate(const GURL& image_url,
164 const gfx::Image& image, 152 const gfx::Image& image,
165 float score, 153 float score,
166 favicon_base::IconType icon_type); 154 favicon_base::IconType icon_type);
167 155
(...skipping 25 matching lines...) Expand all
193 void OnFaviconData(const std::vector<favicon_base::FaviconRawBitmapResult>& 181 void OnFaviconData(const std::vector<favicon_base::FaviconRawBitmapResult>&
194 favicon_bitmap_results); 182 favicon_bitmap_results);
195 183
196 // Schedules a download for the specified entry. This adds the request to 184 // Schedules a download for the specified entry. This adds the request to
197 // download_requests_. 185 // download_requests_.
198 void ScheduleDownload(const GURL& image_url, 186 void ScheduleDownload(const GURL& image_url,
199 favicon_base::IconType icon_type); 187 favicon_base::IconType icon_type);
200 188
201 // Triggered when a download of an image has finished. 189 // Triggered when a download of an image has finished.
202 void OnDidDownloadFavicon( 190 void OnDidDownloadFavicon(
191 favicon_base::IconType icon_type,
203 int id, 192 int id,
204 int http_status_code, 193 int http_status_code,
205 const GURL& image_url, 194 const GURL& image_url,
206 const std::vector<SkBitmap>& bitmaps, 195 const std::vector<SkBitmap>& bitmaps,
207 const std::vector<gfx::Size>& original_bitmap_sizes); 196 const std::vector<gfx::Size>& original_bitmap_sizes);
208 197
209 bool ShouldSaveFavicon(); 198 bool ShouldSaveFavicon();
210 199
211 // Updates |favicon_candidate_| and returns true if it is an exact match. 200 // Updates |favicon_candidate_| and returns true if it is an exact match.
212 bool UpdateFaviconCandidate(const GURL& image_url, 201 bool UpdateFaviconCandidate(const GURL& image_url,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // history, but we need to redownload the icon URLs because the icon in the 250 // history, but we need to redownload the icon URLs because the icon in the
262 // database has expired or the data in the database is incomplete. 251 // database has expired or the data in the database is incomplete.
263 bool initial_history_result_expired_or_incomplete_; 252 bool initial_history_result_expired_or_incomplete_;
264 253
265 // Whether FaviconHandler should ignore history state and determine the 254 // Whether FaviconHandler should ignore history state and determine the
266 // optimal icon URL out of |image_urls_| for |url_| by downloading 255 // optimal icon URL out of |image_urls_| for |url_| by downloading
267 // |image_urls_| one by one. 256 // |image_urls_| one by one.
268 bool redownload_icons_; 257 bool redownload_icons_;
269 258
270 // Requests to the renderer to download favicons. 259 // Requests to the renderer to download favicons.
271 typedef std::map<int, DownloadRequest> DownloadRequests; 260 base::CancelableCallback<Delegate::ImageDownloadCallback::RunType>
272 DownloadRequests download_requests_; 261 download_request_;
273 262
274 // The combination of the supported icon types. 263 // The combination of the supported icon types.
275 const int icon_types_; 264 const int icon_types_;
276 265
277 // Whether the largest icon should be downloaded. 266 // Whether the largest icon should be downloaded.
278 const bool download_largest_icon_; 267 const bool download_largest_icon_;
279 268
280 // The prioritized favicon candidates from the page back from the renderer. 269 // The prioritized favicon candidates from the page back from the renderer.
281 std::vector<favicon::FaviconURL> image_urls_; 270 std::vector<favicon::FaviconURL> image_urls_;
282 271
(...skipping 12 matching lines...) Expand all
295 // The index of the favicon URL in |image_urls_| which is currently being 284 // The index of the favicon URL in |image_urls_| which is currently being
296 // requested from history or downloaded. 285 // requested from history or downloaded.
297 size_t current_candidate_index_; 286 size_t current_candidate_index_;
298 287
299 // Best image we've seen so far. As images are downloaded from the page they 288 // Best image we've seen so far. As images are downloaded from the page they
300 // are stored here. When there is an exact match, or no more images are 289 // are stored here. When there is an exact match, or no more images are
301 // available the favicon service and the current page are updated (assuming 290 // available the favicon service and the current page are updated (assuming
302 // the image is for a favicon). 291 // the image is for a favicon).
303 FaviconCandidate best_favicon_candidate_; 292 FaviconCandidate best_favicon_candidate_;
304 293
305 base::WeakPtrFactory<FaviconHandler> weak_ptr_factory_;
306
307 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); 294 DISALLOW_COPY_AND_ASSIGN(FaviconHandler);
308 }; 295 };
309 296
310 } // namespace favicon 297 } // namespace favicon
311 298
312 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ 299 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | components/favicon/core/favicon_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698