Bug 906990: Part 14. Catch exceptions thrown by getStats, since this can fail in fairly innocuous circumstances. Also, do a better job of error reporting when the stats API is used on a closed PeerConnection. r=jib
authorByron Campen [:bwc] <docfaraday@gmail.com>
Thu, 09 Jan 2014 16:03:19 -0800
changeset 163610 07a8653c8ba66ffe64b0ed649d29991fb9249774
parent 163609 61da9e9b3c28045f06bcdffc8c34aafc96e3f375
child 163611 a79597d4cf6a9d665cf74b69f3f4901696a3c8d3
push idunknown
push userunknown
push dateunknown
reviewersjib
bugs906990
milestone29.0a1
Bug 906990: Part 14. Catch exceptions thrown by getStats, since this can fail in fairly innocuous circumstances. Also, do a better job of error reporting when the stats API is used on a closed PeerConnection. r=jib
dom/media/PeerConnection.js
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -115,31 +115,35 @@ GlobalPCList.prototype = {
       } else if (data == "online") {
         this._networkdown = false;
       }
     }
   },
 
   getStatsForEachPC: function(callback, errorCallback) {
     function getStatsFromPC(pcref) {
-      if (pcref.get()) {
+      try {
         pcref.get().getStatsInternal(null, callback, errorCallback);
+      } catch (e) {
+        errorCallback("Some error getting stats from PC: " + e.toString());
       }
     }
 
     for (let winId in this._list) {
       if (this._list.hasOwnProperty(winId)) {
         this.removeNullRefs(winId);
         if (this._list[winId]) {
           this._list[winId].forEach(getStatsFromPC);
         }
       }
     }
   },
 
+  // TODO(bcampen@mozilla.com): Handle this with a global object in c++
+  // (Bug 958221)
   getLoggingFromFirstPC: function(pattern, callback, errorCallback) {
     for (let winId in this._list) {
       this.removeNullRefs(winId);
       if (this._list[winId]) {
         // We expect removeNullRefs to not leave us with an empty array here
         let pcref = this._list[winId][0];
         pcref.get().getLogging(pattern, callback, errorCallback);
         return;
@@ -153,16 +157,18 @@ function WebrtcGlobalInformation() {
 }
 WebrtcGlobalInformation.prototype = {
   classDescription: "WebrtcGlobalInformation",
   classID: WEBRTC_GLOBAL_CID,
   contractID: WEBRTC_GLOBAL_CONTRACT,
   QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
 
   getAllStats: function(successCallback, failureCallback) {
+    // TODO(bcampen@mozilla.com): Move the work of fanout into c++, and
+    // only callback once. (Bug 958221)
     if (_globalPCList) {
       _globalPCList.getStatsForEachPC(successCallback, failureCallback);
     } else {
       failureCallback("No global PeerConnection list");
     }
   },
 
   getCandPairLogs: function(candPairId, callback, errorCallback) {
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -1344,17 +1344,17 @@ PeerConnectionImpl::GetStats(MediaStream
                                now),
                 NS_DISPATCH_NORMAL);
 #endif
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PeerConnectionImpl::GetLogging(const nsAString& aPattern) {
-  PC_AUTO_ENTER_API_CALL(true);
+  PC_AUTO_ENTER_API_CALL_NO_CHECK();
 
 #ifdef MOZILLA_INTERNAL_API
   std::string pattern(NS_ConvertUTF16toUTF8(aPattern).get());
   RUN_ON_THREAD(mSTSThread,
                 WrapRunnableNM(&PeerConnectionImpl::GetLogging_s,
                                mHandle,
                                mThread,
                                pattern),