diff --git a/netwerk/cache/src/nsCacheService.cpp b/netwerk/cache/src/nsCacheService.cpp index 820053deb0f2..3822cb954b39 100644 --- a/netwerk/cache/src/nsCacheService.cpp +++ b/netwerk/cache/src/nsCacheService.cpp @@ -327,7 +327,7 @@ nsCacheService::CreateSession(const char * clientID, { *result = nsnull; - if (!(mEnableDiskDevice || mEnableMemoryDevice)) + if ((this == nsnull) || !(mEnableDiskDevice || mEnableMemoryDevice)) return NS_ERROR_NOT_AVAILABLE; nsCacheSession * session = new nsCacheSession(clientID, storagePolicy, streamBased); @@ -339,7 +339,48 @@ nsCacheService::CreateSession(const char * clientID, } -/* void visitEntries (in nsICacheVisitor visitor); */ +nsresult +nsCacheService::EvictEntriesForSession(nsCacheSession * session) +{ + return EvictEntriesForClient(session->ClientID()->get(), + session->StoragePolicy()); +} + + +nsresult +nsCacheService::EvictEntriesForClient(const char * clientID, + nsCacheStoragePolicy storagePolicy) +{ + if (this == nsnull) return NS_ERROR_NOT_AVAILABLE; + nsAutoLock lock(mCacheServiceLock); + nsresult rv = NS_OK; + + if (storagePolicy == nsICache::STORE_ANYWHERE || + storagePolicy == nsICache::STORE_ON_DISK) { + + if (mEnableDiskDevice) { + if (!mDiskDevice) { + rv = CreateDiskDevice(); + if (NS_FAILED(rv)) return rv; + } + rv = mDiskDevice->EvictEntries(clientID); + if (NS_FAILED(rv)) return rv; + } + } + + if (storagePolicy == nsICache::STORE_ANYWHERE || + storagePolicy == nsICache::STORE_IN_MEMORY) { + + if (mEnableMemoryDevice) { + rv = mMemoryDevice->EvictEntries(clientID); + if (NS_FAILED(rv)) return rv; + } + } + + return NS_OK; +} + + NS_IMETHODIMP nsCacheService::VisitEntries(nsICacheVisitor *visitor) { nsAutoLock lock(mCacheServiceLock); @@ -374,31 +415,7 @@ NS_IMETHODIMP nsCacheService::VisitEntries(nsICacheVisitor *visitor) NS_IMETHODIMP nsCacheService::EvictEntries(nsCacheStoragePolicy storagePolicy) { - nsresult rv; - - nsAutoLock lock(mCacheServiceLock); - - // XXX what should we do about error handling? - - if (storagePolicy == nsICache::STORE_ANYWHERE || storagePolicy == nsICache::STORE_ON_DISK) { - if (mEnableDiskDevice) { - if (!mDiskDevice) { - rv = CreateDiskDevice(); - if (NS_FAILED(rv)) return rv; - } - rv = mDiskDevice->EvictEntries(nsnull); - if (NS_FAILED(rv)) return rv; - } - } - - if (storagePolicy == nsICache::STORE_ANYWHERE || storagePolicy == nsICache::STORE_IN_MEMORY) { - if (mEnableMemoryDevice) { - rv = mMemoryDevice->EvictEntries(nsnull); - if (NS_FAILED(rv)) return rv; - } - } - - return NS_OK; + return EvictEntriesForClient(nsnull, storagePolicy); } diff --git a/netwerk/cache/src/nsCacheService.h b/netwerk/cache/src/nsCacheService.h index f87411edf71f..b50e0e4a243a 100644 --- a/netwerk/cache/src/nsCacheService.h +++ b/netwerk/cache/src/nsCacheService.h @@ -66,6 +66,11 @@ public: nsICacheListener * listener, nsICacheEntryDescriptor ** result); + nsresult EvictEntriesForSession(nsCacheSession * session); + + nsresult EvictEntriesForClient(const char * clientID, + nsCacheStoragePolicy storagePolicy); + /** * Methods called by nsCacheEntryDescriptor */ diff --git a/netwerk/cache/src/nsCacheSession.cpp b/netwerk/cache/src/nsCacheSession.cpp index 4c1f8507fcb8..67193243c008 100644 --- a/netwerk/cache/src/nsCacheSession.cpp +++ b/netwerk/cache/src/nsCacheSession.cpp @@ -97,5 +97,5 @@ NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const char *key, NS_IMETHODIMP nsCacheSession::EvictEntries() { - return NS_ERROR_NOT_IMPLEMENTED; + return nsCacheService::GlobalInstance()->EvictEntriesForSession(this); } diff --git a/netwerk/cache/src/nsDiskCacheDevice.cpp b/netwerk/cache/src/nsDiskCacheDevice.cpp index b09d8ed5d070..69d8a5b678a8 100644 --- a/netwerk/cache/src/nsDiskCacheDevice.cpp +++ b/netwerk/cache/src/nsDiskCacheDevice.cpp @@ -1122,7 +1122,7 @@ nsresult nsDiskCacheDevice::openOutputStream(nsIFile * file, nsIOutputStream ** return NS_OK; } else { nsCOMPtr transport; - nsresult rv = getTransportForFile(file, nsICache::ACCESS_WRITE, getter_AddRefs(transport)); + rv = getTransportForFile(file, nsICache::ACCESS_WRITE, getter_AddRefs(transport)); if (NS_FAILED(rv)) return rv; return transport->OpenOutputStream(0, ULONG_MAX, 0, result); }