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

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

Issue 1119163003: Save large icons to a new LARGE_ICON type Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: yet more clarifying comments Created 5 years, 7 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 <vector> 9 #include <vector>
10 10
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 FaviconHandler::~FaviconHandler() { 219 FaviconHandler::~FaviconHandler() {
220 } 220 }
221 221
222 // static 222 // static
223 int FaviconHandler::GetIconTypesFromHandlerType( 223 int FaviconHandler::GetIconTypesFromHandlerType(
224 FaviconHandler::Type handler_type) { 224 FaviconHandler::Type handler_type) {
225 switch (handler_type) { 225 switch (handler_type) {
226 case FAVICON: 226 case FAVICON:
227 return favicon_base::FAVICON; 227 return favicon_base::FAVICON;
228 case TOUCH: // Falls through. 228 case TOUCH:
229 return favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON;
229 case LARGE: 230 case LARGE:
230 return favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON; 231 return favicon_base::FAVICON | favicon_base::TOUCH_ICON |
sky 2015/05/06 19:50:42 Why do we need FAVICON here too? If you use FAVICO
Roger McFarlane (Chromium) 2015/05/06 21:22:51 Yes and no. Attempts to get the existing FAVICON
232 favicon_base::TOUCH_PRECOMPOSED_ICON;
231 default: 233 default:
232 NOTREACHED(); 234 NOTREACHED();
233 } 235 }
234 return 0; 236 return 0;
235 } 237 }
236 238
237 void FaviconHandler::FetchFavicon(const GURL& url) { 239 void FaviconHandler::FetchFavicon(const GURL& url) {
238 cancelable_task_tracker_.TryCancelAll(); 240 cancelable_task_tracker_.TryCancelAll();
239 241
240 url_ = url; 242 url_ = url;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 353
352 // TODO(davemoore) Should clear on empty url. Currently we ignore it. 354 // TODO(davemoore) Should clear on empty url. Currently we ignore it.
353 // This appears to be what FF does as well. 355 // This appears to be what FF does as well.
354 if (!image_urls_.empty()) 356 if (!image_urls_.empty())
355 ProcessCurrentUrl(); 357 ProcessCurrentUrl();
356 } 358 }
357 359
358 void FaviconHandler::ProcessCurrentUrl() { 360 void FaviconHandler::ProcessCurrentUrl() {
359 DCHECK(!image_urls_.empty()); 361 DCHECK(!image_urls_.empty());
360 362
363 // TODO(rogerm): To use fetch on demand for large icons: just add the Favicon
364 // record and update the url mappings here, instead of downloading.
365 // i.e., if (handler_type_ == LARGE) { Save(image_urls[0]); return; }
366
361 // current_candidate() may return NULL if download_largest_icon_ is true and 367 // current_candidate() may return NULL if download_largest_icon_ is true and
362 // all the sizes are larger than the max. 368 // all the sizes are larger than the max.
363 if (PageChangedSinceFaviconWasRequested() || !current_candidate()) 369 if (PageChangedSinceFaviconWasRequested() || !current_candidate())
364 return; 370 return;
365 371
366 if (current_candidate()->icon_type == favicon_base::FAVICON && 372 if (current_candidate()->icon_type == favicon_base::FAVICON &&
367 !download_largest_icon_) { 373 !download_largest_icon_) {
368 if (!favicon_expired_or_incomplete_ && 374 if (!favicon_expired_or_incomplete_ &&
369 driver_->GetActiveFaviconValidity() && 375 driver_->GetActiveFaviconValidity() &&
370 DoUrlAndIconMatch(*current_candidate(), 376 DoUrlAndIconMatch(*current_candidate(),
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 446 }
441 } 447 }
442 448
443 if (request_next_icon && image_urls_.size() > 1) { 449 if (request_next_icon && image_urls_.size() > 1) {
444 // Remove the first member of image_urls_ and process the remaining. 450 // Remove the first member of image_urls_ and process the remaining.
445 image_urls_.erase(image_urls_.begin()); 451 image_urls_.erase(image_urls_.begin());
446 ProcessCurrentUrl(); 452 ProcessCurrentUrl();
447 } else { 453 } else {
448 // We have either found the ideal candidate or run out of candidates. 454 // We have either found the ideal candidate or run out of candidates.
449 if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) { 455 if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) {
450 // No more icons to request, set the favicon from the candidate. 456 // If we're specifically handling large icons, save the icon using the
457 // virtual LARGE_ICON type, otherwise save the icon using its true type.
458 favicon_base::IconType saved_type = handler_type_ == LARGE ?
459 favicon_base::LARGE_ICON : best_favicon_candidate_.icon_type;
451 SetFavicon(best_favicon_candidate_.url, best_favicon_candidate_.image_url, 460 SetFavicon(best_favicon_candidate_.url, best_favicon_candidate_.image_url,
452 best_favicon_candidate_.image, 461 best_favicon_candidate_.image, saved_type);
453 best_favicon_candidate_.icon_type);
454 } 462 }
455 // Clear download related state. 463 // Clear download related state.
456 image_urls_.clear(); 464 image_urls_.clear();
457 download_requests_.clear(); 465 download_requests_.clear();
458 best_favicon_candidate_ = FaviconCandidate(); 466 best_favicon_candidate_ = FaviconCandidate();
459 } 467 }
460 } 468 }
461 469
462 bool FaviconHandler::HasPendingTasksForTest() { 470 bool FaviconHandler::HasPendingTasksForTest() {
463 return !download_requests_.empty() || 471 return !download_requests_.empty() ||
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 541
534 bool FaviconHandler::ShouldSaveFavicon(const GURL& url) { 542 bool FaviconHandler::ShouldSaveFavicon(const GURL& url) {
535 if (!driver_->IsOffTheRecord()) 543 if (!driver_->IsOffTheRecord())
536 return true; 544 return true;
537 545
538 // Always save favicon if the page is bookmarked. 546 // Always save favicon if the page is bookmarked.
539 return driver_->IsBookmarked(url); 547 return driver_->IsBookmarked(url);
540 } 548 }
541 549
542 int FaviconHandler::GetMaximalIconSize(favicon_base::IconType icon_type) { 550 int FaviconHandler::GetMaximalIconSize(favicon_base::IconType icon_type) {
551 if (handler_type_ == FaviconHandler::LARGE) {
552 // If we're only concerned with saving large icons, return a fixed large
553 // icon size, unless something is wrong with the icon type.
554 return icon_type == favicon_base::INVALID_ICON ? 0 : 192;
555 }
556
543 switch (icon_type) { 557 switch (icon_type) {
544 case favicon_base::FAVICON: 558 case favicon_base::FAVICON:
545 #if defined(OS_ANDROID) 559 #if defined(OS_ANDROID)
546 return 192; 560 return 192;
547 #else 561 #else
548 return gfx::ImageSkia::GetMaxSupportedScale() * gfx::kFaviconSize; 562 return gfx::ImageSkia::GetMaxSupportedScale() * gfx::kFaviconSize;
549 #endif 563 #endif
550 case favicon_base::TOUCH_ICON: 564 case favicon_base::TOUCH_ICON:
551 case favicon_base::TOUCH_PRECOMPOSED_ICON: 565 case favicon_base::TOUCH_PRECOMPOSED_ICON:
552 return kTouchIconSize; 566 return kTouchIconSize;
567 case favicon_base::LARGE_ICON:
568 // This method is called to get the maximal size when we're about to
569 // request the download of a concrete icon type. LARGE_ICON is a virtual
570 // type, so we're not expecting a call to get a maximal size to downlaod.
sky 2015/05/06 19:50:42 downlaod->download
Roger McFarlane (Chromium) 2015/05/06 21:22:51 Will do.
571 NOTREACHED();
572 return 192;
553 case favicon_base::INVALID_ICON: 573 case favicon_base::INVALID_ICON:
554 return 0; 574 return 0;
555 } 575 }
556 NOTREACHED(); 576 NOTREACHED();
557 return 0; 577 return 0;
558 } 578 }
559 579
560 void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( 580 void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
561 const std::vector<favicon_base::FaviconRawBitmapResult>& 581 const std::vector<favicon_base::FaviconRawBitmapResult>&
562 favicon_bitmap_results) { 582 favicon_bitmap_results) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 gfx::Size largest = 726 gfx::Size largest =
707 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)]; 727 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)];
708 image_url.icon_sizes.clear(); 728 image_url.icon_sizes.clear();
709 image_url.icon_sizes.push_back(largest); 729 image_url.icon_sizes.push_back(largest);
710 } 730 }
711 std::stable_sort(image_urls_.begin(), image_urls_.end(), 731 std::stable_sort(image_urls_.begin(), image_urls_.end(),
712 CompareIconSize); 732 CompareIconSize);
713 } 733 }
714 734
715 } // namespace favicon 735 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698