Bug 979841 - [Tarako]Wifi stay on searching status even scan results available. r=chulee
authorVincent Chang <vchang@mozilla.com>
Wed, 12 Mar 2014 18:25:32 +0800
changeset 190558 f540e87a999b800cbc3dc801c05c2fd1affa0bce
parent 190557 b2498cfb7e3694793a04c1234402a7e013e8b442
child 190559 2d12ebd194c3636a0b0ccb7cdc408686c944678b
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschulee
bugs979841
milestone30.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 979841 - [Tarako]Wifi stay on searching status even scan results available. r=chulee
dom/wifi/DOMWifiManager.js
dom/wifi/WifiWorker.js
--- a/dom/wifi/DOMWifiManager.js
+++ b/dom/wifi/DOMWifiManager.js
@@ -130,94 +130,85 @@ DOMWifiManager.prototype = {
   },
 
   receiveMessage: function(aMessage) {
     let msg = aMessage.json;
     if (msg.mid && msg.mid != this._id)
       return;
 
     let request;
+    if (msg.rid) {
+      request = this.takeRequest(msg.rid);
+      if (!request) {
+        return;
+      }
+    }
+
     switch (aMessage.name) {
       case "WifiManager:getNetworks:Return:OK":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
         break;
 
       case "WifiManager:getNetworks:Return:NO":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireError(request, "Unable to scan for networks");
         break;
 
       case "WifiManager:getKnownNetworks:Return:OK":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
         break;
 
       case "WifiManager:getKnownNetworks:Return:NO":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireError(request, "Unable to get known networks");
         break;
 
       case "WifiManager:associate:Return:OK":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireSuccess(request, true);
         break;
 
       case "WifiManager:associate:Return:NO":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireError(request, "Unable to add the network");
         break;
 
       case "WifiManager:forget:Return:OK":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireSuccess(request, true);
         break;
 
       case "WifiManager:forget:Return:NO":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireError(request, msg.data);
         break;
 
       case "WifiManager:wps:Return:OK":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
         break;
 
       case "WifiManager:wps:Return:NO":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireError(request, msg.data);
         break;
 
       case "WifiManager:setPowerSavingMode:Return:OK":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
         break;
 
       case "WifiManager:setPowerSavingMode:Return:NO":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireError(request, msg.data);
         break;
 
       case "WifiManager:setHttpProxy:Return:OK":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
         break;
 
       case "WifiManager:setHttpProxy:Return:NO":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireError(request, msg.data);
         break;
 
       case "WifiManager:setStaticIpMode:Return:OK":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
         break;
 
       case "WifiManager:setStaticIpMode:Return:NO":
-        request = this.takeRequest(msg.rid);
         Services.DOMRequest.fireError(request, msg.data);
         break;
 
       case "WifiManager:wifiDown":
         this._enabled = false;
         this._currentNetwork = null;
         this._fireEnabledOrDisabled(false);
         break;
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -2397,16 +2397,35 @@ WifiWorker.prototype = {
       // observe our child message managers shutting down, below.
       manager.sendAsyncMessage("WifiManager:" + message, data);
     });
   },
 
   _sendMessage: function(message, success, data, msg) {
     msg.manager.sendAsyncMessage(message + (success ? ":OK" : ":NO"),
                                  { data: data, rid: msg.rid, mid: msg.mid });
+    this._splicePendingRequest(msg);
+  },
+
+  _domRequest: [],
+
+  _splicePendingRequest: function(msg) {
+    for (let i = 0; i < this._domRequest.length; i++) {
+      if (this._domRequest[i].msg === msg) {
+        this._domRequest.splice(i, 1);
+        return;
+      }
+    }
+  },
+
+  _clearPendingRequest: function() {
+    if (this._domRequest.length === 0) return;
+    this._domRequest.forEach(function(req) {
+      this._sendMessage(req.name + ":Return", false, "Wifi is disabled", req.msg);
+    });
   },
 
   receiveMessage: function MessageManager_receiveMessage(aMessage) {
     let msg = aMessage.data || {};
     msg.manager = aMessage.target;
 
     if (WifiManager.p2pSupported()) {
       // If p2pObserver returns something truthy, return it!
@@ -2428,16 +2447,21 @@ WifiWorker.prototype = {
 
       return;
     }
 
     if (!aMessage.target.assertPermission("wifi-manage")) {
       return;
     }
 
+    // We are interested in DOMRequests only.
+    if (aMessage.name != "WifiManager:getState") {
+      this._domRequest.push({name: aMessage.name, msg:msg});
+    }
+
     switch (aMessage.name) {
       case "WifiManager:getNetworks":
         this.getNetworks(msg);
         break;
       case "WifiManager:getKnownNetworks":
         this.getKnownNetworks(msg);
         break;
       case "WifiManager:associate":
@@ -2607,16 +2631,21 @@ WifiWorker.prototype = {
     // supplicantlost.
     if (WifiManager.supplicantStarted)
       WifiManager.start();
 
     this.requestDone();
   },
 
   setWifiEnabled: function(enabled, callback) {
+    // Reply error to pending requests.
+    if (!enabled) {
+      this._clearPendingRequest();
+    }
+
     WifiManager.setWifiEnabled(enabled, callback);
   },
 
   // requestDone() must be called to before callback complete(or error)
   // so next queue in the request quene can be executed.
   queueRequest: function(enabled, callback) {
     if (!callback) {
         throw "Try to enqueue a request without callback";