Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: components/favicon/core/favicon_handler.cc

Issue 2781093002: Add attempt count metric to FaviconHandler (Closed)
Patch Set: Verify expired results are recorded exactly once. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 RecordDownloadAttemptsForHandlerType(
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.DownloadAttempts.Favicons", attempts);
69 return;
Ilya Sherman 2017/04/12 20:43:03 How many download attempts do you expect to see, t
fhorschig 2017/04/13 14:49:35 It should indeed be << 10.
70 case FaviconDriverObserver::NON_TOUCH_LARGEST:
71 UMA_HISTOGRAM_COUNTS_100("Favicons.DownloadAttempts.LargeIcons",
72 attempts);
73 return;
74 case FaviconDriverObserver::TOUCH_LARGEST:
75 UMA_HISTOGRAM_COUNTS_100("Favicons.DownloadAttempts.TouchIcons",
76 attempts);
77 return;
78 }
79 NOTREACHED();
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
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 num_download_requests_(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 12 matching lines...) Expand all
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();
200 notification_icon_url_ = GURL(); 221 notification_icon_url_ = GURL();
201 notification_icon_type_ = favicon_base::INVALID_ICON; 222 notification_icon_type_ = favicon_base::INVALID_ICON;
223 num_download_requests_ = 0;
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(
210 url_, icon_types_, preferred_icon_size(), 232 url_, icon_types_, preferred_icon_size(),
211 base::Bind( 233 base::Bind(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 num_download_requests_ = 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
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 // OnDidDownloadFavicon() can only be called after requesting a download, so
426 // |num_download_requests_| can never be 0.
427 RecordDownloadAttemptsForHandlerType(handler_type_, num_download_requests_);
402 // We have either found the ideal candidate or run out of candidates. 428 // We have either found the ideal candidate or run out of candidates.
403 if (best_favicon_.candidate.icon_type != favicon_base::INVALID_ICON) { 429 if (best_favicon_.candidate.icon_type != favicon_base::INVALID_ICON) {
404 // No more icons to request, set the favicon from the candidate. 430 // No more icons to request, set the favicon from the candidate.
405 SetFavicon(best_favicon_.candidate.icon_url, best_favicon_.image, 431 SetFavicon(best_favicon_.candidate.icon_url, best_favicon_.image,
406 best_favicon_.candidate.icon_type); 432 best_favicon_.candidate.icon_type);
407 } 433 }
408 // Clear download related state. 434 // Clear download related state.
409 current_candidate_index_ = candidates_.size(); 435 current_candidate_index_ = candidates_.size();
436 num_download_requests_ = 0;
410 best_favicon_ = DownloadedFavicon(); 437 best_favicon_ = DownloadedFavicon();
411 } 438 }
412 } 439 }
413 440
414 const std::vector<GURL> FaviconHandler::GetIconURLs() const { 441 const std::vector<GURL> FaviconHandler::GetIconURLs() const {
415 std::vector<GURL> icon_urls; 442 std::vector<GURL> icon_urls;
416 for (const FaviconCandidate& candidate : candidates_) 443 for (const FaviconCandidate& candidate : candidates_)
417 icon_urls.push_back(candidate.icon_url); 444 icon_urls.push_back(candidate.icon_url);
418 return icon_urls; 445 return icon_urls;
419 } 446 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 (has_results && !DoUrlsAndIconsMatch(current_candidate()->icon_url, 537 (has_results && !DoUrlsAndIconsMatch(current_candidate()->icon_url,
511 current_candidate()->icon_type, 538 current_candidate()->icon_type,
512 favicon_bitmap_results))) { 539 favicon_bitmap_results))) {
513 // The icon URLs have been updated since the favicon data was requested. 540 // The icon URLs have been updated since the favicon data was requested.
514 return; 541 return;
515 } 542 }
516 543
517 if (has_expired_or_incomplete_result) { 544 if (has_expired_or_incomplete_result) {
518 ScheduleDownload(current_candidate()->icon_url, 545 ScheduleDownload(current_candidate()->icon_url,
519 current_candidate()->icon_type); 546 current_candidate()->icon_type);
547 } else if (num_download_requests_ > 0) {
548 RecordDownloadAttemptsForHandlerType(handler_type_, num_download_requests_);
520 } 549 }
521 } 550 }
522 551
523 void FaviconHandler::ScheduleDownload(const GURL& image_url, 552 void FaviconHandler::ScheduleDownload(const GURL& image_url,
524 favicon_base::IconType icon_type) { 553 favicon_base::IconType icon_type) {
525 DCHECK(image_url.is_valid()); 554 DCHECK(image_url.is_valid());
526 // Note that CancelableCallback starts cancelled. 555 // Note that CancelableCallback starts cancelled.
527 DCHECK(download_request_.IsCancelled()) << "More than one ongoing download"; 556 DCHECK(download_request_.IsCancelled()) << "More than one ongoing download";
528 if (service_ && service_->WasUnableToDownloadFavicon(image_url)) { 557 if (service_ && service_->WasUnableToDownloadFavicon(image_url)) {
529 DVLOG(1) << "Skip Failed FavIcon: " << image_url; 558 DVLOG(1) << "Skip Failed FavIcon: " << image_url;
530 OnDidDownloadFavicon(icon_type, 0, 0, image_url, std::vector<SkBitmap>(), 559 OnDidDownloadFavicon(icon_type, 0, 0, image_url, std::vector<SkBitmap>(),
531 std::vector<gfx::Size>()); 560 std::vector<gfx::Size>());
532 return; 561 return;
533 } 562 }
563 ++num_download_requests_;
534 download_request_.Reset(base::Bind(&FaviconHandler::OnDidDownloadFavicon, 564 download_request_.Reset(base::Bind(&FaviconHandler::OnDidDownloadFavicon,
535 base::Unretained(this), icon_type)); 565 base::Unretained(this), icon_type));
536 // A max bitmap size is specified to avoid receiving huge bitmaps in 566 // A max bitmap size is specified to avoid receiving huge bitmaps in
537 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() 567 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload()
538 // for more details about the max bitmap size. 568 // for more details about the max bitmap size.
539 const int download_id = 569 const int download_id =
540 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), 570 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_),
541 download_request_.callback()); 571 download_request_.callback());
542 DCHECK_NE(download_id, 0); 572 DCHECK_NE(download_id, 0);
543 } 573 }
544 574
545 } // namespace favicon 575 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698