Fix bug 75171 "implement nsCacheSession::EvictEntries", sr = darin.

This commit is contained in:
gordon%netscape.com 2001-04-09 08:14:08 +00:00
Родитель 80b13132e3
Коммит 0e2c10a02c
4 изменённых файлов: 51 добавлений и 29 удалений

71
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);
}

5
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
*/

2
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);
}

2
netwerk/cache/src/nsDiskCacheDevice.cpp поставляемый
Просмотреть файл

@ -1122,7 +1122,7 @@ nsresult nsDiskCacheDevice::openOutputStream(nsIFile * file, nsIOutputStream **
return NS_OK;
} else {
nsCOMPtr<nsITransport> 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);
}