Bug 1418430. P1 - always check "reopen on error" when a connection is closed. r=bechen,gerald

The server might send us fewer bytes than requested. So we also need
"reopen on error" in this case as well.

MozReview-Commit-ID: Fi82x4h1TZ0

--HG--
extra : rebase_source : 3a19838de9c11545f00778623735c7e9a5cb1439
This commit is contained in:
JW Wang 2017-11-22 10:35:48 +08:00
parent b444fbea2a
commit df2b00d7a6
3 changed files with 6 additions and 16 deletions

View File

@ -84,7 +84,7 @@ ChannelMediaResource::Listener::OnStopRequest(nsIRequest* aRequest,
MOZ_ASSERT(NS_IsMainThread());
if (!mResource)
return NS_OK;
return mResource->OnStopRequest(aRequest, aStatus, mReopenOnError);
return mResource->OnStopRequest(aRequest, aStatus);
}
nsresult
@ -371,9 +371,7 @@ ChannelMediaResource::ParseContentRangeHeader(nsIHttpChannel * aHttpChan,
}
nsresult
ChannelMediaResource::OnStopRequest(nsIRequest* aRequest,
nsresult aStatus,
bool aReopenOnError)
ChannelMediaResource::OnStopRequest(nsIRequest* aRequest, nsresult aStatus)
{
NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!");
NS_ASSERTION(!mSuspendAgent.IsSuspended(),
@ -393,7 +391,7 @@ ChannelMediaResource::OnStopRequest(nsIRequest* aRequest,
ModifyLoadFlags(loadFlags & ~nsIRequest::LOAD_BACKGROUND);
}
mCacheStream.NotifyDataEnded(mLoadID, aStatus, aReopenOnError);
mCacheStream.NotifyDataEnded(mLoadID, aStatus, true /*aReopenOnError*/);
return NS_OK;
}
@ -719,9 +717,6 @@ ChannelMediaResource::Resume()
if (mChannel) {
// Just wake up our existing channel
mChannelStatistics.Start();
// if an error occurs after Resume, assume it's because the server
// timed out the connection and we should reopen it.
mListener->SetReopenOnError();
element->DownloadResumed();
} else {
int64_t totalLength = GetLength();

View File

@ -174,7 +174,6 @@ public:
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
void Revoke();
void SetReopenOnError() { mReopenOnError = true; }
private:
Mutex mMutex;
@ -182,9 +181,6 @@ public:
// So it can be read without lock on the main thread or on other threads
// with the lock.
RefPtr<ChannelMediaResource> mResource;
// When this flag is set, if we get a network error we should silently
// reopen the stream. Main thread only.
bool mReopenOnError = false;
const int64_t mOffset;
const uint32_t mLoadID;
@ -199,9 +195,7 @@ protected:
bool IsSuspendedByCache();
// These are called on the main thread by Listener.
nsresult OnStartRequest(nsIRequest* aRequest, int64_t aRequestOffset);
nsresult OnStopRequest(nsIRequest* aRequest,
nsresult aStatus,
bool aReopenOnError);
nsresult OnStopRequest(nsIRequest* aRequest, nsresult aStatus);
nsresult OnDataAvailable(uint32_t aLoadID,
nsIInputStream* aStream,
uint32_t aCount);

View File

@ -2140,7 +2140,8 @@ MediaCacheStream::NotifyDataEndedInternal(uint32_t aLoadID,
// Note that aStatus might have succeeded --- this might be a normal close
// --- even in situations where the server cut us off because we were
// suspended. So we need to "reopen on error" in that case too. The only
// suspended. It is also possible that the server sends us fewer bytes than
// requested. So we need to "reopen on error" in that case too. The only
// cases where we don't need to reopen are when *we* closed the stream.
// But don't reopen if we need to seek and we don't think we can... that would
// cause us to just re-read the stream, which would be really bad.