Bug 786283 - Followup fixes to avoid notifying the same DOM request twice. r=vchang DONTBUILD
authorBlake Kaplan <mrbkap@gmail.com>
Tue, 28 Aug 2012 16:46:45 -0300
changeset 105679 61faabceedd4d18ac34178fca4f5e4fd16b4f26e
parent 105677 a0240c1043eefc60f08dc3e4dd2e8a0043b0d75e
child 105680 9e267fbca9fb42fe17e199bc83c44f79b1333107
child 105740 1f93692fea1ebc066e7df9119da5d8f5d16d3565
child 111044 51863e61a2828ec874494f38225cfc1a28c803b4
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersvchang
bugs786283
milestone18.0a1
Bug 786283 - Followup fixes to avoid notifying the same DOM request twice. r=vchang DONTBUILD
dom/wifi/WifiWorker.js
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -2021,29 +2021,33 @@ WifiWorker.prototype = {
 
   getNetworks: function(msg) {
     const message = "WifiManager:getNetworks:Return";
     if (!WifiManager.enabled) {
       this._sendMessage(message, false, "Wifi is disabled", msg);
       return;
     }
 
-    this.waitForScan((function (networks) {
+    let callback = (function (networks) {
       this._sendMessage(message, networks !== null, networks, msg);
-    }).bind(this));
+    }).bind(this);
+    this.waitForScan(callback);
 
-    WifiManager.scan(true, function(ok) {
+    WifiManager.scan(true, (function(ok) {
       // If the scan command succeeded, we're done.
       if (ok)
         return;
 
+      // Avoid sending multiple responses.
+      this.wantScanResults.splice(this.wantScanResults.indexOf(callback), 1);
+
       // Otherwise, let the client know that it failed, it's responsible for
       // trying again in a few seconds.
       this._sendMessage(message, false, "ScanFailed", msg);
-    });
+    }).bind(this));
   },
 
   _notifyAfterStateChange: function(success, newState) {
     // First, notify all of the requests that were trying to make this change.
     let state = this._stateRequests[0].enabled;
 
     // If the new state is not the same as state, then we weren't processing
     // the first request (we were racing somehow) so don't notify.