Bug 1367705. P2 - since RecordStatisticsTo() is removed in P1, we can now init mChannelStatistics in the constructor. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 02 Jun 2017 11:51:52 +0800
changeset 589336 d7f2f1bbda79e2481097805ec96c6d998cf4f730
parent 589335 5499ffd4747b6128bbf912971e965e8791cd6226
child 589337 30c22d38fb736e939566c923856b5d61314fa7c4
push id62332
push userjwwang@mozilla.com
push dateTue, 06 Jun 2017 02:46:10 +0000
bugs1367705
milestone55.0a1
Bug 1367705. P2 - since RecordStatisticsTo() is removed in P1, we can now init mChannelStatistics in the constructor. MozReview-Commit-ID: 5YcxnO368ex
dom/media/MediaResource.cpp
dom/media/MediaResource.h
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -68,29 +68,49 @@ MediaResource::Destroy()
                           NewNonOwningRunnableMethod(this, &MediaResource::Destroy));
   MOZ_ALWAYS_SUCCEEDS(rv);
 }
 
 NS_IMPL_ADDREF(MediaResource)
 NS_IMPL_RELEASE_WITH_DESTROY(MediaResource, Destroy())
 NS_IMPL_QUERY_INTERFACE0(MediaResource)
 
-ChannelMediaResource::ChannelMediaResource(MediaResourceCallback* aCallback,
-                                           nsIChannel* aChannel,
-                                           nsIURI* aURI,
-                                           const MediaContainerType& aContainerType,
-                                           bool aIsPrivateBrowsing)
-  : BaseMediaResource(aCallback, aChannel, aURI, aContainerType),
-    mOffset(0),
-    mReopenOnError(false),
-    mIgnoreClose(false),
-    mCacheStream(this, aIsPrivateBrowsing),
-    mLock("ChannelMediaResource.mLock"),
-    mIgnoreResume(false),
-    mSuspendAgent(mChannel)
+ChannelMediaResource::ChannelMediaResource(
+  MediaResourceCallback* aCallback,
+  nsIChannel* aChannel,
+  nsIURI* aURI,
+  const MediaContainerType& aContainerType,
+  bool aIsPrivateBrowsing)
+  : BaseMediaResource(aCallback, aChannel, aURI, aContainerType)
+  , mOffset(0)
+  , mReopenOnError(false)
+  , mIgnoreClose(false)
+  , mCacheStream(this, aIsPrivateBrowsing)
+  , mLock("ChannelMediaResource.mLock")
+  , mChannelStatistics(new MediaChannelStatistics())
+  , mIgnoreResume(false)
+  , mSuspendAgent(mChannel)
+{
+}
+
+ChannelMediaResource::ChannelMediaResource(
+  MediaResourceCallback* aCallback,
+  nsIChannel* aChannel,
+  nsIURI* aURI,
+  const MediaContainerType& aContainerType,
+  MediaChannelStatistics* aStatistics)
+  : BaseMediaResource(aCallback, aChannel, aURI, aContainerType)
+  , mOffset(0)
+  , mReopenOnError(false)
+  , mIgnoreClose(false)
+  , mCacheStream(this, /* aIsPrivateBrowsing = */ false)
+  , mLock("ChannelMediaResource.mLock")
+  , mChannelStatistics(new MediaChannelStatistics(aStatistics))
+  , mIgnoreResume(false)
+  , mSuspendAgent(mChannel)
 {
 }
 
 ChannelMediaResource::~ChannelMediaResource()
 {
   if (mListener) {
     // Kill its reference to us since we're going away
     mListener->Revoke();
@@ -503,20 +523,16 @@ ChannelMediaResource::OnDataAvailable(ns
 
   return NS_OK;
 }
 
 nsresult ChannelMediaResource::Open(nsIStreamListener **aStreamListener)
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
-  if (!mChannelStatistics) {
-    mChannelStatistics = new MediaChannelStatistics();
-  }
-
   nsresult rv = mCacheStream.Init();
   if (NS_FAILED(rv))
     return rv;
   NS_ASSERTION(mOffset == 0, "Who set mOffset already?");
 
   if (!mChannel) {
     // When we're a clone, the decoder might ask us to Open even though
     // we haven't established an mChannel (because we might not need one)
@@ -625,31 +641,27 @@ bool ChannelMediaResource::CanClone()
   return mCacheStream.IsAvailableForSharing();
 }
 
 already_AddRefed<MediaResource> ChannelMediaResource::CloneData(MediaResourceCallback* aCallback)
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
   NS_ASSERTION(mCacheStream.IsAvailableForSharing(), "Stream can't be cloned");
 
-  RefPtr<ChannelMediaResource> resource =
-    new ChannelMediaResource(aCallback,
-                             nullptr,
-                             mURI,
-                             GetContentType());
+  RefPtr<ChannelMediaResource> resource = new ChannelMediaResource(
+    aCallback, nullptr, mURI, GetContentType(), mChannelStatistics);
   if (resource) {
     // Initially the clone is treated as suspended by the cache, because
     // we don't have a channel. If the cache needs to read data from the clone
     // it will call CacheClientResume (or CacheClientSeek with aResume true)
     // which will recreate the channel. This way, if all of the media data
     // is already in the cache we don't create an unnecessary HTTP channel
     // and perform a useless HTTP transaction.
     resource->mSuspendAgent.Suspend();
     resource->mCacheStream.InitAsClone(&mCacheStream);
-    resource->mChannelStatistics = new MediaChannelStatistics(mChannelStatistics);
     resource->mChannelStatistics->Stop();
   }
   return resource.forget();
 }
 
 void ChannelMediaResource::CloseChannel()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -525,17 +525,22 @@ private:
  */
 class ChannelMediaResource : public BaseMediaResource
 {
 public:
   ChannelMediaResource(MediaResourceCallback* aDecoder,
                        nsIChannel* aChannel,
                        nsIURI* aURI,
                        const MediaContainerType& aContainerType,
-                       bool aIsPrivateBrowsing = false);
+                       bool aIsPrivateBrowsing);
+  ChannelMediaResource(MediaResourceCallback* aDecoder,
+                       nsIChannel* aChannel,
+                       nsIURI* aURI,
+                       const MediaContainerType& aContainerType,
+                       MediaChannelStatistics* aStatistics);
   ~ChannelMediaResource();
 
   // These are called on the main thread by MediaCache. These must
   // not block or grab locks, because the media cache is holding its lock.
   // Notify that data is available from the cache. This can happen even
   // if this stream didn't read any data, since another stream might have
   // received data for the same resource.
   void CacheClientNotifyDataReceived();