| OLD | NEW |
| 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> | 10 #include <map> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.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" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/task/cancelable_task_tracker.h" | 17 #include "base/task/cancelable_task_tracker.h" |
| 18 #include "components/favicon/core/favicon_driver_observer.h" | 18 #include "components/favicon/core/favicon_driver_observer.h" |
| 19 #include "components/favicon/core/favicon_url.h" | 19 #include "components/favicon/core/favicon_url.h" |
| 20 #include "components/favicon_base/favicon_callback.h" | 20 #include "components/favicon_base/favicon_callback.h" |
| 21 #include "ui/gfx/favicon_size.h" | 21 #include "ui/gfx/favicon_size.h" |
| 22 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 class SkBitmap; | 25 class SkBitmap; |
| 26 | 26 |
| 27 namespace favicon { | 27 namespace favicon { |
| 28 | 28 |
| 29 class FaviconService; | 29 class FaviconService; |
| 30 class TestFaviconHandler; | |
| 31 | 30 |
| 32 // FaviconHandler works with FaviconDriver to fetch the specific type of | 31 // FaviconHandler works with FaviconDriver to fetch the specific type of |
| 33 // favicon. | 32 // favicon. |
| 34 // | 33 // |
| 35 // FetchFavicon requests the favicon from the favicon service which in turn | 34 // FetchFavicon requests the favicon from the favicon service which in turn |
| 36 // requests the favicon from the history database. At this point | 35 // requests the favicon from the history database. At this point |
| 37 // we only know the URL of the page, and not necessarily the url of the | 36 // we only know the URL of the page, and not necessarily the url of the |
| 38 // favicon. To ensure we handle reloading stale favicons as well as | 37 // favicon. To ensure we handle reloading stale favicons as well as |
| 39 // reloading a favicon on page reload we always request the favicon from | 38 // reloading a favicon on page reload we always request the favicon from |
| 40 // history regardless of whether the active favicon is valid. | 39 // history regardless of whether the active favicon is valid. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 FaviconDriverObserver::NotificationIconType notification_icon_type, | 113 FaviconDriverObserver::NotificationIconType notification_icon_type, |
| 115 const GURL& icon_url, | 114 const GURL& icon_url, |
| 116 bool icon_url_changed, | 115 bool icon_url_changed, |
| 117 const gfx::Image& image) = 0; | 116 const gfx::Image& image) = 0; |
| 118 }; | 117 }; |
| 119 | 118 |
| 120 // |delegate| must not be nullptr and must outlive this class. | 119 // |delegate| must not be nullptr and must outlive this class. |
| 121 FaviconHandler(FaviconService* service, | 120 FaviconHandler(FaviconService* service, |
| 122 Delegate* delegate, | 121 Delegate* delegate, |
| 123 FaviconDriverObserver::NotificationIconType handler_type); | 122 FaviconDriverObserver::NotificationIconType handler_type); |
| 124 virtual ~FaviconHandler(); | 123 ~FaviconHandler(); |
| 125 | 124 |
| 126 // Initiates loading the favicon for the specified url. | 125 // Initiates loading the favicon for the specified url. |
| 127 void FetchFavicon(const GURL& url); | 126 void FetchFavicon(const GURL& url); |
| 128 | 127 |
| 129 // Message Handler. Must be public, because also called from | 128 // Message Handler. Must be public, because also called from |
| 130 // PrerenderContents. Collects the |image_urls| list. | 129 // PrerenderContents. Collects the |image_urls| list. |
| 131 void OnUpdateFaviconURL(const GURL& page_url, | 130 void OnUpdateFaviconURL(const GURL& page_url, |
| 132 const std::vector<favicon::FaviconURL>& candidates); | 131 const std::vector<favicon::FaviconURL>& candidates); |
| 133 | 132 |
| 134 // For testing. | |
| 135 const std::vector<favicon::FaviconURL>& image_urls() const { | |
| 136 return image_urls_; | |
| 137 } | |
| 138 | |
| 139 // Returns whether the handler is waiting for a download to complete or for | 133 // Returns whether the handler is waiting for a download to complete or for |
| 140 // data from the FaviconService. Reserved for testing. | 134 // data from the FaviconService. Reserved for testing. |
| 141 bool HasPendingTasksForTest(); | 135 bool HasPendingTasksForTest(); |
| 142 | 136 |
| 143 protected: | |
| 144 // These virtual methods make FaviconHandler testable and are overridden by | |
| 145 // TestFaviconHandler. | |
| 146 | |
| 147 // Ask the favicon from history | |
| 148 virtual void UpdateFaviconMappingAndFetch( | |
| 149 const GURL& page_url, | |
| 150 const GURL& icon_url, | |
| 151 favicon_base::IconType icon_type, | |
| 152 const favicon_base::FaviconResultsCallback& callback, | |
| 153 base::CancelableTaskTracker* tracker); | |
| 154 | |
| 155 virtual void GetFaviconFromFaviconService( | |
| 156 const GURL& icon_url, | |
| 157 favicon_base::IconType icon_type, | |
| 158 const favicon_base::FaviconResultsCallback& callback, | |
| 159 base::CancelableTaskTracker* tracker); | |
| 160 | |
| 161 virtual void GetFaviconForURLFromFaviconService( | |
| 162 const GURL& page_url, | |
| 163 int icon_types, | |
| 164 const favicon_base::FaviconResultsCallback& callback, | |
| 165 base::CancelableTaskTracker* tracker); | |
| 166 | |
| 167 virtual void SetHistoryFavicons(const GURL& page_url, | |
| 168 const GURL& icon_url, | |
| 169 favicon_base::IconType icon_type, | |
| 170 const gfx::Image& image); | |
| 171 | |
| 172 // Returns true if the favicon should be saved. | |
| 173 virtual bool ShouldSaveFavicon(); | |
| 174 | |
| 175 private: | 137 private: |
| 176 // For testing: | |
| 177 friend class TestFaviconHandler; | |
| 178 | |
| 179 // Represents an in progress download of an image from the renderer. | 138 // Represents an in progress download of an image from the renderer. |
| 180 struct DownloadRequest { | 139 struct DownloadRequest { |
| 181 DownloadRequest(); | 140 DownloadRequest(); |
| 182 ~DownloadRequest(); | 141 ~DownloadRequest(); |
| 183 | 142 |
| 184 DownloadRequest(const GURL& image_url, favicon_base::IconType icon_type); | 143 DownloadRequest(const GURL& image_url, favicon_base::IconType icon_type); |
| 185 | 144 |
| 186 GURL image_url; | 145 GURL image_url; |
| 187 favicon_base::IconType icon_type; | 146 favicon_base::IconType icon_type; |
| 188 }; | 147 }; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 void ScheduleDownload(const GURL& image_url, | 193 void ScheduleDownload(const GURL& image_url, |
| 235 favicon_base::IconType icon_type); | 194 favicon_base::IconType icon_type); |
| 236 | 195 |
| 237 // Triggered when a download of an image has finished. | 196 // Triggered when a download of an image has finished. |
| 238 void DidDownloadFavicon(int id, | 197 void DidDownloadFavicon(int id, |
| 239 int http_status_code, | 198 int http_status_code, |
| 240 const GURL& image_url, | 199 const GURL& image_url, |
| 241 const std::vector<SkBitmap>& bitmaps, | 200 const std::vector<SkBitmap>& bitmaps, |
| 242 const std::vector<gfx::Size>& original_bitmap_sizes); | 201 const std::vector<gfx::Size>& original_bitmap_sizes); |
| 243 | 202 |
| 203 bool ShouldSaveFavicon(); |
| 204 |
| 244 // Updates |favicon_candidate_| and returns true if it is an exact match. | 205 // Updates |favicon_candidate_| and returns true if it is an exact match. |
| 245 bool UpdateFaviconCandidate(const GURL& image_url, | 206 bool UpdateFaviconCandidate(const GURL& image_url, |
| 246 const gfx::Image& image, | 207 const gfx::Image& image, |
| 247 float score, | 208 float score, |
| 248 favicon_base::IconType icon_type); | 209 favicon_base::IconType icon_type); |
| 249 | 210 |
| 250 // Sets the image data for the favicon. | 211 // Sets the image data for the favicon. |
| 251 void SetFavicon(const GURL& icon_url, | 212 void SetFavicon(const GURL& icon_url, |
| 252 const gfx::Image& image, | 213 const gfx::Image& image, |
| 253 favicon_base::IconType icon_type); | 214 favicon_base::IconType icon_type); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 FaviconCandidate best_favicon_candidate_; | 297 FaviconCandidate best_favicon_candidate_; |
| 337 | 298 |
| 338 base::WeakPtrFactory<FaviconHandler> weak_ptr_factory_; | 299 base::WeakPtrFactory<FaviconHandler> weak_ptr_factory_; |
| 339 | 300 |
| 340 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); | 301 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); |
| 341 }; | 302 }; |
| 342 | 303 |
| 343 } // namespace favicon | 304 } // namespace favicon |
| 344 | 305 |
| 345 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ | 306 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ |
| OLD | NEW |