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

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

Issue 2738663002: FaviconHandler test rewrite
Patch Set: Merge branch 'mastiz_cl' into favicon_handler_unittest2 Created 3 years, 9 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
Index: components/favicon/core/favicon_handler.cc
diff --git a/components/favicon/core/favicon_handler.cc b/components/favicon/core/favicon_handler.cc
index 5e2d8ad1e70c47c6c934d49db59482bf17ad33a3..0f0c18431156066491a60107a8c93db26505b773 100644
--- a/components/favicon/core/favicon_handler.cc
+++ b/components/favicon/core/favicon_handler.cc
@@ -395,6 +395,25 @@ void FaviconHandler::OnUpdateFaviconURL(
OnGotInitialHistoryDataAndIconURLCandidates();
}
+// static
+int FaviconHandler::GetMaximalIconSize(favicon_base::IconType icon_type) {
+ switch (icon_type) {
+ case favicon_base::FAVICON:
+#if defined(OS_ANDROID)
+ return 192;
+#else
+ return gfx::ImageSkia::GetMaxSupportedScale() * gfx::kFaviconSize;
+#endif
+ case favicon_base::TOUCH_ICON:
+ case favicon_base::TOUCH_PRECOMPOSED_ICON:
+ return kTouchIconSize;
+ case favicon_base::INVALID_ICON:
+ return 0;
+ }
+ NOTREACHED();
+ return 0;
+}
+
void FaviconHandler::OnGotInitialHistoryDataAndIconURLCandidates() {
if (!initial_history_result_expired_or_incomplete_ &&
DoUrlAndIconMatch(*current_candidate(), notification_icon_url_,
@@ -555,24 +574,6 @@ bool FaviconHandler::ShouldSaveFavicon() {
return delegate_->IsBookmarked(url_);
}
-int FaviconHandler::GetMaximalIconSize(favicon_base::IconType icon_type) {
- switch (icon_type) {
- case favicon_base::FAVICON:
-#if defined(OS_ANDROID)
- return 192;
-#else
- return gfx::ImageSkia::GetMaxSupportedScale() * gfx::kFaviconSize;
-#endif
- case favicon_base::TOUCH_ICON:
- case favicon_base::TOUCH_PRECOMPOSED_ICON:
- return kTouchIconSize;
- case favicon_base::INVALID_ICON:
- return 0;
- }
- NOTREACHED();
- return 0;
-}
-
void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
const std::vector<favicon_base::FaviconRawBitmapResult>&
favicon_bitmap_results) {
@@ -661,31 +662,24 @@ void FaviconHandler::OnFaviconData(const std::vector<
void FaviconHandler::ScheduleDownload(const GURL& image_url,
favicon_base::IconType icon_type) {
DCHECK(image_url.is_valid());
- if (service_ && service_->WasUnableToDownloadFavicon(image_url)) {
- DVLOG(1) << "Skip Failed FavIcon: " << image_url;
- OnDidDownloadFavicon(0, 0, image_url, std::vector<SkBitmap>(),
- std::vector<gfx::Size>());
- return;
+ int download_id = 0;
+ if (service_ && !service_->WasUnableToDownloadFavicon(image_url)) {
+ // A max bitmap size is specified to avoid receiving huge bitmaps in
+ // OnDidDownloadFavicon(). See FaviconDriver::StartDownload()
+ // for more details about the max bitmap size.
+ download_id = delegate_->DownloadImage(
+ image_url, GetMaximalIconSize(icon_type),
+ base::Bind(&FaviconHandler::OnDidDownloadFavicon,
+ weak_ptr_factory_.GetWeakPtr()));
}
- // A max bitmap size is specified to avoid receiving huge bitmaps in
- // OnDidDownloadFavicon(). See FaviconDriver::StartDownload()
- // for more details about the max bitmap size.
- const int download_id =
- delegate_->DownloadImage(image_url, GetMaximalIconSize(icon_type),
- base::Bind(&FaviconHandler::OnDidDownloadFavicon,
- weak_ptr_factory_.GetWeakPtr()));
// Download ids should be unique.
DCHECK(download_requests_.find(download_id) == download_requests_.end());
download_requests_[download_id] = DownloadRequest(image_url, icon_type);
- // TODO(mastiz): Remove the download_id == 0 handling because it's not used
- // in production code, only tests.
if (download_id == 0) {
- // If DownloadFavicon() did not start a download, it returns a download id
- // of 0. We still need to call OnDidDownloadFavicon() because the method is
- // responsible for initiating the data request for the next candidate.
- OnDidDownloadFavicon(download_id, 0, image_url, std::vector<SkBitmap>(),
+ DVLOG(1) << "Skip Failed FavIcon: " << image_url;
+ OnDidDownloadFavicon(0, 404, image_url, std::vector<SkBitmap>(),
std::vector<gfx::Size>());
}
}

Powered by Google App Engine
This is Rietveld 408576698