Bug 1016785 - Switch to use UUID instead of LOCATION to identify incoming services r=wesj
authorMark Finkle <mfinkle@mozilla.com>
Wed, 04 Jun 2014 15:25:04 -0400
changeset 206888 a9b2fcd44bec187638a881eda547731d268a0f61
parent 206887 748b4ffb759e97e4495d6f92948c9f8fed585155
child 206889 1d19acb6394d08e14e714773ea469651a527fb9b
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs1016785
milestone32.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 1016785 - Switch to use UUID instead of LOCATION to identify incoming services r=wesj
mobile/android/base/tests/testSimpleDiscovery.js
mobile/android/modules/SimpleServiceDiscovery.jsm
--- a/mobile/android/base/tests/testSimpleDiscovery.js
+++ b/mobile/android/base/tests/testSimpleDiscovery.js
@@ -7,17 +7,17 @@
 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/SimpleServiceDiscovery.jsm");
 
 function discovery_observer(subject, topic, data) {
   do_print("Observer: " + data);
 
-  let service = SimpleServiceDiscovery.findServiceForLocation(data);
+  let service = SimpleServiceDiscovery.findServiceForID(data);
   if (!service)
     return;
 
   do_check_eq(service.friendlyName, "Pretend Device");
   do_check_eq(service.uuid, "uuid:5ec9ff92-e8b2-4a94-a72c-76b34e6dabb1");
   do_check_eq(service.manufacturer, "Copy Cat Inc.");
   do_check_eq(service.modelName, "Eureka Dongle");
 
--- a/mobile/android/modules/SimpleServiceDiscovery.jsm
+++ b/mobile/android/modules/SimpleServiceDiscovery.jsm
@@ -7,19 +7,19 @@
 
 this.EXPORTED_SYMBOLS = ["SimpleServiceDiscovery"];
 
 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
-function log(msg) {
-  Services.console.logStringMessage("[SSDP] " + msg);
-}
+// Define the "log" function as a binding of the Log.d function so it specifies
+// the "debug" priority and a log tag.
+let log = Cu.import("resource://gre/modules/AndroidLog.jsm", {}).AndroidLog.d.bind(null, "SSDP");
 
 XPCOMUtils.defineLazyGetter(this, "converter", function () {
   let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
   conv.charset = "utf8";
   return conv;
 });
 
 // Spec information:
@@ -213,18 +213,18 @@ var SimpleServiceDiscovery = {
   _searchShutdown: function _searchShutdown() {
     if (this._searchSocket) {
       // This will call onStopListening.
       this._searchSocket.close();
 
       // Clean out any stale services
       for (let [key, service] of this._services) {
         if (service.lastPing != this._searchTimestamp) {
-          Services.obs.notifyObservers(null, EVENT_SERVICE_LOST, service.location);
-          this._services.delete(service.location);
+          Services.obs.notifyObservers(null, EVENT_SERVICE_LOST, service.uuid);
+          this._services.delete(service.uuid);
         }
       }
     }
   },
 
   registerTarget: function registerTarget(aTarget, aAppFactory) {
     // Only add if we don't already know about this target
     if (!this._targets.has(aTarget)) {
@@ -239,19 +239,19 @@ var SimpleServiceDiscovery = {
 
     // Find the registration for the target
     if (this._targets.has(aService.target)) {
       return this._targets.get(aService.target).factory(aService);
     }
     return null;
   },
 
-  findServiceForLocation: function findServiceForLocation(aLocation) {
-    if (this._services.has(aLocation)) {
-      return this._services.get(aLocation);
+  findServiceForID: function findServiceForID(aUUID) {
+    if (this._services.has(aUUID)) {
+      return this._services.get(aUUID);
     }
     return null;
   },
 
   // Returns an array copy of the active services
   get services() {
     let array = [];
     for (let [key, service] of this._services) {
@@ -274,21 +274,21 @@ var SimpleServiceDiscovery = {
         if (aService.appsURL && !aService.appsURL.endsWith("/"))
           aService.appsURL += "/";
         aService.friendlyName = doc.querySelector("friendlyName").textContent;
         aService.uuid = doc.querySelector("UDN").textContent;
         aService.manufacturer = doc.querySelector("manufacturer").textContent;
         aService.modelName = doc.querySelector("modelName").textContent;
 
         // Only add and notify if we don't already know about this service
-        if (!this._services.has(aService.location)) {
-          this._services.set(aService.location, aService);
-          Services.obs.notifyObservers(null, EVENT_SERVICE_FOUND, aService.location);
+        if (!this._services.has(aService.uuid)) {
+          this._services.set(aService.uuid, aService);
+          Services.obs.notifyObservers(null, EVENT_SERVICE_FOUND, aService.uuid);
         }
 
         // Make sure we remember this service is not stale
-        this._services.get(aService.location).lastPing = this._searchTimestamp;
+        this._services.get(aService.uuid).lastPing = this._searchTimestamp;
       }
     }).bind(this), false);
 
     xhr.send(null);
   }
 }