Send out an event if we found a cached favicon downloader for new homepage URL. Issue #1940

This commit is contained in:
Maurice Parker 2020-03-24 12:21:08 -05:00
parent 9918f6c2e1
commit a6e75df412
2 changed files with 20 additions and 9 deletions

View File

@ -178,11 +178,6 @@ final class FaviconDownloader {
remainingFaviconURLs[homePageURL] = nil
if self.homePageToFaviconURLCache[homePageURL] == nil {
self.homePageToFaviconURLCache[homePageURL] = singleFaviconDownloader.faviconURL
self.homePageToFaviconURLCacheDirty = true
}
postFaviconDidBecomeAvailableNotification(singleFaviconDownloader.faviconURL)
}
@ -232,8 +227,22 @@ private extension FaviconDownloader {
func faviconDownloader(withURL faviconURL: String, homePageURL: String?) -> SingleFaviconDownloader {
var firstTimeSeeingHomepageURL = false
if let homePageURL = homePageURL, self.homePageToFaviconURLCache[homePageURL] == nil {
self.homePageToFaviconURLCache[homePageURL] = faviconURL
self.homePageToFaviconURLCacheDirty = true
firstTimeSeeingHomepageURL = true
}
if let downloader = singleFaviconDownloaderCache[faviconURL] {
downloader.downloadFaviconIfNeeded()
if firstTimeSeeingHomepageURL && !downloader.downloadFaviconIfNeeded() {
// This is to handle the scenario where we have different homepages, but the same favicon.
// This happens for Twitter and probably other sites like Blogger. Because the favicon
// is cached, we wouldn't send out a notification that it is now available unless we send
// it here.
postFaviconDidBecomeAvailableNotification(faviconURL)
}
return downloader
}

View File

@ -48,21 +48,23 @@ final class SingleFaviconDownloader {
findFavicon()
}
func downloadFaviconIfNeeded() {
func downloadFaviconIfNeeded() -> Bool {
// If we dont have an image, and lastDownloadAttemptDate is a while ago, try again.
if let _ = iconImage {
return
return false
}
let retryInterval: TimeInterval = 30 * 60 // 30 minutes
if Date().timeIntervalSince(lastDownloadAttemptDate) < retryInterval {
return
return false
}
lastDownloadAttemptDate = Date()
findFavicon()
return true
}
}