Chromium Code Reviews| Index: components/favicon/core/favicon_handler.h |
| diff --git a/components/favicon/core/favicon_handler.h b/components/favicon/core/favicon_handler.h |
| index bbd470c16ae54cece9673fe7490b3374bad98ee8..cfaba62ae07a2176d68574b68e3b0e00ab3ed3db 100644 |
| --- a/components/favicon/core/favicon_handler.h |
| +++ b/components/favicon/core/favicon_handler.h |
| @@ -13,6 +13,7 @@ |
| #include "base/callback_forward.h" |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "base/task/cancelable_task_tracker.h" |
| #include "components/favicon/core/favicon_driver_observer.h" |
| #include "components/favicon/core/favicon_url.h" |
| @@ -25,7 +26,6 @@ class SkBitmap; |
| namespace favicon { |
| -class FaviconDriver; |
| class FaviconService; |
| class TestFaviconHandler; |
| @@ -77,15 +77,52 @@ class TestFaviconHandler; |
| class FaviconHandler { |
| public: |
| + class Delegate { |
| + public: |
| + // Mimics WebContents::ImageDownloadCallback. |
| + typedef base::Callback<void( |
| + int id, |
| + int status_code, |
| + const GURL& image_url, |
| + const std::vector<SkBitmap>& bitmaps, |
| + const std::vector<gfx::Size>& original_bitmap_sizes)> |
| + ImageDownloadCallback; |
| + |
| + // Starts the download for the given favicon. When finished, the callback |
| + // is called with the results. Returns the unique id of the download |
| + // request, which will also be passed to the callback. In case of error, 0 |
| + // is returned and no callback will be called. |
| + // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out |
| + // from the bitmap results. If there are no bitmap results <= |
| + // |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size| |
| + // and is the only result. A |max_bitmap_size| of 0 means unlimited. |
| + virtual int DownloadImage(const GURL& url, |
| + int max_image_size, |
| + ImageDownloadCallback callback) = 0; |
|
pkotwicz
2017/02/22 02:37:54
Might as well use WebContents::ImageDownloadCallba
mastiz
2017/02/23 21:55:54
I can't add a dependency to WebContents in shared
pkotwicz
2017/02/24 16:04:46
You're right. I forgot about iOS
|
| + |
| + // Returns whether the user is operating in an off-the-record context. |
| + virtual bool IsOffTheRecord() = 0; |
| + |
| + // Returns whether |url| is bookmarked. |
| + virtual bool IsBookmarked(const GURL& url) = 0; |
| + |
| + // Notifies that the favicon image has been updated, which the delegate |
| + // would typically propagate to FaviconDriverObserver::OnFaviconUpdated(), |
| + // see its documentation for details. |
|
pkotwicz
2017/02/22 02:37:54
Nit: "Replace the ',' with '.'
"Notifies that the
mastiz
2017/02/23 21:55:54
Done.
|
| + virtual void OnFaviconUpdated( |
| + const GURL& page_url, |
| + FaviconDriverObserver::NotificationIconType notification_icon_type, |
| + const GURL& icon_url, |
| + bool icon_url_changed, |
| + const gfx::Image& image) = 0; |
| + }; |
| + |
| + // |delegate| must not be nullptr and must outlive this class. |
| FaviconHandler(FaviconService* service, |
| - FaviconDriver* driver, |
| + Delegate* delegate, |
| FaviconDriverObserver::NotificationIconType handler_type); |
| virtual ~FaviconHandler(); |
| - // Returns the bit mask of favicon_base::IconType based on the handler's type. |
| - static int GetIconTypesFromHandlerType( |
| - FaviconDriverObserver::NotificationIconType handler_type); |
| - |
| // Initiates loading the favicon for the specified url. |
| void FetchFavicon(const GURL& url); |
| @@ -94,21 +131,6 @@ class FaviconHandler { |
| void OnUpdateFaviconURL(const GURL& page_url, |
| const std::vector<favicon::FaviconURL>& candidates); |
| - // Called when the history request for favicon data mapped to |url_| has |
| - // completed and the renderer has told us the icon URLs used by |url_| |
| - void OnGotInitialHistoryDataAndIconURLCandidates(); |
| - |
| - // Message handler for ImageHostMsg_DidDownloadImage. Called when the image |
| - // at |image_url| has been downloaded. |
| - // |bitmaps| is a list of all the frames of the image at |image_url|. |
| - // |original_bitmap_sizes| are the sizes of |bitmaps| before they were resized |
| - // to the maximum bitmap size passed to DownloadFavicon(). |
| - void OnDidDownloadFavicon( |
| - int id, |
| - const GURL& image_url, |
| - const std::vector<SkBitmap>& bitmaps, |
| - const std::vector<gfx::Size>& original_bitmap_sizes); |
| - |
| // For testing. |
| const std::vector<favicon::FaviconURL>& image_urls() const { |
| return image_urls_; |
| @@ -122,9 +144,6 @@ class FaviconHandler { |
| // These virtual methods make FaviconHandler testable and are overridden by |
| // TestFaviconHandler. |
| - // Asks the render to download favicon, returns the request id. |
| - virtual int DownloadFavicon(const GURL& image_url, int max_bitmap_size); |
| - |
| // Ask the favicon from history |
| virtual void UpdateFaviconMappingAndFetch( |
| const GURL& page_url, |
| @@ -184,10 +203,18 @@ class FaviconHandler { |
| favicon_base::IconType icon_type; |
| }; |
| + // Returns the bit mask of favicon_base::IconType based on the handler's type. |
| + static int GetIconTypesFromHandlerType( |
| + FaviconDriverObserver::NotificationIconType handler_type); |
|
pkotwicz
2017/02/22 02:37:54
Nit: Reorder the functions in the .cc file to matc
mastiz
2017/02/23 21:55:54
I started to do this when I realized that many of
pkotwicz
2017/02/24 16:04:46
Sorting the functions in a follow up CL is fine by
|
| + |
| // Get the maximal icon size in pixels for a icon of type |icon_type| for the |
| // current platform. |
| static int GetMaximalIconSize(favicon_base::IconType icon_type); |
| + // Called when the history request for favicon data mapped to |url_| has |
| + // completed and the renderer has told us the icon URLs used by |url_| |
| + void OnGotInitialHistoryDataAndIconURLCandidates(); |
| + |
| // See description above class for details. |
| void OnFaviconDataForInitialURLFromFaviconService(const std::vector< |
| favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results); |
| @@ -207,6 +234,13 @@ class FaviconHandler { |
| void ScheduleDownload(const GURL& image_url, |
| favicon_base::IconType icon_type); |
| + // Triggered when a download of an image has finished. |
| + void DidDownloadFavicon(int id, |
|
pkotwicz
2017/02/22 02:37:54
Nit: Keep the function name as OnDidDownloadFavico
mastiz
2017/02/23 21:55:54
Done.
|
| + int http_status_code, |
| + const GURL& image_url, |
| + const std::vector<SkBitmap>& bitmaps, |
| + const std::vector<gfx::Size>& original_bitmap_sizes); |
| + |
| // Updates |favicon_candidate_| and returns true if it is an exact match. |
| bool UpdateFaviconCandidate(const GURL& image_url, |
| const gfx::Image& image, |
| @@ -288,8 +322,8 @@ class FaviconHandler { |
| // testing. |
| FaviconService* service_; |
| - // This handler's driver, owns this object. |
| - FaviconDriver* driver_; |
| + // This handler's delegate. |
| + Delegate* delegate_; |
| // The index of the favicon URL in |image_urls_| which is currently being |
| // requested from history or downloaded. |
| @@ -301,6 +335,8 @@ class FaviconHandler { |
| // the image is for a favicon). |
| FaviconCandidate best_favicon_candidate_; |
| + base::WeakPtrFactory<FaviconHandler> weak_ptr_factory_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(FaviconHandler); |
| }; |