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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 attempts); | 77 attempts); |
78 return; | 78 return; |
79 case FaviconDriverObserver::TOUCH_LARGEST: | 79 case FaviconDriverObserver::TOUCH_LARGEST: |
80 UMA_HISTOGRAM_SPARSE_SLOWLY("Favicons.DownloadAttempts.TouchIcons", | 80 UMA_HISTOGRAM_SPARSE_SLOWLY("Favicons.DownloadAttempts.TouchIcons", |
81 attempts); | 81 attempts); |
82 return; | 82 return; |
83 } | 83 } |
84 NOTREACHED(); | 84 NOTREACHED(); |
85 } | 85 } |
86 | 86 |
| 87 void RecordDownloadOutcome(FaviconHandler::DownloadOutcome outcome) { |
| 88 UMA_HISTOGRAM_ENUMERATION( |
| 89 "Favicons.DownloadOutcome", outcome, |
| 90 FaviconHandler::DownloadOutcome::DOWNLOAD_OUTCOME_COUNT); |
| 91 } |
| 92 |
87 // Returns true if |bitmap_results| is non-empty and: | 93 // Returns true if |bitmap_results| is non-empty and: |
88 // - At least one of the bitmaps in |bitmap_results| is expired | 94 // - At least one of the bitmaps in |bitmap_results| is expired |
89 // OR | 95 // OR |
90 // - |bitmap_results| is missing favicons for |desired_size_in_dip| and one of | 96 // - |bitmap_results| is missing favicons for |desired_size_in_dip| and one of |
91 // the scale factors in favicon_base::GetFaviconScales(). | 97 // the scale factors in favicon_base::GetFaviconScales(). |
92 bool HasExpiredOrIncompleteResult( | 98 bool HasExpiredOrIncompleteResult( |
93 int desired_size_in_dip, | 99 int desired_size_in_dip, |
94 const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) { | 100 const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) { |
95 if (bitmap_results.empty()) | 101 if (bitmap_results.empty()) |
96 return false; | 102 return false; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 int id, | 383 int id, |
378 int http_status_code, | 384 int http_status_code, |
379 const GURL& image_url, | 385 const GURL& image_url, |
380 const std::vector<SkBitmap>& bitmaps, | 386 const std::vector<SkBitmap>& bitmaps, |
381 const std::vector<gfx::Size>& original_bitmap_sizes) { | 387 const std::vector<gfx::Size>& original_bitmap_sizes) { |
382 // Mark download as finished. | 388 // Mark download as finished. |
383 download_request_.Cancel(); | 389 download_request_.Cancel(); |
384 | 390 |
385 if (bitmaps.empty() && http_status_code == 404) { | 391 if (bitmaps.empty() && http_status_code == 404) { |
386 DVLOG(1) << "Failed to Download Favicon:" << image_url; | 392 DVLOG(1) << "Failed to Download Favicon:" << image_url; |
| 393 RecordDownloadOutcome(DownloadOutcome::FAILED); |
387 service_->UnableToDownloadFavicon(image_url); | 394 service_->UnableToDownloadFavicon(image_url); |
388 } | 395 } |
389 | 396 |
390 bool request_next_icon = true; | 397 bool request_next_icon = true; |
391 if (!bitmaps.empty()) { | 398 if (!bitmaps.empty()) { |
| 399 RecordDownloadOutcome(DownloadOutcome::SUCCEEDED); |
392 float score = 0.0f; | 400 float score = 0.0f; |
393 gfx::ImageSkia image_skia; | 401 gfx::ImageSkia image_skia; |
394 if (download_largest_icon_) { | 402 if (download_largest_icon_) { |
395 std::vector<size_t> best_indices; | 403 std::vector<size_t> best_indices; |
396 SelectFaviconFrameIndices(original_bitmap_sizes, | 404 SelectFaviconFrameIndices(original_bitmap_sizes, |
397 GetDesiredPixelSizes(handler_type_), | 405 GetDesiredPixelSizes(handler_type_), |
398 &best_indices, &score); | 406 &best_indices, &score); |
399 DCHECK_EQ(1U, best_indices.size()); | 407 DCHECK_EQ(1U, best_indices.size()); |
400 image_skia = | 408 image_skia = |
401 gfx::ImageSkia::CreateFrom1xBitmap(bitmaps[best_indices.front()]); | 409 gfx::ImageSkia::CreateFrom1xBitmap(bitmaps[best_indices.front()]); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 } | 558 } |
551 } | 559 } |
552 | 560 |
553 void FaviconHandler::ScheduleDownload(const GURL& image_url, | 561 void FaviconHandler::ScheduleDownload(const GURL& image_url, |
554 favicon_base::IconType icon_type) { | 562 favicon_base::IconType icon_type) { |
555 DCHECK(image_url.is_valid()); | 563 DCHECK(image_url.is_valid()); |
556 // Note that CancelableCallback starts cancelled. | 564 // Note that CancelableCallback starts cancelled. |
557 DCHECK(download_request_.IsCancelled()) << "More than one ongoing download"; | 565 DCHECK(download_request_.IsCancelled()) << "More than one ongoing download"; |
558 if (service_->WasUnableToDownloadFavicon(image_url)) { | 566 if (service_->WasUnableToDownloadFavicon(image_url)) { |
559 DVLOG(1) << "Skip Failed FavIcon: " << image_url; | 567 DVLOG(1) << "Skip Failed FavIcon: " << image_url; |
| 568 RecordDownloadOutcome(DownloadOutcome::SKIPPED); |
560 OnDidDownloadFavicon(icon_type, 0, 0, image_url, std::vector<SkBitmap>(), | 569 OnDidDownloadFavicon(icon_type, 0, 0, image_url, std::vector<SkBitmap>(), |
561 std::vector<gfx::Size>()); | 570 std::vector<gfx::Size>()); |
562 return; | 571 return; |
563 } | 572 } |
564 ++num_download_requests_; | 573 ++num_download_requests_; |
565 download_request_.Reset(base::Bind(&FaviconHandler::OnDidDownloadFavicon, | 574 download_request_.Reset(base::Bind(&FaviconHandler::OnDidDownloadFavicon, |
566 base::Unretained(this), icon_type)); | 575 base::Unretained(this), icon_type)); |
567 // A max bitmap size is specified to avoid receiving huge bitmaps in | 576 // A max bitmap size is specified to avoid receiving huge bitmaps in |
568 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 577 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
569 // for more details about the max bitmap size. | 578 // for more details about the max bitmap size. |
570 const int download_id = | 579 const int download_id = |
571 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), | 580 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), |
572 download_request_.callback()); | 581 download_request_.callback()); |
573 DCHECK_NE(download_id, 0); | 582 DCHECK_NE(download_id, 0); |
574 } | 583 } |
575 | 584 |
576 } // namespace favicon | 585 } // namespace favicon |
OLD | NEW |