Bug 1395855. P2 - store the offset of range request. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Sat, 09 Sep 2017 00:37:40 +0800
changeset 429753 951c770131ae5da7afce2778aca453c98e6da141
parent 429752 803f854237c1408d652d02dbcad0900f12a05960
child 429754 d77458b0217acff5f6f1938b733eb26985bb2788
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1395855
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1395855. P2 - store the offset of range request. r=cpearce So we know what to pass to SetupChannelHeaders() when the channel is redirected. MozReview-Commit-ID: DbCPGA3qIyn
dom/media/MediaResource.cpp
dom/media/MediaResource.h
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -145,27 +145,30 @@ ChannelMediaResource::Listener::OnDataAv
                                                 uint32_t aCount)
 {
   // This might happen off the main thread.
   MOZ_DIAGNOSTIC_ASSERT(mResource);
   return mResource->OnDataAvailable(aRequest, aStream, aCount);
 }
 
 nsresult
-ChannelMediaResource::Listener::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
-                                                       nsIChannel* aNewChannel,
-                                                       uint32_t aFlags,
-                                                       nsIAsyncVerifyRedirectCallback* cb)
+ChannelMediaResource::Listener::AsyncOnChannelRedirect(
+  nsIChannel* aOld,
+  nsIChannel* aNew,
+  uint32_t aFlags,
+  nsIAsyncVerifyRedirectCallback* cb)
 {
   nsresult rv = NS_OK;
-  if (mResource)
-    rv = mResource->OnChannelRedirect(aOldChannel, aNewChannel, aFlags);
+  if (mResource) {
+    rv = mResource->OnChannelRedirect(aOld, aNew, aFlags, mOffset);
+  }
 
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
+  }
 
   cb->OnRedirectVerifyCallback(NS_OK);
   return NS_OK;
 }
 
 nsresult
 ChannelMediaResource::Listener::CheckListenerChain()
 {
@@ -416,22 +419,24 @@ ChannelMediaResource::OnStopRequest(nsIR
   if (loadFlags & nsIRequest::LOAD_BACKGROUND) {
     ModifyLoadFlags(loadFlags & ~nsIRequest::LOAD_BACKGROUND);
   }
 
   return NS_OK;
 }
 
 nsresult
-ChannelMediaResource::OnChannelRedirect(nsIChannel* aOld, nsIChannel* aNew,
-                                        uint32_t aFlags)
+ChannelMediaResource::OnChannelRedirect(nsIChannel* aOld,
+                                        nsIChannel* aNew,
+                                        uint32_t aFlags,
+                                        int64_t aOffset)
 {
   mChannel = aNew;
   mSuspendAgent.NotifyChannelOpened(mChannel);
-  return SetupChannelHeaders(GetOffset());
+  return SetupChannelHeaders(aOffset);
 }
 
 nsresult
 ChannelMediaResource::CopySegmentToCache(nsIPrincipal* aPrincipal,
                                          const char* aFromSegment,
                                          uint32_t aCount,
                                          uint32_t* aWriteCount)
 {
@@ -510,30 +515,30 @@ ChannelMediaResource::Open(nsIStreamList
   }
 
   nsresult rv = mCacheStream.Init(cl);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   MOZ_ASSERT(GetOffset() == 0, "Who set offset already?");
-  mListener = new Listener(this);
+  mListener = new Listener(this, 0);
   *aStreamListener = mListener;
   NS_ADDREF(*aStreamListener);
   return NS_OK;
 }
 
 nsresult
 ChannelMediaResource::OpenChannel(int64_t aOffset)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mChannel);
   MOZ_ASSERT(!mListener, "Listener should have been removed by now");
 
-  mListener = new Listener(this);
+  mListener = new Listener(this, aOffset);
   nsresult rv = mChannel->SetNotificationCallbacks(mListener.get());
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = SetupChannelHeaders(aOffset);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = mChannel->AsyncOpen2(mListener);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -505,43 +505,50 @@ public:
   class Listener final
     : public nsIStreamListener
     , public nsIInterfaceRequestor
     , public nsIChannelEventSink
     , public nsIThreadRetargetableStreamListener
   {
     ~Listener() {}
   public:
-    explicit Listener(ChannelMediaResource* aResource) : mResource(aResource) {}
+    Listener(ChannelMediaResource* aResource, int64_t aOffset)
+      : mResource(aResource)
+      , mOffset(aOffset)
+    {}
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIREQUESTOBSERVER
     NS_DECL_NSISTREAMLISTENER
     NS_DECL_NSICHANNELEVENTSINK
     NS_DECL_NSIINTERFACEREQUESTOR
     NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
 
     void Revoke() { mResource = nullptr; }
 
   private:
     RefPtr<ChannelMediaResource> mResource;
+    const int64_t mOffset;
   };
   friend class Listener;
 
   nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override;
 
 protected:
   bool IsSuspendedByCache();
   // These are called on the main thread by Listener.
   nsresult OnStartRequest(nsIRequest* aRequest);
   nsresult OnStopRequest(nsIRequest* aRequest, nsresult aStatus);
   nsresult OnDataAvailable(nsIRequest* aRequest,
                            nsIInputStream* aStream,
                            uint32_t aCount);
-  nsresult OnChannelRedirect(nsIChannel* aOld, nsIChannel* aNew, uint32_t aFlags);
+  nsresult OnChannelRedirect(nsIChannel* aOld,
+                             nsIChannel* aNew,
+                             uint32_t aFlags,
+                             int64_t aOffset);
 
   // Opens the channel, using an HTTP byte range request to start at aOffset
   // if possible. Main thread only.
   nsresult OpenChannel(int64_t aOffset);
   nsresult RecreateChannel();
   // Add headers to HTTP request. Main thread only.
   nsresult SetupChannelHeaders(int64_t aOffset);
   // Closes the channel. Main thread only.