Bug 1401461. P1 - remove ChannelMediaResource::Listener::Revoke(). r=gerald

See comment 0 for the rationale. We check |aRequest != mResource->mChannel|
to know if a new channel is being loaded and the call should be aborted.

MozReview-Commit-ID: 6G1x7cXNvAq

--HG--
extra : rebase_source : 3114979192346e257f5d8040b8e0ffffa419d3f5
extra : source : eeb067bc2905dfa6fb5764fd42ebb78e1b71a61d
This commit is contained in:
JW Wang 2017-09-20 14:37:18 +08:00
Родитель 02939c27b3
Коммит 3ce1e10aba
2 изменённых файлов: 9 добавлений и 10 удалений

Просмотреть файл

@ -68,8 +68,9 @@ nsresult
ChannelMediaResource::Listener::OnStartRequest(nsIRequest* aRequest, ChannelMediaResource::Listener::OnStartRequest(nsIRequest* aRequest,
nsISupports* aContext) nsISupports* aContext)
{ {
if (!mResource) if (aRequest != mResource->mChannel) {
return NS_OK; return NS_OK;
}
return mResource->OnStartRequest(aRequest, mOffset); return mResource->OnStartRequest(aRequest, mOffset);
} }
@ -78,8 +79,9 @@ ChannelMediaResource::Listener::OnStopRequest(nsIRequest* aRequest,
nsISupports* aContext, nsISupports* aContext,
nsresult aStatus) nsresult aStatus)
{ {
if (!mResource) if (aRequest != mResource->mChannel) {
return NS_OK; return NS_OK;
}
return mResource->OnStopRequest(aRequest, aStatus); return mResource->OnStopRequest(aRequest, aStatus);
} }
@ -91,7 +93,9 @@ ChannelMediaResource::Listener::OnDataAvailable(nsIRequest* aRequest,
uint32_t aCount) uint32_t aCount)
{ {
// This might happen off the main thread. // This might happen off the main thread.
MOZ_DIAGNOSTIC_ASSERT(mResource); // Don't check |aRequest != mResource->mChannel| for it is a data race to read
// mResource->mChannel off the main thread. Instead we check the load ID to
// determine if the data is from an old channel.
return mResource->OnDataAvailable(mLoadID, aStream, aCount); return mResource->OnDataAvailable(mLoadID, aStream, aCount);
} }
@ -103,7 +107,7 @@ ChannelMediaResource::Listener::AsyncOnChannelRedirect(
nsIAsyncVerifyRedirectCallback* cb) nsIAsyncVerifyRedirectCallback* cb)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (mResource) { if (aOld == mResource->mChannel) {
rv = mResource->OnChannelRedirect(aOld, aNew, aFlags, mOffset); rv = mResource->OnChannelRedirect(aOld, aNew, aFlags, mOffset);
} }
@ -415,8 +419,6 @@ ChannelMediaResource::OnDataAvailable(uint32_t aLoadID,
uint32_t aCount) uint32_t aCount)
{ {
// This might happen off the main thread. // This might happen off the main thread.
// Don't assert |mChannel.get() == aRequest| since reading mChannel here off
// the main thread is a data race.
RefPtr<ChannelMediaResource> self = this; RefPtr<ChannelMediaResource> self = this;
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction( nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
@ -587,7 +589,6 @@ void ChannelMediaResource::CloseChannel()
} }
if (mListener) { if (mListener) {
mListener->Revoke();
mListener = nullptr; mListener = nullptr;
} }
} }

Просмотреть файл

@ -128,10 +128,8 @@ public:
NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
void Revoke() { mResource = nullptr; }
private: private:
RefPtr<ChannelMediaResource> mResource; const RefPtr<ChannelMediaResource> mResource;
const int64_t mOffset; const int64_t mOffset;
const uint32_t mLoadID; const uint32_t mLoadID;
}; };