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

Side by Side Diff: chrome/browser/favicon/favicon_handler.cc

Issue 10870022: Change FaviconData to be able to return data for multiple bitmaps for same icon URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
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 "chrome/browser/favicon/favicon_handler.h" 5 #include "chrome/browser/favicon/favicon_handler.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 // For FAVICON. 270 // For FAVICON.
271 if (current_candidate()->icon_type == FaviconURL::FAVICON) { 271 if (current_candidate()->icon_type == FaviconURL::FAVICON) {
272 if (!favicon_expired_ && entry->GetFavicon().valid && 272 if (!favicon_expired_ && entry->GetFavicon().valid &&
273 DoUrlAndIconMatch(*current_candidate(), entry->GetFavicon().url, 273 DoUrlAndIconMatch(*current_candidate(), entry->GetFavicon().url,
274 history::FAVICON)) 274 history::FAVICON))
275 return; 275 return;
276 276
277 entry->GetFavicon().url = current_candidate()->icon_url; 277 entry->GetFavicon().url = current_candidate()->icon_url;
278 } else if (!favicon_expired_ && got_favicon_from_history_ && 278 } else if (!favicon_expired_ && got_favicon_from_history_ &&
279 history_icon_.is_valid() && 279 history_icon_.has_valid_bitmaps() &&
280 DoUrlAndIconMatch( 280 DoUrlAndIconMatch(
281 *current_candidate(), 281 *current_candidate(),
282 history_icon_.icon_url, history_icon_.icon_type)) { 282 history_icon_.icon_url, history_icon_.icon_type)) {
283 return; 283 return;
284 } 284 }
285 285
286 if (got_favicon_from_history_) 286 if (got_favicon_from_history_)
287 DownloadFaviconOrAskHistory(entry->GetURL(), current_candidate()->icon_url, 287 DownloadFaviconOrAskHistory(entry->GetURL(), current_candidate()->icon_url,
288 ToHistoryIconType(current_candidate()->icon_type)); 288 ToHistoryIconType(current_candidate()->icon_type));
289 } 289 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return true; 389 return true;
390 390
391 // Otherwise store the favicon if the page is bookmarked. 391 // Otherwise store the favicon if the page is bookmarked.
392 BookmarkModel* bookmark_model = 392 BookmarkModel* bookmark_model =
393 BookmarkModelFactory::GetForProfile(profile_); 393 BookmarkModelFactory::GetForProfile(profile_);
394 return bookmark_model && bookmark_model->IsBookmarked(url); 394 return bookmark_model && bookmark_model->IsBookmarked(url);
395 } 395 }
396 396
397 void FaviconHandler::OnFaviconDataForInitialURL( 397 void FaviconHandler::OnFaviconDataForInitialURL(
398 FaviconService::Handle handle, 398 FaviconService::Handle handle,
399 history::FaviconData favicon) { 399 history::FaviconData favicon_data,
400 std::vector<GURL> icon_urls_in_db) {
400 NavigationEntry* entry = GetEntry(); 401 NavigationEntry* entry = GetEntry();
401 if (!entry) 402 if (!entry)
402 return; 403 return;
403 404
404 got_favicon_from_history_ = true; 405 got_favicon_from_history_ = true;
405 history_icon_ = favicon; 406 history_icon_ = favicon_data;
406 407
407 favicon_expired_ = (favicon.known_icon && favicon.expired); 408 favicon_expired_ = (favicon_data.known_icon && favicon_data.expired());
408 409
409 if (favicon.known_icon && favicon.icon_type == history::FAVICON && 410 if (favicon_data.known_icon && favicon_data.icon_type == history::FAVICON &&
410 !entry->GetFavicon().valid && 411 !entry->GetFavicon().valid &&
411 (!current_candidate() || 412 (!current_candidate() ||
412 DoUrlAndIconMatch( 413 DoUrlAndIconMatch(*current_candidate(),
413 *current_candidate(), favicon.icon_url, favicon.icon_type))) { 414 favicon_data.icon_url, favicon_data.icon_type))) {
414 // The db knows the favicon (although it may be out of date) and the entry 415 // The db knows the favicon (although it may be out of date) and the entry
415 // doesn't have an icon. Set the favicon now, and if the favicon turns out 416 // doesn't have an icon. Set the favicon now, and if the favicon turns out
416 // to be expired (or the wrong url) we'll fetch later on. This way the 417 // to be expired (or the wrong url) we'll fetch later on. This way the
417 // user doesn't see a flash of the default favicon. 418 // user doesn't see a flash of the default favicon.
418 entry->GetFavicon().url = favicon.icon_url; 419 entry->GetFavicon().url = favicon_data.icon_url;
419 if (favicon.is_valid()) 420 if (favicon_data.has_valid_bitmaps())
420 UpdateFavicon(entry, favicon.image_data); 421 UpdateFavicon(entry, favicon_data.first_bitmap());
421 entry->GetFavicon().valid = true; 422 entry->GetFavicon().valid = true;
422 } 423 }
423 424
424 if (favicon.known_icon && !favicon.expired) { 425 if (favicon_data.known_icon && !favicon_data.expired()) {
425 if (current_candidate() && 426 if (current_candidate() &&
426 !DoUrlAndIconMatch( 427 !DoUrlAndIconMatch(*current_candidate(),
427 *current_candidate(), favicon.icon_url, favicon.icon_type)) { 428 favicon_data.icon_url, favicon_data.icon_type)) {
428 // Mapping in the database is wrong. DownloadFavIconOrAskHistory will 429 // Mapping in the database is wrong. DownloadFavIconOrAskHistory will
429 // update the mapping for this url and download the favicon if we don't 430 // update the mapping for this url and download the favicon if we don't
430 // already have it. 431 // already have it.
431 DownloadFaviconOrAskHistory(entry->GetURL(), 432 DownloadFaviconOrAskHistory(entry->GetURL(),
432 current_candidate()->icon_url, 433 current_candidate()->icon_url,
433 static_cast<history::IconType>(current_candidate()->icon_type)); 434 static_cast<history::IconType>(current_candidate()->icon_type));
434 } 435 }
435 } else if (current_candidate()) { 436 } else if (current_candidate()) {
436 // We know the official url for the favicon, by either don't have the 437 // We know the official url for the favicon, by either don't have the
437 // favicon or its expired. Continue on to DownloadFaviconOrAskHistory to 438 // favicon or its expired. Continue on to DownloadFaviconOrAskHistory to
(...skipping 28 matching lines...) Expand all
466 // This is asynchronous. The history service will call back when done. 467 // This is asynchronous. The history service will call back when done.
467 // Issue the request and associate the current page ID with it. 468 // Issue the request and associate the current page ID with it.
468 UpdateFaviconMappingAndFetch(page_url, icon_url, icon_type, 469 UpdateFaviconMappingAndFetch(page_url, icon_url, icon_type,
469 &cancelable_consumer_, 470 &cancelable_consumer_,
470 base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this))); 471 base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this)));
471 } 472 }
472 } 473 }
473 } 474 }
474 475
475 void FaviconHandler::OnFaviconData(FaviconService::Handle handle, 476 void FaviconHandler::OnFaviconData(FaviconService::Handle handle,
476 history::FaviconData favicon) { 477 history::FaviconData favicon_data,
478 std::vector<GURL> icon_urls_in_db) {
477 NavigationEntry* entry = GetEntry(); 479 NavigationEntry* entry = GetEntry();
478 if (!entry) 480 if (!entry)
479 return; 481 return;
480 482
481 // No need to update the favicon url. By the time we get here 483 // No need to update the favicon url. By the time we get here
482 // UpdateFaviconURL will have set the favicon url. 484 // UpdateFaviconURL will have set the favicon url.
483 if (favicon.icon_type == history::FAVICON) { 485 if (favicon_data.icon_type == history::FAVICON) {
484 if (favicon.is_valid()) { 486 if (favicon_data.has_valid_bitmaps()) {
485 // There is a favicon, set it now. If expired we'll download the current 487 // There is a favicon, set it now. If expired we'll download the current
486 // one again, but at least the user will get some icon instead of the 488 // one again, but at least the user will get some icon instead of the
487 // default and most likely the current one is fine anyway. 489 // default and most likely the current one is fine anyway.
488 UpdateFavicon(entry, favicon.image_data); 490 UpdateFavicon(entry, favicon_data.first_bitmap());
489 } 491 }
490 if (!favicon.known_icon || favicon.expired) { 492 if (!favicon_data.known_icon || favicon_data.expired()) {
491 // We don't know the favicon, or it is out of date. Request the current 493 // We don't know the favicon, or it is out of date. Request the current
492 // one. 494 // one.
493 ScheduleDownload(entry->GetURL(), entry->GetFavicon().url, 495 ScheduleDownload(entry->GetURL(), entry->GetFavicon().url,
494 preferred_icon_size(), 496 preferred_icon_size(),
495 history::FAVICON, 497 history::FAVICON,
496 FaviconTabHelper::ImageDownloadCallback()); 498 FaviconTabHelper::ImageDownloadCallback());
497 } 499 }
498 } else if (current_candidate() && (!favicon.known_icon || favicon.expired || 500 } else if (current_candidate() &&
499 !(DoUrlAndIconMatch( 501 (!favicon_data.known_icon || favicon_data.expired() ||
500 *current_candidate(), favicon.icon_url, favicon.icon_type)))) { 502 !(DoUrlAndIconMatch(*current_candidate(),
503 favicon_data.icon_url, favicon_data.icon_type)))) {
501 // We don't know the favicon, it is out of date or its type is not same as 504 // We don't know the favicon, it is out of date or its type is not same as
502 // one got from page. Request the current one. 505 // one got from page. Request the current one.
503 ScheduleDownload(entry->GetURL(), current_candidate()->icon_url, 506 ScheduleDownload(entry->GetURL(), current_candidate()->icon_url,
504 preferred_icon_size(), 507 preferred_icon_size(),
505 ToHistoryIconType(current_candidate()->icon_type), 508 ToHistoryIconType(current_candidate()->icon_type),
506 FaviconTabHelper::ImageDownloadCallback()); 509 FaviconTabHelper::ImageDownloadCallback());
507 } 510 }
508 history_icon_ = favicon; 511 history_icon_ = favicon_data;
509 } 512 }
510 513
511 int FaviconHandler::ScheduleDownload( 514 int FaviconHandler::ScheduleDownload(
512 const GURL& url, 515 const GURL& url,
513 const GURL& image_url, 516 const GURL& image_url,
514 int image_size, 517 int image_size,
515 history::IconType icon_type, 518 history::IconType icon_type,
516 const FaviconTabHelper::ImageDownloadCallback& callback) { 519 const FaviconTabHelper::ImageDownloadCallback& callback) {
517 const int download_id = DownloadFavicon(image_url, image_size); 520 const int download_id = DownloadFavicon(image_url, image_size);
518 if (download_id) { 521 if (download_id) {
(...skipping 13 matching lines...) Expand all
532 int height = bitmap.height(); 535 int height = bitmap.height();
533 if (width > 0 && height > 0) { 536 if (width > 0 && height > 0) {
534 gfx::CalculateFaviconTargetSize(&width, &height); 537 gfx::CalculateFaviconTargetSize(&width, &height);
535 return gfx::Image(skia::ImageOperations::Resize( 538 return gfx::Image(skia::ImageOperations::Resize(
536 bitmap, skia::ImageOperations::RESIZE_LANCZOS3, 539 bitmap, skia::ImageOperations::RESIZE_LANCZOS3,
537 width, height)); 540 width, height));
538 } 541 }
539 542
540 return image; 543 return image;
541 } 544 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698