Closed Bug 1372655 Opened 7 years ago Closed 7 years ago

Notify other clients when uploading the local clients record for the first time

Categories

(Firefox for Android Graveyard :: Android Sync, enhancement, P1)

enhancement

Tracking

(firefox57 verified)

VERIFIED FIXED
Firefox 57
Tracking Status
firefox57 --- verified

People

(Reporter: eoger, Assigned: eoger)

References

Details

Attachments

(1 file)

This is basically the Android equivalent of bug 1363412.

This would trigger a clients collection sync on other devices immediately after ours connects, allowing the other clients to send a tab right away.
Priority: -- → P3
Priority: P3 → P2
Blocks: 1386016
Assignee: nobody → eoger
Status: NEW → ASSIGNED
Priority: P2 → P1
Comment on attachment 8893542 [details]
Bug 1372655 - Notify other clients when uploading the local clients record for the first time.

https://reviewboard.mozilla.org/r/164612/#review170318

Thanks for the patch! I think it generally does what you want (sans the double-notify bit); re-flag me once you clean it up.

::: mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccountClient20.java:936
(Diff revision 1)
> +      body.put("payload", payload);
> +    }
> +    if (TTL != null) {
> +      body.put("TTL", TTL);
> +    }
> +    notifyDevices(sessionToken, body, delegate);

All right, this is officially starting to move into "hacky" territory.

Perhaps make a builder for the payload body, and write some unit tests for it? Should be pretty easy.

Subtle errors are easily introduced in such code over time, and making sure boundaries between systems are solid is important - that's where we often see the bugs crop up.

::: mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/SyncClientsEngineStage.java:191
(Diff revision 1)
> +        }
>  
>          return;
>        }
>        checkAndUpload();
> +      if (isFirstLocalClientRecordUpload) {

I think it's possible that we'll notify some clients twice?

e.g. all was going well - our local client record was on the server, etc.

Then some roque client comes in and writes over the collection, erasing our client record.

Locally, say we're sending a tab. So we modified some client record.

We download client records, don't see our record, notify clients we just modified, but also mark this operation as "first local client record upload" and notify everyone again.

::: mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/SyncClientsEngineStage.java:200
(Diff revision 1)
> +
> +    private void notifyAllClients() {
> +      notifyClients(null);
>      }
>  
> -    private void notifyClients(final List<String> devicesToNotify) {
> +    // Null devicesToNotify means "Send to everyone"

Try to write your methods in a way that you don't pass around nulls on purpose. Another potential source of bugs.
Attachment #8893542 - Flags: review?(gkruglov) → review-
Comment on attachment 8893542 [details]
Bug 1372655 - Notify other clients when uploading the local clients record for the first time.

https://reviewboard.mozilla.org/r/164612/#review170318

> I think it's possible that we'll notify some clients twice?
> 
> e.g. all was going well - our local client record was on the server, etc.
> 
> Then some roque client comes in and writes over the collection, erasing our client record.
> 
> Locally, say we're sending a tab. So we modified some client record.
> 
> We download client records, don't see our record, notify clients we just modified, but also mark this operation as "first local client record upload" and notify everyone again.

Even if this happens, which is pretty unlikely, this is fine since we are just sending a "sync your clients collection" message.
(In reply to Edouard Oger [:eoger] from comment #4)
> Even if this happens, which is pretty unlikely, this is fine since we are
> just sending a "sync your clients collection" message.

And are you confident all other clients will behave correctly/sanely in that case, now and in the future? E.g., see recent iOS push message hurdles.
Comment on attachment 8893542 [details]
Bug 1372655 - Notify other clients when uploading the local clients record for the first time.

https://reviewboard.mozilla.org/r/164612/#review171742

OK, but tests would still be nice ;-)

::: mobile/android/services/src/main/java/org/mozilla/gecko/sync/stage/SyncClientsEngineStage.java:135
(Diff revision 2)
>      @Override
>      public void handleRequestSuccess(SyncStorageResponse response) {
> +      final Context context = session.getContext();
> +      final Account account = FirefoxAccounts.getFirefoxAccount(context);
> +      final boolean hasAccount = account != null;
> +      final AndroidFxAccount fxAccount = hasAccount ? new AndroidFxAccount(context, account) : null;

Something's gone really wrong if you don't have an account at this point.
Attachment #8893542 - Flags: review?(gkruglov) → review+
Pushed by eoger@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/24a164a008b9
Notify other clients when uploading the local clients record for the first time. r=Grisha
https://hg.mozilla.org/mozilla-central/rev/24a164a008b9
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 57
Verified Fixed in Beta 56.0b7 on Windows 10 and in Firefox Beta 56.0b7 on Android v7.0 on an LG V20 device.
Status: RESOLVED → VERIFIED
Product: Android Background Services → Firefox for Android
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: