| 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 <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 namespace favicon { | 25 namespace favicon { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const int kNonTouchLargestIconSize = 192; | 28 const int kNonTouchLargestIconSize = 192; |
| 29 | 29 |
| 30 // Size (along each axis) of a touch icon. This currently corresponds to | 30 // Size (along each axis) of a touch icon. This currently corresponds to |
| 31 // the apple touch icon for iPad. | 31 // the apple touch icon for iPad. |
| 32 const int kTouchIconSize = 144; | 32 const int kTouchIconSize = 144; |
| 33 | 33 |
| 34 // Returns true if all of the icon URLs and icon types in |bitmap_results| are | |
| 35 // identical and if they match |icon_url| and |icon_type|. Returns false if | |
| 36 // |bitmap_results| is empty. | |
| 37 bool DoUrlsAndIconsMatch( | |
| 38 const GURL& icon_url, | |
| 39 favicon_base::IconType icon_type, | |
| 40 const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) { | |
| 41 if (bitmap_results.empty()) | |
| 42 return false; | |
| 43 | |
| 44 for (const auto& bitmap_result : bitmap_results) { | |
| 45 if (icon_url != bitmap_result.icon_url || | |
| 46 icon_type != bitmap_result.icon_type) { | |
| 47 return false; | |
| 48 } | |
| 49 } | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 53 // Return true if |bitmap_result| is expired. | 34 // Return true if |bitmap_result| is expired. |
| 54 bool IsExpired(const favicon_base::FaviconRawBitmapResult& bitmap_result) { | 35 bool IsExpired(const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
| 55 return bitmap_result.expired; | 36 return bitmap_result.expired; |
| 56 } | 37 } |
| 57 | 38 |
| 58 // Return true if |bitmap_result| is valid. | 39 // Return true if |bitmap_result| is valid. |
| 59 bool IsValid(const favicon_base::FaviconRawBitmapResult& bitmap_result) { | 40 bool IsValid(const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
| 60 return bitmap_result.is_valid(); | 41 return bitmap_result.is_valid(); |
| 61 } | 42 } |
| 62 | 43 |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 favicon_bitmap_results) { | 456 favicon_bitmap_results) { |
| 476 got_favicon_from_history_ = true; | 457 got_favicon_from_history_ = true; |
| 477 bool has_valid_result = HasValidResult(favicon_bitmap_results); | 458 bool has_valid_result = HasValidResult(favicon_bitmap_results); |
| 478 initial_history_result_expired_or_incomplete_ = | 459 initial_history_result_expired_or_incomplete_ = |
| 479 !has_valid_result || | 460 !has_valid_result || |
| 480 HasExpiredOrIncompleteResult(preferred_icon_size(), | 461 HasExpiredOrIncompleteResult(preferred_icon_size(), |
| 481 favicon_bitmap_results); | 462 favicon_bitmap_results); |
| 482 redownload_icons_ = initial_history_result_expired_or_incomplete_ && | 463 redownload_icons_ = initial_history_result_expired_or_incomplete_ && |
| 483 !favicon_bitmap_results.empty(); | 464 !favicon_bitmap_results.empty(); |
| 484 | 465 |
| 485 if (has_valid_result && (!current_candidate() || | 466 if (has_valid_result) { |
| 486 DoUrlsAndIconsMatch(current_candidate()->icon_url, | 467 // The db knows the favicon (although it may be out of date). Set the |
| 487 current_candidate()->icon_type, | 468 // favicon now, and if the favicon turns out to be expired (or the wrong |
| 488 favicon_bitmap_results))) { | 469 // url) we'll fetch later on. This way the user doesn't see a flash of the |
| 489 // The db knows the favicon (although it may be out of date) and the entry | 470 // default favicon. |
| 490 // doesn't have an icon. Set the favicon now, and if the favicon turns out | |
| 491 // to be expired (or the wrong url) we'll fetch later on. This way the | |
| 492 // user doesn't see a flash of the default favicon. | |
| 493 NotifyFaviconUpdated(favicon_bitmap_results); | 471 NotifyFaviconUpdated(favicon_bitmap_results); |
| 494 } | 472 } |
| 495 | 473 |
| 496 if (current_candidate()) | 474 if (current_candidate()) |
| 497 OnGotInitialHistoryDataAndIconURLCandidates(); | 475 OnGotInitialHistoryDataAndIconURLCandidates(); |
| 498 } | 476 } |
| 499 | 477 |
| 500 void FaviconHandler::DownloadCurrentCandidateOrAskFaviconService() { | 478 void FaviconHandler::DownloadCurrentCandidateOrAskFaviconService() { |
| 501 GURL icon_url = current_candidate()->icon_url; | 479 GURL icon_url = current_candidate()->icon_url; |
| 502 favicon_base::IconType icon_type = current_candidate()->icon_type; | 480 favicon_base::IconType icon_type = current_candidate()->icon_type; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 // A max bitmap size is specified to avoid receiving huge bitmaps in | 549 // A max bitmap size is specified to avoid receiving huge bitmaps in |
| 572 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 550 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
| 573 // for more details about the max bitmap size. | 551 // for more details about the max bitmap size. |
| 574 const int download_id = | 552 const int download_id = |
| 575 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), | 553 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), |
| 576 image_download_request_.callback()); | 554 image_download_request_.callback()); |
| 577 DCHECK_NE(download_id, 0); | 555 DCHECK_NE(download_id, 0); |
| 578 } | 556 } |
| 579 | 557 |
| 580 } // namespace favicon | 558 } // namespace favicon |
| OLD | NEW |