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

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

Issue 2703603002: Improve FaviconHandler tests by testing public API (Closed)
Patch Set: Created 3 years, 10 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 45c47830f88382bbc1f1b31da5519e0141602cc5..b792a9012ad0c471fee437445a2b83683d0f1a8f 100644
--- a/components/favicon/core/favicon_handler.cc
+++ b/components/favicon/core/favicon_handler.cc
@@ -262,11 +262,14 @@ void FaviconHandler::FetchFavicon(const GURL& url) {
// 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
// available.
- GetFaviconForURLFromFaviconService(
- url_, icon_types_,
- base::Bind(&FaviconHandler::OnFaviconDataForInitialURLFromFaviconService,
- base::Unretained(this)),
- &cancelable_task_tracker_);
+ if (service_) {
+ service_->GetFaviconForPageURL(
+ url_, icon_types_, preferred_icon_size(),
+ base::Bind(
+ &FaviconHandler::OnFaviconDataForInitialURLFromFaviconService,
+ base::Unretained(this)),
+ &cancelable_task_tracker_);
+ }
}
bool FaviconHandler::UpdateFaviconCandidate(const GURL& image_url,
@@ -319,8 +322,8 @@ bool FaviconHandler::UpdateFaviconCandidate(const GURL& image_url,
void FaviconHandler::SetFavicon(const GURL& icon_url,
const gfx::Image& image,
favicon_base::IconType icon_type) {
- if (ShouldSaveFavicon())
- SetHistoryFavicons(url_, icon_url, icon_type, image);
+ if (service_ && ShouldSaveFavicon())
+ service_->SetFavicons(url_, icon_url, icon_type, image);
NotifyFaviconUpdated(icon_url, icon_type, image);
}
@@ -498,54 +501,6 @@ bool FaviconHandler::HasPendingTasksForTest() {
cancelable_task_tracker_.HasTrackedTasks();
}
-void FaviconHandler::UpdateFaviconMappingAndFetch(
- const GURL& page_url,
- const GURL& icon_url,
- favicon_base::IconType icon_type,
- const favicon_base::FaviconResultsCallback& callback,
- base::CancelableTaskTracker* tracker) {
- // TODO(pkotwicz): pass in all of |image_urls_| to
- // UpdateFaviconMappingsAndFetch().
- if (service_) {
- std::vector<GURL> icon_urls;
- icon_urls.push_back(icon_url);
- service_->UpdateFaviconMappingsAndFetch(page_url, icon_urls, icon_type,
- preferred_icon_size(), callback,
- tracker);
- }
-}
-
-void FaviconHandler::GetFaviconFromFaviconService(
- const GURL& icon_url,
- favicon_base::IconType icon_type,
- const favicon_base::FaviconResultsCallback& callback,
- base::CancelableTaskTracker* tracker) {
- if (service_) {
- service_->GetFavicon(icon_url, icon_type, preferred_icon_size(), callback,
- tracker);
- }
-}
-
-void FaviconHandler::GetFaviconForURLFromFaviconService(
- const GURL& page_url,
- int icon_types,
- const favicon_base::FaviconResultsCallback& callback,
- base::CancelableTaskTracker* tracker) {
- if (service_) {
- service_->GetFaviconForPageURL(page_url, icon_types, preferred_icon_size(),
- callback, tracker);
- }
-}
-
-void FaviconHandler::SetHistoryFavicons(const GURL& page_url,
- const GURL& icon_url,
- favicon_base::IconType icon_type,
- const gfx::Image& image) {
- if (service_) {
- service_->SetFavicons(page_url, icon_url, icon_type, image);
- }
-}
-
bool FaviconHandler::ShouldSaveFavicon() {
if (!delegate_->IsOffTheRecord())
return true;
@@ -605,13 +560,13 @@ void FaviconHandler::DownloadCurrentCandidateOrAskFaviconService() {
if (redownload_icons_) {
// We have the mapping, but the favicon is out of date. Download it now.
ScheduleDownload(icon_url, icon_type);
- } else {
+ } else if (service_) {
// We don't know the favicon, but we may have previously downloaded the
// favicon for another page that shares the same favicon. Ask for the
// favicon given the favicon URL.
if (delegate_->IsOffTheRecord()) {
- GetFaviconFromFaviconService(
- icon_url, icon_type,
+ service_->GetFavicon(
+ icon_url, icon_type, preferred_icon_size(),
base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this)),
&cancelable_task_tracker_);
} else {
@@ -620,8 +575,10 @@ void FaviconHandler::DownloadCurrentCandidateOrAskFaviconService() {
// 2. If the favicon exists in the database, this updates the database to
// include the mapping between the page url and the favicon url.
// This is asynchronous. The history service will call back when done.
- UpdateFaviconMappingAndFetch(
- url_, icon_url, icon_type,
+ // TODO(pkotwicz): pass in all of |image_urls_| to
+ // UpdateFaviconMappingsAndFetch().
+ service_->UpdateFaviconMappingsAndFetch(
+ url_, {icon_url}, icon_type, preferred_icon_size(),
base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this)),
&cancelable_task_tracker_);
}

Powered by Google App Engine
This is Rietveld 408576698