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

Unified Diff: components/favicon/core/favicon_handler.cc

Issue 1084473002: Simplify FaviconHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_favicon4
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/favicon/core/favicon_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/favicon/core/favicon_handler.cc
diff --git a/components/favicon/core/favicon_handler.cc b/components/favicon/core/favicon_handler.cc
index aff16261e47917a0680e7ec581d1644f29875f1f..ed01175de06fc6894e6f9421809ab86e366bfa98 100644
--- a/components/favicon/core/favicon_handler.cc
+++ b/components/favicon/core/favicon_handler.cc
@@ -235,7 +235,10 @@ void FaviconHandler::FetchFavicon(const GURL& url) {
url_ = url;
favicon_expired_or_incomplete_ = got_favicon_from_history_ = false;
+ download_requests_.clear();
image_urls_.clear();
+ history_results_.clear();
+ best_favicon_candidate_ = FaviconCandidate();
// Request the favicon from the history service. In parallel to this the
// renderer is going to notify us (well WebContents) when the favicon url is
@@ -298,19 +301,12 @@ void FaviconHandler::SetFavicon(const GURL& url,
if (ShouldSaveFavicon(url))
SetHistoryFavicons(url, icon_url, icon_type, image);
- if (!UrlMatches(url, url_) || PageChangedSinceFaviconWasRequested())
pkotwicz 2015/04/13 02:55:30 I removed the UrlMatches() check because we clear
sky 2015/04/13 19:47:37 It's not clear to me this is right. From the comme
pkotwicz 2015/04/13 20:06:46 I am still checking PageChangedSinceFaviconWasRequ
sky 2015/04/13 21:01:21 Is there a particular reason to push the check lik
pkotwicz 2015/04/13 21:19:18 I made this change because I had a hard time under
sky 2015/04/13 22:50:42 The idea is that we still persist a favicon we dow
pkotwicz 2015/04/19 23:59:04 Yes, this got broken in 2012 (https://chromiumcode
- return;
-
- NotifyFaviconAvailable(
- icon_url,
- image,
- icon_type == favicon_base::FAVICON && !download_largest_icon_);
+ NotifyFaviconAvailable(icon_url, image);
}
void FaviconHandler::NotifyFaviconAvailable(
const std::vector<favicon_base::FaviconRawBitmapResult>&
- favicon_bitmap_results,
- bool is_active_favicon) {
+ favicon_bitmap_results) {
gfx::Image resized_image = favicon_base::SelectFaviconFramesFromPNGs(
favicon_bitmap_results,
favicon_base::GetFaviconScales(),
@@ -319,23 +315,27 @@ void FaviconHandler::NotifyFaviconAvailable(
// not matter which result we get the |icon_url| from.
const GURL icon_url = favicon_bitmap_results.empty() ?
GURL() : favicon_bitmap_results[0].icon_url;
- NotifyFaviconAvailable(icon_url, resized_image, is_active_favicon);
+ NotifyFaviconAvailable(icon_url, resized_image);
}
void FaviconHandler::NotifyFaviconAvailable(const GURL& icon_url,
- const gfx::Image& image,
- bool is_active_favicon) {
+ const gfx::Image& image) {
gfx::Image image_with_adjusted_colorspace = image;
favicon_base::SetFaviconColorSpace(&image_with_adjusted_colorspace);
+ bool is_active_favicon =
Roger McFarlane (Chromium) 2015/04/13 14:21:49 How would this interact with download requests ini
pkotwicz 2015/04/13 15:59:21 Downloads initiated from a different part of Chrom
+ (handler_type_ == FAVICON && !download_largest_icon_);
+
driver_->OnFaviconAvailable(
image_with_adjusted_colorspace, icon_url, is_active_favicon);
}
void FaviconHandler::OnUpdateFaviconURL(
const std::vector<FaviconURL>& candidates) {
+ download_requests_.clear();
image_urls_.clear();
best_favicon_candidate_ = FaviconCandidate();
+
for (const FaviconURL& candidate : candidates) {
if (!candidate.icon_url.is_empty() && (candidate.icon_type & icon_types_))
image_urls_.push_back(candidate);
@@ -393,14 +393,19 @@ void FaviconHandler::OnDidDownloadFavicon(
DownloadRequest download_request = i->second;
download_requests_.erase(i);
- if (current_candidate() &&
- DoUrlAndIconMatch(*current_candidate(),
- image_url,
- download_request.icon_type)) {
- bool request_next_icon = true;
- float score = 0.0f;
- gfx::ImageSkia image_skia;
- if (download_largest_icon_ && !bitmaps.empty()) {
+ if (PageChangedSinceFaviconWasRequested() ||
pkotwicz 2015/04/13 02:55:30 I think that the original code has the PageChanged
+ !current_candidate() ||
+ !DoUrlAndIconMatch(*current_candidate(),
+ image_url,
+ download_request.icon_type)) {
+ return;
+ }
+
+ bool request_next_icon = true;
+ float score = 0.0f;
+ gfx::ImageSkia image_skia;
+ if (!bitmaps.empty()) {
+ if (download_largest_icon_) {
int index = -1;
// Use the largest bitmap if FaviconURL doesn't have sizes attribute.
if (current_candidate()->icon_sizes.empty()) {
@@ -424,30 +429,27 @@ void FaviconHandler::OnDidDownloadFavicon(
gfx::Image image(image_skia);
// The downloaded icon is still valid when there is no FaviconURL update
// during the downloading.
- if (!bitmaps.empty()) {
pkotwicz 2015/04/13 02:55:30 I removed this check because it is redundant
- request_next_icon = !UpdateFaviconCandidate(
- download_request.url, image_url, image, score,
- download_request.icon_type);
- }
- }
- if (request_next_icon && !PageChangedSinceFaviconWasRequested() &&
- image_urls_.size() > 1) {
- // Remove the first member of image_urls_ and process the remaining.
- image_urls_.erase(image_urls_.begin());
- ProcessCurrentUrl();
- } else if (best_favicon_candidate_.icon_type !=
- favicon_base::INVALID_ICON) {
- // No more icons to request, set the favicon from the candidate.
- SetFavicon(best_favicon_candidate_.url,
- best_favicon_candidate_.image_url,
- best_favicon_candidate_.image,
- best_favicon_candidate_.icon_type);
- // Reset candidate.
- image_urls_.clear();
- download_requests_.clear();
- best_favicon_candidate_ = FaviconCandidate();
+ request_next_icon = !UpdateFaviconCandidate(
+ download_request.url, image_url, image, score,
+ download_request.icon_type);
}
}
+
+ if (request_next_icon && image_urls_.size() > 1) {
+ // Remove the first member of image_urls_ and process the remaining.
+ image_urls_.erase(image_urls_.begin());
+ ProcessCurrentUrl();
+ } else if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) {
+ // No more icons to request, set the favicon from the candidate.
+ SetFavicon(best_favicon_candidate_.url,
+ best_favicon_candidate_.image_url,
+ best_favicon_candidate_.image,
+ best_favicon_candidate_.icon_type);
+ // Reset candidate.
+ image_urls_.clear();
+ download_requests_.clear();
+ best_favicon_candidate_ = FaviconCandidate();
+ }
}
bool FaviconHandler::HasPendingTasksForTest() {
@@ -569,7 +571,7 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
// doesn't have an icon. Set the favicon now, and if the favicon turns out
// to be expired (or the wrong url) we'll fetch later on. This way the
// user doesn't see a flash of the default favicon.
- NotifyFaviconAvailable(favicon_bitmap_results, true);
+ NotifyFaviconAvailable(favicon_bitmap_results);
} else {
// If |favicon_bitmap_results| does not have any valid results, treat the
// favicon as if it's expired.
@@ -599,7 +601,7 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
// renderer to download the icon.
if (has_valid_result && (handler_type_ != FAVICON || download_largest_icon_))
- NotifyFaviconAvailable(favicon_bitmap_results, false);
+ NotifyFaviconAvailable(favicon_bitmap_results);
}
void FaviconHandler::DownloadFaviconOrAskFaviconService(
@@ -647,7 +649,7 @@ void FaviconHandler::OnFaviconData(const std::vector<
// There is a favicon, set it now. If expired we'll download the current
// one again, but at least the user will get some icon instead of the
// default and most likely the current one is fine anyway.
- NotifyFaviconAvailable(favicon_bitmap_results, true);
+ NotifyFaviconAvailable(favicon_bitmap_results);
}
if (has_expired_or_incomplete_result) {
// The favicon is out of date. Request the current one.
@@ -668,11 +670,11 @@ void FaviconHandler::OnFaviconData(const std::vector<
if (has_valid_result &&
(handler_type_ != FAVICON || download_largest_icon_)) {
- NotifyFaviconAvailable(favicon_bitmap_results, false);
+ NotifyFaviconAvailable(favicon_bitmap_results);
}
}
-int FaviconHandler::ScheduleDownload(const GURL& url,
+void FaviconHandler::ScheduleDownload(const GURL& url,
const GURL& image_url,
favicon_base::IconType icon_type) {
// A max bitmap size is specified to avoid receiving huge bitmaps in
@@ -686,8 +688,6 @@ int FaviconHandler::ScheduleDownload(const GURL& url,
download_requests_[download_id] =
DownloadRequest(url, image_url, icon_type);
}
-
- return download_id;
}
void FaviconHandler::SortAndPruneImageUrls() {
« no previous file with comments | « components/favicon/core/favicon_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698