Bug 1367705. P2 - since RecordStatisticsTo() is removed in P1, we can now init mChannelStatistics in the constructor. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Fri, 02 Jun 2017 11:51:52 +0800
changeset 412923 1ab72fcadc31dc40647053a8d89e38cd2919529d
parent 412922 b4002383a249f859a4fbb1c7f68bd763f526e731
child 412924 4037edd64d872dd8789b1377eb2b8fd7e89ab1fd
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1367705
milestone55.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 1367705. P2 - since RecordStatisticsTo() is removed in P1, we can now init mChannelStatistics in the constructor. r=cpearce 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();