Bug 1497977 p6 - Also send a collection_changed push notification when uploading our client record following an fxa device id change. r=nalexander
authorEdouard Oger <eoger@fastmail.com>
Wed, 17 Oct 2018 18:23:14 +0000
changeset 490165 3506efe6428a9247e324af7a06dc82f61af781f1
parent 490164 60c949b40f469cdb459a1ec9d31efce727593c3a
child 490166 1d8eba4911f02fd91a0072bbc12ddbbb70d13b42
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersnalexander
bugs1497977
milestone64.0a1
Bug 1497977 p6 - Also send a collection_changed push notification when uploading our client record following an fxa device id change. r=nalexander Depends on D8611 Differential Revision: https://phabricator.services.mozilla.com/D8612
mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/SyncClientsEngineStage.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/SyncClientsEngineStage.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/SyncClientsEngineStage.java
@@ -74,16 +74,17 @@ public class SyncClientsEngineStage exte
   protected ClientUploadDelegate clientUploadDelegate;
   protected ClientDownloadDelegate clientDownloadDelegate;
 
   // Be sure to use this safely via getClientsDatabaseAccessor/closeDataAccessor.
   protected ClientsDatabaseAccessor db;
 
   protected volatile boolean shouldWipe;
   protected volatile boolean shouldUploadLocalRecord;     // Set if, e.g., we received commands or need to refresh our version.
+  protected volatile boolean shouldNotifyOtherClients = false; // If set, ask the FxA server to notify other clients that the client collection changed.
   protected final AtomicInteger uploadAttemptsCount = new AtomicInteger();
   protected final List<ClientRecord> modifiedClientsToUpload = new ArrayList<ClientRecord>();
 
   protected int getClientsCount() {
     return getClientsDatabaseAccessor().clientsCount();
   }
 
   protected synchronized ClientsDatabaseAccessor getClientsDatabaseAccessor() {
@@ -139,21 +140,20 @@ public class SyncClientsEngineStage exte
       session.config.persistServerClientsTimestamp(response.normalizedWeaveTimestamp());
       BaseResource.consumeEntity(response);
 
       // Wipe the clients table if it still hasn't been wiped but needs to be.
       wipeAndStore(null);
 
       // If we successfully downloaded all records but ours was not one of them
       // then reset the timestamp.
-      boolean isFirstLocalClientRecordUpload = false;
       if (!localAccountGUIDDownloaded) {
         Logger.info(LOG_TAG, "Local client GUID does not exist on the server. Upload timestamp will be reset.");
         session.config.persistServerClientRecordTimestamp(0);
-        isFirstLocalClientRecordUpload = true;
+        shouldNotifyOtherClients = true;
       }
       localAccountGUIDDownloaded = false;
 
       final int clientsCount;
       try {
         clientsCount = getClientsCount();
       } finally {
         // Close the database to clear cached readableDatabase/writableDatabase
@@ -179,26 +179,26 @@ public class SyncClientsEngineStage exte
           }
         }
 
         // This method is synchronous, there's no risk of notifying the clients
         // before we actually uploaded the records
         uploadRemoteRecords();
 
         // We will send a push notification later anyway.
-        if (!isFirstLocalClientRecordUpload && account != null) {
+        if (!shouldNotifyOtherClients && account != null) {
           // Notify the clients who got their record written
           final AndroidFxAccount fxAccount = new AndroidFxAccount(context, account);
           notifyClients(fxAccount, devicesToNotify, NOTIFY_TAB_SENT_TTL_SECS, COLLECTION_MODIFIED_REASON_SENDTAB);
         }
 
         return;
       }
       checkAndUpload();
-      if (isFirstLocalClientRecordUpload && account != null) {
+      if (shouldNotifyOtherClients && account != null) {
         final AndroidFxAccount fxAccount = new AndroidFxAccount(context, account);
         notifyAllClients(fxAccount, 0, COLLECTION_MODIFIED_REASON_FIRSTSYNC);
       }
     }
 
     private void notifyClients(@NonNull AndroidFxAccount fxAccount, @NonNull List<String> devicesToNotify,
                                long ttl, @NonNull String reason) {
       final ExtendedJSONObject body = createNotifyClientsBody(devicesToNotify, ttl, reason);
@@ -580,16 +580,17 @@ public class SyncClientsEngineStage exte
     } else {
       fxaDeviceId = null;
     }
 
     if (!TextUtils.equals(r.fxaDeviceId, fxaDeviceId) ||
         !getLocalClientVersion().equals(r.version) ||
         !getLocalClientProtocols().equals(r.protocols)) {
       shouldUploadLocalRecord = true;
+      shouldNotifyOtherClients = true;
     }
     processCommands(r.commands);
   }
 
   protected void processCommands(JSONArray commands) {
     if (commands == null ||
         commands.size() == 0) {
       return;