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

Side by Side Diff: chrome/browser/favicon/favicon_handler.h

Issue 9696057: Prioritize smaller favicons over larger ones for tabs, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Appease clang Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/favicon/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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_HANDLER_H_ 5 #ifndef CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_
6 #define CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ 6 #define CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "chrome/browser/cancelable_request.h" 14 #include "chrome/browser/cancelable_request.h"
15 #include "chrome/browser/favicon/favicon_service.h" 15 #include "chrome/browser/favicon/favicon_service.h"
16 #include "chrome/browser/favicon/favicon_tab_helper.h" 16 #include "chrome/browser/favicon/favicon_tab_helper.h"
17 #include "chrome/common/favicon_url.h" 17 #include "chrome/common/favicon_url.h"
18 #include "chrome/common/ref_counted_util.h" 18 #include "chrome/common/ref_counted_util.h"
19 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
20 #include "ui/gfx/favicon_size.h" 20 #include "ui/gfx/favicon_size.h"
21 #include "ui/gfx/image/image.h"
21 22
22 class FaviconHandlerDelegate; 23 class FaviconHandlerDelegate;
23 class Profile; 24 class Profile;
24 class RefCountedMemory; 25 class RefCountedMemory;
25 class SkBitmap; 26 class SkBitmap;
26 class TabContents; 27 class TabContents;
27 28
28 namespace content { 29 namespace content {
29 class NavigationEntry; 30 class NavigationEntry;
30 } 31 }
31 32
32 namespace gfx {
33 class Image;
34 }
35
36 // FaviconHandler works with FaviconTabHelper to fetch the specific type of 33 // FaviconHandler works with FaviconTabHelper to fetch the specific type of
37 // favicon. 34 // favicon.
38 // 35 //
39 // FetchFavicon requests the favicon from the favicon service which in turn 36 // FetchFavicon requests the favicon from the favicon service which in turn
40 // requests the favicon from the history database. At this point 37 // requests the favicon from the history database. At this point
41 // we only know the URL of the page, and not necessarily the url of the 38 // we only know the URL of the page, and not necessarily the url of the
42 // favicon. To ensure we handle reloading stale favicons as well as 39 // favicon. To ensure we handle reloading stale favicons as well as
43 // reloading a favicon on page reload we always request the favicon from 40 // reloading a favicon on page reload we always request the favicon from
44 // history regardless of whether the NavigationEntry has a favicon. 41 // history regardless of whether the NavigationEntry has a favicon.
45 // 42 //
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 const GURL& image_url, 162 const GURL& image_url,
166 const FaviconTabHelper::ImageDownloadCallback& callback, 163 const FaviconTabHelper::ImageDownloadCallback& callback,
167 history::IconType icon_type); 164 history::IconType icon_type);
168 165
169 GURL url; 166 GURL url;
170 GURL image_url; 167 GURL image_url;
171 FaviconTabHelper::ImageDownloadCallback callback; 168 FaviconTabHelper::ImageDownloadCallback callback;
172 history::IconType icon_type; 169 history::IconType icon_type;
173 }; 170 };
174 171
172 struct FaviconCandidate {
173 FaviconCandidate() {}
sky 2012/03/13 23:46:06 Don't inline this, and add a destructor (that isn'
stevenjb 2012/03/14 21:35:26 Done.
174 GURL url;
175 GURL image_url;
176 gfx::Image image;
177 history::IconType icon_type;
178 };
179 typedef std::vector<FaviconCandidate> FaviconCandidates;
180
175 // See description above class for details. 181 // See description above class for details.
176 void OnFaviconDataForInitialURL(FaviconService::Handle handle, 182 void OnFaviconDataForInitialURL(FaviconService::Handle handle,
177 history::FaviconData favicon); 183 history::FaviconData favicon);
178 184
179 // If the favicon has expired, asks the renderer to download the favicon. 185 // If the favicon has expired, asks the renderer to download the favicon.
180 // Otherwise asks history to update the mapping between page url and icon 186 // Otherwise asks history to update the mapping between page url and icon
181 // url with a callback to OnFaviconData when done. 187 // url with a callback to OnFaviconData when done.
182 void DownloadFaviconOrAskHistory(const GURL& page_url, 188 void DownloadFaviconOrAskHistory(const GURL& page_url,
183 const GURL& icon_url, 189 const GURL& icon_url,
184 history::IconType icon_type); 190 history::IconType icon_type);
185 191
186 // See description above class for details. 192 // See description above class for details.
187 void OnFaviconData(FaviconService::Handle handle, 193 void OnFaviconData(FaviconService::Handle handle,
188 history::FaviconData favicon); 194 history::FaviconData favicon);
189 195
190 // Schedules a download for the specified entry. This adds the request to 196 // Schedules a download for the specified entry. This adds the request to
191 // download_requests_. 197 // download_requests_.
192 int ScheduleDownload(const GURL& url, 198 int ScheduleDownload(const GURL& url,
193 const GURL& image_url, 199 const GURL& image_url,
194 int image_size, 200 int image_size,
195 history::IconType icon_type, 201 history::IconType icon_type,
196 const FaviconTabHelper::ImageDownloadCallback& callback); 202 const FaviconTabHelper::ImageDownloadCallback& callback);
197 203
198 // Sets the image data for the favicon. This is invoked asynchronously after 204 // Adds a favicon candidate. This is invoked asynchronously after we request
199 // we request the TabContents to download the favicon. 205 // the TabContents to download the favicon.
206 void AddFaviconCandidate(const GURL& url,
207 const GURL& icon_url,
208 const gfx::Image& image,
209 history::IconType icon_type);
210
211 // Once all candidates are download, this picks one and calls SetFavicon().
212 void SetFaviconFromCandidates();
213
214 // Sets the image data for the favicon.
200 void SetFavicon(const GURL& url, 215 void SetFavicon(const GURL& url,
201 const GURL& icon_url, 216 const GURL& icon_url,
202 const gfx::Image& image, 217 const gfx::Image& image,
203 history::IconType icon_type); 218 history::IconType icon_type);
204 219
205 // Converts the FAVICON's image data to an SkBitmap and sets it on the 220 // Converts the FAVICON's image data to an SkBitmap and sets it on the
206 // NavigationEntry. 221 // NavigationEntry.
207 // If the TabContents has a delegate, it is notified of the new favicon 222 // If the TabContents has a delegate, it is notified of the new favicon
208 // (INVALIDATE_FAVICON). 223 // (INVALIDATE_FAVICON).
209 void UpdateFavicon(content::NavigationEntry* entry, 224 void UpdateFavicon(content::NavigationEntry* entry,
210 scoped_refptr<RefCountedMemory> data); 225 scoped_refptr<RefCountedMemory> data);
211 void UpdateFavicon(content::NavigationEntry* entry, const gfx::Image* image); 226 void UpdateFavicon(content::NavigationEntry* entry, const gfx::Image* image);
212 227
213 // If the image is not already at its preferred size, scales the image such 228 // If the image is not already at its preferred size, scales the image such
214 // that either the width and/or height is 16 pixels wide. Does nothing if the 229 // that either the width and/or height is 16 pixels wide. Does nothing if the
michaelbai 2012/03/14 05:01:03 16 -> preferred_size()?
stevenjb 2012/03/14 21:35:26 Actually, we always scale to gfx::kFaviconSize. I
215 // image is empty. 230 // image is empty.
216 gfx::Image ResizeFaviconIfNeeded(const gfx::Image& image); 231 gfx::Image ResizeFaviconIfNeeded(const gfx::Image& image);
217 232
218 void FetchFaviconInternal(); 233 void FetchFaviconInternal();
219 234
220 // Return the current candidate if any. 235 // Return the current candidate if any.
221 FaviconURL* current_candidate() { 236 FaviconURL* current_candidate() {
222 return (urls_.size() > current_url_index_) ? 237 return (urls_.size() > current_url_index_) ?
223 &urls_[current_url_index_] : NULL; 238 &urls_[current_url_index_] : NULL;
224 } 239 }
225 240
226 // Returns the preferred_icon_size according icon_types_, 0 means no 241 // Returns the preferred_icon_size according icon_types_, 0 means no
227 // preference. 242 // preference.
228 int preferred_icon_size() { 243 int preferred_icon_size() {
229 return icon_types_ == history::FAVICON ? gfx::kFaviconSize : 0; 244 return icon_types_ == history::FAVICON ? gfx::kFaviconSize : 0;
michaelbai 2012/03/14 05:01:03 How will you specified the icon size (32x32) you w
stevenjb 2012/03/14 21:35:26 We handle launcher icons in a separate piece of co
230 } 245 }
231 246
232 // Used for history requests. 247 // Used for history requests.
233 CancelableRequestConsumer cancelable_consumer_; 248 CancelableRequestConsumer cancelable_consumer_;
234 249
235 // URL of the page we're requesting the favicon for. 250 // URL of the page we're requesting the favicon for.
236 GURL url_; 251 GURL url_;
237 252
238 // Whether we got the initial response for the favicon back from the renderer. 253 // Whether we got the initial response for the favicon back from the renderer.
239 // See "Favicon Details" in tab_contents.cc for more details. 254 // See "Favicon Details" in tab_contents.cc for more details.
(...skipping 20 matching lines...) Expand all
260 275
261 // The FaviconData from history. 276 // The FaviconData from history.
262 history::FaviconData history_icon_; 277 history::FaviconData history_icon_;
263 278
264 // The Profile associated with this handler. 279 // The Profile associated with this handler.
265 Profile* profile_; 280 Profile* profile_;
266 281
267 // This handler's delegate. 282 // This handler's delegate.
268 FaviconHandlerDelegate* delegate_; // weak 283 FaviconHandlerDelegate* delegate_; // weak
269 284
285 // Vector of favicon candidates.
286 FaviconCandidates favicon_candidates_;
287
270 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); 288 DISALLOW_COPY_AND_ASSIGN(FaviconHandler);
271 }; 289 };
272 290
273 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ 291 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/favicon/favicon_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698