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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
15 #include "base/metrics/histogram_macros.h" | |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "components/favicon/core/favicon_service.h" | 17 #include "components/favicon/core/favicon_service.h" |
17 #include "components/favicon_base/favicon_util.h" | 18 #include "components/favicon_base/favicon_util.h" |
18 #include "components/favicon_base/select_favicon_frames.h" | 19 #include "components/favicon_base/select_favicon_frames.h" |
19 #include "skia/ext/image_operations.h" | 20 #include "skia/ext/image_operations.h" |
20 #include "ui/gfx/codec/png_codec.h" | 21 #include "ui/gfx/codec/png_codec.h" |
21 #include "ui/gfx/image/image_skia.h" | 22 #include "ui/gfx/image/image_skia.h" |
22 #include "ui/gfx/image/image_util.h" | 23 #include "ui/gfx/image/image_util.h" |
23 | 24 |
24 namespace favicon { | 25 namespace favicon { |
(...skipping 27 matching lines...) Expand all Loading... | |
52 // Return true if |bitmap_result| is expired. | 53 // Return true if |bitmap_result| is expired. |
53 bool IsExpired(const favicon_base::FaviconRawBitmapResult& bitmap_result) { | 54 bool IsExpired(const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
54 return bitmap_result.expired; | 55 return bitmap_result.expired; |
55 } | 56 } |
56 | 57 |
57 // Return true if |bitmap_result| is valid. | 58 // Return true if |bitmap_result| is valid. |
58 bool IsValid(const favicon_base::FaviconRawBitmapResult& bitmap_result) { | 59 bool IsValid(const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
59 return bitmap_result.is_valid(); | 60 return bitmap_result.is_valid(); |
60 } | 61 } |
61 | 62 |
63 void RecordAttemptsForHandlerType( | |
64 FaviconDriverObserver::NotificationIconType handler_type, | |
65 int attempts) { | |
66 switch (handler_type) { | |
67 case FaviconDriverObserver::NON_TOUCH_16_DIP: | |
68 UMA_HISTOGRAM_COUNTS_100("Favicons.FaviconDownloadAttempts", attempts); | |
69 return; | |
70 case FaviconDriverObserver::NON_TOUCH_LARGEST: | |
71 UMA_HISTOGRAM_COUNTS_100("Favicons.LargeIconDownloadAttempts", attempts); | |
72 return; | |
73 case FaviconDriverObserver::TOUCH_LARGEST: | |
74 UMA_HISTOGRAM_COUNTS_100("Favicons.TouchIconDownloadAttempts", attempts); | |
75 return; | |
76 } | |
77 NOTREACHED(); | |
78 } | |
79 | |
62 // Returns true if |bitmap_results| is non-empty and: | 80 // Returns true if |bitmap_results| is non-empty and: |
63 // - At least one of the bitmaps in |bitmap_results| is expired | 81 // - At least one of the bitmaps in |bitmap_results| is expired |
64 // OR | 82 // OR |
65 // - |bitmap_results| is missing favicons for |desired_size_in_dip| and one of | 83 // - |bitmap_results| is missing favicons for |desired_size_in_dip| and one of |
66 // the scale factors in favicon_base::GetFaviconScales(). | 84 // the scale factors in favicon_base::GetFaviconScales(). |
67 bool HasExpiredOrIncompleteResult( | 85 bool HasExpiredOrIncompleteResult( |
68 int desired_size_in_dip, | 86 int desired_size_in_dip, |
69 const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) { | 87 const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) { |
70 if (bitmap_results.empty()) | 88 if (bitmap_results.empty()) |
71 return false; | 89 return false; |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 downloaded_favicon.candidate.score = score; | 410 downloaded_favicon.candidate.score = score; |
393 request_next_icon = !UpdateFaviconCandidate(downloaded_favicon); | 411 request_next_icon = !UpdateFaviconCandidate(downloaded_favicon); |
394 } | 412 } |
395 } | 413 } |
396 | 414 |
397 if (request_next_icon && current_candidate_index_ + 1 < candidates_.size()) { | 415 if (request_next_icon && current_candidate_index_ + 1 < candidates_.size()) { |
398 // Process the next candidate. | 416 // Process the next candidate. |
399 ++current_candidate_index_; | 417 ++current_candidate_index_; |
400 DownloadCurrentCandidateOrAskFaviconService(); | 418 DownloadCurrentCandidateOrAskFaviconService(); |
401 } else { | 419 } else { |
420 RecordAttemptsForHandlerType(handler_type_, current_candidate_index_ + 1); | |
402 // We have either found the ideal candidate or run out of candidates. | 421 // We have either found the ideal candidate or run out of candidates. |
403 if (best_favicon_.candidate.icon_type != favicon_base::INVALID_ICON) { | 422 if (best_favicon_.candidate.icon_type != favicon_base::INVALID_ICON) { |
404 // No more icons to request, set the favicon from the candidate. | 423 // No more icons to request, set the favicon from the candidate. |
405 SetFavicon(best_favicon_.candidate.icon_url, best_favicon_.image, | 424 SetFavicon(best_favicon_.candidate.icon_url, best_favicon_.image, |
406 best_favicon_.candidate.icon_type); | 425 best_favicon_.candidate.icon_type); |
407 } | 426 } |
408 // Clear download related state. | 427 // Clear download related state. |
409 current_candidate_index_ = candidates_.size(); | 428 current_candidate_index_ = candidates_.size(); |
410 best_favicon_ = DownloadedFavicon(); | 429 best_favicon_ = DownloadedFavicon(); |
411 } | 430 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 bool has_valid_result = HasValidResult(favicon_bitmap_results); | 515 bool has_valid_result = HasValidResult(favicon_bitmap_results); |
497 bool has_expired_or_incomplete_result = | 516 bool has_expired_or_incomplete_result = |
498 !has_valid_result || HasExpiredOrIncompleteResult(preferred_icon_size(), | 517 !has_valid_result || HasExpiredOrIncompleteResult(preferred_icon_size(), |
499 favicon_bitmap_results); | 518 favicon_bitmap_results); |
500 | 519 |
501 if (has_valid_result) { | 520 if (has_valid_result) { |
502 // There is a valid favicon. Notify any observers. It is useful to notify | 521 // There is a valid favicon. Notify any observers. It is useful to notify |
503 // the observers even if the favicon is expired or incomplete (incorrect | 522 // the observers even if the favicon is expired or incomplete (incorrect |
504 // size) because temporarily showing the user an expired favicon or | 523 // size) because temporarily showing the user an expired favicon or |
505 // streched favicon is preferable to showing the user the default favicon. | 524 // streched favicon is preferable to showing the user the default favicon. |
525 RecordAttemptsForHandlerType(handler_type_, current_candidate_index_); | |
pkotwicz
2017/04/10 14:58:11
Why are we recording Favicons.FaviconDownloadAttem
fhorschig
2017/04/10 15:05:21
Because TestRecordDownloadAttemptsFinishedByCache
pkotwicz
2017/04/10 17:26:10
Sorry for the confusion earlier. I think that we n
fhorschig
2017/04/11 12:07:20
I agree, It's more explicit and future-proof in we
| |
506 NotifyFaviconUpdated(favicon_bitmap_results); | 526 NotifyFaviconUpdated(favicon_bitmap_results); |
507 } | 527 } |
508 | 528 |
509 if (!current_candidate() || | 529 if (!current_candidate() || |
510 (has_results && !DoUrlsAndIconsMatch(current_candidate()->icon_url, | 530 (has_results && !DoUrlsAndIconsMatch(current_candidate()->icon_url, |
511 current_candidate()->icon_type, | 531 current_candidate()->icon_type, |
512 favicon_bitmap_results))) { | 532 favicon_bitmap_results))) { |
513 // The icon URLs have been updated since the favicon data was requested. | 533 // The icon URLs have been updated since the favicon data was requested. |
514 return; | 534 return; |
515 } | 535 } |
(...skipping 20 matching lines...) Expand all Loading... | |
536 // A max bitmap size is specified to avoid receiving huge bitmaps in | 556 // A max bitmap size is specified to avoid receiving huge bitmaps in |
537 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 557 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
538 // for more details about the max bitmap size. | 558 // for more details about the max bitmap size. |
539 const int download_id = | 559 const int download_id = |
540 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), | 560 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), |
541 download_request_.callback()); | 561 download_request_.callback()); |
542 DCHECK_NE(download_id, 0); | 562 DCHECK_NE(download_id, 0); |
543 } | 563 } |
544 | 564 |
545 } // namespace favicon | 565 } // namespace favicon |
OLD | NEW |