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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 request_next_icon = !UpdateFaviconCandidate( | 432 request_next_icon = !UpdateFaviconCandidate( |
433 download_request.url, image_url, image, score, | 433 download_request.url, image_url, image, score, |
434 download_request.icon_type); | 434 download_request.icon_type); |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 if (request_next_icon && image_urls_.size() > 1) { | 438 if (request_next_icon && image_urls_.size() > 1) { |
439 // Remove the first member of image_urls_ and process the remaining. | 439 // Remove the first member of image_urls_ and process the remaining. |
440 image_urls_.erase(image_urls_.begin()); | 440 image_urls_.erase(image_urls_.begin()); |
441 ProcessCurrentUrl(); | 441 ProcessCurrentUrl(); |
442 } else if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) { | 442 } else { |
Roger McFarlane (Chromium)
2015/04/27 14:25:48
nit: Maybe return after ProcessCurrentUrl() ...
| |
443 // No more icons to request, set the favicon from the candidate. | 443 if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) { |
444 SetFavicon(best_favicon_candidate_.url, | 444 // No more icons to request, set the favicon from the candidate. |
445 best_favicon_candidate_.image_url, | 445 SetFavicon(best_favicon_candidate_.url, best_favicon_candidate_.image_url, |
446 best_favicon_candidate_.image, | 446 best_favicon_candidate_.image, |
447 best_favicon_candidate_.icon_type); | 447 best_favicon_candidate_.icon_type); |
448 } | |
448 // Reset candidate. | 449 // Reset candidate. |
449 image_urls_.clear(); | 450 image_urls_.clear(); |
450 download_requests_.clear(); | 451 download_requests_.clear(); |
451 best_favicon_candidate_ = FaviconCandidate(); | 452 best_favicon_candidate_ = FaviconCandidate(); |
452 } | 453 } |
453 } | 454 } |
454 | 455 |
455 bool FaviconHandler::HasPendingTasksForTest() { | 456 bool FaviconHandler::HasPendingTasksForTest() { |
456 return !download_requests_.empty() || | 457 return !download_requests_.empty() || |
457 cancelable_task_tracker_.HasTrackedTasks(); | 458 cancelable_task_tracker_.HasTrackedTasks(); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 } | 676 } |
676 | 677 |
677 void FaviconHandler::ScheduleDownload(const GURL& url, | 678 void FaviconHandler::ScheduleDownload(const GURL& url, |
678 const GURL& image_url, | 679 const GURL& image_url, |
679 favicon_base::IconType icon_type) { | 680 favicon_base::IconType icon_type) { |
680 // A max bitmap size is specified to avoid receiving huge bitmaps in | 681 // A max bitmap size is specified to avoid receiving huge bitmaps in |
681 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 682 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
682 // for more details about the max bitmap size. | 683 // for more details about the max bitmap size. |
683 const int download_id = DownloadFavicon(image_url, | 684 const int download_id = DownloadFavicon(image_url, |
684 GetMaximalIconSize(icon_type)); | 685 GetMaximalIconSize(icon_type)); |
685 if (download_id) { | 686 |
686 // Download ids should be unique. | 687 // Download ids should be unique. |
687 DCHECK(download_requests_.find(download_id) == download_requests_.end()); | 688 DCHECK(download_requests_.find(download_id) == download_requests_.end()); |
688 download_requests_[download_id] = | 689 download_requests_[download_id] = DownloadRequest(url, image_url, icon_type); |
Roger McFarlane (Chromium)
2015/04/27 14:25:48
This reads like you could have collisions on multi
| |
689 DownloadRequest(url, image_url, icon_type); | 690 |
691 if (download_id == 0) { | |
Roger McFarlane (Chromium)
2015/04/27 14:25:48
As per above, comment that you trigger the handler
pkotwicz
2015/04/27 18:50:54
You are right, this is non-obvious. I have added a
| |
692 OnDidDownloadFavicon(download_id, image_url, std::vector<SkBitmap>(), | |
693 std::vector<gfx::Size>()); | |
694 | |
690 } | 695 } |
691 } | 696 } |
692 | 697 |
693 void FaviconHandler::SortAndPruneImageUrls() { | 698 void FaviconHandler::SortAndPruneImageUrls() { |
694 // Not using const-reference since the loop mutates FaviconURL::icon_sizes. | 699 // Not using const-reference since the loop mutates FaviconURL::icon_sizes. |
695 for (FaviconURL& image_url : image_urls_) { | 700 for (FaviconURL& image_url : image_urls_) { |
696 if (image_url.icon_sizes.empty()) | 701 if (image_url.icon_sizes.empty()) |
697 continue; | 702 continue; |
698 | 703 |
699 gfx::Size largest = | 704 gfx::Size largest = |
700 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)]; | 705 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)]; |
701 image_url.icon_sizes.clear(); | 706 image_url.icon_sizes.clear(); |
702 image_url.icon_sizes.push_back(largest); | 707 image_url.icon_sizes.push_back(largest); |
703 } | 708 } |
704 std::stable_sort(image_urls_.begin(), image_urls_.end(), | 709 std::stable_sort(image_urls_.begin(), image_urls_.end(), |
705 CompareIconSize); | 710 CompareIconSize); |
706 } | 711 } |
707 | 712 |
708 } // namespace favicon | 713 } // namespace favicon |
OLD | NEW |