Bug 1415438 - move mReopenOnError from ChannelMediaResource to ChannelMediaResource::Listener.
http://searchfox.org/mozilla-central/rev/ed212c79cfe86357e9a5740082b9364e7f6e526f/dom/media/ChannelMediaResource.cpp#727-729
mReopenOnError is a flag to reopen the channel when resume fails.
It makes more sense to associate this member with the channel we are resuming.
MozReview-Commit-ID: DwKUyvyzWdi
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -24,29 +24,27 @@ mozilla::LazyLogModule gMediaResourceLog
namespace mozilla {
ChannelMediaResource::ChannelMediaResource(MediaResourceCallback* aCallback,
nsIChannel* aChannel,
nsIURI* aURI,
bool aIsPrivateBrowsing)
: BaseMediaResource(aCallback, aChannel, aURI)
- , mReopenOnError(false)
, mCacheStream(this, aIsPrivateBrowsing)
, mSuspendAgent(mChannel, mCacheStream)
{
}
ChannelMediaResource::ChannelMediaResource(
MediaResourceCallback* aCallback,
nsIChannel* aChannel,
nsIURI* aURI,
const MediaChannelStatistics& aStatistics)
: BaseMediaResource(aCallback, aChannel, aURI)
- , mReopenOnError(false)
, mCacheStream(this, /* aIsPrivateBrowsing = */ false)
, mChannelStatistics(aStatistics)
, mSuspendAgent(mChannel, mCacheStream)
{
}
ChannelMediaResource::~ChannelMediaResource()
{
@@ -81,17 +79,17 @@ ChannelMediaResource::Listener::OnStartR
nsresult
ChannelMediaResource::Listener::OnStopRequest(nsIRequest* aRequest,
nsISupports* aContext,
nsresult aStatus)
{
MOZ_ASSERT(NS_IsMainThread());
if (!mResource)
return NS_OK;
- return mResource->OnStopRequest(aRequest, aStatus);
+ return mResource->OnStopRequest(aRequest, aStatus, mReopenOnError);
}
nsresult
ChannelMediaResource::Listener::OnDataAvailable(nsIRequest* aRequest,
nsISupports* aContext,
nsIInputStream* aStream,
uint64_t aOffset,
uint32_t aCount)
@@ -291,17 +289,16 @@ ChannelMediaResource::OnStartRequest(nsI
// Update principals before OnDataAvailable() putting the data in the cache.
// This is important, we want to make sure all principals are updated before
// any consumer can see the new data.
UpdatePrincipal();
mCacheStream.NotifyDataStarted(mLoadID, startOffset, seekable);
mIsTransportSeekable = seekable;
mChannelStatistics.Start();
- mReopenOnError = false;
mSuspendAgent.UpdateSuspendedStatusIfNeeded();
// Fires an initial progress event.
owner->DownloadProgressed();
// TODO: Don't turn this on until we fix all data races.
nsCOMPtr<nsIThreadRetargetableRequest> retarget;
@@ -366,32 +363,34 @@ ChannelMediaResource::ParseContentRangeH
LOG("Received bytes [%" PRId64 "] to [%" PRId64 "] of [%" PRId64 "] for decoder[%p]",
aRangeStart, aRangeEnd, aRangeTotal, mCallback.get());
return NS_OK;
}
nsresult
-ChannelMediaResource::OnStopRequest(nsIRequest* aRequest, nsresult aStatus)
+ChannelMediaResource::OnStopRequest(nsIRequest* aRequest,
+ nsresult aStatus,
+ bool aReopenOnError)
{
NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!");
NS_ASSERTION(!mSuspendAgent.IsSuspended(),
"How can OnStopRequest fire while we're suspended?");
MOZ_DIAGNOSTIC_ASSERT(!mClosed);
mChannelStatistics.Stop();
// 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
// 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.
- if (mReopenOnError && aStatus != NS_ERROR_PARSED_DATA_CACHED &&
+ if (aReopenOnError && aStatus != NS_ERROR_PARSED_DATA_CACHED &&
aStatus != NS_BINDING_ABORTED &&
(GetOffset() == 0 || (GetLength() > 0 && GetOffset() != GetLength() &&
mIsTransportSeekable))) {
// If the stream did close normally, restart the channel if we're either
// at the start of the resource, or if the server is seekable and we're
// not at the end of stream. We don't restart the stream if we're at the
// end because not all web servers handle this case consistently; see:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1373618#c36
@@ -725,17 +724,17 @@ ChannelMediaResource::Resume()
MOZ_DIAGNOSTIC_ASSERT(element);
if (mSuspendAgent.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.
- mReopenOnError = true;
+ mListener->SetReopenOnError();
element->DownloadResumed();
} else {
int64_t totalLength = GetLength();
// If mOffset is at the end of the stream, then we shouldn't try to
// seek to it. The seek will fail and be wasted anyway. We can leave
// the channel dead; if the media cache wants to read some other data
// in the future, it will call CacheClientSeek itself which will reopen the
// channel.
--- a/dom/media/ChannelMediaResource.h
+++ b/dom/media/ChannelMediaResource.h
@@ -176,37 +176,44 @@ public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSICHANNELEVENTSINK
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
void Revoke();
+ void SetReopenOnError() { mReopenOnError = true; }
private:
Mutex mMutex;
// mResource should only be modified on the main thread with the lock.
// 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;
};
friend class Listener;
nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override;
protected:
nsresult Seek(int64_t aOffset, bool aResume);
bool IsSuspendedByCache();
// These are called on the main thread by Listener.
nsresult OnStartRequest(nsIRequest* aRequest, int64_t aRequestOffset);
- nsresult OnStopRequest(nsIRequest* aRequest, nsresult aStatus);
+ nsresult OnStopRequest(nsIRequest* aRequest,
+ nsresult aStatus,
+ bool aReopenOnError);
nsresult OnDataAvailable(uint32_t aLoadID,
nsIInputStream* aStream,
uint32_t aCount);
nsresult OnChannelRedirect(nsIChannel* aOld,
nsIChannel* aNew,
uint32_t aFlags,
int64_t aOffset);
@@ -250,19 +257,16 @@ protected:
// The last reported seekability state for the underlying channel
bool mIsTransportSeekable = false;
RefPtr<Listener> mListener;
// A mono-increasing integer to uniquely identify the channel we are loading.
uint32_t mLoadID = 0;
// Used by the cache to store the offset to seek to when we are resumed.
// -1 means no seek initiated by the cache is waiting.
int64_t mPendingSeekOffset = -1;
- // When this flag is set, if we get a network error we should silently
- // reopen the stream.
- bool mReopenOnError;
// Any thread access
MediaCacheStream mCacheStream;
MediaChannelStatistics mChannelStatistics;
ChannelSuspendAgent mSuspendAgent;
};