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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
14 #include "base/metrics/histogram_macros.h" | |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "components/favicon/core/favicon_service.h" | 16 #include "components/favicon/core/favicon_service.h" |
16 #include "components/favicon_base/favicon_util.h" | 17 #include "components/favicon_base/favicon_util.h" |
17 #include "components/favicon_base/select_favicon_frames.h" | 18 #include "components/favicon_base/select_favicon_frames.h" |
18 #include "skia/ext/image_operations.h" | 19 #include "skia/ext/image_operations.h" |
19 #include "ui/gfx/codec/png_codec.h" | 20 #include "ui/gfx/codec/png_codec.h" |
20 #include "ui/gfx/image/image_skia.h" | 21 #include "ui/gfx/image/image_skia.h" |
21 #include "ui/gfx/image/image_util.h" | 22 #include "ui/gfx/image/image_util.h" |
22 | 23 |
23 namespace favicon { | 24 namespace favicon { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 got_favicon_from_history_(false), | 203 got_favicon_from_history_(false), |
203 initial_history_result_expired_or_incomplete_(false), | 204 initial_history_result_expired_or_incomplete_(false), |
204 redownload_icons_(false), | 205 redownload_icons_(false), |
205 icon_types_(FaviconHandler::GetIconTypesFromHandlerType(handler_type)), | 206 icon_types_(FaviconHandler::GetIconTypesFromHandlerType(handler_type)), |
206 download_largest_icon_( | 207 download_largest_icon_( |
207 handler_type == FaviconDriverObserver::NON_TOUCH_LARGEST || | 208 handler_type == FaviconDriverObserver::NON_TOUCH_LARGEST || |
208 handler_type == FaviconDriverObserver::TOUCH_LARGEST), | 209 handler_type == FaviconDriverObserver::TOUCH_LARGEST), |
209 notification_icon_type_(favicon_base::INVALID_ICON), | 210 notification_icon_type_(favicon_base::INVALID_ICON), |
210 service_(service), | 211 service_(service), |
211 delegate_(delegate), | 212 delegate_(delegate), |
213 request_attempts_(0), | |
212 current_candidate_index_(0u) { | 214 current_candidate_index_(0u) { |
213 DCHECK(delegate_); | 215 DCHECK(delegate_); |
214 } | 216 } |
215 | 217 |
216 FaviconHandler::~FaviconHandler() { | 218 FaviconHandler::~FaviconHandler() { |
217 } | 219 } |
218 | 220 |
219 // static | 221 // static |
220 int FaviconHandler::GetIconTypesFromHandlerType( | 222 int FaviconHandler::GetIconTypesFromHandlerType( |
221 FaviconDriverObserver::NotificationIconType handler_type) { | 223 FaviconDriverObserver::NotificationIconType handler_type) { |
222 switch (handler_type) { | 224 switch (handler_type) { |
223 case FaviconDriverObserver::NON_TOUCH_16_DIP: | 225 case FaviconDriverObserver::NON_TOUCH_16_DIP: |
224 case FaviconDriverObserver::NON_TOUCH_LARGEST: | 226 case FaviconDriverObserver::NON_TOUCH_LARGEST: |
225 return favicon_base::FAVICON; | 227 return favicon_base::FAVICON; |
226 case FaviconDriverObserver::TOUCH_LARGEST: | 228 case FaviconDriverObserver::TOUCH_LARGEST: |
227 return favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON; | 229 return favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON; |
228 } | 230 } |
229 return 0; | 231 return 0; |
230 } | 232 } |
231 | 233 |
232 void FaviconHandler::FetchFavicon(const GURL& url) { | 234 void FaviconHandler::FetchFavicon(const GURL& url) { |
233 cancelable_task_tracker_.TryCancelAll(); | 235 cancelable_task_tracker_.TryCancelAll(); |
234 | 236 |
235 url_ = url; | 237 url_ = url; |
236 | 238 |
237 initial_history_result_expired_or_incomplete_ = false; | 239 initial_history_result_expired_or_incomplete_ = false; |
238 redownload_icons_ = false; | 240 redownload_icons_ = false; |
239 got_favicon_from_history_ = false; | 241 got_favicon_from_history_ = false; |
240 download_request_.Cancel(); | 242 download_request_.Cancel(); |
243 request_attempts_ = 0; | |
241 image_urls_.clear(); | 244 image_urls_.clear(); |
242 notification_icon_url_ = GURL(); | 245 notification_icon_url_ = GURL(); |
243 notification_icon_type_ = favicon_base::INVALID_ICON; | 246 notification_icon_type_ = favicon_base::INVALID_ICON; |
244 current_candidate_index_ = 0u; | 247 current_candidate_index_ = 0u; |
245 best_favicon_candidate_ = FaviconCandidate(); | 248 best_favicon_candidate_ = FaviconCandidate(); |
246 | 249 |
247 // Request the favicon from the history service. In parallel to this the | 250 // Request the favicon from the history service. In parallel to this the |
248 // renderer is going to notify us (well WebContents) when the favicon url is | 251 // renderer is going to notify us (well WebContents) when the favicon url is |
249 // available. | 252 // available. |
250 if (service_) { | 253 if (service_) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 | 368 |
366 // Ignore FaviconURL::icon_sizes because FaviconURL::icon_sizes is not stored | 369 // Ignore FaviconURL::icon_sizes because FaviconURL::icon_sizes is not stored |
367 // in the history database. | 370 // in the history database. |
368 if (image_urls_.size() == pruned_candidates.size() && | 371 if (image_urls_.size() == pruned_candidates.size() && |
369 std::equal(pruned_candidates.begin(), pruned_candidates.end(), | 372 std::equal(pruned_candidates.begin(), pruned_candidates.end(), |
370 image_urls_.begin(), FaviconURLsEqualIgnoringSizes)) { | 373 image_urls_.begin(), FaviconURLsEqualIgnoringSizes)) { |
371 return; | 374 return; |
372 } | 375 } |
373 | 376 |
374 download_request_.Cancel(); | 377 download_request_.Cancel(); |
378 request_attempts_ = 0; | |
375 image_urls_ = pruned_candidates; | 379 image_urls_ = pruned_candidates; |
376 current_candidate_index_ = 0u; | 380 current_candidate_index_ = 0u; |
377 best_favicon_candidate_ = FaviconCandidate(); | 381 best_favicon_candidate_ = FaviconCandidate(); |
378 | 382 |
379 // TODO(davemoore) Should clear on empty url. Currently we ignore it. | 383 // TODO(davemoore) Should clear on empty url. Currently we ignore it. |
380 // This appears to be what FF does as well. | 384 // This appears to be what FF does as well. |
381 if (current_candidate() && got_favicon_from_history_) | 385 if (current_candidate() && got_favicon_from_history_) |
382 OnGotInitialHistoryDataAndIconURLCandidates(); | 386 OnGotInitialHistoryDataAndIconURLCandidates(); |
383 } | 387 } |
384 | 388 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 !UpdateFaviconCandidate(image_url, image, score, icon_type); | 470 !UpdateFaviconCandidate(image_url, image, score, icon_type); |
467 } | 471 } |
468 } | 472 } |
469 | 473 |
470 if (request_next_icon && current_candidate_index_ + 1 < image_urls_.size()) { | 474 if (request_next_icon && current_candidate_index_ + 1 < image_urls_.size()) { |
471 // Process the next candidate. | 475 // Process the next candidate. |
472 ++current_candidate_index_; | 476 ++current_candidate_index_; |
473 DownloadCurrentCandidateOrAskFaviconService(); | 477 DownloadCurrentCandidateOrAskFaviconService(); |
474 } else { | 478 } else { |
475 // We have either found the ideal candidate or run out of candidates. | 479 // We have either found the ideal candidate or run out of candidates. |
480 if (handler_type_ == FaviconDriverObserver::TOUCH_LARGEST) { | |
481 UMA_HISTOGRAM_COUNTS_100("Favicons.LargeIconDownloadAttempts", | |
jkrcal
2017/03/30 07:53:28
Can we actually have three histogram per each Favi
fhorschig
2017/04/03 09:56:49
I added a third historgram but it's slightly diffe
| |
482 request_attempts_); | |
483 } else { | |
484 UMA_HISTOGRAM_COUNTS_100("Favicons.DownloadAttempts", request_attempts_); | |
485 } | |
476 if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) { | 486 if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) { |
477 // No more icons to request, set the favicon from the candidate. | 487 // No more icons to request, set the favicon from the candidate. |
478 SetFavicon(best_favicon_candidate_.image_url, | 488 SetFavicon(best_favicon_candidate_.image_url, |
479 best_favicon_candidate_.image, | 489 best_favicon_candidate_.image, |
480 best_favicon_candidate_.icon_type); | 490 best_favicon_candidate_.icon_type); |
481 } | 491 } |
482 // Clear download related state. | 492 // Clear download related state. |
483 current_candidate_index_ = image_urls_.size(); | 493 current_candidate_index_ = image_urls_.size(); |
494 request_attempts_ = 0; | |
484 best_favicon_candidate_ = FaviconCandidate(); | 495 best_favicon_candidate_ = FaviconCandidate(); |
485 } | 496 } |
486 } | 497 } |
487 | 498 |
488 bool FaviconHandler::HasPendingTasksForTest() { | 499 bool FaviconHandler::HasPendingTasksForTest() { |
489 return !download_request_.IsCancelled() || | 500 return !download_request_.IsCancelled() || |
490 cancelable_task_tracker_.HasTrackedTasks(); | 501 cancelable_task_tracker_.HasTrackedTasks(); |
491 } | 502 } |
492 | 503 |
493 bool FaviconHandler::ShouldSaveFavicon() { | 504 bool FaviconHandler::ShouldSaveFavicon() { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 // Note that CancelableCallback starts cancelled. | 602 // Note that CancelableCallback starts cancelled. |
592 DCHECK(download_request_.IsCancelled()) << "More than one ongoing download"; | 603 DCHECK(download_request_.IsCancelled()) << "More than one ongoing download"; |
593 if (service_ && service_->WasUnableToDownloadFavicon(image_url)) { | 604 if (service_ && service_->WasUnableToDownloadFavicon(image_url)) { |
594 DVLOG(1) << "Skip Failed FavIcon: " << image_url; | 605 DVLOG(1) << "Skip Failed FavIcon: " << image_url; |
595 OnDidDownloadFavicon(icon_type, 0, 0, image_url, std::vector<SkBitmap>(), | 606 OnDidDownloadFavicon(icon_type, 0, 0, image_url, std::vector<SkBitmap>(), |
596 std::vector<gfx::Size>()); | 607 std::vector<gfx::Size>()); |
597 return; | 608 return; |
598 } | 609 } |
599 download_request_.Reset(base::Bind(&FaviconHandler::OnDidDownloadFavicon, | 610 download_request_.Reset(base::Bind(&FaviconHandler::OnDidDownloadFavicon, |
600 base::Unretained(this), icon_type)); | 611 base::Unretained(this), icon_type)); |
612 ++request_attempts_; | |
601 // A max bitmap size is specified to avoid receiving huge bitmaps in | 613 // A max bitmap size is specified to avoid receiving huge bitmaps in |
602 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 614 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
603 // for more details about the max bitmap size. | 615 // for more details about the max bitmap size. |
604 const int download_id = delegate_->DownloadImage( | 616 const int download_id = delegate_->DownloadImage( |
605 image_url, GetMaximalIconSize(icon_type), download_request_.callback()); | 617 image_url, GetMaximalIconSize(icon_type), download_request_.callback()); |
606 DCHECK_NE(download_id, 0); | 618 DCHECK_NE(download_id, 0); |
607 } | 619 } |
608 | 620 |
609 } // namespace favicon | 621 } // namespace favicon |
OLD | NEW |