From a31f0fcaf2c9db00c54e071c0ea8f0932fba4453 Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Thu, 1 Mar 2001 02:49:26 +0000 Subject: [PATCH] [not part of the build] Added code to update the entry's data size as data is streamed to the memory cache. git-svn-id: svn://10.0.0.236/trunk@88265 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/netwerk/cache/src/nsMemoryCacheDevice.cpp | 5 ++++- mozilla/netwerk/cache/src/nsMemoryCacheTransport.cpp | 10 ++++++++-- mozilla/netwerk/cache/src/nsMemoryCacheTransport.h | 5 +++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mozilla/netwerk/cache/src/nsMemoryCacheDevice.cpp b/mozilla/netwerk/cache/src/nsMemoryCacheDevice.cpp index 325ba5dd4c2..7f10bc09ff2 100644 --- a/mozilla/netwerk/cache/src/nsMemoryCacheDevice.cpp +++ b/mozilla/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/mozilla/netwerk/cache/src/nsMemoryCacheTransport.cpp b/mozilla/netwerk/cache/src/nsMemoryCacheTransport.cpp index 288cf2be6a7..0739492f378 100644 --- a/mozilla/netwerk/cache/src/nsMemoryCacheTransport.cpp +++ b/mozilla/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/mozilla/netwerk/cache/src/nsMemoryCacheTransport.h b/mozilla/netwerk/cache/src/nsMemoryCacheTransport.h index 3ba25bbe73a..8f052bb8c47 100644 --- a/mozilla/netwerk/cache/src/nsMemoryCacheTransport.h +++ b/mozilla/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