Index: components/favicon/core/favicon_handler.h |
diff --git a/components/favicon/core/favicon_handler.h b/components/favicon/core/favicon_handler.h |
index f3d9d4b662c5d9c6f034cacffc7f5a8cfd67d9db..45db6d59b0754c189762cc89047bb97d26e898f8 100644 |
--- a/components/favicon/core/favicon_handler.h |
+++ b/components/favicon/core/favicon_handler.h |
@@ -68,14 +68,63 @@ class FaviconService; |
// favicon. |
// |
// When the renderer downloads favicons, it considers the entire list of |
-// favicon candidates, if |download_largest_favicon_| is true, the largest |
-// favicon will be used, otherwise the one that best matches the preferred size |
-// is chosen (or the first one if there is no preferred size). Once the |
-// matching favicon has been determined, SetFavicon is called which updates |
-// the page's favicon and notifies the database to save the favicon. |
+// favicon candidates. Among those, the one that matches |target_spec_| |
+// is chosen first. Once the matching favicon has been determined, SetFavicon |
+// is called which updates the page's favicon and notifies the database to save |
+// the favicon. |
class FaviconHandler { |
public: |
+ class TargetSpec { |
+ public: |
+ static TargetSpec ForLargest(); |
+ static TargetSpec For16x16Dips(); |
+ |
+ TargetSpec(const TargetSpec&); |
+ ~TargetSpec(); |
+ |
+ // Returns the target sizes to be fetched, sorted in ascending order. |
+ // FaviconHandler will ensure a bitmap for each pixel sizes |
+ // either by searching among candidates for an exact match, or by resampling |
+ // the closest match. |
+ std::vector<int> GetPixelSizes() const; |
+ |
+ // Returns the maximum value instead of all. |
+ int GetMaxPixelSize() const; |
+ |
+ // Returns whether the spec is requiring the best-matching bitmap only. |
+ bool WantsBestBitmapOnly() const; |
+ |
+ // Compares two sizes in pixels, i.e. whether |size1| is a better match than |
+ // |size2| for |pixel_size|. |
+ bool IsBetterMatch(const gfx::Size& size1, const gfx::Size& size2) const; |
+ |
+ // Checks if |bitmap_results| contains all bitmaps required by this |
+ // specification. |
+ bool HasCompleteResult( |
+ const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) |
+ const; |
+ |
+ gfx::ImageSkia CreateImageSkia( |
+ const std::vector<SkBitmap>& bitmaps, |
+ const std::vector<gfx::Size>& original_bitmap_sizes) const; |
+ |
+ gfx::Image CreateImageFromCache( |
+ const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) |
+ const; |
+ |
+ private: |
+ TargetSpec(); |
+ |
+ // Map representing the target sizes to be fetched and their corresponding |
+ // scale factors. |
+ std::map<int, float> pixel_sizes_; |
+ |
+ // If true, FaviconHandler will resample candidates whenever needed to |
+ // ensure that bitmaps for all |pixel_sizes| are produced. |
+ bool ensure_exact_size_; |
+ }; |
+ |
class Delegate { |
public: |
// Mimics WebContents::ImageDownloadCallback. |
@@ -162,12 +211,10 @@ class FaviconHandler { |
FaviconCandidate(const GURL& image_url, |
const gfx::Image& image, |
- float score, |
favicon_base::IconType icon_type); |
GURL image_url; |
gfx::Image image; |
- float score; |
favicon_base::IconType icon_type; |
}; |
@@ -208,10 +255,10 @@ class FaviconHandler { |
bool ShouldSaveFavicon(); |
- // Updates |favicon_candidate_| and returns true if it is an exact match. |
+ // Updates |favicon_candidate_| and returns true if no more candidates should |
+ // be processed (e.g. an exact match was found). |
bool UpdateFaviconCandidate(const GURL& image_url, |
const gfx::Image& image, |
- float score, |
favicon_base::IconType icon_type); |
// Sets the image data for the favicon. |
@@ -238,12 +285,6 @@ class FaviconHandler { |
: nullptr; |
} |
- // Returns the preferred size of the image. 0 means no preference (any size |
- // will do). |
- int preferred_icon_size() const { |
- return download_largest_icon_ ? 0 : gfx::kFaviconSize; |
- } |
- |
// Used for FaviconService requests. |
base::CancelableTaskTracker cancelable_task_tracker_; |
@@ -274,8 +315,8 @@ class FaviconHandler { |
// The combination of the supported icon types. |
const int icon_types_; |
- // Whether the largest icon should be downloaded. |
- const bool download_largest_icon_; |
+ // Desired icon size. |
+ const TargetSpec target_spec_; |
// The prioritized favicon candidates from the page back from the renderer. |
std::vector<favicon::FaviconURL> image_urls_; |