diff --git a/mozilla/camino/src/browser/SiteIconCache.h b/mozilla/camino/src/browser/SiteIconCache.h index 3694037c69a..27838f37c00 100644 --- a/mozilla/camino/src/browser/SiteIconCache.h +++ b/mozilla/camino/src/browser/SiteIconCache.h @@ -55,6 +55,7 @@ // containing a uuid and expiration date. NSMutableDictionary* mURLToImageMap; // memory cache of images + BOOL mSuppressSaveNotification; } + (SiteIconCache*)sharedSiteIconCache; diff --git a/mozilla/camino/src/browser/SiteIconCache.mm b/mozilla/camino/src/browser/SiteIconCache.mm index c550e811daa..89f4470f5c0 100644 --- a/mozilla/camino/src/browser/SiteIconCache.mm +++ b/mozilla/camino/src/browser/SiteIconCache.mm @@ -20,6 +20,7 @@ * * Contributor(s): * Simon Fraser + * Stuart Morgan * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -63,6 +64,7 @@ static NSString* const kCacheEntryExpirationDateKey = @"exp_date"; - (void)postSaveNotification; - (void)saveCacheNotification:(NSNotification*)inNotification; +- (void)shutdownNotification:(NSNotification*)inNotification; @end @@ -90,12 +92,17 @@ static NSString* const kCacheEntryExpirationDateKey = @"exp_date"; selector:@selector(saveCacheNotification:) name:kCacheIndexSaveNotificationName object:self]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(shutdownNotification:) + name:NSApplicationWillTerminateNotification + object:nil]; } return self; } - (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; [mURLToEntryMap release]; [mURLToImageMap release]; [super dealloc]; @@ -261,6 +268,9 @@ static NSString* const kCacheEntryExpirationDateKey = @"exp_date"; - (void)postSaveNotification { + if (mSuppressSaveNotification) + return; + NSNotification* saveCacheNote = [NSNotification notificationWithName:kCacheIndexSaveNotificationName object:self userInfo:nil]; @@ -278,4 +288,29 @@ static NSString* const kCacheEntryExpirationDateKey = @"exp_date"; NSLog(@"Failed to save site icon cache index"); } +- (void)shutdownNotification:(NSNotification*)inNotification +{ + // Clear out expired icons. Exempt anything that was requested during this + // session (mostly to avoid making the "lost bookmark icons" issue worse). + NSMutableSet* removalCandidateURLs = [NSMutableSet setWithArray:[mURLToEntryMap allKeys]]; + NSSet* memoryCacheURLs = [NSSet setWithArray:[mURLToImageMap allKeys]]; + [removalCandidateURLs minusSet:memoryCacheURLs]; + + mSuppressSaveNotification = YES; + NSEnumerator* urlEnumerator = [removalCandidateURLs objectEnumerator]; + NSString* url; + time_t startTime = time(NULL); + while ((url = [urlEnumerator nextObject])) { + BOOL expired; + NSString* uuid = [self UUIDForURL:url expired:&expired]; + if (uuid && expired) + [self removeImageForURL:url uuid:uuid]; + // Never spend more than a second or two doing cleanup, so we don't slam + // first-upgrade users (or users who visit a lot of sites over a very long + // session) at shutdown. + if (time(NULL) - startTime > 1) + break; + } +} + @end