Fix bug 111049 "add attribute to nsICacheSession to detect device availability". sr=darin.

This commit is contained in:
gordon%netscape.com 2002-01-24 01:25:25 +00:00
parent efd43a6ced
commit b032cdadb8
4 changed files with 42 additions and 0 deletions

View File

@ -71,4 +71,10 @@ interface nsICacheSession : nsISupports
* Evict all entries for this session's clientID according to its storagePolicy.
*/
void evictEntries();
/**
* Return whether any of the cache devices implied by the session storage policy
* are currently enabled for instantiation if they don't already exist.
*/
PRBool isStorageEnabled();
};

View File

@ -555,6 +555,31 @@ nsCacheService::EvictEntriesForClient(const char * clientID,
}
nsresult
nsCacheService::IsStorageEnabledForPolicy(nsCacheStoragePolicy storagePolicy,
PRBool * result)
{
if (gService == nsnull) return NS_ERROR_NOT_AVAILABLE;
nsAutoLock lock(gService->mCacheServiceLock);
if (gService->mEnableMemoryDevice &&
(storagePolicy == nsICache::STORE_ANYWHERE ||
storagePolicy == nsICache::STORE_IN_MEMORY)) {
*result = PR_TRUE;
}
else if (gService->mEnableDiskDevice &&
(storagePolicy == nsICache::STORE_ANYWHERE ||
storagePolicy == nsICache::STORE_ON_DISK ||
storagePolicy == nsICache::STORE_ON_DISK_AS_FILE)) {
*result = PR_TRUE;
} else {
*result = PR_FALSE;
}
return NS_OK;
}
NS_IMETHODIMP nsCacheService::VisitEntries(nsICacheVisitor *visitor)
{
nsAutoLock lock(mCacheServiceLock);

View File

@ -77,6 +77,9 @@ public:
nsresult EvictEntriesForClient(const char * clientID,
nsCacheStoragePolicy storagePolicy);
static nsresult IsStorageEnabledForPolicy(nsCacheStoragePolicy storagePolicy,
PRBool * result);
/**
* Methods called by nsCacheEntryDescriptor
*/

View File

@ -104,3 +104,11 @@ NS_IMETHODIMP nsCacheSession::EvictEntries()
{
return nsCacheService::GlobalInstance()->EvictEntriesForSession(this);
}
NS_IMETHODIMP nsCacheSession::IsStorageEnabled(PRBool *result)
{
return nsCacheService::IsStorageEnabledForPolicy(StoragePolicy(), result);
}