Bug 1124507 - Keep WifP2p internal state and send to DOM facing object on init. r=vchang
authorHenry Chang <hchang@mozilla.com>
Tue, 27 Jan 2015 19:15:07 +0800
changeset 226907 fbc6b6da65974ac03a9dcd6eb5bccc9ee2835f8e
parent 226785 cdd62a8caf30f87d5b61d232ee525ab73f16469f
child 226908 3e430f2ff603361fa9e453fc59ce8ac6c2c03ae1
push id54950
push userphilringnalda@gmail.com
push dateSat, 31 Jan 2015 17:14:09 +0000
treeherdermozilla-inbound@37cbadfe1bc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvchang
bugs1124507
milestone38.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 1124507 - Keep WifP2p internal state and send to DOM facing object on init. r=vchang
dom/wifi/DOMWifiP2pManager.js
dom/wifi/WifiP2pManager.jsm
dom/wifi/WifiP2pWorkerObserver.jsm
--- a/dom/wifi/DOMWifiP2pManager.js
+++ b/dom/wifi/DOMWifiP2pManager.js
@@ -111,16 +111,21 @@ MozWifiP2pManager.prototype = {
 
     this.initDOMRequestHelper(aWindow, messages);
     this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
 
     // Notify the internal a new DOM mananger is created.
     let state = this._mm.sendSyncMessage("WifiP2pManager:getState")[0];
     if (state) {
       debug('State: ' + JSON.stringify(state));
+      this.enabled = state.enabled;
+      this.currentPeer = state.currentPeer;
+      if (state.groupOwner) {
+        this.groupOwner = new MozWifiP2pGroupOwner(state.groupOwner);
+      }
     } else {
       debug('Failed to get state');
     }
   },
 
   uninit: function() {
   },
 
--- a/dom/wifi/WifiP2pManager.jsm
+++ b/dom/wifi/WifiP2pManager.jsm
@@ -592,22 +592,24 @@ function P2pStateMachine(aP2pCommand, aN
 
   // The state where we are trying to enable wifi p2p.
   var stateEnabling = _sm.makeState("ENABLING", {
     enter: function() {
 
       function onFailure()
       {
         _onEnabled(false);
+        _observer.onDisabled();
         _sm.gotoState(stateDisabled);
       }
 
       function onSuccess()
       {
         _onEnabled(true);
+        _observer.onEnabled();
         _sm.gotoState(stateInactive);
       }
 
       _sm.pause();
 
       // This function will only call back on success.
       function connectToSupplicantIfNeeded(callback) {
         if (aP2pCommand.getSdkVersion() >= 19) {
@@ -1330,16 +1332,17 @@ function P2pStateMachine(aP2pCommand, aN
         debug('Stop DHCP server result: ' + success);
         aP2pCommand.p2pDisable(function(success) {
           debug('P2P function disabled');
           closeSupplicantConnectionIfNeeded(function() {
             debug('Supplicant connection closed');
             gNetworkService.disableInterface(P2P_INTERFACE_NAME, function (success){
               debug('Disabled interface: ' + P2P_INTERFACE_NAME);
               _onDisabled(true);
+              _observer.onDisabled();
               _sm.gotoState(stateDisabled);
             });
           });
         });
       });
 
       function closeSupplicantConnectionIfNeeded(callback) {
         // No need to connect to supplicant on KK. Call back directly.
--- a/dom/wifi/WifiP2pWorkerObserver.jsm
+++ b/dom/wifi/WifiP2pWorkerObserver.jsm
@@ -34,16 +34,19 @@ this.WifiP2pWorkerObserver = function(aD
       dump('-------------- WifiP2pWorkerObserver: ' + aMsg);
     }
   }
 
   // Private member variables.
   let _localDevice;
   let _peerList = {}; // List of P2pDevice.
   let _domManagers = [];
+  let _enabled = false;
+  let _groupOwner = null;
+  let _currentPeer = null;
 
   // Constructor of P2pDevice. It will be exposed to DOM.
   //
   // @param aPeer object representing a P2P device:
   //   .name: string for the device name.
   //   .address: Mac address.
   //   .isGroupOwner: boolean to indicate if this device is the group owner.
   //   .wpsCapabilities: array of string of {"pbc", "display", "keypad"}.
@@ -125,20 +128,22 @@ this.WifiP2pWorkerObserver = function(aD
   return {
     onLocalDeviceChanged: function(aDevice) {
       _localDevice = aDevice;
       debug('Local device updated to: ' + JSON.stringify(_localDevice));
     },
 
     onEnabled: function() {
       _peerList = [];
+      _enabled = true;
       fireEvent("p2pUp", {});
     },
 
     onDisbaled: function() {
+      _enabled = false;
       fireEvent("p2pDown", {});
     },
 
     onPeerFound: function(aPeer) {
       let newFoundPeer = new P2pDevice(aPeer);
       let origianlPeer = _peerList[aPeer.address];
       _peerList[aPeer.address] = newFoundPeer;
       if (origianlPeer) {
@@ -177,27 +182,34 @@ this.WifiP2pWorkerObserver = function(aD
         debug('Unknown peer connected: ' + aPeer.address);
         peer = new P2pDevice(aPeer);
         _peerList[aPeer.address] = peer;
         handlePeerListUpdated();
       }
       peer.connectionStatus = CONNECTION_STATUS_CONNECTED;
       peer.isGroupOwner = (aPeer.address === aGroupOwner.address);
 
+      _groupOwner = go;
+      _currentPeer = peer;
+
       fireEvent('onconnected', { groupOwner: go, peer: peer });
     },
 
     onDisconnected: function(aPeer) {
       let peer = _peerList[aPeer.address];
       if (!peer) {
         debug('Unknown peer disconnected: ' + aPeer.address);
         return;
       }
 
       peer.connectionStatus = CONNECTION_STATUS_DISCONNECTED;
+
+      _groupOwner = null;
+      _currentPeer = null;
+
       fireEvent('ondisconnected', { peer: peer });
     },
 
     getObservedDOMMessages: function() {
       return [
         "WifiP2pManager:getState",
         "WifiP2pManager:getPeerList",
         "WifiP2pManager:setScanEnabled",
@@ -222,17 +234,21 @@ this.WifiP2pWorkerObserver = function(aD
 
       if (!aMessage.target.assertPermission("wifi-manage")) {
         return;
       }
 
       switch (aMessage.name) {
         case "WifiP2pManager:getState": // A new DOM manager is created.
           addDomManager(msg);
-          return { peerList: _peerList, }; // Synchronous call. Simply return it.
+          return { // Synchronous call. Simply return it.
+            enabled: _enabled,
+            groupOwner: _groupOwner,
+            currentPeer: _currentPeer
+          };
 
         case "WifiP2pManager:setScanEnabled":
           {
             let enabled = msg.data;
 
             aDomMsgResponder.setScanEnabled(enabled, function(success) {
               returnMessage(aMessage.name, success, (success ? true : "ERROR"), msg);
             });