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

Unified Diff: chrome/browser/favicon/favicon_tab_helper.cc

Issue 684983003: Add Observer in FaviconTabHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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: chrome/browser/favicon/favicon_tab_helper.cc
diff --git a/chrome/browser/favicon/favicon_tab_helper.cc b/chrome/browser/favicon/favicon_tab_helper.cc
index 3992f8f02aca60b86bc066008245594ad18c5a90..62350b32461b437ed92ac8d467f133c2d6f73c74 100644
--- a/chrome/browser/favicon/favicon_tab_helper.cc
+++ b/chrome/browser/favicon/favicon_tab_helper.cc
@@ -136,6 +136,14 @@ void FaviconTabHelper::SaveFavicon() {
entry->GetURL(), favicon.url, favicon_base::FAVICON, favicon.image);
}
+void FaviconTabHelper::AddObserver(Observer* observer) {
+ observer_list_.AddObserver(observer);
+}
+
+void FaviconTabHelper::RemoveObserver(Observer* observer) {
+ observer_list_.RemoveObserver(observer);
+}
+
int FaviconTabHelper::StartDownload(const GURL& url, int max_image_size) {
FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS);
@@ -151,14 +159,6 @@ int FaviconTabHelper::StartDownload(const GURL& url, int max_image_size) {
base::Bind(&FaviconTabHelper::DidDownloadFavicon,base::Unretained(this)));
}
-void FaviconTabHelper::NotifyFaviconUpdated(bool icon_url_changed) {
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_FAVICON_UPDATED,
- content::Source<WebContents>(web_contents()),
- content::Details<bool>(&icon_url_changed));
- web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
-}
-
bool FaviconTabHelper::IsOffTheRecord() {
DCHECK(web_contents());
return web_contents()->GetBrowserContext()->IsOffTheRecord();
@@ -195,6 +195,29 @@ void FaviconTabHelper::SetActiveFaviconValidity(bool validity) {
GetFaviconStatus().valid = validity;
}
+void FaviconTabHelper::OnFaviconAvailable(const gfx::Image& image,
+ const GURL& icon_url,
+ bool update_active_favicon) {
+ if (update_active_favicon) {
+ // No matter what happens, we need to mark the favicon as being set.
+ SetActiveFaviconValidity(true);
+ bool icon_url_changed = GetActiveFaviconURL() != icon_url;
+ SetActiveFaviconURL(icon_url);
+
+ if (image.IsEmpty())
+ return;
+
+ SetActiveFaviconImage(image);
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_FAVICON_UPDATED,
+ content::Source<WebContents>(web_contents()),
+ content::Details<bool>(&icon_url_changed));
+ web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
+ }
+ if (!image.IsEmpty())
+ FOR_EACH_OBSERVER(Observer, observer_list_, OnFaviconAvailable(image));
+}
+
content::FaviconStatus& FaviconTabHelper::GetFaviconStatus() {
DCHECK(web_contents()->GetController().GetActiveEntry());
return web_contents()->GetController().GetActiveEntry()->GetFavicon();

Powered by Google App Engine
This is Rietveld 408576698