[gnome-shell/gnome-3-2] NetworkMenu: don't query DBus properties of removed objects



commit 552ae78557ec5a99f568b84b926539c4ea1cef45
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Fri Oct 14 16:46:52 2011 +0200

    NetworkMenu: don't query DBus properties of removed objects
    
    Calling nm_access_point_get_ssid() in the handler of the
    access-point-removed signal can result in DBus request, which will
    then fail because the object was already removed at the server side.
    Instead, use a difference function to retrieve the access point
    object (the network), that compares directly by object identity.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=651378

 js/ui/status/network.js |   33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 4f368e3..966e872 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -1104,10 +1104,10 @@ NMDeviceWireless.prototype = {
         let activeAp = this.device.active_access_point;
 
         if (activeAp) {
-            let pos = this._findNetwork(activeAp);
+            let res = this._findExistingNetwork(activeAp);
 
-            if (pos != -1)
-                this._activeNetwork = this._networks[pos];
+            if (res != null)
+                this._activeNetwork = this._networks[res.network];
         }
 
         // we don't refresh the view here, setActiveConnection will
@@ -1181,6 +1181,18 @@ NMDeviceWireless.prototype = {
         return true;
     },
 
+    _findExistingNetwork: function(accessPoint) {
+        for (let i = 0; i < this._networks.length; i++) {
+            let apObj = this._networks[i];
+            for (let j = 0; j < apObj.accessPoints.length; j++) {
+                if (apObj.accessPoints[j] == accessPoint)
+                    return { network: i, ap: j };
+            }
+        }
+
+        return null;
+    },
+
     _findNetwork: function(accessPoint) {
         if (accessPoint.get_ssid() == null)
             return -1;
@@ -1273,22 +1285,15 @@ NMDeviceWireless.prototype = {
     },
 
     _accessPointRemoved: function(device, accessPoint) {
-        let pos = this._findNetwork(accessPoint);
-
-        if (pos == -1) {
-            log('Removing an access point that was never added');
-            return;
-        }
-
-        let apObj = this._networks[pos];
-        let i = apObj.accessPoints.indexOf(accessPoint);
+        let res = this._findExistingNetwork(accessPoint);
 
-        if (i == -1) {
+        if (res == null) {
             log('Removing an access point that was never added');
             return;
         }
 
-        apObj.accessPoints.splice(i, 1);
+        let apObj = this._networks[res.network];
+        apObj.accessPoints.splice(res.ap, 1);
 
         if (apObj.accessPoints.length == 0) {
             if (this._activeNetwork == apObj)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]