Bug 1346438 - Specify X-I-U-S header value as 0 when uploading crypto/keys r=nalexander,rnewman draft
authorGrigory Kruglov <gkruglov@mozilla.com>
Fri, 17 Mar 2017 19:09:43 -0700
changeset 501770 864678b5489e0a2f416f5196a97581bd7c902b61
parent 501769 d9a1b49076aebcff7300c570bc8a4fd85a92d048
child 550005 d73c3f0402dd35f276f5164c1b3c6c77c23ceb31
push id50121
push usergkruglov@mozilla.com
push dateMon, 20 Mar 2017 23:41:58 +0000
reviewersnalexander, rnewman
bugs1346438
milestone55.0a1
Bug 1346438 - Specify X-I-U-S header value as 0 when uploading crypto/keys r=nalexander,rnewman MozReview-Commit-ID: GTcZUdvVU8E
mobile/android/services/src/main/java/org/mozilla/gecko/sync/GlobalSession.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/GlobalSession.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/GlobalSession.java
@@ -562,38 +562,38 @@ public class GlobalSession implements Ht
   }
 
   public void fetchInfoCollections(JSONRecordFetchDelegate callback) throws URISyntaxException {
     final JSONRecordFetcher fetcher = new JSONRecordFetcher(config.infoCollectionsURL(), getAuthHeaderProvider());
     fetcher.fetch(callback);
   }
 
   /**
-   * Upload new crypto/keys.
+   * Upload new crypto/keys with X-If-Unmodified-Since=0
    *
    * @param keys
    *          new keys.
    * @param keyUploadDelegate
    *          a delegate.
    */
-  public void uploadKeys(final CollectionKeys keys,
+  public void uploadKeys(final CollectionKeys keys, final long timestamp,
                          final KeyUploadDelegate keyUploadDelegate) {
     SyncStorageRecordRequest request;
     try {
       request = new SyncStorageRecordRequest(this.config.keysURI());
     } catch (URISyntaxException e) {
       keyUploadDelegate.onKeyUploadFailed(e);
       return;
     }
 
     request.delegate = new SyncStorageRequestDelegate() {
 
       @Override
       public String ifUnmodifiedSince() {
-        return null;
+        return Utils.millisecondsToDecimalSecondsString(timestamp);
       }
 
       @Override
       public void handleRequestSuccess(SyncStorageResponse response) {
         Logger.debug(LOG_TAG, "Keys uploaded.");
         BaseResource.consumeEntity(response); // We don't need the response at all.
         keyUploadDelegate.onKeysUploaded();
       }
@@ -822,19 +822,20 @@ public class GlobalSession implements Ht
               Logger.warn(LOG_TAG, "Got exception generating new keys; failing fresh start.", e);
               freshStartDelegate.onFreshStartFailed(e);
             }
             if (keys == null) {
               Logger.warn(LOG_TAG, "Got null keys from generateNewKeys; failing fresh start.");
               freshStartDelegate.onFreshStartFailed(null);
             }
 
-            // Upload new keys.
+            // Upload new keys. Assert that no other client uploaded keys yet by setting X-I-U-S to 0.
+            // See Bug 1346438.
             Logger.info(LOG_TAG, "Uploading new crypto/keys.");
-            session.uploadKeys(keys, new KeyUploadDelegate() {
+            session.uploadKeys(keys, 0L, new KeyUploadDelegate() {
               @Override
               public void onKeysUploaded() {
                 Logger.info(LOG_TAG, "Uploaded new crypto/keys.");
                 freshStartDelegate.onFreshStart();
               }
 
               @Override
               public void onKeyUploadFailed(Exception e) {