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 #include "chrome/browser/favicon/favicon_handler.h" | 5 #include "chrome/browser/favicon/favicon_handler.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/favicon/chrome_favicon_client.h" | 8 #include "chrome/browser/favicon/chrome_favicon_client.h" |
9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" | 9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" |
10 #include "chrome/browser/favicon/favicon_service.h" | 10 #include "chrome/browser/favicon/favicon_service.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 favicon_base::FaviconResultsCallback callback_; | 170 favicon_base::FaviconResultsCallback callback_; |
171 | 171 |
172 private: | 172 private: |
173 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); | 173 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); |
174 }; | 174 }; |
175 | 175 |
176 } // namespace | 176 } // namespace |
177 | 177 |
178 class TestFaviconClient : public FaviconClient { | 178 class TestFaviconClient : public FaviconClient { |
179 public: | 179 public: |
180 virtual ~TestFaviconClient() {}; | 180 ~TestFaviconClient() override{}; |
181 | 181 |
182 virtual FaviconService* GetFaviconService() override { | 182 FaviconService* GetFaviconService() override { |
183 // Just give none NULL value, so overridden methods can be hit. | 183 // Just give none NULL value, so overridden methods can be hit. |
184 return (FaviconService*)(1); | 184 return (FaviconService*)(1); |
185 } | 185 } |
186 | 186 |
187 virtual bool IsBookmarked(const GURL& url) override { return false; } | 187 bool IsBookmarked(const GURL& url) override { return false; } |
188 }; | 188 }; |
189 | 189 |
190 class TestFaviconDriver : public FaviconDriver { | 190 class TestFaviconDriver : public FaviconDriver { |
191 public: | 191 public: |
192 TestFaviconDriver() : favicon_validity_(false) {} | 192 TestFaviconDriver() : favicon_validity_(false) {} |
193 | 193 |
194 virtual ~TestFaviconDriver() { | 194 virtual ~TestFaviconDriver() { |
195 } | 195 } |
196 | 196 |
197 virtual bool IsOffTheRecord() override { return false; } | 197 bool IsOffTheRecord() override { return false; } |
198 | 198 |
199 virtual const gfx::Image GetActiveFaviconImage() override { return image_; } | 199 const gfx::Image GetActiveFaviconImage() override { return image_; } |
200 | 200 |
201 virtual const GURL GetActiveFaviconURL() override { return favicon_url_; } | 201 const GURL GetActiveFaviconURL() override { return favicon_url_; } |
202 | 202 |
203 virtual bool GetActiveFaviconValidity() override { return favicon_validity_; } | 203 bool GetActiveFaviconValidity() override { return favicon_validity_; } |
204 | 204 |
205 virtual const GURL GetActiveURL() override { return url_; } | 205 const GURL GetActiveURL() override { return url_; } |
206 | 206 |
207 virtual void SetActiveFaviconImage(gfx::Image image) override { | 207 void SetActiveFaviconImage(gfx::Image image) override { image_ = image; } |
208 image_ = image; | |
209 } | |
210 | 208 |
211 virtual void SetActiveFaviconURL(GURL favicon_url) override { | 209 void SetActiveFaviconURL(GURL favicon_url) override { |
212 favicon_url_ = favicon_url; | 210 favicon_url_ = favicon_url; |
213 } | 211 } |
214 | 212 |
215 virtual void SetActiveFaviconValidity(bool favicon_validity) override { | 213 void SetActiveFaviconValidity(bool favicon_validity) override { |
216 favicon_validity_ = favicon_validity; | 214 favicon_validity_ = favicon_validity; |
217 } | 215 } |
218 | 216 |
219 virtual int StartDownload(const GURL& url, | 217 int StartDownload(const GURL& url, int max_bitmap_size) override { |
220 int max_bitmap_size) override { | |
221 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " | 218 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " |
222 << "should never be called in tests."; | 219 << "should never be called in tests."; |
223 return -1; | 220 return -1; |
224 } | 221 } |
225 | 222 |
226 virtual void NotifyFaviconUpdated(bool icon_url_changed) override { | 223 void NotifyFaviconUpdated(bool icon_url_changed) override { |
227 ADD_FAILURE() << "TestFaviconDriver::NotifyFaviconUpdated() " | 224 ADD_FAILURE() << "TestFaviconDriver::NotifyFaviconUpdated() " |
228 << "should never be called in tests."; | 225 << "should never be called in tests."; |
229 } | 226 } |
230 | 227 |
231 void SetActiveURL(GURL url) { url_ = url; } | 228 void SetActiveURL(GURL url) { url_ = url; } |
232 | 229 |
233 private: | 230 private: |
234 GURL favicon_url_; | 231 GURL favicon_url_; |
235 GURL url_; | 232 GURL url_; |
236 gfx::Image image_; | 233 gfx::Image image_; |
(...skipping 15 matching lines...) Expand all Loading... |
252 TestFaviconDriver* driver, | 249 TestFaviconDriver* driver, |
253 Type type, | 250 Type type, |
254 bool download_largest_icon) | 251 bool download_largest_icon) |
255 : FaviconHandler(client, driver, type, download_largest_icon), | 252 : FaviconHandler(client, driver, type, download_largest_icon), |
256 download_id_(0), | 253 download_id_(0), |
257 num_favicon_updates_(0) { | 254 num_favicon_updates_(0) { |
258 driver->SetActiveURL(page_url); | 255 driver->SetActiveURL(page_url); |
259 download_handler_.reset(new DownloadHandler(this)); | 256 download_handler_.reset(new DownloadHandler(this)); |
260 } | 257 } |
261 | 258 |
262 virtual ~TestFaviconHandler() { | 259 ~TestFaviconHandler() override {} |
263 } | |
264 | 260 |
265 HistoryRequestHandler* history_handler() { | 261 HistoryRequestHandler* history_handler() { |
266 return history_handler_.get(); | 262 return history_handler_.get(); |
267 } | 263 } |
268 | 264 |
269 // This method will take the ownership of the given handler. | 265 // This method will take the ownership of the given handler. |
270 void set_history_handler(HistoryRequestHandler* handler) { | 266 void set_history_handler(HistoryRequestHandler* handler) { |
271 history_handler_.reset(handler); | 267 history_handler_.reset(handler); |
272 } | 268 } |
273 | 269 |
(...skipping 16 matching lines...) Expand all Loading... |
290 | 286 |
291 FaviconURL* current_candidate() { | 287 FaviconURL* current_candidate() { |
292 return FaviconHandler::current_candidate(); | 288 return FaviconHandler::current_candidate(); |
293 } | 289 } |
294 | 290 |
295 const FaviconCandidate& best_favicon_candidate() { | 291 const FaviconCandidate& best_favicon_candidate() { |
296 return best_favicon_candidate_; | 292 return best_favicon_candidate_; |
297 } | 293 } |
298 | 294 |
299 protected: | 295 protected: |
300 virtual void UpdateFaviconMappingAndFetch( | 296 void UpdateFaviconMappingAndFetch( |
301 const GURL& page_url, | 297 const GURL& page_url, |
302 const GURL& icon_url, | 298 const GURL& icon_url, |
303 favicon_base::IconType icon_type, | 299 favicon_base::IconType icon_type, |
304 const favicon_base::FaviconResultsCallback& callback, | 300 const favicon_base::FaviconResultsCallback& callback, |
305 base::CancelableTaskTracker* tracker) override { | 301 base::CancelableTaskTracker* tracker) override { |
306 history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, | 302 history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, |
307 icon_type, callback)); | 303 icon_type, callback)); |
308 } | 304 } |
309 | 305 |
310 virtual void GetFaviconFromFaviconService( | 306 void GetFaviconFromFaviconService( |
311 const GURL& icon_url, | 307 const GURL& icon_url, |
312 favicon_base::IconType icon_type, | 308 favicon_base::IconType icon_type, |
313 const favicon_base::FaviconResultsCallback& callback, | 309 const favicon_base::FaviconResultsCallback& callback, |
314 base::CancelableTaskTracker* tracker) override { | 310 base::CancelableTaskTracker* tracker) override { |
315 history_handler_.reset(new HistoryRequestHandler(GURL(), icon_url, | 311 history_handler_.reset(new HistoryRequestHandler(GURL(), icon_url, |
316 icon_type, callback)); | 312 icon_type, callback)); |
317 } | 313 } |
318 | 314 |
319 virtual void GetFaviconForURLFromFaviconService( | 315 void GetFaviconForURLFromFaviconService( |
320 const GURL& page_url, | 316 const GURL& page_url, |
321 int icon_types, | 317 int icon_types, |
322 const favicon_base::FaviconResultsCallback& callback, | 318 const favicon_base::FaviconResultsCallback& callback, |
323 base::CancelableTaskTracker* tracker) override { | 319 base::CancelableTaskTracker* tracker) override { |
324 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), | 320 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), |
325 icon_types, callback)); | 321 icon_types, callback)); |
326 } | 322 } |
327 | 323 |
328 virtual int DownloadFavicon(const GURL& image_url, | 324 int DownloadFavicon(const GURL& image_url, int max_bitmap_size) override { |
329 int max_bitmap_size) override { | |
330 download_id_++; | 325 download_id_++; |
331 std::vector<int> sizes; | 326 std::vector<int> sizes; |
332 sizes.push_back(0); | 327 sizes.push_back(0); |
333 download_handler_->AddDownload( | 328 download_handler_->AddDownload( |
334 download_id_, image_url, sizes, max_bitmap_size); | 329 download_id_, image_url, sizes, max_bitmap_size); |
335 return download_id_; | 330 return download_id_; |
336 } | 331 } |
337 | 332 |
338 virtual void SetHistoryFavicons(const GURL& page_url, | 333 void SetHistoryFavicons(const GURL& page_url, |
339 const GURL& icon_url, | 334 const GURL& icon_url, |
340 favicon_base::IconType icon_type, | 335 favicon_base::IconType icon_type, |
341 const gfx::Image& image) override { | 336 const gfx::Image& image) override { |
342 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); | 337 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); |
343 std::vector<unsigned char> bitmap_data(bytes->front(), | 338 std::vector<unsigned char> bitmap_data(bytes->front(), |
344 bytes->front() + bytes->size()); | 339 bytes->front() + bytes->size()); |
345 history_handler_.reset(new HistoryRequestHandler( | 340 history_handler_.reset(new HistoryRequestHandler( |
346 page_url, icon_url, icon_type, bitmap_data, image.Size())); | 341 page_url, icon_url, icon_type, bitmap_data, image.Size())); |
347 } | 342 } |
348 | 343 |
349 virtual bool ShouldSaveFavicon(const GURL& url) override { | 344 bool ShouldSaveFavicon(const GURL& url) override { return true; } |
350 return true; | |
351 } | |
352 | 345 |
353 virtual void NotifyFaviconUpdated(bool icon_url_changed) override { | 346 void NotifyFaviconUpdated(bool icon_url_changed) override { |
354 ++num_favicon_updates_; | 347 ++num_favicon_updates_; |
355 } | 348 } |
356 | 349 |
357 GURL page_url_; | 350 GURL page_url_; |
358 | 351 |
359 private: | 352 private: |
360 | 353 |
361 // The unique id of a download request. It will be returned to a | 354 // The unique id of a download request. It will be returned to a |
362 // FaviconHandler. | 355 // FaviconHandler. |
363 int download_id_; | 356 int download_id_; |
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | 1542 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); |
1550 EXPECT_NE(0, download_id); | 1543 EXPECT_NE(0, download_id); |
1551 // Report download success with HTTP 200 status. | 1544 // Report download success with HTTP 200 status. |
1552 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | 1545 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, |
1553 empty_icons, empty_icon_sizes); | 1546 empty_icons, empty_icon_sizes); |
1554 // Icon is not marked as UnableToDownload as HTTP status is not 404. | 1547 // Icon is not marked as UnableToDownload as HTTP status is not 404. |
1555 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | 1548 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); |
1556 } | 1549 } |
1557 | 1550 |
1558 } // namespace. | 1551 } // namespace. |
OLD | NEW |