Ignore:
Timestamp:
Sep 21, 2009, 12:55:04 PM (13 years ago)
Author:
livings124
Message:

better use of the cache object for tracker favicons, so if an icon is removed from the cache, it will be fetched again the next time it's needed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/InfoWindowController.m

    r9154 r9156  
    196196    {
    197197        fTrackerIconCache = [[NSCache alloc] init];
    198         fTrackerIconLoaded = [[NSMutableSet alloc] init];
     198        fTrackerIconLoading = [[NSMutableSet alloc] init];
    199199    }
    200200    else
     
    239239   
    240240    [fTrackerIconCache release];
    241     [fTrackerIconLoaded release];
     241    [fTrackerIconLoading release];
    242242   
    243243    [fPreviewPanel release];
     
    930930           
    931931            //let's try getting the favicon without using any subdomains
    932             NSURL * favIconUrl;
     932            NSString * baseAddress;
    933933            if ([hostComponents count] > 1)
    934                 favIconUrl = [NSURL URLWithString: [NSString stringWithFormat: @"%@://%@.%@/favicon.ico", [address scheme],
    935                                 [hostComponents objectAtIndex: [hostComponents count] - 2], [hostComponents lastObject]]];
     934                baseAddress = [NSString stringWithFormat: @"%@://%@.%@", [address scheme],
     935                                [hostComponents objectAtIndex: [hostComponents count] - 2], [hostComponents lastObject]];
    936936            else
    937                 favIconUrl = [NSURL URLWithString: [NSString stringWithFormat: @"%@://%@/favicon.ico", [address scheme],
    938                                 [hostComponents lastObject]]];
    939            
    940             NSImage * icon = nil;
    941             if ([fTrackerIconLoaded containsObject: favIconUrl])
    942                 icon = [fTrackerIconCache objectForKey: favIconUrl];
    943             else
    944                 [NSThread detachNewThreadSelector: @selector(loadTrackerIcon:) toTarget: self withObject: favIconUrl];
    945            
    946             return icon;
     937                baseAddress = [NSString stringWithFormat: @"%@://%@", [address scheme], [hostComponents lastObject]];
     938           
     939            id icon = [fTrackerIconCache objectForKey: baseAddress];
     940            if (!icon && ![fTrackerIconLoading containsObject: baseAddress])
     941            {
     942                [fTrackerIconLoading addObject: baseAddress];
     943                [NSThread detachNewThreadSelector: @selector(loadTrackerIcon:) toTarget: self withObject: baseAddress];
     944            }
     945           
     946            return (icon && icon != [NSNull null]) ? icon : nil;
    947947        }
    948948        if ([ident isEqualToString: @"Address"])
     
    954954}
    955955
    956 - (void) loadTrackerIcon: (NSURL *) favIconUrl
     956- (void) loadTrackerIcon: (NSString *) baseAddress
    957957{
    958958    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    959959   
    960     [fTrackerIconLoaded addObject: favIconUrl];
    961    
     960    NSURL * favIconUrl = [NSURL URLWithString: [baseAddress stringByAppendingString: @"/favicon.ico"]];
    962961    NSImage * icon = [[NSImage alloc] initWithContentsOfURL: favIconUrl];
    963962    if (icon)
    964963    {
    965         [fTrackerIconCache setObject: icon forKey: favIconUrl];
     964        [fTrackerIconCache setObject: icon forKey: baseAddress];
    966965        [icon release];
    967966    }
    968    
     967    else
     968        [fTrackerIconCache setObject: [NSNull null] forKey: baseAddress];
     969   
     970    [fTrackerIconLoading removeObject: baseAddress];
     971
    969972    [pool drain];
    970973}
Note: See TracChangeset for help on using the changeset viewer.