Bug 1354721 - Cleanup network geo provider: removed unneeded draft
authorGarvan Keeley <garvankeeley@gmail.com>
Tue, 11 Apr 2017 12:19:47 -0400
changeset 560580 e6bc8d02d2c79e66b1b5502364dc2551e69c71c5
parent 560499 c7f0d68df6ba68f720719d333aa4009b91150a18
child 560582 28cff1d72c4ac6c761c8559c7b2106e0b19a51bd
push id53460
push userbmo:gkeeley@mozilla.com
push dateTue, 11 Apr 2017 16:29:04 +0000
bugs1354721
milestone55.0a1
Bug 1354721 - Cleanup network geo provider: removed unneeded listener function wrapper and the call to non-existent listener.locationUpdatePending() MozReview-Commit-ID: 2HqXKy52xEW
dom/system/NetworkGeolocationProvider.js
--- a/dom/system/NetworkGeolocationProvider.js
+++ b/dom/system/NetworkGeolocationProvider.js
@@ -361,75 +361,64 @@ WifiGeoPositionProvider.prototype = {
 
     let useCached = isCachedRequestMoreAccurateThanServerRequest(data.cellTowers,
                                                                  data.wifiAccessPoints);
 
     LOG("Use request cache:" + useCached + " reason:" + gDebugCacheReasoning);
 
     if (useCached) {
       gCachedRequest.location.timestamp = Date.now();
-      this.notifyListener("update", [gCachedRequest.location]);
+      this.listener.update(gCachedRequest.location);
       return;
     }
 
     // From here on, do a network geolocation request //
     let url = Services.urlFormatter.formatURLPref("geo.wifi.uri");
     LOG("Sending request");
 
     let xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
                         .createInstance(Ci.nsIXMLHttpRequest);
 
-    this.notifyListener("locationUpdatePending");
-
     try {
       xhr.open("POST", url, true);
       xhr.channel.loadFlags = Ci.nsIChannel.LOAD_ANONYMOUS;
     } catch (e) {
-      this.notifyListener("notifyError",
-                          [POSITION_UNAVAILABLE]);
+      this.listener.notifyError(POSITION_UNAVAILABLE);
       return;
     }
     xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
     xhr.responseType = "json";
     xhr.mozBackgroundRequest = true;
     xhr.timeout = Services.prefs.getIntPref("geo.wifi.xhr.timeout");
     xhr.ontimeout = (function() {
       LOG("Location request XHR timed out.")
-      this.notifyListener("notifyError",
-                          [POSITION_UNAVAILABLE]);
+      this.listener.notifyError(POSITION_UNAVAILABLE);
     }).bind(this);
     xhr.onerror = (function() {
-      this.notifyListener("notifyError",
-                          [POSITION_UNAVAILABLE]);
+      this.listener.notifyError(POSITION_UNAVAILABLE);
     }).bind(this);
+
     xhr.onload = (function() {
       LOG("server returned status: " + xhr.status + " --> " +  JSON.stringify(xhr.response));
       if ((xhr.channel instanceof Ci.nsIHttpChannel && xhr.status != 200) ||
           !xhr.response || !xhr.response.location) {
-        this.notifyListener("notifyError",
-                            [POSITION_UNAVAILABLE]);
+        this.listener.notifyError(POSITION_UNAVAILABLE);
         return;
       }
 
       let newLocation = new WifiGeoPositionObject(xhr.response.location.lat,
                                                   xhr.response.location.lng,
                                                   xhr.response.accuracy);
 
-      this.notifyListener("update", [newLocation]);
+      this.listener.update(newLocation);
       gCachedRequest = new CachedRequest(newLocation, data.cellTowers, data.wifiAccessPoints);
     }).bind(this);
 
     var requestData = JSON.stringify(data);
     LOG("sending " + requestData);
     xhr.send(requestData);
   },
 
-  notifyListener: function(listenerFunc, args) {
-    args = args || [];
-    try {
-      this.listener[listenerFunc].apply(this.listener, args);
-    } catch(e) {
-      Cu.reportError(e);
-    }
+  enableLoggingToListener: function(isEnabled) {
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WifiGeoPositionProvider]);