Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of the Sync Manager #1447

Merged
merged 20 commits into from Sep 17, 2019
Merged

Initial implementation of the Sync Manager #1447

merged 20 commits into from Sep 17, 2019

Conversation

thomcc
Copy link
Contributor

@thomcc thomcc commented Jul 23, 2019

Fixes #1382, although this might just become a rolling PR, since I don't think we want to land broken bindings.

See also mozilla-mobile/android-components#2727

This also required some number of changes to various other pieces in support.

The biggest differences between this and the API @mhammond proposed in our docs:

  1. set_places/set_logins needs to be called to pass the handles of the places/logins items.
  2. Swift support is entirely out of scope, and so most of the existing sync infrastructure is just left alone.
  3. I've added a SyncReason.ENABLED_CHANGED for cases where we're triggering a sync of no engines just to update enabled.
  4. wipe is gone, for now, as it's not clear when 'delete all local data of all engines' would be used in such a way that going through the sync manager is desired. (Just delete the database files, TBH).

Compared to #1208 (which is... surprisingly still not landed...), I still only return the declined list over the FFI. It's not 100% clear that I should expose anything more than that?

This is a draft PR, but I'd like feedback on the (Kotlin parts of the) API so far. Note that I'll be deprecating (eventually removing the existing kotlin sync APIs), but that's not yet reflected here.

r? @Amejia481, @grigoryk, @mhammond

Pull Request checklist

  • Quality: This PR builds and tests run cleanly
    • cargo test --all produces no test failures
    • cargo clippy --all --all-targets --all-features runs without emitting any warnings
    • cargo fmt does not produce any changes to the code
    • ./gradlew ktlint detekt runs without emitting any warnings
    • swiftformat --swiftversion 4 megazords components/*/ios && swiftlint runs without emitting any warnings or producing changes
    • Note: For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGES_UNRELEASED.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due dilligence applied in selecting them.

* Base class for sync manager errors. Generally should not
* have concrete instances.
*/
open class SyncManagerException(msg: String) : Exception(msg)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe sealed classes could be an alternative here.

@thomcc
Copy link
Contributor Author

thomcc commented Aug 29, 2019

2 things not fully finished

  1. Declined handling not 100% threaded through everything.
  2. Sync manager forces use of both places and logins, instead of allowing them to be optional.

First of these I'll finish tomorrow ASAP (had more time in meetings than anticipated today) which should unblock @grigoryk's ability to test against this branch. 2nd I'll finish before landing but it shouldn't impact the overall shape of things.

As-is this probably should unblock @linacambridge's ability to integrate clients engine.

@thomcc thomcc force-pushed the smanager branch 2 times, most recently from 95b9581 to 9f84c35 Compare September 3, 2019 17:49
@thomcc thomcc changed the title Initial implementation of the Kotlin Sync Manager API Initial implementation of the Sync Manager Sep 3, 2019
@thomcc
Copy link
Contributor Author

thomcc commented Sep 3, 2019

Ignore the dep summary failure, that's because this currently forces lockwise to contain the places deps, which i'll fix after I do a little testing to make sure this all works as intended.

Copy link
Member

@mhammond mhammond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good. However, I'd like to better understand why "accepted" isn't supported? I'd really like to avoid having Fenix spend effort on something we want to go away in the short term (and I really don't want "accepted" to not happen short term). It's particularly important IMO because IIUC we will be implementing "choose what to sync" sooner rather than later for Fenix, and because the set of engines supported is different to desktop we'll have a problem. IOW, we need to implement support for "accepted" on desktop ASAP rather than deferring the implementation on Fenix!)

(I'm fine with the spelling of "accepted" in the RFC not being exactly how it is implemented - if you think that's necessary, let's discuss it!)

@@ -87,6 +84,34 @@ pub struct GlobalState {
pub keys: EncryptedBso,
}

fn same_declined(a: &[String], b: &[String]) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this looks correct, does a unit test for it make sense?


impl MetaGlobalRecord {
// TODO: this function needs to change once we understand 'accepted'.
pub fn update_declined_engines(&mut self, changes: &HashMap<String, bool>) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this better named "maybe_update_declined"? Either way, a comment explaining the bool return probably makes sense.

@@ -66,6 +66,9 @@ pub struct SyncResult {
/// The general health.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the comment at the top of this struct need updating?

crate, and in some cases stretches (or arguably breaks) the abstraction barrier
that `sync15` puts up.

Unfortunately, places/logins/etc depend on sync15 directly, and so to prevent a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like some of the issue here WRT stretching/breaking the abstractions is keeping sync_multiple in sync15, but logins (and even places) probably doesn't actually need that?

components/sync_manager/ffi/src/lib.rs Outdated Show resolved Hide resolved
components/sync_manager/ffi/src/lib.rs Show resolved Hide resolved
components/sync_manager/src/ffi.rs Outdated Show resolved Hide resolved
pub struct SyncManager {
mem_cached_state: Option<MemoryCachedState>,
places: Weak<PlacesApi>,
logins: Weak<Mutex<PasswordEngine>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact logins has a Mutex but PlacesApi doesn't seems like there's some inconsistency here that should be abstracted away lower?

(The fact we can't just work with traits surprises me too, but I guess there's a good reason hidden away somewhere)

components/sync_manager/src/manager.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@linabutler linabutler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great, and I ❤️ the sync_multiple refactor, that function was getting really long and complicated. I also wouldn't mind seeing this again with accepted, but I left a few comments and questions in the meantime!

components/logins/ffi/src/lib.rs Show resolved Hide resolved
components/sync15/src/client.rs Show resolved Hide resolved
components/sync15/src/state.rs Show resolved Hide resolved
components/sync15/src/sync_multiple.rs Show resolved Hide resolved
components/sync15/src/state.rs Outdated Show resolved Hide resolved
components/sync_manager/ffi/Cargo.toml Outdated Show resolved Hide resolved
@thomcc
Copy link
Contributor Author

thomcc commented Sep 16, 2019

@linacambridge This should be ready for you to take another look I think?

Copy link
Contributor

@linabutler linabutler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! :shipit:

components/sync15/src/state.rs Show resolved Hide resolved
components/sync15/src/client.rs Outdated Show resolved Hide resolved
components/sync15/src/state.rs Show resolved Hide resolved
components/sync15/src/sync_multiple.rs Outdated Show resolved Hide resolved
components/sync_manager/src/manager.rs Show resolved Hide resolved
components/sync_manager/src/manager.rs Show resolved Hide resolved
@thomcc
Copy link
Contributor Author

thomcc commented Sep 17, 2019

Will land once green

@thomcc thomcc merged commit 433e00a into master Sep 17, 2019
@linabutler linabutler deleted the smanager branch September 17, 2019 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Kotlin bindings for the sync manager
4 participants