-
Notifications
You must be signed in to change notification settings - Fork 229
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
Wrap the autofill implementation in an Arc<> to help the sync manager. #3935
Conversation
The other thing I meant to say is that as we discussed, this inverts how the sync manager gets engines. Currently, something (ie, Fenix code) needs a reference to both places and the sync manager and calls (something like) However, in this world, Fenix only needs a reference to the autofill store, and can do just |
cc @jhugman for context on that uniffi ticket. |
components/autofill/src/db/store.rs
Outdated
// This is the type that uniffi exposes. It holds an `Arc<Mutex<>>` around the | ||
// actual implementation, because we need access to the `Arc<Mutex<>>` for | ||
// integration with the sync manager. Our UDL also defines us as being | ||
// "ThreadSafe" to we manage our own locking via the `Mutex` - but this means |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "so" we manage?
// in practice we are actually held via an `Arc<Arc<Mutex<>>>` - but one day | ||
// https://github.com/mozilla/uniffi-rs/issues/417 will give us access to the | ||
// `Arc<>` uniffi owns, which means we can drop this mess entirely (ie, `Store`) | ||
// can then just have a mutex around the DB. | ||
pub struct Store { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the Store
struct need to be public? It looks like StoreImpl
is the type that is being imported. Or if both should be public maybe an explanation as to which should be used in what circumstances. There may be an easy explanation that I'm missing, but I could see myself getting confused in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got confusing quickly and sadly they both need to be pub. Store
needs to be pub because the sync manager uses it (StoreImpl has the Arc<Store>
which we clone and hand to the sync manager, so it gets the Store
) and Store
needs to be pub because autofill-utils needs it to get the sync engines.
So yeah, this sucks and I added some comments, but hopefully we can get rid of this confusion with the proposed autofill enhancements.
I'm about to put up a new version that doesn't wrap the entire store in an |
4e6569b
to
705477c
Compare
705477c
to
6f533f2
Compare
Codecov Report
@@ Coverage Diff @@
## main #3935 +/- ##
=======================================
Coverage 0.00% 0.00%
=======================================
Files 101 75 -26
Lines 5903 4439 -1464
=======================================
+ Misses 5903 4439 -1464
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This patch works-around the lack of the functionlity described in mozilla/uniffi-rs#417. In short, it splits the store into 2 parts - the uniffi-exposed "wrapper" and the actual implementation. This "wrapper" wraps the implementation in an `Arc<>`, so that it can hand a clone of this `Arc<>` to the sync manager, so that it can construct sync engines, causing us to end up with multiple references to the `Store` being alive but without any being actual `&` references. The database itself continues to be wrapped in a `Mutex<>` It also makes some changes in the sync manager, really just enough to convince me that it will work - there will be plenty of other places that will need similar treatment. I chose to use the `SyncEngine` trait exclusively there, which I think makes sense because ideally we'd use that trait *everywhere* to avoid the Sync Manager knowing about the implementation (but it would still require it to link to all those crates, so that's just a code-simplicity issue)
6f533f2
to
c38ce09
Compare
This patch works-around the lack of the functionality described
in mozilla/uniffi-rs#417.
In short, it splits the store into 2 parts - the
uniffi-exposed "wrapper" and the actual implementation.
This "wrapper" wraps the implementation in an
Arc<Mutex>>
, sothat it can hand a clone of this
Arc<>
to the sync manager, sothat it can construct sync engines, causing us to end up with
multiple references to the
Store
being alive but without anybeing actual
&
references.(Thinking some more about it, I probably could have done this
slightly differently, and just wrapped the DB itself, but I
ended up somewhat automatically taking this route because this
is what the shape would naturally be if uniffi helped us.
I think passing the entire store around does make more sense
in the longer term anyway (eg, there might be other state beyond
the DB) and is what the other components do, but it does make
this patch bigger than it would otherwise be)
It also makes some changes in the sync manager, really just
enough to convince me that it will work - there will be plenty
of other places that will need similar treatment. I chose to
use the
SyncEngine
trait exclusively there, which I think makessense because ideally we'd use that trait everywhere to avoid the
Sync Manager knowing about the implementation (but it would still
require it to link to all those crates, so that's just a
code-simplicity issue)