diff --git a/netwerk/cache/src/nsMemoryCacheDevice.cpp b/netwerk/cache/src/nsMemoryCacheDevice.cpp index 325ba5dd4c2b..7f10bc09ff2d 100644 --- a/netwerk/cache/src/nsMemoryCacheDevice.cpp +++ b/netwerk/cache/src/nsMemoryCacheDevice.cpp @@ -129,7 +129,10 @@ nsMemoryCacheDevice::GetTransportForEntry( nsCacheEntry * entry, if (!*transport) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(*transport); - return entry->SetData(*transport); + rv = entry->SetData(*transport); + if (NS_SUCCEEDED(rv)) + NS_STATIC_CAST(nsMemoryCacheTransport *, *transport)->SetCacheEntry(entry); + return rv; } } diff --git a/netwerk/cache/src/nsMemoryCacheTransport.cpp b/netwerk/cache/src/nsMemoryCacheTransport.cpp index 288cf2be6a7f..0739492f3785 100644 --- a/netwerk/cache/src/nsMemoryCacheTransport.cpp +++ b/netwerk/cache/src/nsMemoryCacheTransport.cpp @@ -22,6 +22,7 @@ */ #include "nsMemoryCacheTransport.h" +#include "nsCacheEntry.h" #include "nsIProxyObjectManager.h" #include "nsIServiceManager.h" #include "nsCRT.h" @@ -81,7 +82,8 @@ nsReadFromInputStream(nsIOutputStream *aOutput, //---------------------------------------------------------------------------- nsMemoryCacheTransport::nsMemoryCacheTransport() - : mOutputStream(nsnull) + : mCacheEntry(nsnull) + , mOutputStream(nsnull) , mSegmentSize(NS_MEMORY_CACHE_SEGMENT_SIZE) , mMaxSize(NS_MEMORY_CACHE_BUFFER_SIZE) , mSegments(nsnull) @@ -166,6 +168,10 @@ nsMemoryCacheTransport::AddToBytesWritten(PRUint32 aCount) req->Process(); } + // update the data size recorded in the cache entry + if (mCacheEntry) + mCacheEntry->SetDataSize(mWriteCursor); + return NS_OK; } @@ -185,7 +191,7 @@ nsresult nsMemoryCacheTransport::ReadRequestCompleted(nsMemoryCacheReadRequest *aReader) { // remove the reader from the list of readers - PR_REMOVE_LINK(aReader); + PR_REMOVE_AND_INIT_LINK(aReader); aReader->SetTransport(nsnull); return NS_OK; } diff --git a/netwerk/cache/src/nsMemoryCacheTransport.h b/netwerk/cache/src/nsMemoryCacheTransport.h index 3ba25bbe73aa..8f052bb8c476 100644 --- a/netwerk/cache/src/nsMemoryCacheTransport.h +++ b/netwerk/cache/src/nsMemoryCacheTransport.h @@ -37,6 +37,7 @@ #define NS_MEMORY_CACHE_SEGMENT_SIZE 1024 #define NS_MEMORY_CACHE_BUFFER_SIZE 1024 * 1024 +class nsCacheEntry; class nsMemoryCacheReadRequest; class nsMemoryCacheIS; // non-blocking input stream class nsMemoryCacheBS; // blocking stream base class @@ -59,6 +60,8 @@ public: nsresult Init(PRUint32 aBufSegmentSize, PRUint32 aBufMaxSize); + void SetCacheEntry(nsCacheEntry *e) { mCacheEntry = e; } + /* private */ nsresult GetReadSegment(PRUint32 aOffset, char **aPtr, PRUint32 *aCount); @@ -93,6 +96,8 @@ private: nsSegment *GetNthSegment(PRUint32 aIndex); private: + nsCacheEntry *mCacheEntry; + nsMemoryCacheBOS *mOutputStream; // weak ref PRCList mInputStreams; // weak ref to objects PRCList mReadRequests; // weak ref to objects