From 12078dfe436b9246a1ed470e25630b2902855cf2 Mon Sep 17 00:00:00 2001 From: "vladimir@pobox.com" Date: Fri, 7 Dec 2007 14:07:03 -0800 Subject: [PATCH] b=406849, SetCacheAsFile(true) on memory-cached loads is broken, patch from bz, r+sr=bisei, a=schrep --- netwerk/cache/src/nsCacheEntryDescriptor.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/netwerk/cache/src/nsCacheEntryDescriptor.cpp b/netwerk/cache/src/nsCacheEntryDescriptor.cpp index aa50f7fb2842..409efd935632 100644 --- a/netwerk/cache/src/nsCacheEntryDescriptor.cpp +++ b/netwerk/cache/src/nsCacheEntryDescriptor.cpp @@ -322,7 +322,8 @@ nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *result) nsCacheServiceAutoLock lock; if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE; - return mCacheEntry->StoragePolicy(); + *result = mCacheEntry->StoragePolicy(); + return NS_OK; } @@ -336,7 +337,16 @@ nsCacheEntryDescriptor::SetStoragePolicy(nsCacheStoragePolicy policy) PRBool storageEnabled = PR_FALSE; storageEnabled = nsCacheService::IsStorageEnabledForPolicy_Locked(policy); if (!storageEnabled) return NS_ERROR_FAILURE; + + // Don't change the storage policy of entries we can't write + if (!(mAccessGranted & ACCESS_WRITE)) + return NS_ERROR_NOT_AVAILABLE; + // Don't allow a cache entry to move from memory-only to anything else + if (mCacheEntry->StoragePolicy() == nsICache::STORE_IN_MEMORY && + policy != nsICache::STORE_IN_MEMORY) + return NS_ERROR_NOT_AVAILABLE; + mCacheEntry->SetStoragePolicy(policy); mCacheEntry->MarkEntryDirty(); return NS_OK;