Chromium Code Reviews| 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 "components/favicon/core/favicon_handler.h" | 5 #include "components/favicon/core/favicon_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 | 468 |
| 469 if (!image_skia.isNull()) { | 469 if (!image_skia.isNull()) { |
| 470 gfx::Image image(image_skia); | 470 gfx::Image image(image_skia); |
| 471 // The downloaded icon is still valid when there is no FaviconURL update | 471 // The downloaded icon is still valid when there is no FaviconURL update |
| 472 // during the downloading. | 472 // during the downloading. |
| 473 request_next_icon = !UpdateFaviconCandidate(image_url, image, score, | 473 request_next_icon = !UpdateFaviconCandidate(image_url, image, score, |
| 474 download_request.icon_type); | 474 download_request.icon_type); |
| 475 } | 475 } |
| 476 } | 476 } |
| 477 | 477 |
| 478 if (request_next_icon && current_candidate_index_ + 1 < image_urls_.size()) { | 478 if (request_next_icon && IncrementCurrentCandidateIndex()) { |
| 479 // Process the next candidate. | 479 // Process the next candidate. |
| 480 ++current_candidate_index_; | |
| 481 DownloadCurrentCandidateOrAskFaviconService(); | 480 DownloadCurrentCandidateOrAskFaviconService(); |
| 482 } else { | 481 } else { |
| 483 // We have either found the ideal candidate or run out of candidates. | 482 // We have either found the ideal candidate or run out of candidates. |
| 484 if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) { | 483 if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) { |
| 485 // No more icons to request, set the favicon from the candidate. | 484 // No more icons to request, set the favicon from the candidate. |
| 486 SetFavicon(best_favicon_candidate_.image_url, | 485 SetFavicon(best_favicon_candidate_.image_url, |
| 487 best_favicon_candidate_.image, | 486 best_favicon_candidate_.image, |
| 488 best_favicon_candidate_.icon_type); | 487 best_favicon_candidate_.icon_type); |
| 489 } | 488 } |
| 490 // Clear download related state. | 489 // Clear download related state. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 // doesn't have an icon. Set the favicon now, and if the favicon turns out | 591 // doesn't have an icon. Set the favicon now, and if the favicon turns out |
| 593 // to be expired (or the wrong url) we'll fetch later on. This way the | 592 // to be expired (or the wrong url) we'll fetch later on. This way the |
| 594 // user doesn't see a flash of the default favicon. | 593 // user doesn't see a flash of the default favicon. |
| 595 NotifyFaviconUpdated(favicon_bitmap_results); | 594 NotifyFaviconUpdated(favicon_bitmap_results); |
| 596 } | 595 } |
| 597 | 596 |
| 598 if (current_candidate()) | 597 if (current_candidate()) |
| 599 OnGotInitialHistoryDataAndIconURLCandidates(); | 598 OnGotInitialHistoryDataAndIconURLCandidates(); |
| 600 } | 599 } |
| 601 | 600 |
| 601 bool FaviconHandler::IncrementCurrentCandidateIndex() { | |
| 602 if (current_candidate_index_ + 1 >= image_urls_.size()) | |
| 603 return false; | |
| 604 ++current_candidate_index_; | |
| 605 return true; | |
| 606 } | |
| 607 | |
| 602 void FaviconHandler::DownloadCurrentCandidateOrAskFaviconService() { | 608 void FaviconHandler::DownloadCurrentCandidateOrAskFaviconService() { |
| 603 GURL icon_url = current_candidate()->icon_url; | 609 GURL icon_url = current_candidate()->icon_url; |
| 604 favicon_base::IconType icon_type = current_candidate()->icon_type; | 610 favicon_base::IconType icon_type = current_candidate()->icon_type; |
| 605 | 611 |
| 606 if (redownload_icons_) { | 612 if (redownload_icons_) { |
| 607 // We have the mapping, but the favicon is out of date. Download it now. | 613 // We have the mapping, but the favicon is out of date. Download it now. |
| 608 ScheduleDownload(icon_url, icon_type); | 614 ScheduleDownload(icon_url, icon_type); |
| 609 } else { | 615 } else { |
| 610 // We don't know the favicon, but we may have previously downloaded the | 616 // We don't know the favicon, but we may have previously downloaded the |
| 611 // favicon for another page that shares the same favicon. Ask for the | 617 // favicon for another page that shares the same favicon. Ask for the |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 | 660 |
| 655 if (has_expired_or_incomplete_result) { | 661 if (has_expired_or_incomplete_result) { |
| 656 ScheduleDownload(current_candidate()->icon_url, | 662 ScheduleDownload(current_candidate()->icon_url, |
| 657 current_candidate()->icon_type); | 663 current_candidate()->icon_type); |
| 658 } | 664 } |
| 659 } | 665 } |
| 660 | 666 |
| 661 void FaviconHandler::ScheduleDownload(const GURL& image_url, | 667 void FaviconHandler::ScheduleDownload(const GURL& image_url, |
| 662 favicon_base::IconType icon_type) { | 668 favicon_base::IconType icon_type) { |
| 663 DCHECK(image_url.is_valid()); | 669 DCHECK(image_url.is_valid()); |
| 670 if (service_ && service_->WasUnableToDownloadFavicon(image_url)) { | |
|
pkotwicz
2017/03/02 21:20:26
Won't this cause a regression? In particular if a
mastiz
2017/03/03 14:21:14
I think you're right. I tried to add tests that wo
pkotwicz
2017/03/03 18:31:16
This bug is reproduceable on the desktop for a Fav
mastiz
2017/03/03 20:37:01
This seems so unlikely that I'd rather not add tes
pkotwicz
2017/03/03 20:56:14
Fair enough
| |
| 671 DVLOG(1) << "Skip Failed FavIcon: " << image_url; | |
| 672 // Process the next candidate. | |
| 673 if (IncrementCurrentCandidateIndex()) { | |
| 674 DownloadCurrentCandidateOrAskFaviconService(); | |
| 675 } | |
| 676 return; | |
| 677 } | |
| 664 // A max bitmap size is specified to avoid receiving huge bitmaps in | 678 // A max bitmap size is specified to avoid receiving huge bitmaps in |
| 665 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 679 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
| 666 // for more details about the max bitmap size. | 680 // for more details about the max bitmap size. |
| 667 const int download_id = | 681 const int download_id = |
| 668 delegate_->DownloadImage(image_url, GetMaximalIconSize(icon_type), | 682 delegate_->DownloadImage(image_url, GetMaximalIconSize(icon_type), |
| 669 base::Bind(&FaviconHandler::OnDidDownloadFavicon, | 683 base::Bind(&FaviconHandler::OnDidDownloadFavicon, |
| 670 weak_ptr_factory_.GetWeakPtr())); | 684 weak_ptr_factory_.GetWeakPtr())); |
| 671 | 685 |
| 672 // Download ids should be unique. | 686 // Download ids should be unique. |
| 673 DCHECK(download_requests_.find(download_id) == download_requests_.end()); | 687 DCHECK(download_requests_.find(download_id) == download_requests_.end()); |
| 674 download_requests_[download_id] = DownloadRequest(image_url, icon_type); | 688 download_requests_[download_id] = DownloadRequest(image_url, icon_type); |
| 675 | 689 |
| 676 if (download_id == 0) { | 690 if (download_id == 0) { |
|
pkotwicz
2017/03/02 21:20:26
Looking at the implementation of DownloadImage() I
mastiz
2017/03/03 14:21:14
Tests currently return download_id in case of fail
pkotwicz
2017/03/03 18:31:16
Please add a TODO and file a bug :)
mastiz
2017/03/03 20:37:01
Added a TODO, not filing a bug because it's a mino
pkotwicz
2017/03/03 20:56:14
Fair enough
| |
| 677 // If DownloadFavicon() did not start a download, it returns a download id | 691 // If DownloadFavicon() did not start a download, it returns a download id |
| 678 // of 0. We still need to call OnDidDownloadFavicon() because the method is | 692 // of 0. We still need to call OnDidDownloadFavicon() because the method is |
| 679 // responsible for initiating the data request for the next candidate. | 693 // responsible for initiating the data request for the next candidate. |
| 680 OnDidDownloadFavicon(download_id, 0, image_url, std::vector<SkBitmap>(), | 694 OnDidDownloadFavicon(download_id, 0, image_url, std::vector<SkBitmap>(), |
| 681 std::vector<gfx::Size>()); | 695 std::vector<gfx::Size>()); |
| 682 } | 696 } |
| 683 } | 697 } |
| 684 | 698 |
| 685 } // namespace favicon | 699 } // namespace favicon |
| OLD | NEW |