b=406849, SetCacheAsFile(true) on memory-cached loads is broken, patch from bz, r+sr=bisei, a=schrep
authorvladimir@pobox.com
Fri, 07 Dec 2007 14:07:03 -0800
changeset 8818 450b1f89292447f35eff6c3a6cfe2ba0d0fc416a
parent 8817 4098ae5668451ef9c581ea6b9c4211d260faec77
child 8819 6ff807a919ba2b710173c7838b18d649ce16b706
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherderautoland@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersschrep
bugs406849
milestone1.9b2pre
b=406849, SetCacheAsFile(true) on memory-cached loads is broken, patch from bz, r+sr=bisei, a=schrep
netwerk/cache/src/nsCacheEntryDescriptor.cpp
--- a/netwerk/cache/src/nsCacheEntryDescriptor.cpp
+++ b/netwerk/cache/src/nsCacheEntryDescriptor.cpp
@@ -317,31 +317,41 @@ nsCacheEntryDescriptor::GetAccessGranted
 
 NS_IMETHODIMP
 nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *result)
 {
     NS_ENSURE_ARG_POINTER(result);
     nsCacheServiceAutoLock lock;
     if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;
     
-    return mCacheEntry->StoragePolicy();
+    *result = mCacheEntry->StoragePolicy();
+    return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsCacheEntryDescriptor::SetStoragePolicy(nsCacheStoragePolicy policy)
 {
     nsCacheServiceAutoLock lock;
     if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;
     // XXX validate policy against session?
     
     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;
 }
 
 
 NS_IMETHODIMP
 nsCacheEntryDescriptor::GetFile(nsIFile ** result)