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

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

Issue 10968026: Use the default favicon in place of stale favicons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 9 #include <algorithm>
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 "chrome/browser/bookmarks/bookmark_model.h" 15 #include "chrome/browser/bookmarks/bookmark_model.h"
16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
17 #include "chrome/browser/favicon/favicon_service_factory.h" 17 #include "chrome/browser/favicon/favicon_service_factory.h"
18 #include "chrome/browser/favicon/favicon_util.h" 18 #include "chrome/browser/favicon/favicon_util.h"
19 #include "chrome/browser/history/select_favicon_frames.h" 19 #include "chrome/browser/history/select_favicon_frames.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/common/icon_messages.h" 21 #include "chrome/common/icon_messages.h"
22 #include "content/public/browser/favicon_status.h" 22 #include "content/public/browser/favicon_status.h"
23 #include "content/public/browser/navigation_entry.h" 23 #include "content/public/browser/navigation_entry.h"
24 #include "grit/ui_resources.h"
24 #include "skia/ext/image_operations.h" 25 #include "skia/ext/image_operations.h"
26 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/codec/png_codec.h" 27 #include "ui/gfx/codec/png_codec.h"
26 #include "ui/gfx/image/image.h" 28 #include "ui/gfx/image/image.h"
27 #include "ui/gfx/image/image_skia.h" 29 #include "ui/gfx/image/image_skia.h"
28 #include "ui/gfx/image/image_util.h" 30 #include "ui/gfx/image/image_util.h"
29 31
30 using content::NavigationEntry; 32 using content::NavigationEntry;
31 33
32 namespace { 34 namespace {
33 35
34 // Returns history::IconType the given icon_type corresponds to. 36 // Returns history::IconType the given icon_type corresponds to.
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (!entry) 365 if (!entry)
364 return; 366 return;
365 367
366 // For FAVICON. 368 // For FAVICON.
367 if (current_candidate()->icon_type == FaviconURL::FAVICON) { 369 if (current_candidate()->icon_type == FaviconURL::FAVICON) {
368 if (!favicon_expired_or_incomplete_ && entry->GetFavicon().valid && 370 if (!favicon_expired_or_incomplete_ && entry->GetFavicon().valid &&
369 DoUrlAndIconMatch(*current_candidate(), entry->GetFavicon().url, 371 DoUrlAndIconMatch(*current_candidate(), entry->GetFavicon().url,
370 history::FAVICON)) 372 history::FAVICON))
371 return; 373 return;
372 374
375 // TODO(msw): valid depending on url, or leave as-is?
376 entry->GetFavicon().valid = false;
373 entry->GetFavicon().url = current_candidate()->icon_url; 377 entry->GetFavicon().url = current_candidate()->icon_url;
378 // TODO(msw): Will this cause flicker? Do this when the fetch errors out?
379 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
380 entry->GetFavicon().image = rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON);
374 } else if (!favicon_expired_or_incomplete_ && got_favicon_from_history_ && 381 } else if (!favicon_expired_or_incomplete_ && got_favicon_from_history_ &&
375 HasValidResult(history_results_) && 382 HasValidResult(history_results_) &&
376 DoUrlsAndIconsMatch(*current_candidate(), history_results_)) { 383 DoUrlsAndIconsMatch(*current_candidate(), history_results_)) {
377 return; 384 return;
378 } 385 }
379 386
380 if (got_favicon_from_history_) 387 if (got_favicon_from_history_)
381 DownloadFaviconOrAskHistory(entry->GetURL(), current_candidate()->icon_url, 388 DownloadFaviconOrAskHistory(entry->GetURL(), current_candidate()->icon_url,
382 ToHistoryIconType(current_candidate()->icon_type)); 389 ToHistoryIconType(current_candidate()->icon_type));
383 } 390 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // during the downloading. 428 // during the downloading.
422 bool request_next_icon = true; 429 bool request_next_icon = true;
423 if (!errored) { 430 if (!errored) {
424 request_next_icon = !UpdateFaviconCandidate( 431 request_next_icon = !UpdateFaviconCandidate(
425 i->second.url, image_url, image, score, i->second.icon_type); 432 i->second.url, image_url, image, score, i->second.icon_type);
426 } 433 }
427 if (request_next_icon && GetEntry() && image_urls_.size() > 1) { 434 if (request_next_icon && GetEntry() && image_urls_.size() > 1) {
428 // Remove the first member of image_urls_ and process the remaining. 435 // Remove the first member of image_urls_ and process the remaining.
429 image_urls_.pop_front(); 436 image_urls_.pop_front();
430 ProcessCurrentUrl(); 437 ProcessCurrentUrl();
431 } else if (favicon_candidate_.icon_type != history::INVALID_ICON) { 438 } else {
439 // Show the default favicon if the response was invalid.
440 if (favicon_candidate_.icon_type != history::INVALID_ICON) {
441 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
442 favicon_candidate_.image = rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON);
443 // TODO(msw): the icon_type is not necessarily |FAVICON|...
444 favicon_candidate_.icon_type = history::FAVICON;
445 }
446
432 // No more icons to request, set the favicon from the candidate. 447 // No more icons to request, set the favicon from the candidate.
433 SetFavicon(favicon_candidate_.url, 448 SetFavicon(favicon_candidate_.url,
434 favicon_candidate_.image_url, 449 favicon_candidate_.image_url,
435 favicon_candidate_.image, 450 favicon_candidate_.image,
436 favicon_candidate_.icon_type); 451 favicon_candidate_.icon_type);
437 // Reset candidate. 452 // Reset candidate.
438 image_urls_.clear(); 453 image_urls_.clear();
439 favicon_candidate_ = FaviconCandidate(); 454 favicon_candidate_ = FaviconCandidate();
440 } 455 }
441 } 456 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 const int download_id = DownloadFavicon(image_url, image_size); 660 const int download_id = DownloadFavicon(image_url, image_size);
646 if (download_id) { 661 if (download_id) {
647 // Download ids should be unique. 662 // Download ids should be unique.
648 DCHECK(download_requests_.find(download_id) == download_requests_.end()); 663 DCHECK(download_requests_.find(download_id) == download_requests_.end());
649 download_requests_[download_id] = 664 download_requests_[download_id] =
650 DownloadRequest(url, image_url, callback, icon_type); 665 DownloadRequest(url, image_url, callback, icon_type);
651 } 666 }
652 667
653 return download_id; 668 return download_id;
654 } 669 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698