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

Side by Side Diff: components/favicon/core/favicon_handler.h

Issue 2703603002: Improve FaviconHandler tests by testing public API (Closed)
Patch Set: Removed UpdateFaviconMappingsAndFetch() Created 3 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
« no previous file with comments | « components/favicon/core/BUILD.gn ('k') | components/favicon/core/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) 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
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. 133 // For testing.
135 const std::vector<favicon::FaviconURL>& image_urls() const { 134 const std::vector<favicon::FaviconURL>& image_urls() const {
136 return image_urls_; 135 return image_urls_;
137 } 136 }
138 137
139 // Returns whether the handler is waiting for a download to complete or for 138 // Returns whether the handler is waiting for a download to complete or for
140 // data from the FaviconService. Reserved for testing. 139 // data from the FaviconService. Reserved for testing.
141 bool HasPendingTasksForTest(); 140 bool HasPendingTasksForTest();
142 141
143 protected: 142 // Get the maximal icon size in pixels for a icon of type |icon_type| for the
144 // These virtual methods make FaviconHandler testable and are overridden by 143 // current platform.
145 // TestFaviconHandler. 144 static int GetMaximalIconSize(favicon_base::IconType icon_type);
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 145
175 private: 146 private:
176 // For testing:
177 friend class TestFaviconHandler;
178
179 // Represents an in progress download of an image from the renderer. 147 // Represents an in progress download of an image from the renderer.
180 struct DownloadRequest { 148 struct DownloadRequest {
181 DownloadRequest(); 149 DownloadRequest();
182 ~DownloadRequest(); 150 ~DownloadRequest();
183 151
184 DownloadRequest(const GURL& image_url, favicon_base::IconType icon_type); 152 DownloadRequest(const GURL& image_url, favicon_base::IconType icon_type);
185 153
186 GURL image_url; 154 GURL image_url;
187 favicon_base::IconType icon_type; 155 favicon_base::IconType icon_type;
188 }; 156 };
(...skipping 11 matching lines...) Expand all
200 GURL image_url; 168 GURL image_url;
201 gfx::Image image; 169 gfx::Image image;
202 float score; 170 float score;
203 favicon_base::IconType icon_type; 171 favicon_base::IconType icon_type;
204 }; 172 };
205 173
206 // Returns the bit mask of favicon_base::IconType based on the handler's type. 174 // Returns the bit mask of favicon_base::IconType based on the handler's type.
207 static int GetIconTypesFromHandlerType( 175 static int GetIconTypesFromHandlerType(
208 FaviconDriverObserver::NotificationIconType handler_type); 176 FaviconDriverObserver::NotificationIconType handler_type);
209 177
210 // Get the maximal icon size in pixels for a icon of type |icon_type| for the
211 // current platform.
212 static int GetMaximalIconSize(favicon_base::IconType icon_type);
213
214 // Called when the history request for favicon data mapped to |url_| has 178 // Called when the history request for favicon data mapped to |url_| has
215 // completed and the renderer has told us the icon URLs used by |url_| 179 // completed and the renderer has told us the icon URLs used by |url_|
216 void OnGotInitialHistoryDataAndIconURLCandidates(); 180 void OnGotInitialHistoryDataAndIconURLCandidates();
217 181
218 // See description above class for details. 182 // See description above class for details.
219 void OnFaviconDataForInitialURLFromFaviconService(const std::vector< 183 void OnFaviconDataForInitialURLFromFaviconService(const std::vector<
220 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results); 184 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results);
221 185
222 // If the favicon currently mapped to |url_| has expired, downloads the 186 // If the favicon currently mapped to |url_| has expired, downloads the
223 // current candidate favicon from the renderer. Otherwise requests data for 187 // current candidate favicon from the renderer. Otherwise requests data for
(...skipping 11 matching lines...) Expand all
235 favicon_base::IconType icon_type); 199 favicon_base::IconType icon_type);
236 200
237 // Triggered when a download of an image has finished. 201 // Triggered when a download of an image has finished.
238 void OnDidDownloadFavicon( 202 void OnDidDownloadFavicon(
239 int id, 203 int id,
240 int http_status_code, 204 int http_status_code,
241 const GURL& image_url, 205 const GURL& image_url,
242 const std::vector<SkBitmap>& bitmaps, 206 const std::vector<SkBitmap>& bitmaps,
243 const std::vector<gfx::Size>& original_bitmap_sizes); 207 const std::vector<gfx::Size>& original_bitmap_sizes);
244 208
209 bool ShouldSaveFavicon();
210
245 // Updates |favicon_candidate_| and returns true if it is an exact match. 211 // Updates |favicon_candidate_| and returns true if it is an exact match.
246 bool UpdateFaviconCandidate(const GURL& image_url, 212 bool UpdateFaviconCandidate(const GURL& image_url,
247 const gfx::Image& image, 213 const gfx::Image& image,
248 float score, 214 float score,
249 favicon_base::IconType icon_type); 215 favicon_base::IconType icon_type);
250 216
251 // Sets the image data for the favicon. 217 // Sets the image data for the favicon.
252 void SetFavicon(const GURL& icon_url, 218 void SetFavicon(const GURL& icon_url,
253 const gfx::Image& image, 219 const gfx::Image& image,
254 favicon_base::IconType icon_type); 220 favicon_base::IconType icon_type);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 FaviconCandidate best_favicon_candidate_; 303 FaviconCandidate best_favicon_candidate_;
338 304
339 base::WeakPtrFactory<FaviconHandler> weak_ptr_factory_; 305 base::WeakPtrFactory<FaviconHandler> weak_ptr_factory_;
340 306
341 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); 307 DISALLOW_COPY_AND_ASSIGN(FaviconHandler);
342 }; 308 };
343 309
344 } // namespace favicon 310 } // namespace favicon
345 311
346 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ 312 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_
OLDNEW
« no previous file with comments | « components/favicon/core/BUILD.gn ('k') | components/favicon/core/favicon_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698