Bug 533038 - 6. Add flush-cache-entry to flush specific jars from the cache, r=taras a=blocking-beta6

This commit is contained in:
Michael Wu 2010-09-08 20:39:19 -07:00
parent 2be2e1f425
commit 9c8e7039fc

View File

@ -1050,6 +1050,7 @@ nsZipReaderCache::Init(PRUint32 cacheSize)
{
os->AddObserver(this, "memory-pressure", PR_TRUE);
os->AddObserver(this, "chrome-flush-caches", PR_TRUE);
os->AddObserver(this, "flush-cache-entry", PR_TRUE);
}
// ignore failure of the observer registration.
@ -1317,6 +1318,32 @@ nsZipReaderCache::Observe(nsISupports *aSubject,
mZips.Enumerate(DropZipReaderCache, nsnull);
mZips.Reset();
}
else if (strcmp(aTopic, "flush-cache-entry") == 0) {
nsCOMPtr<nsIFile> file = do_QueryInterface(aSubject);
if (!file)
return NS_OK;
nsCAutoString uri;
if (NS_FAILED(file->GetNativePath(uri)))
return NS_OK;
uri.Insert(NS_LITERAL_CSTRING("file:"), 0);
nsCStringKey key(uri);
nsAutoLock lock(mLock);
nsJAR* zip = static_cast<nsJAR*>(static_cast<nsIZipReader*>(mZips.Get(&key)));
if (!zip)
return NS_OK;
#ifdef ZIP_CACHE_HIT_RATE
mZipCacheFlushes++;
#endif
zip->SetZipReaderCache(nsnull);
mZips.Remove(&key);
NS_RELEASE(zip);
}
return NS_OK;
}