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
This commit is contained in:
gagan%netscape.com
2000-03-14 01:30:57 +00:00
parent ba5e34466d
commit 7d1212b38e
6 changed files with 40 additions and 27 deletions

View File

@@ -6563,7 +6563,7 @@ NS_IMETHODIMP nsImapMockChannel::AsyncRead(PRUint32 startPosition, PRInt32 readC
if (cacheEntry && contentLength > 0 && !partialFlag)
{
nsCOMPtr<nsIChannel> 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

View File

@@ -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<nsIOutputStream> 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;
}

View File

@@ -75,7 +75,6 @@ protected:
private:
nsCOMPtr<nsCachedNetData> mCacheEntry;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsIChannel> mProxyChannel;
nsLoadFlags mLoadAttributes;
};

View File

@@ -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<nsIChannel> 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));

View File

@@ -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

View File

@@ -923,7 +923,7 @@ nsHTTPChannel::ReadFromCache(PRUint32 aStartPosition, PRInt32 aReadCount)
// Create a cache transport to read the cached response...
nsCOMPtr<nsIChannel> 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<nsIChannel> 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);