Bug 1472238: compare old and new versions and prefer what we had r?lina draft
authorEthan Glasser-Camp <ethan@betacantrips.com>
Fri, 29 Jun 2018 12:49:55 -0400
changeset 823237 556fde500b41934115537741c6d606f6147db0fa
parent 823236 d36b97b0a90050aa53e621df0ef0d1de1685114c
push id117622
push userbmo:eglassercamp@mozilla.com
push dateThu, 26 Jul 2018 21:32:07 +0000
reviewerslina
bugs1472238
milestone63.0a1
Bug 1472238: compare old and new versions and prefer what we had r?lina When a component registers after having already registered once, there are two sources of truth for the version ID: one implicit in the connection to Megaphone, and one coming from the component call to addListener. Try to handle this more thoroughly. MozReview-Commit-ID: EsYgO0mzQ9w
dom/push/PushBroadcastService.jsm
--- a/dom/push/PushBroadcastService.jsm
+++ b/dom/push/PushBroadcastService.jsm
@@ -114,21 +114,32 @@ var BroadcastService = class {
     if (typeof version !== "string") {
       throw new TypeError("version should be a string");
     }
     if (!version) {
       throw new TypeError("version should not be an empty string");
     }
 
     const isNew = !this.jsonFile.data.listeners.hasOwnProperty(broadcastId);
+    const oldVersion = !isNew && this.jsonFile.data.listeners[broadcastId].version;
+    if (!isNew && oldVersion != version) {
+      console.warn("Versions differ while adding listener for", broadcastId,
+                   ". Got", version, "but JSON file says", oldVersion, ".");
+    }
 
     // Update listeners before telling the pushService to subscribe,
     // in case it would disregard the update in the small window
     // between getting listeners and setting state to RUNNING.
-    this.jsonFile.data.listeners[broadcastId] = {version, sourceInfo};
+    //
+    // Keep the old version (if we have it) because Megaphone is
+    // really the source of truth for the current version of this
+    // broadcaster, and the old version is whatever we've either
+    // gotten from Megaphone or what we've told to Megaphone and
+    // haven't been corrected.
+    this.jsonFile.data.listeners[broadcastId] = {version: oldVersion || version, sourceInfo};
     this.jsonFile.saveSoon();
 
     if (isNew) {
       await this.pushService.subscribeBroadcast(broadcastId, version);
     }
   }
 
   async receivedBroadcastMessage(broadcasts) {