Bug 906595 - Fix check rules for devices don't unload WIFI driver. r=vchang
authorChuck Lee <chulee@mozilla.com>
Mon, 19 Aug 2013 17:06:56 +0800
changeset 156165 fed47be3907e9ecf4d4448fabd6744116613eb7f
parent 156164 25721ca5b28d053f5fea4a3bbc8f1933c0c7f356
child 156166 04b11fc91c34cabb45a0d180723f626f34b18c4b
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvchang
bugs906595
milestone26.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 906595 - Fix check rules for devices don't unload WIFI driver. r=vchang
dom/wifi/WifiWorker.js
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -159,17 +159,21 @@ var WifiManager = (function() {
   function voidControlMessage(cmd, callback) {
     controlMessage({ cmd: cmd }, function (data) {
       callback(data.status);
     });
   }
 
   var driverLoaded = false;
 
-  manager.getDriverLoaded = function() { return driverLoaded; }
+  manager.checkDriverState = function(expectState) {
+    if (!unloadDriverEnabled)
+      return true;
+    return (expectState === driverLoaded);
+  }
 
   function loadDriver(callback) {
     if (driverLoaded) {
       callback(0);
       return;
     }
 
     voidControlMessage("load_driver", function(status) {
@@ -2838,59 +2842,59 @@ WifiWorker.prototype = {
   },
 
   _notifyAfterStateChange: function(success, newState) {
     if (!this._stateRequests.length)
       return;
 
     // First, notify all of the requests that were trying to make this change.
     let state = this._stateRequests[0].enabled;
-    let driverLoaded = WifiManager.getDriverLoaded();
+    let driverReady = WifiManager.checkDriverState(newState);
 
     // It is callback function's responsibility to handle the pending request.
     // So we just return here.
     if (this._stateRequests.length > 0
         && ("callback" in this._stateRequests[0])) {
       return;
     }
 
     // If the new state is not the same as state or new state is not the same as
     // driver loaded state, then we weren't processing the first request (we
     // were racing somehow) so don't notify.
     // For newState is false(disable), we expect driverLoaded is false(driver unloaded)
     // to proceed, and vice versa.
-    if (!success || (newState === driverLoaded && state === newState)) {
+    if (!success || (driverReady && state === newState)) {
       do {
         if (!("callback" in this._stateRequests[0])) {
           this._stateRequests.shift();
         }
         // Don't remove more than one request if the previous one failed.
       } while (success &&
                this._stateRequests.length &&
                !("callback" in this._stateRequests[0]) &&
                this._stateRequests[0].enabled === state);
     }
     // If there were requests queued after this one, run them.
     if (this._stateRequests.length > 0) {
       let self = this;
       let callback = null;
       this._callbackTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-      if (newState === driverLoaded) {
-        // Driver status is as same as new state, proceed next request.
+      if (driverReady) {
+        // Driver is ready for next request.
         callback = function(timer) {
           if ("callback" in self._stateRequests[0]) {
             self._stateRequests[0].callback.call(self, self._stateRequests[0].enabled);
           } else {
             WifiManager.setWifiEnabled(self._stateRequests[0].enabled,
                                        self._setWifiEnabledCallback.bind(self));
           }
           timer = null;
         };
       } else {
-        // Driver status is not as same as new state, wait driver.
+        // Wait driver until it's ready.
         callback = function(timer) {
           self._notifyAfterStateChange(success, newState);
           timer = null;
         };
       }
       this._callbackTimer.initWithCallback(callback, 1000, Ci.nsITimer.TYPE_ONE_SHOT);
     }
   },