Bug 1147857: followup patch to continue BuildStats cleanup r=jib
authorRandell Jesup <rjesup@jesup.org>
Sat, 28 Mar 2015 21:45:42 -0400
changeset 266727 015fa1d7c54805889f3cfe179f63b6c60ebd1fdc
parent 266726 9e3ecca831d87c957a7ae8e7e5fe758d7385a785
child 266728 99c3baae746dab74dee6bee92173621ce20b4dc1
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1147857
milestone39.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 1147857: followup patch to continue BuildStats cleanup r=jib
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -2805,34 +2805,37 @@ nsresult
 PeerConnectionImpl::BuildStatsQuery_m(
     mozilla::dom::MediaStreamTrack *aSelector,
     RTCStatsQuery *query) {
 
   if (!HasMedia()) {
     return NS_ERROR_UNEXPECTED;
   }
 
-  // Note: mMedia->ice_ctx() is deleted on STS thread; so make sure we grab and hold
-  // a ref instead of making multiple calls.  NrIceCtx uses threadsafe refcounting.
-  query->iceCtx = mMedia->ice_ctx();
-  if (!query->iceCtx) {
-    CSFLogError(logTag, "Could not build stats query, no ice_ctx");
-    return NS_ERROR_UNEXPECTED;
-  }
   if (!mThread) {
     CSFLogError(logTag, "Could not build stats query, no MainThread");
     return NS_ERROR_UNEXPECTED;
   }
 
   nsresult rv = GetTimeSinceEpoch(&(query->now));
   if (NS_FAILED(rv)) {
     CSFLogError(logTag, "Could not build stats query, could not get timestamp");
     return rv;
   }
 
+  // Note: mMedia->ice_ctx() is deleted on STS thread; so make sure we grab and hold
+  // a ref instead of making multiple calls.  NrIceCtx uses threadsafe refcounting.
+  // NOTE: Do this after all other failure tests, to ensure we don't
+  // accidentally release the Ctx on Mainthread.
+  query->iceCtx = mMedia->ice_ctx();
+  if (!query->iceCtx) {
+    CSFLogError(logTag, "Could not build stats query, no ice_ctx");
+    return NS_ERROR_UNEXPECTED;
+  }
+
   // We do not use the pcHandle here, since that's risky to expose to content.
   query->report = new RTCStatsReportInternalConstruct(
       NS_ConvertASCIItoUTF16(mName.c_str()),
       query->now);
 
   query->iceStartTime = mIceStartTime;
   query->failed = isFailed(mIceConnectionState);
 
--- a/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
+++ b/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
@@ -162,33 +162,41 @@ WebrtcGlobalInformation::GetAllStats(
          p != ctx->mPeerConnections.end();
          ++p) {
       MOZ_ASSERT(p->second);
 
       if (!pcIdFilter.WasPassed() ||
           pcIdFilter.Value().EqualsASCII(p->second->GetIdAsAscii().c_str())) {
         if (p->second->HasMedia()) {
           queries->append(nsAutoPtr<RTCStatsQuery>(new RTCStatsQuery(true)));
-          p->second->BuildStatsQuery_m(nullptr, // all tracks
-                                       queries->back());
+          if (NS_WARN_IF(NS_FAILED(p->second->BuildStatsQuery_m(nullptr, // all tracks
+                                                                queries->back())))) {
+            queries->popBack();
+          } else {
+            MOZ_ASSERT(queries->back()->report);
+          }
         }
       }
     }
   }
 
-  // CallbackObject does not support threadsafe refcounting, and must be
-  // destroyed on main.
-  nsMainThreadPtrHandle<WebrtcGlobalStatisticsCallback> callbackHandle(
-    new nsMainThreadPtrHolder<WebrtcGlobalStatisticsCallback>(&aStatsCallback));
+  if (!queries->empty()) {
+    // CallbackObject does not support threadsafe refcounting, and must be
+    // destroyed on main.
+    nsMainThreadPtrHandle<WebrtcGlobalStatisticsCallback> callbackHandle(
+      new nsMainThreadPtrHolder<WebrtcGlobalStatisticsCallback>(&aStatsCallback));
 
-  rv = RUN_ON_THREAD(stsThread,
-                     WrapRunnableNM(&GetAllStats_s, callbackHandle, queries),
-                     NS_DISPATCH_NORMAL);
+    rv = RUN_ON_THREAD(stsThread,
+                       WrapRunnableNM(&GetAllStats_s, callbackHandle, queries),
+                       NS_DISPATCH_NORMAL);
 
-  aRv = rv;
+    aRv = rv;
+  } else {
+    aRv = NS_OK;
+  }
 }
 
 void
 WebrtcGlobalInformation::GetLogging(
   const GlobalObject& aGlobal,
   const nsAString& aPattern,
   WebrtcGlobalLoggingCallback& aLoggingCallback,
   ErrorResult& aRv)