pub trait BridgedEngine: Send + Sync {
Show 13 methods
// Required methods
fn last_sync(&self) -> Result<i64>;
fn set_last_sync(&self, last_sync_millis: i64) -> Result<()>;
fn sync_id(&self) -> Result<Option<String>>;
fn reset_sync_id(&self) -> Result<String>;
fn ensure_current_sync_id(&self, new_sync_id: &str) -> Result<String>;
fn sync_started(&self) -> Result<()>;
fn store_incoming(&self, incoming_records: Vec<IncomingBso>) -> Result<()>;
fn apply(&self) -> Result<ApplyResults>;
fn set_uploaded(
&self,
server_modified_millis: i64,
ids: &[Guid],
) -> Result<()>;
fn sync_finished(&self) -> Result<()>;
fn reset(&self) -> Result<()>;
fn wipe(&self) -> Result<()>;
// Provided method
fn prepare_for_sync(&self, _client_data: &str) -> Result<()> { ... }
}
Expand description
A BridgedEngine acts as a bridge between application-services, rust implemented sync engines and sync engines as defined by Desktop Firefox.
Desktop Firefox has an abstract implementation of a Sync Engine with a number of functions each engine is expected to override. Engines implemented in Rust use a different shape (specifically, the SyncEngine trait), so this BridgedEngine trait adapts between the 2.
Required Methods§
sourcefn last_sync(&self) -> Result<i64>
fn last_sync(&self) -> Result<i64>
Returns the last sync time, in milliseconds, for this engine’s collection. This is called before each sync, to determine the lower bound for new records to fetch from the server.
sourcefn set_last_sync(&self, last_sync_millis: i64) -> Result<()>
fn set_last_sync(&self, last_sync_millis: i64) -> Result<()>
Sets the last sync time, in milliseconds. This is called throughout the sync, to fast-forward the stored last sync time to match the timestamp on the uploaded records.
sourcefn sync_id(&self) -> Result<Option<String>>
fn sync_id(&self) -> Result<Option<String>>
Returns the sync ID for this engine’s collection. This is only used in tests.
sourcefn reset_sync_id(&self) -> Result<String>
fn reset_sync_id(&self) -> Result<String>
Resets the sync ID for this engine’s collection, returning the new ID.
As a side effect, implementations should reset all local Sync state,
as in reset
.
(Note that bridged engines never maintain the “global” guid - that’s all managed
by the bridged_engine consumer (ie, desktop). bridged_engines only care about
the per-collection one.)
sourcefn ensure_current_sync_id(&self, new_sync_id: &str) -> Result<String>
fn ensure_current_sync_id(&self, new_sync_id: &str) -> Result<String>
Ensures that the locally stored sync ID for this engine’s collection
matches the new_sync_id
from the server. If the two don’t match,
implementations should reset all local Sync state, as in reset
.
This method returns the assigned sync ID, which can be either the
new_sync_id
, or a different one if the engine wants to force other
devices to reset their Sync state for this collection the next time they
sync.
sourcefn sync_started(&self) -> Result<()>
fn sync_started(&self) -> Result<()>
Indicates that the engine is about to start syncing. This is called
once per sync, and always before store_incoming
.
sourcefn store_incoming(&self, incoming_records: Vec<IncomingBso>) -> Result<()>
fn store_incoming(&self, incoming_records: Vec<IncomingBso>) -> Result<()>
Stages a batch of incoming Sync records. This is called multiple times per sync, once for each batch. Implementations can use the signal to check if the operation was aborted, and cancel any pending work.
sourcefn apply(&self) -> Result<ApplyResults>
fn apply(&self) -> Result<ApplyResults>
Applies all staged records, reconciling changes on both sides and resolving conflicts. Returns a list of records to upload.
sourcefn set_uploaded(&self, server_modified_millis: i64, ids: &[Guid]) -> Result<()>
fn set_uploaded(&self, server_modified_millis: i64, ids: &[Guid]) -> Result<()>
Indicates that the given record IDs were uploaded successfully to the server. This is called multiple times per sync, once for each batch upload.
sourcefn sync_finished(&self) -> Result<()>
fn sync_finished(&self) -> Result<()>
Indicates that all records have been uploaded. At this point, any record
IDs marked for upload that haven’t been passed to set_uploaded
, can be
assumed to have failed: for example, because the server rejected a record
with an invalid TTL or sort index.
Provided Methods§
sourcefn prepare_for_sync(&self, _client_data: &str) -> Result<()>
fn prepare_for_sync(&self, _client_data: &str) -> Result<()>
Tells the tabs engine about recent FxA devices. A bit of a leaky abstraction as it only
makes sense for tabs.
The arg is a json serialized ClientData
struct.