Bug 536316 - e10s HTTP: channel refcounting. r=jduell

This commit is contained in:
josh@joshmatthews.net 2010-04-24 00:19:33 +10:00
parent 24be06f9cd
commit c6adba047f
5 changed files with 27 additions and 8 deletions

View File

@ -99,8 +99,8 @@ NeckoChild::DeallocPHttpChannel(PHttpChannelChild* channel)
{
NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPHttpChannel called by non-child!");
HttpChannelChild *p = static_cast<HttpChannelChild*>(channel);
p->Release();
// Delete channel (HttpChannelChild's refcnt must already hit 0 to get here)
delete channel;
return true;
}

View File

@ -67,8 +67,20 @@ HttpChannelChild::~HttpChannelChild()
// HttpChannelChild::nsISupports
//-----------------------------------------------------------------------------
NS_IMPL_ADDREF_INHERITED(HttpChannelChild, HttpBaseChannel)
NS_IMPL_RELEASE_INHERITED(HttpChannelChild, HttpBaseChannel)
// Override nsHashPropertyBag's AddRef: we don't need thread-safe refcnt
NS_IMPL_ADDREF(HttpChannelChild)
NS_IMPL_RELEASE_WITH_DESTROY(HttpChannelChild, RefcountHitZero())
void
HttpChannelChild::RefcountHitZero()
{
if (mWasOpened) {
// NeckoChild::DeallocPHttpChannel will delete this
PHttpChannelChild::Send__delete__(this);
} else {
delete this; // we never opened IPDL channel
}
}
NS_INTERFACE_MAP_BEGIN(HttpChannelChild)
NS_INTERFACE_MAP_ENTRY(nsIRequest)
@ -158,6 +170,10 @@ HttpChannelChild::RecvOnStopRequest(const nsresult& statusCode)
nsresult rv = mListener->OnStopRequest(this, mListenerContext, statusCode);
mListener = 0;
mListenerContext = 0;
// Corresponding AddRef in AsyncOpen().
this->Release();
if (!NS_SUCCEEDED(rv)) {
// TODO: Cancel request: see notes in OnStartRequest
return false;
@ -218,7 +234,8 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext)
if (NS_FAILED(rv))
return rv;
// This corresponds to Release() in DeallocPHttpChannel
// The socket transport layer in the chrome process now has a logical ref to
// us, until either OnStopRequest or OnRedirect is called.
this->AddRef();
// TODO: Combine constructor and AsyncOpen to save one IPC msg

View File

@ -120,6 +120,7 @@ public:
NS_IMETHOD SetPriority(PRInt32 value);
protected:
void RefcountHitZero();
bool RecvOnStartRequest(const nsHttpResponseHead& responseHead);
bool RecvOnDataAvailable(const nsCString& data,
const PRUint32& offset,

View File

@ -103,12 +103,11 @@ HttpChannelParent::RecvAsyncOpen(const IPC::URI& aURI,
if (NS_FAILED(rv))
return false; // TODO: send fail msg to child, return true
nsCOMPtr<nsIChannel> chan;
rv = NS_NewChannel(getter_AddRefs(chan), uri, ios, nsnull, nsnull, loadFlags);
rv = NS_NewChannel(getter_AddRefs(mChannel), uri, ios, nsnull, nsnull, loadFlags);
if (NS_FAILED(rv))
return false; // TODO: send fail msg to child, return true
nsHttpChannel *httpChan = static_cast<nsHttpChannel *>(chan.get());
nsHttpChannel *httpChan = static_cast<nsHttpChannel *>(mChannel.get());
if (originalUri)
httpChan->SetOriginalURI(originalUri);

View File

@ -78,6 +78,8 @@ protected:
const PRBool& forceAllowThirdPartyCookie);
virtual bool RecvSetPriority(const PRUint16& priority);
nsCOMPtr<nsIChannel> mChannel;
};
} // namespace net