From 7d1212b38ee634604fdb7fd6a8fbcd9ac88f3dfb Mon Sep 17 00:00:00 2001 From: "gagan%netscape.com" Date: Tue, 14 Mar 2000 01:30:57 +0000 Subject: [PATCH] Fix for bug 30385. we were keeping a proxy channel in cache unnecessarily. Resulting in huge leaks. This was a left over from rpotts changes to cache. a=jar, perm to checkin on the branch=chofman git-svn-id: svn://10.0.0.236/branches/nscp_beta1_BRANCH@62795 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/mailnews/imap/src/nsImapProtocol.cpp | 2 +- .../netwerk/cache/mgr/nsCacheEntryChannel.cpp | 48 +++++++++++++------ .../netwerk/cache/mgr/nsCacheEntryChannel.h | 1 - mozilla/netwerk/cache/mgr/nsCachedNetData.cpp | 5 +- .../netwerk/cache/public/nsICachedNetData.idl | 7 +-- .../protocol/http/src/nsHTTPChannel.cpp | 4 +- 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/mozilla/mailnews/imap/src/nsImapProtocol.cpp b/mozilla/mailnews/imap/src/nsImapProtocol.cpp index a8b40ad0240..66bed194d09 100644 --- a/mozilla/mailnews/imap/src/nsImapProtocol.cpp +++ b/mozilla/mailnews/imap/src/nsImapProtocol.cpp @@ -6563,7 +6563,7 @@ NS_IMETHODIMP nsImapMockChannel::AsyncRead(PRUint32 startPosition, PRInt32 readC if (cacheEntry && contentLength > 0 && !partialFlag) { nsCOMPtr cacheChannel; - rv = cacheEntry->NewChannel(m_loadGroup, this, getter_AddRefs(cacheChannel)); + rv = cacheEntry->NewChannel(m_loadGroup, getter_AddRefs(cacheChannel)); if (NS_SUCCEEDED(rv)) { // turn around and make our ref on m_url an owning ref...and force the url to remove diff --git a/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.cpp b/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.cpp index 0a7f51dee7d..664fc14d24d 100644 --- a/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.cpp +++ b/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.cpp @@ -30,9 +30,14 @@ #include "nsIStreamListener.h" #include "nsIAllocator.h" -nsCacheEntryChannel::nsCacheEntryChannel(nsCachedNetData* aCacheEntry, nsIChannel* aChannel, - nsILoadGroup* aLoadGroup): - nsChannelProxy(aChannel), mCacheEntry(aCacheEntry), mLoadGroup(aLoadGroup), mLoadAttributes(0) +nsCacheEntryChannel::nsCacheEntryChannel( + nsCachedNetData* aCacheEntry, + nsIChannel* aChannel, + nsILoadGroup* aLoadGroup): + nsChannelProxy(aChannel), + mCacheEntry(aCacheEntry), + mLoadGroup(aLoadGroup), + mLoadAttributes(0) { NS_ASSERTION(aCacheEntry->mChannelCount < 0xFF, "Overflowed channel counter"); mCacheEntry->mChannelCount++; @@ -44,14 +49,20 @@ nsCacheEntryChannel::~nsCacheEntryChannel() mCacheEntry->mChannelCount--; } -NS_IMPL_THREADSAFE_ISUPPORTS3(nsCacheEntryChannel, nsISupports, nsIChannel, nsIRequest) +NS_IMPL_THREADSAFE_ISUPPORTS3(nsCacheEntryChannel, + nsISupports, + nsIChannel, + nsIRequest) // A proxy for nsIOutputStream class CacheOutputStream : public nsIOutputStream { public: - CacheOutputStream(nsIOutputStream *aOutputStream, nsCachedNetData *aCacheEntry): - mOutputStream(aOutputStream), mCacheEntry(aCacheEntry), mStartTime(PR_IntervalNow()) + CacheOutputStream(nsIOutputStream *aOutputStream, + nsCachedNetData *aCacheEntry): + mOutputStream(aOutputStream), + mCacheEntry(aCacheEntry), + mStartTime(PR_IntervalNow()) { NS_INIT_REFCNT(); } virtual ~CacheOutputStream() { @@ -90,12 +101,14 @@ protected: NS_IMPL_THREADSAFE_ISUPPORTS1(CacheOutputStream, nsIOutputStream) NS_IMETHODIMP -nsCacheEntryChannel::OpenOutputStream(PRUint32 aStartPosition, nsIOutputStream* *aOutputStream) +nsCacheEntryChannel::OpenOutputStream(PRUint32 aStartPosition, + nsIOutputStream* *aOutputStream) { nsresult rv; nsCOMPtr baseOutputStream; - rv = mChannel->OpenOutputStream(aStartPosition, getter_AddRefs(baseOutputStream)); + rv = mChannel->OpenOutputStream(aStartPosition, + getter_AddRefs(baseOutputStream)); if (NS_FAILED(rv)) return rv; mCacheEntry->NoteUpdate(); @@ -110,16 +123,19 @@ nsCacheEntryChannel::OpenOutputStream(PRUint32 aStartPosition, nsIOutputStream* } NS_IMETHODIMP -nsCacheEntryChannel::OpenInputStream(PRUint32 aStartPosition, PRInt32 aReadCount, - nsIInputStream* *aInputStream) +nsCacheEntryChannel::OpenInputStream(PRUint32 aStartPosition, + PRInt32 aReadCount, + nsIInputStream* *aInputStream) { mCacheEntry->NoteAccess(); return mChannel->OpenInputStream(aStartPosition, aReadCount, aInputStream); } NS_IMETHODIMP -nsCacheEntryChannel::AsyncRead(PRUint32 aStartPosition, PRInt32 aReadCount, - nsISupports *aContext, nsIStreamListener *aListener) +nsCacheEntryChannel::AsyncRead(PRUint32 aStartPosition, + PRInt32 aReadCount, + nsISupports *aContext, + nsIStreamListener *aListener) { nsresult rv; @@ -138,9 +154,11 @@ nsCacheEntryChannel::AsyncRead(PRUint32 aStartPosition, PRInt32 aReadCount, // No async writes allowed to the cache yet NS_IMETHODIMP -nsCacheEntryChannel::AsyncWrite(nsIInputStream *aFromStream, PRUint32 aStartPosition, - PRInt32 aWriteCount, nsISupports *aContext, - nsIStreamObserver *aObserver) +nsCacheEntryChannel::AsyncWrite(nsIInputStream *aFromStream, + PRUint32 aStartPosition, + PRInt32 aWriteCount, + nsISupports *aContext, + nsIStreamObserver *aObserver) { return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.h b/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.h index d9078e0d7c2..596357a6a1c 100644 --- a/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.h +++ b/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.h @@ -75,7 +75,6 @@ protected: private: nsCOMPtr mCacheEntry; nsCOMPtr mLoadGroup; - nsCOMPtr mProxyChannel; nsLoadFlags mLoadAttributes; }; diff --git a/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp b/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp index 44daeae3d98..a7348206e2c 100644 --- a/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp +++ b/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp @@ -1035,7 +1035,7 @@ nsCachedNetData::GetCache(nsINetDataCache* *aCache) } NS_IMETHODIMP -nsCachedNetData::NewChannel(nsILoadGroup* aLoadGroup, nsIChannel* aProxyChannel, nsIChannel* *aChannel) +nsCachedNetData::NewChannel(nsILoadGroup* aLoadGroup, nsIChannel* *aChannel) { nsresult rv; nsCOMPtr channel; @@ -1049,7 +1049,6 @@ nsCachedNetData::NewChannel(nsILoadGroup* aLoadGroup, nsIChannel* aProxyChannel, cacheEntryChannel = new nsCacheEntryChannel(this, channel, aLoadGroup); if (!cacheEntryChannel) return NS_ERROR_OUT_OF_MEMORY; - cacheEntryChannel->mProxyChannel = aProxyChannel; *aChannel = cacheEntryChannel; NS_ADDREF(*aChannel); @@ -1089,7 +1088,7 @@ public: // Just in case the protocol handler forgot to set this flag... mCacheEntry->SetFlag(nsCachedNetData::UPDATE_IN_PROGRESS); - rv = mCacheEntry->NewChannel(0, 0, getter_AddRefs(mChannel)); + rv = mCacheEntry->NewChannel(0, getter_AddRefs(mChannel)); if (NS_FAILED(rv)) return rv; return mChannel->OpenOutputStream(aStartingOffset, getter_AddRefs(mCacheStream)); diff --git a/mozilla/netwerk/cache/public/nsICachedNetData.idl b/mozilla/netwerk/cache/public/nsICachedNetData.idl index 47585a6efae..3cba8045240 100644 --- a/mozilla/netwerk/cache/public/nsICachedNetData.idl +++ b/mozilla/netwerk/cache/public/nsICachedNetData.idl @@ -210,12 +210,9 @@ interface nsICachedNetData : nsISupports * * Though nsIChannel provides for both async and synchronous I/O APIs, both * may not be implemented. Only AsyncRead() and OpenOutputStream() is - * required. The aProxyChannel argument allows another channel to be - * specified as the proffered argument to nsIStreamListener methods rather - * than the cache's own channel. + * required. */ - nsIChannel newChannel(in nsILoadGroup aLoadGroup, - in nsIChannel aProxyChannel); + nsIChannel newChannel(in nsILoadGroup aLoadGroup); /** * This method can be used by a caching protocol handler to store data in diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPChannel.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPChannel.cpp index 1a18097374e..b55b80784ee 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPChannel.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHTTPChannel.cpp @@ -923,7 +923,7 @@ nsHTTPChannel::ReadFromCache(PRUint32 aStartPosition, PRInt32 aReadCount) // Create a cache transport to read the cached response... nsCOMPtr cacheTransport; - rv = mCacheEntry->NewChannel(mLoadGroup, this, getter_AddRefs(cacheTransport)); + rv = mCacheEntry->NewChannel(mLoadGroup, getter_AddRefs(cacheTransport)); if (NS_FAILED(rv)) return rv; mRequest->SetTransport(cacheTransport); @@ -1832,7 +1832,7 @@ nsHTTPChannel::ProcessNotModifiedResponse(nsIStreamListener *aListener) // Create a cache transport to read the cached response... nsCOMPtr cacheTransport; - rv = mCacheEntry->NewChannel(mLoadGroup, this, getter_AddRefs(cacheTransport)); + rv = mCacheEntry->NewChannel(mLoadGroup, getter_AddRefs(cacheTransport)); if (NS_FAILED(rv)) return rv; mRequest->SetTransport(cacheTransport);