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

Unified 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: Rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/favicon/favicon_handler.cc » ('j') | chrome/browser/favicon/favicon_handler.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/favicon/favicon_handler.h
diff --git a/chrome/browser/favicon/favicon_handler.h b/chrome/browser/favicon/favicon_handler.h
index a59e944c42e6e66b7ba81b97b05851c1de1c8a01..bd3a73b25a45d7b0a00e39e42e0598e0c2061c4b 100644
--- a/chrome/browser/favicon/favicon_handler.h
+++ b/chrome/browser/favicon/favicon_handler.h
@@ -17,22 +17,19 @@
#include "chrome/common/favicon_url.h"
#include "chrome/common/ref_counted_util.h"
#include "googleurl/src/gurl.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/favicon_size.h"
+#include "ui/gfx/image/image.h"
class FaviconHandlerDelegate;
class Profile;
class RefCountedMemory;
-class SkBitmap;
class TabContents;
namespace content {
class NavigationEntry;
}
-namespace gfx {
-class Image;
-}
-
// FaviconHandler works with FaviconTabHelper to fetch the specific type of
// favicon.
//
@@ -72,9 +69,11 @@ class Image;
// db knew about the favicon), or requests the renderer to download the
// favicon.
//
-// When the renderer downloads the favicon SetFavicon is invoked,
-// at which point we update the favicon of the NavigationEntry and notify
-// the database to save the favicon.
+// When the renderer downloads favicons, it considers the entire list of
+// favicon candidates and chooses the one that best matches the preferred size
+// (or the first one if there is no preferred size). Once the matching favicon
+// has been determined, SetFavicon is called which updates the favicon of the
+// NavigationEntry and notifies the database to save the favicon.
class FaviconHandler {
public:
@@ -104,10 +103,14 @@ class FaviconHandler {
const FaviconTabHelper::ImageDownloadCallback& callback);
// Message Handler. Must be public, because also called from
- // PrerenderContents.
+ // PrerenderContents. Collects the |image_urls| list.
void OnUpdateFaviconURL(int32 page_id,
const std::vector<FaviconURL>& candidates);
+ // Processes the current image_irls_ entry, requesting the image from the
+ // history / download service.
+ void ProcessCurrentUrl();
+
void OnDidDownloadFavicon(int id,
const GURL& image_url,
bool errored,
@@ -172,6 +175,23 @@ class FaviconHandler {
history::IconType icon_type;
};
+ struct FaviconCandidate {
+ FaviconCandidate();
+ ~FaviconCandidate();
+
+ FaviconCandidate(const GURL& url,
+ const GURL& image_url,
+ const gfx::Image& image,
+ const SkBitmap& bitmap,
+ history::IconType icon_type);
+
+ GURL url;
+ GURL image_url;
+ gfx::Image image;
+ SkBitmap bitmap;
+ history::IconType icon_type;
+ };
+
// See description above class for details.
void OnFaviconDataForInitialURL(FaviconService::Handle handle,
history::FaviconData favicon);
@@ -195,11 +215,17 @@ class FaviconHandler {
history::IconType icon_type,
const FaviconTabHelper::ImageDownloadCallback& callback);
- // Sets the image data for the favicon. This is invoked asynchronously after
- // we request the TabContents to download the favicon.
+ // Updates |favicon_candidate_| and returns true if it is an exact match.
+ bool UpdateFaviconCandidate(const GURL& url,
+ const GURL& image_url,
+ const gfx::Image& image,
+ history::IconType icon_type);
+
+ // Sets the image data for the favicon.
void SetFavicon(const GURL& url,
const GURL& icon_url,
const gfx::Image& image,
+ const SkBitmap& bitmap,
history::IconType icon_type);
// Converts the FAVICON's image data to an SkBitmap and sets it on the
@@ -211,16 +237,15 @@ class FaviconHandler {
void UpdateFavicon(content::NavigationEntry* entry, const gfx::Image* image);
// If the image is not already at its preferred size, scales the image such
- // that either the width and/or height is 16 pixels wide. Does nothing if the
- // image is empty.
+ // that either the width and/or height == gfx::kFaviconSize. Does nothing if
+ // the image is empty.
gfx::Image ResizeFaviconIfNeeded(const gfx::Image& image);
void FetchFaviconInternal();
// Return the current candidate if any.
FaviconURL* current_candidate() {
- return (urls_.size() > current_url_index_) ?
- &urls_[current_url_index_] : NULL;
+ return (image_urls_.size() > 0) ? &image_urls_[0] : NULL;
}
// Returns the preferred_icon_size according icon_types_, 0 means no
@@ -253,10 +278,7 @@ class FaviconHandler {
const int icon_types_;
// The prioritized favicon candidates from the page back from the renderer.
- std::vector<FaviconURL> urls_;
-
- // The current candidate's index in urls_.
- size_t current_url_index_;
+ std::deque<FaviconURL> image_urls_;
// The FaviconData from history.
history::FaviconData history_icon_;
@@ -267,6 +289,9 @@ class FaviconHandler {
// This handler's delegate.
FaviconHandlerDelegate* delegate_; // weak
+ // Current favicon candidate.
+ FaviconCandidate favicon_candidate_;
+
DISALLOW_COPY_AND_ASSIGN(FaviconHandler);
};
« no previous file with comments | « no previous file | chrome/browser/favicon/favicon_handler.cc » ('j') | chrome/browser/favicon/favicon_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698