Bug 956935 - Include supported Sync protocol versions in Android client records. r=nalexander
authorRichard Newman <rnewman@mozilla.com>
Tue, 07 Jan 2014 15:24:36 -0800
changeset 162511 bb178433abe38e6413d40176e1ec3e365072366b
parent 162510 d31244f88612f6c71f9c7cd079a43cbb279a1fa1
child 162512 65d443d32bf6fabe6b10ee116da8a068546c7fa8
push id25956
push usernalexander@mozilla.com
push dateWed, 08 Jan 2014 18:09:17 +0000
treeherdermozilla-central@a30925f7f28e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs956935
milestone29.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 956935 - Include supported Sync protocol versions in Android client records. r=nalexander
mobile/android/base/sync/repositories/domain/ClientRecord.java
mobile/android/base/sync/stage/SyncClientsEngineStage.java
--- a/mobile/android/base/sync/repositories/domain/ClientRecord.java
+++ b/mobile/android/base/sync/repositories/domain/ClientRecord.java
@@ -14,16 +14,19 @@ import org.mozilla.gecko.sync.repositori
 public class ClientRecord extends Record {
   private static final String LOG_TAG = "ClientRecord";
 
   public static final String CLIENT_TYPE         = "mobile";
   public static final String COLLECTION_NAME     = "clients";
   public static final long CLIENTS_TTL = 21 * 24 * 60 * 60; // 21 days in seconds.
   public static final String DEFAULT_CLIENT_NAME = "Default Name";
 
+  public static final String PROTOCOL_LEGACY_SYNC = "1.1";
+  // public static final String PROTOCOL_FXA_SYNC = "1.5";
+
   /**
    * Each of these fields is 'owned' by the client it represents. For example,
    * the "version" field is the Firefox version of that client; some time after
    * that client upgrades, it'll upload a new record with its new version.
    *
    * The only exception is for commands. When a command is sent to a client, the
    * sender will download its current record, append the command to the
    * "commands" array, and reupload the record. After processing, the recipient
@@ -31,16 +34,17 @@ public class ClientRecord extends Record
    *
    * Note that the version, then, will remain the version of the recipient, as
    * with the other descriptive fields.
    */
   public String name = ClientRecord.DEFAULT_CLIENT_NAME;
   public String type = ClientRecord.CLIENT_TYPE;
   public String version = null;                      // Free-form string, optional.
   public JSONArray commands;
+  public JSONArray protocols;
 
   public ClientRecord(String guid, String collection, long lastModified, boolean deleted) {
     super(guid, collection, lastModified, deleted);
     this.ttl = CLIENTS_TTL;
   }
 
   public ClientRecord(String guid, String collection, long lastModified) {
     this(guid, collection, lastModified, false);
@@ -69,28 +73,39 @@ public class ClientRecord extends Record
     }
 
     try {
       commands = payload.getArray("commands");
     } catch (NonArrayJSONException e) {
       Logger.debug(LOG_TAG, "Got non-array commands in client record " + guid, e);
       commands = null;
     }
+
+    try {
+      protocols = payload.getArray("protocols");
+    } catch (NonArrayJSONException e) {
+      Logger.debug(LOG_TAG, "Got non-array protocols in client record " + guid, e);
+      protocols = null;
+    }
   }
 
   @Override
   protected void populatePayload(ExtendedJSONObject payload) {
     putPayload(payload, "id",   this.guid);
     putPayload(payload, "name", this.name);
     putPayload(payload, "type", this.type);
     putPayload(payload, "version", this.version);
 
     if (this.commands != null) {
       payload.put("commands",  this.commands);
     }
+
+    if (this.protocols != null) {
+      payload.put("protocols",  this.protocols);
+    }
   }
 
   @Override
   public boolean equals(Object o) {
     if (!(o instanceof ClientRecord) || !super.equals(o)) {
       return false;
     }
 
@@ -98,17 +113,18 @@ public class ClientRecord extends Record
   }
 
   @Override
   public boolean equalPayloads(Object o) {
     if (!(o instanceof ClientRecord) || !super.equalPayloads(o)) {
       return false;
     }
 
-    // Don't compare versions.
+    // Don't compare versions or protocols, no matter how much we might want to.
+    // They're not required by the spec.
     ClientRecord other = (ClientRecord) o;
     if (!RepoUtils.stringsEqual(other.name, this.name) ||
         !RepoUtils.stringsEqual(other.type, this.type)) {
       return false;
     }
     return true;
   }
 
@@ -117,16 +133,17 @@ public class ClientRecord extends Record
     ClientRecord out = new ClientRecord(guid, this.collection, this.lastModified, this.deleted);
     out.androidID = androidID;
     out.sortIndex = this.sortIndex;
     out.ttl       = this.ttl;
 
     out.name = this.name;
     out.type = this.type;
     out.version = this.version;
+    out.protocols = this.protocols;
     return out;
   }
 
 /*
 Example record:
 
 {id:"relf31w7B4F1",
  name:"marina_mac",
--- a/mobile/android/base/sync/stage/SyncClientsEngineStage.java
+++ b/mobile/android/base/sync/stage/SyncClientsEngineStage.java
@@ -355,23 +355,30 @@ public class SyncClientsEngineStage exte
   public Integer getStorageVersion() {
     return VersionConstants.CLIENTS_ENGINE_VERSION;
   }
 
   protected String getLocalClientVersion() {
     return GlobalConstants.MOZ_APP_VERSION;
   }
 
+  protected JSONArray getLocalClientProtocols() {
+    final JSONArray protocols = new JSONArray();
+    protocols.add(ClientRecord.PROTOCOL_LEGACY_SYNC);
+    return protocols;
+  }
+
   protected ClientRecord newLocalClientRecord(ClientsDataDelegate delegate) {
     final String ourGUID = delegate.getAccountGUID();
     final String ourName = delegate.getClientName();
 
     ClientRecord r = new ClientRecord(ourGUID);
     r.name = ourName;
     r.version = getLocalClientVersion();
+    r.protocols = getLocalClientProtocols();
     return r;
   }
 
   // TODO: Bug 726055 - More considered handling of when to sync.
   protected boolean shouldDownload() {
     // Ask info/collections whether a download is needed.
     return true;
   }
@@ -392,17 +399,18 @@ public class SyncClientsEngineStage exte
     long now = System.currentTimeMillis();
     long age = now - lastUpload;
     return age >= CLIENTS_TTL_REFRESH;
   }
 
   protected void handleDownloadedLocalRecord(ClientRecord r) {
     session.config.persistServerClientRecordTimestamp(r.lastModified);
 
-    if (!getLocalClientVersion().equals(r.version)) {
+    if (!getLocalClientVersion().equals(r.version) ||
+        !getLocalClientProtocols().equals(r.protocols)) {
       shouldUploadLocalRecord = true;
     }
     processCommands(r.commands);
   }
 
   protected void processCommands(JSONArray commands) {
     if (commands == null ||
         commands.size() == 0) {