Bug 1147857 - Followup patch to continue BuildStats cleanup. r=jib, a=lmandel
authorRandell Jesup <rjesup@jesup.org>
Sat, 28 Mar 2015 21:45:42 -0400
changeset 258222 108255910fbf
parent 258221 2c5d97fcb993
child 258223 85c87a6f453f
push id4623
push userryanvm@gmail.com
push date2015-04-03 01:49 +0000
treeherdermozilla-beta@9c755cdc241c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib, lmandel
bugs1147857
milestone38.0
Bug 1147857 - Followup patch to continue BuildStats cleanup. r=jib, a=lmandel
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
@@ -2795,34 +2795,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)