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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 } | 633 } |
634 } | 634 } |
635 } | 635 } |
636 | 636 |
637 void FaviconHandler::OnFaviconData(const std::vector< | 637 void FaviconHandler::OnFaviconData(const std::vector< |
638 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results) { | 638 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results) { |
639 if (PageChangedSinceFaviconWasRequested()) | 639 if (PageChangedSinceFaviconWasRequested()) |
640 return; | 640 return; |
641 | 641 |
642 bool has_results = !favicon_bitmap_results.empty(); | 642 bool has_results = !favicon_bitmap_results.empty(); |
643 bool has_expired_or_incomplete_result = HasExpiredOrIncompleteResult( | 643 bool has_expired_or_incomplete_result = HasExpiredOrIncompleteResult( |
Roger McFarlane (Chromium)
2015/04/27 15:38:30
has_results && HasExpired...?
See ONFaviconDataFo
pkotwicz
2015/04/27 18:26:36
I have changed HasExpiredOrIncompleteResult() to r
| |
644 preferred_icon_size(), favicon_bitmap_results); | 644 preferred_icon_size(), favicon_bitmap_results); |
pkotwicz
2015/04/13 04:55:18
Yes, storing this in |favicon_expired_or_incomplet
| |
645 bool has_valid_result = HasValidResult(favicon_bitmap_results); | 645 bool has_valid_result = HasValidResult(favicon_bitmap_results); |
646 history_results_ = favicon_bitmap_results; | |
Roger McFarlane (Chromium)
2015/04/13 17:45:37
Do you need to save the results if they're not val
pkotwicz
2015/04/25 01:14:48
It is unclear what the correct behavior is.
- The
pkotwicz
2015/04/25 01:19:41
The reason that it might be nice to only update |h
| |
646 | 647 |
647 if (has_results && handler_type_ == FAVICON && !download_largest_icon_) { | 648 if (has_valid_result) { |
648 if (has_valid_result) { | 649 // There is a valid favicon. Notify any observers. It is useful to notify |
649 // There is a favicon, set it now. If expired we'll download the current | 650 // the observers even if the favicon is expired or incomplete (incorrect |
650 // one again, but at least the user will get some icon instead of the | 651 // size) because temporarily showing the user an expired favicon or |
651 // default and most likely the current one is fine anyway. | 652 // streched favicon is preferable to showing the user the default favicon. |
652 NotifyFaviconAvailable(favicon_bitmap_results); | 653 NotifyFaviconAvailable(favicon_bitmap_results); |
653 } | 654 } |
654 if (has_expired_or_incomplete_result) { | 655 |
655 // The favicon is out of date. Request the current one. | 656 if (!current_candidate() || |
656 ScheduleDownload(driver_->GetActiveURL(), | 657 (has_results && |
657 driver_->GetActiveFaviconURL(), | 658 !DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results))) { |
658 favicon_base::FAVICON); | 659 // The icon URLs have been updated since the favicon data was requested. |
659 } | 660 return; |
660 } else if (current_candidate() && | 661 } |
661 (!has_results || has_expired_or_incomplete_result || | 662 |
662 !(DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results)))) { | 663 if (!has_results || has_expired_or_incomplete_result) { |
663 // We don't know the favicon, it is out of date or its type is not same as | |
664 // one got from page. Request the current one. | |
pkotwicz
2015/04/13 04:55:18
The results should be empty if the type is differe
| |
665 ScheduleDownload(driver_->GetActiveURL(), | 664 ScheduleDownload(driver_->GetActiveURL(), |
666 current_candidate()->icon_url, | 665 current_candidate()->icon_url, |
667 current_candidate()->icon_type); | 666 current_candidate()->icon_type); |
668 } | 667 } |
669 history_results_ = favicon_bitmap_results; | |
670 | |
671 if (has_valid_result && | |
672 (handler_type_ != FAVICON || download_largest_icon_)) { | |
673 NotifyFaviconAvailable(favicon_bitmap_results); | |
674 } | |
675 } | 668 } |
676 | 669 |
677 void FaviconHandler::ScheduleDownload(const GURL& url, | 670 void FaviconHandler::ScheduleDownload(const GURL& url, |
678 const GURL& image_url, | 671 const GURL& image_url, |
679 favicon_base::IconType icon_type) { | 672 favicon_base::IconType icon_type) { |
680 // A max bitmap size is specified to avoid receiving huge bitmaps in | 673 // A max bitmap size is specified to avoid receiving huge bitmaps in |
681 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 674 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
682 // for more details about the max bitmap size. | 675 // for more details about the max bitmap size. |
683 const int download_id = DownloadFavicon(image_url, | 676 const int download_id = DownloadFavicon(image_url, |
684 GetMaximalIconSize(icon_type)); | 677 GetMaximalIconSize(icon_type)); |
(...skipping 14 matching lines...) Expand all Loading... | |
699 gfx::Size largest = | 692 gfx::Size largest = |
700 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)]; | 693 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)]; |
701 image_url.icon_sizes.clear(); | 694 image_url.icon_sizes.clear(); |
702 image_url.icon_sizes.push_back(largest); | 695 image_url.icon_sizes.push_back(largest); |
703 } | 696 } |
704 std::stable_sort(image_urls_.begin(), image_urls_.end(), | 697 std::stable_sort(image_urls_.begin(), image_urls_.end(), |
705 CompareIconSize); | 698 CompareIconSize); |
706 } | 699 } |
707 | 700 |
708 } // namespace favicon | 701 } // namespace favicon |
OLD | NEW |