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 // The name of the histogram must not be a variable. | |
67 switch (handler_type) { | |
68 case FaviconDriverObserver::NON_TOUCH_16_DIP: | |
69 UMA_HISTOGRAM_COUNTS_100("Favicons.FaviconDownloadAttempts", attempts); | |
70 return; | |
71 case FaviconDriverObserver::NON_TOUCH_LARGEST: | |
72 UMA_HISTOGRAM_COUNTS_100("Favicons.LargeIconDownloadAttempts", attempts); | |
73 return; | |
74 case FaviconDriverObserver::TOUCH_LARGEST: | |
75 UMA_HISTOGRAM_COUNTS_100("Favicons.TouchIconDownloadAttempts", attempts); | |
76 return; | |
pkotwicz
2017/04/04 13:04:37
Can we use the same histogram for Favicons.LargeIc
fhorschig
2017/04/10 09:55:50
Done.
fhorschig
2017/04/10 13:59:41
I was informed that we might have a large delay on
| |
77 } | |
78 NOTREACHED(); | |
79 return; | |
pkotwicz
2017/04/04 13:04:37
Nit: The return here is redundant
fhorschig
2017/04/10 09:55:50
Gone.
| |
80 } | |
81 | |
62 // Returns true if |bitmap_results| is non-empty and: | 82 // Returns true if |bitmap_results| is non-empty and: |
63 // - At least one of the bitmaps in |bitmap_results| is expired | 83 // - At least one of the bitmaps in |bitmap_results| is expired |
64 // OR | 84 // OR |
65 // - |bitmap_results| is missing favicons for |desired_size_in_dip| and one of | 85 // - |bitmap_results| is missing favicons for |desired_size_in_dip| and one of |
66 // the scale factors in favicon_base::GetFaviconScales(). | 86 // the scale factors in favicon_base::GetFaviconScales(). |
67 bool HasExpiredOrIncompleteResult( | 87 bool HasExpiredOrIncompleteResult( |
68 int desired_size_in_dip, | 88 int desired_size_in_dip, |
69 const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) { | 89 const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) { |
70 if (bitmap_results.empty()) | 90 if (bitmap_results.empty()) |
71 return false; | 91 return false; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 got_favicon_from_history_(false), | 180 got_favicon_from_history_(false), |
161 initial_history_result_expired_or_incomplete_(false), | 181 initial_history_result_expired_or_incomplete_(false), |
162 redownload_icons_(false), | 182 redownload_icons_(false), |
163 icon_types_(FaviconHandler::GetIconTypesFromHandlerType(handler_type)), | 183 icon_types_(FaviconHandler::GetIconTypesFromHandlerType(handler_type)), |
164 download_largest_icon_( | 184 download_largest_icon_( |
165 handler_type == FaviconDriverObserver::NON_TOUCH_LARGEST || | 185 handler_type == FaviconDriverObserver::NON_TOUCH_LARGEST || |
166 handler_type == FaviconDriverObserver::TOUCH_LARGEST), | 186 handler_type == FaviconDriverObserver::TOUCH_LARGEST), |
167 notification_icon_type_(favicon_base::INVALID_ICON), | 187 notification_icon_type_(favicon_base::INVALID_ICON), |
168 service_(service), | 188 service_(service), |
169 delegate_(delegate), | 189 delegate_(delegate), |
190 request_attempts_(0), | |
170 current_candidate_index_(0u) { | 191 current_candidate_index_(0u) { |
171 DCHECK(delegate_); | 192 DCHECK(delegate_); |
172 } | 193 } |
173 | 194 |
174 FaviconHandler::~FaviconHandler() { | 195 FaviconHandler::~FaviconHandler() { |
175 } | 196 } |
176 | 197 |
177 // static | 198 // static |
178 int FaviconHandler::GetIconTypesFromHandlerType( | 199 int FaviconHandler::GetIconTypesFromHandlerType( |
179 FaviconDriverObserver::NotificationIconType handler_type) { | 200 FaviconDriverObserver::NotificationIconType handler_type) { |
(...skipping 10 matching lines...) Expand all Loading... | |
190 void FaviconHandler::FetchFavicon(const GURL& url) { | 211 void FaviconHandler::FetchFavicon(const GURL& url) { |
191 cancelable_task_tracker_.TryCancelAll(); | 212 cancelable_task_tracker_.TryCancelAll(); |
192 | 213 |
193 url_ = url; | 214 url_ = url; |
194 | 215 |
195 initial_history_result_expired_or_incomplete_ = false; | 216 initial_history_result_expired_or_incomplete_ = false; |
196 redownload_icons_ = false; | 217 redownload_icons_ = false; |
197 got_favicon_from_history_ = false; | 218 got_favicon_from_history_ = false; |
198 download_request_.Cancel(); | 219 download_request_.Cancel(); |
199 candidates_.clear(); | 220 candidates_.clear(); |
221 request_attempts_ = 0; | |
200 notification_icon_url_ = GURL(); | 222 notification_icon_url_ = GURL(); |
201 notification_icon_type_ = favicon_base::INVALID_ICON; | 223 notification_icon_type_ = favicon_base::INVALID_ICON; |
202 current_candidate_index_ = 0u; | 224 current_candidate_index_ = 0u; |
203 best_favicon_ = DownloadedFavicon(); | 225 best_favicon_ = DownloadedFavicon(); |
204 | 226 |
205 // Request the favicon from the history service. In parallel to this the | 227 // Request the favicon from the history service. In parallel to this the |
206 // renderer is going to notify us (well WebContents) when the favicon url is | 228 // renderer is going to notify us (well WebContents) when the favicon url is |
207 // available. | 229 // available. |
208 if (service_) { | 230 if (service_) { |
209 service_->GetFaviconForPageURL( | 231 service_->GetFaviconForPageURL( |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 &FaviconCandidate::CompareScore); | 326 &FaviconCandidate::CompareScore); |
305 | 327 |
306 if (candidates_.size() == sorted_candidates.size() && | 328 if (candidates_.size() == sorted_candidates.size() && |
307 std::equal(sorted_candidates.begin(), sorted_candidates.end(), | 329 std::equal(sorted_candidates.begin(), sorted_candidates.end(), |
308 candidates_.begin())) { | 330 candidates_.begin())) { |
309 return; | 331 return; |
310 } | 332 } |
311 | 333 |
312 download_request_.Cancel(); | 334 download_request_.Cancel(); |
313 candidates_ = std::move(sorted_candidates); | 335 candidates_ = std::move(sorted_candidates); |
336 request_attempts_ = 0; | |
314 current_candidate_index_ = 0u; | 337 current_candidate_index_ = 0u; |
315 best_favicon_ = DownloadedFavicon(); | 338 best_favicon_ = DownloadedFavicon(); |
316 | 339 |
317 // TODO(davemoore) Should clear on empty url. Currently we ignore it. | 340 // TODO(davemoore) Should clear on empty url. Currently we ignore it. |
318 // This appears to be what FF does as well. | 341 // This appears to be what FF does as well. |
319 if (current_candidate() && got_favicon_from_history_) | 342 if (current_candidate() && got_favicon_from_history_) |
320 OnGotInitialHistoryDataAndIconURLCandidates(); | 343 OnGotInitialHistoryDataAndIconURLCandidates(); |
321 } | 344 } |
322 | 345 |
323 // static | 346 // static |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 downloaded_favicon.candidate.score = score; | 415 downloaded_favicon.candidate.score = score; |
393 request_next_icon = !UpdateFaviconCandidate(downloaded_favicon); | 416 request_next_icon = !UpdateFaviconCandidate(downloaded_favicon); |
394 } | 417 } |
395 } | 418 } |
396 | 419 |
397 if (request_next_icon && current_candidate_index_ + 1 < candidates_.size()) { | 420 if (request_next_icon && current_candidate_index_ + 1 < candidates_.size()) { |
398 // Process the next candidate. | 421 // Process the next candidate. |
399 ++current_candidate_index_; | 422 ++current_candidate_index_; |
400 DownloadCurrentCandidateOrAskFaviconService(); | 423 DownloadCurrentCandidateOrAskFaviconService(); |
401 } else { | 424 } else { |
425 RecordAttemptsForHandlerType(handler_type_, request_attempts_); | |
pkotwicz
2017/04/04 13:04:38
Can you store |current_candidate_index_ + 1| inste
fhorschig
2017/04/10 09:55:50
Done. This captures 404s as attempts as well.
| |
402 // We have either found the ideal candidate or run out of candidates. | 426 // We have either found the ideal candidate or run out of candidates. |
403 if (best_favicon_.candidate.icon_type != favicon_base::INVALID_ICON) { | 427 if (best_favicon_.candidate.icon_type != favicon_base::INVALID_ICON) { |
404 // No more icons to request, set the favicon from the candidate. | 428 // No more icons to request, set the favicon from the candidate. |
405 SetFavicon(best_favicon_.candidate.icon_url, best_favicon_.image, | 429 SetFavicon(best_favicon_.candidate.icon_url, best_favicon_.image, |
406 best_favicon_.candidate.icon_type); | 430 best_favicon_.candidate.icon_type); |
407 } | 431 } |
408 // Clear download related state. | 432 // Clear download related state. |
409 current_candidate_index_ = candidates_.size(); | 433 current_candidate_index_ = candidates_.size(); |
434 request_attempts_ = 0; | |
410 best_favicon_ = DownloadedFavicon(); | 435 best_favicon_ = DownloadedFavicon(); |
411 } | 436 } |
412 } | 437 } |
413 | 438 |
414 const std::vector<GURL> FaviconHandler::GetIconURLs() const { | 439 const std::vector<GURL> FaviconHandler::GetIconURLs() const { |
415 std::vector<GURL> icon_urls; | 440 std::vector<GURL> icon_urls; |
416 for (const FaviconCandidate& candidate : candidates_) | 441 for (const FaviconCandidate& candidate : candidates_) |
417 icon_urls.push_back(candidate.icon_url); | 442 icon_urls.push_back(candidate.icon_url); |
418 return icon_urls; | 443 return icon_urls; |
419 } | 444 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 // Note that CancelableCallback starts cancelled. | 551 // Note that CancelableCallback starts cancelled. |
527 DCHECK(download_request_.IsCancelled()) << "More than one ongoing download"; | 552 DCHECK(download_request_.IsCancelled()) << "More than one ongoing download"; |
528 if (service_ && service_->WasUnableToDownloadFavicon(image_url)) { | 553 if (service_ && service_->WasUnableToDownloadFavicon(image_url)) { |
529 DVLOG(1) << "Skip Failed FavIcon: " << image_url; | 554 DVLOG(1) << "Skip Failed FavIcon: " << image_url; |
530 OnDidDownloadFavicon(icon_type, 0, 0, image_url, std::vector<SkBitmap>(), | 555 OnDidDownloadFavicon(icon_type, 0, 0, image_url, std::vector<SkBitmap>(), |
531 std::vector<gfx::Size>()); | 556 std::vector<gfx::Size>()); |
532 return; | 557 return; |
533 } | 558 } |
534 download_request_.Reset(base::Bind(&FaviconHandler::OnDidDownloadFavicon, | 559 download_request_.Reset(base::Bind(&FaviconHandler::OnDidDownloadFavicon, |
535 base::Unretained(this), icon_type)); | 560 base::Unretained(this), icon_type)); |
561 ++request_attempts_; | |
536 // A max bitmap size is specified to avoid receiving huge bitmaps in | 562 // A max bitmap size is specified to avoid receiving huge bitmaps in |
537 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 563 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
538 // for more details about the max bitmap size. | 564 // for more details about the max bitmap size. |
539 const int download_id = | 565 const int download_id = |
540 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), | 566 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), |
541 download_request_.callback()); | 567 download_request_.callback()); |
542 DCHECK_NE(download_id, 0); | 568 DCHECK_NE(download_id, 0); |
543 } | 569 } |
544 | 570 |
545 } // namespace favicon | 571 } // namespace favicon |
OLD | NEW |