bug 795305 - http channel can drop callback references sooner on asyncopen failures r=jduell

--HG--
extra : rebase_source : 95240c7f54ef177e285217f4c35cd2474f78aed2
This commit is contained in:
Patrick McManus 2012-10-02 20:18:34 -04:00
parent 3b7c8e5c4f
commit 470dbbad79
3 changed files with 28 additions and 38 deletions

View File

@ -1420,6 +1420,15 @@ HttpBaseChannel::SetNewListener(nsIStreamListener *aListener, nsIStreamListener
// HttpBaseChannel helpers
//-----------------------------------------------------------------------------
void
HttpBaseChannel::ReleaseListeners()
{
mListener = nullptr;
mListenerContext = nullptr;
mCallbacks = nullptr;
mProgressSink = nullptr;
}
void
HttpBaseChannel::DoNotifyListener()
{
@ -1430,14 +1439,12 @@ HttpBaseChannel::DoNotifyListener()
mListener->OnStartRequest(this, mListenerContext);
mIsPending = false;
mListener->OnStopRequest(this, mListenerContext, mStatus);
mListener = 0;
mListenerContext = 0;
} else {
mIsPending = false;
}
// We have to make sure to drop the reference to the callbacks too
mCallbacks = nullptr;
mProgressSink = nullptr;
// We have to make sure to drop the references to listeners and callbacks
// no longer needed
ReleaseListeners();
DoNotifyListenerCleanup();
}

View File

@ -193,6 +193,9 @@ protected:
void DoNotifyListener();
virtual void DoNotifyListenerCleanup() = 0;
// drop reference to listener, its callbacks, and the progress sink
void ReleaseListeners();
nsresult ApplyContentConversions();
void AddCookiesToRequest();

View File

@ -1649,13 +1649,7 @@ nsHttpChannel::OpenRedirectChannel(nsresult rv)
notifier.RedirectSucceeded();
// disconnect from the old listeners...
mListener = nullptr;
mListenerContext = nullptr;
// ...and the old callbacks
mCallbacks = nullptr;
mProgressSink = nullptr;
ReleaseListeners();
return NS_OK;
}
@ -1716,13 +1710,7 @@ nsHttpChannel::ContinueDoReplaceWithProxy(nsresult rv)
notifier.RedirectSucceeded();
// disconnect from the old listeners...
mListener = nullptr;
mListenerContext = nullptr;
// ...and the old callbacks
mCallbacks = nullptr;
mProgressSink = nullptr;
ReleaseListeners();
return rv;
}
@ -2284,13 +2272,7 @@ nsHttpChannel::ContinueProcessFallback(nsresult rv)
notifier.RedirectSucceeded();
// disconnect from our listener
mListener = 0;
mListenerContext = 0;
// and from our callbacks
mCallbacks = nullptr;
mProgressSink = nullptr;
ReleaseListeners();
mFallingBack = true;
@ -4130,13 +4112,8 @@ nsHttpChannel::ContinueProcessRedirection(nsresult rv)
notifier.RedirectSucceeded();
// disconnect from our listener
mListener = 0;
mListenerContext = 0;
ReleaseListeners();
// and from our callbacks
mCallbacks = nullptr;
mProgressSink = nullptr;
return NS_OK;
}
@ -4319,8 +4296,10 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
nsresult rv;
rv = NS_CheckPortSafety(mURI);
if (NS_FAILED(rv))
if (NS_FAILED(rv)) {
ReleaseListeners();
return rv;
}
// Remember the cookie header that was set, if any
const char *cookieHeader = mRequestHead.PeekHeader(nsHttp::Cookie);
@ -4355,7 +4334,11 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
if (!mProxyInfo && NS_SUCCEEDED(ResolveProxy()))
return NS_OK;
return BeginConnect();
rv = BeginConnect();
if (NS_FAILED(rv))
ReleaseListeners();
return rv;
}
nsresult
@ -5007,8 +4990,6 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st
if (mListener) {
LOG((" calling OnStopRequest\n"));
mListener->OnStopRequest(this, mListenerContext, status);
mListener = 0;
mListenerContext = 0;
}
if (mCacheEntry) {
@ -5041,8 +5022,7 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st
// We don't need this info anymore
CleanRedirectCacheChainIfNecessary();
mCallbacks = nullptr;
mProgressSink = nullptr;
ReleaseListeners();
return NS_OK;
}