Bug 1401461. P2 - don't call mChannelStatistics.AddBytes() if the data is from an old channel. draft
authorJW Wang <jwwang@mozilla.com>
Wed, 20 Sep 2017 14:41:17 +0800
changeset 668293 b05a90254c021dc899f35e9d14afc9d83923987a
parent 668292 f4d3f875d3c62e8243e56efec14828070d3e3dcf
child 668295 1f460b84a4eae7869859ca316950d71b4330f9ec
child 668973 57e1b54c03c45af12fc66eb03e4614d6a3df486e
push id81004
push userjwwang@mozilla.com
push dateThu, 21 Sep 2017 13:50:51 +0000
bugs1401461
milestone57.0a1
Bug 1401461. P2 - don't call mChannelStatistics.AddBytes() if the data is from an old channel. MozReview-Commit-ID: GIVwoGpo43R
dom/media/ChannelMediaResource.cpp
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -431,18 +431,23 @@ nsresult
 ChannelMediaResource::OnDataAvailable(uint32_t aLoadID,
                                       nsIInputStream* aStream,
                                       uint32_t aCount)
 {
   // This might happen off the main thread.
 
   RefPtr<ChannelMediaResource> self = this;
   nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
-    "ChannelMediaResource::OnDataAvailable",
-    [self, aCount]() { self->mChannelStatistics.AddBytes(aCount); });
+    "ChannelMediaResource::OnDataAvailable", [self, aCount, aLoadID]() {
+      if (aLoadID != self->mLoadID) {
+        // Ignore data from the old channel.
+        return;
+      }
+      self->mChannelStatistics.AddBytes(aCount);
+    });
   mCallback->AbstractMainThread()->Dispatch(r.forget());
 
   Closure closure{ aLoadID, this };
   uint32_t count = aCount;
   while (count > 0) {
     uint32_t read;
     nsresult rv =
       aStream->ReadSegments(CopySegmentToCache, &closure, count, &read);