Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Integrate appservices SyncManager #2727

Closed
grigoryk opened this issue Apr 12, 2019 · 7 comments · Fixed by #4480
Closed

Integrate appservices SyncManager #2727

grigoryk opened this issue Apr 12, 2019 · 7 comments · Fixed by #4480
Assignees
Labels
a-s Application Services work needed 🐉 Fenix Feature needed for Fenix P1 <sync> Component: sync-logins
Milestone

Comments

@grigoryk
Copy link
Contributor

grigoryk commented Apr 12, 2019

┆Issue is synchronized with this Jira Task

@grigoryk grigoryk added 🐉 Fenix Feature needed for Fenix <sync> Component: sync-logins 🚢 AS dependent labels Apr 12, 2019
@grigoryk grigoryk added the blocked Blocked pull requests and issues label Apr 30, 2019
@bifleming bifleming added a-s Application Services work needed and removed 🚢 AS dependent labels May 30, 2019
@vesta0 vesta0 moved this from 🐉 Fenix Backlog to 🚷 Blocked in A-C: Android Components Sprint Planning May 31, 2019
@bifleming bifleming added this to Blocked by A-S in Fenix: A-S Bugs Jun 12, 2019
@vesta0 vesta0 added the P1 label Jun 26, 2019
@bifleming bifleming moved this from Blocked items need for Fenix after Q4 to Blocked items needed for Fenix Q3 in Fenix: A-S Bugs Jun 27, 2019
@vesta0 vesta0 added this to Backlog in A-C: Choose What to Sync via automation Jul 9, 2019
@st3fan st3fan changed the title Intergate appservices SyncManager Integrate appservices SyncManager Jul 15, 2019
@liuche
Copy link
Contributor

liuche commented Jul 17, 2019

@grigoryk we're looking at this for Fenix Q3 - can you give some context on what this is blocked by? It seems like a series of bugs linking to each other :)

@grigoryk
Copy link
Contributor Author

Landing this is blocked on parts of this "epic": mozilla/application-services#1316 (it's tracked in jira, but i've asked that updates are mentioned in that issue).

Rust SyncManager RFC describes an API that is very close to what will land above, allowing us to start integration work in a-c.

From another direction, there is the WebExtension work. See #3826 and #3817.

Project board that tracks this work overall: https://github.com/orgs/mozilla-mobile/projects/37

@liuche
Copy link
Contributor

liuche commented Jul 18, 2019

Thanks! This is really helpful.

@grigoryk
Copy link
Contributor Author

Some implementation details.

Our current sync implementation directly calls sync on configured SyncableStore objects, passing in SyncAuthInfo. Our sync worker implementation is thus as follows: obtain cached auth info, and iterate over configured stores calling sync for each one.

Straw-man API as described in the rfc introduces a SyncManager API, and a concept of an Engine, which is an abstraction over one or more sync1.5 collections, and possibly other things.

enum Engine {
  History, // The "History" and "Forms" stores.
  Bookmarks, // The "Bookmark" store.
  Passwords,
}

SyncManager will have a sync method, that takes SyncParams.

fn sync(&self, params: SyncParams) -> Result<SyncResult>;
// Instead of massive param and result lists, we use structures.
// This structure is passed to each and every sync.
struct SyncParams {
  // The engines to Sync. None means "sync all"
  engines: Option<Vec<Engine>>,
  // Why this sync is being done.
  reason: SyncReason,

  // Any state changes which should be done as part of this sync.
  engine_state_changes: Vec<EngineState>,

  // An opaque state "blob". This should be persisted by the app so it is
  // reused next sync.
  persisted_state: Option<String>,
}
struct SyncResult {
  // The general health.
  service_status: ServiceStatus,

  // The result for each engine.
  engine_results: HashMap<Engine, Result<()>>,

  // The list of declined engines, or None if we failed to get that far.
  declined_engines: Option<Vec<Engine>>,

  // When we are allowed to sync again. If > now() then there's some kind
  // of back-off. Note that it's not strictly necessary for the app to
  // enforce this (ie, it can keep asking us to sync, but we might decline).
  // But we might not too - eg, we might try a user-initiated sync.
  next_sync_allowed_at: Timestamp,

  // New opaque state which should be persisted by the embedding app and supplied
  // the next time Sync is called.
  persisted_state: String,

  // Telemetry. Nailing this down is tbd.
  telemetry: Option<JSONValue>,
}

sync methods exposed on individual stores can be treated as deprecated, and are likely to be removed at some point. This doesn't bode well for our concept SyncableStore that storage layers can implement. We don't have to remove this right away.

However, this means we should be able to remove the GlobalSyncableStoreProvider singleton.

New concepts:

  • persisted state resulting from each sync, that need to be passed along to the next sync
  • list of enabled engines as a sync parameter
  • list of disabled engines as a result coming out of sync (recall that this is a global list; other clients might have changed it)
    • this needs to be propagated upward to the application UI

So, start working on this by figuring out the following items:

  • how to persist sync state. SharedPreferences is probably fine. Sync worker should own read/write of this state
  • how to persist list of enabled/disabled engines (again, SharedPreferences should be fine)
    • how to expose that list to the application
    • how to allow application to monitor changes to that list. Likely as part of existing SyncStatus observers
  • FxaAccountManager API for changing the list of enabled engines, and engines that are allowed to be synced. We already have a SyncConfig that is a good fit here.
  • how to treat telemetry. Currently this is done at the Connection level, beneath PlacesStorage. - see assembleHistoryPing. We won't be going through storage instances directly while syncing anymore, and so that logic should be moved out someplace where sync worker can access it

@Amejia481 Amejia481 self-assigned this Jul 19, 2019
@Amejia481 Amejia481 moved this from Backlog to In progress in A-C: Choose What to Sync Jul 22, 2019
@Amejia481 Amejia481 moved this from 🚷 Blocked to 🏃‍♀️ In Progress in A-C: Android Components Sprint Planning Jul 22, 2019
@Amejia481 Amejia481 removed this from 🏃‍♀️ In Progress in A-C: Android Components Sprint Planning Jul 23, 2019
@Amejia481 Amejia481 added this to ⏳ Sprint Backlog in A-C: Android Components Sprint Planning Aug 19, 2019
@Amejia481 Amejia481 moved this from ⏳ Sprint Backlog to 🏃‍♀️ In Progress in A-C: Android Components Sprint Planning Aug 20, 2019
@Amejia481 Amejia481 moved this from 🏃‍♀️ In Progress to 🚷 Blocked in A-C: Android Components Sprint Planning Aug 28, 2019
@grigoryk grigoryk moved this from 🚷 Blocked to 🏃‍♀️ In Progress in A-C: Android Components Sprint Planning Sep 3, 2019
@grigoryk grigoryk removed the blocked Blocked pull requests and issues label Sep 3, 2019
@grigoryk
Copy link
Contributor Author

grigoryk commented Sep 3, 2019

We've done a first pass at this locally against a straw-man API, and now the a-s PR (mozilla/application-services#1447) is in a state where we can start testing this end-to-end.

@Amejia481 Amejia481 moved this from 🏃‍♀️ In Progress to ⏳ Sprint Backlog in A-C: Android Components Sprint Planning Sep 4, 2019
@grigoryk grigoryk self-assigned this Sep 13, 2019
@Amejia481 Amejia481 moved this from ⏳ Sprint Backlog to 🚷 Blocked in A-C: Android Components Sprint Planning Sep 16, 2019
@Amejia481 Amejia481 added the blocked Blocked pull requests and issues label Sep 16, 2019
@sblatz
Copy link
Contributor

sblatz commented Sep 18, 2019

@Amejia481 Is this still blocked? From @grigoryk's comment on the Fenix ticket, it seems like this is ready to be implemented in AC?

@Amejia481
Copy link
Contributor

Thanks for keeping an eye on it, two days ago it has some pending work from AS, but now it has finally landed mozilla/application-services#1447 (comment)

@Amejia481 Amejia481 removed the blocked Blocked pull requests and issues label Sep 18, 2019
@vesta0 vesta0 moved this from Items needed for Fenix Q3 to Items needed for Fenix Q4 in Fenix: A-S Bugs Sep 27, 2019
@bors bors bot closed this as completed in 83ffd01 Sep 27, 2019
A-C: Android Components Sprint Planning automation moved this from 🚷 Blocked to 🏁 Done Sep 27, 2019
A-C: Choose What to Sync automation moved this from In progress to Done Sep 27, 2019
@bifleming bifleming removed this from Items needed for Fenix Q4 2019 in Fenix: A-S Bugs Sep 30, 2019
@pocmo pocmo added this to the ⛑ 15.0.0 milestone Oct 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a-s Application Services work needed 🐉 Fenix Feature needed for Fenix P1 <sync> Component: sync-logins
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

7 participants