Skip to content

Commit 3a4ab53

Browse files
committed
Remove sync15's "standalone-sync" feature, remove UDL for a single enum.
Remove the udl for sync15 - it just had one enum. "Bonus" update of the crate to 2024, which is a bigger diff than I anticipated. Seems ok though?
1 parent 32693fe commit 3a4ab53

33 files changed

Lines changed: 84 additions & 469 deletions

components/logins/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ default = []
1111
keydb = ["nss/keydb", "dep:async-trait", "dep:futures"]
1212

1313
[dependencies]
14-
# TODO: we've enabled the "standalone-sync" feature - see the description
15-
# of this feature in sync15's Cargo.toml for what we should do instead.
16-
sync15 = { path = "../sync15", features=["standalone-sync"] }
14+
sync15 = { path = "../sync15" }
1715
serde = "1"
1816
serde_derive = "1"
1917
serde_json = "1"

components/logins/src/error.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub use error_support::{debug, error, info, trace, warn};
1212

1313
use error_support::{ErrorHandling, GetErrorHandling};
1414
use jwcrypto::JwCryptoError;
15-
use sync15::Error as Sync15Error;
1615

1716
// Errors we return via the public interface.
1817
#[derive(Debug, thiserror::Error)]
@@ -50,9 +49,6 @@ pub enum LoginsApiError {
5049
#[error("{reason}")]
5150
Interrupted { reason: String },
5251

53-
#[error("SyncAuthInvalid error {reason}")]
54-
SyncAuthInvalid { reason: String },
55-
5652
#[error("Unexpected Error: {reason}")]
5753
UnexpectedLoginsApiError { reason: String },
5854
}
@@ -87,9 +83,6 @@ pub enum Error {
8783
#[error("decryption failed: {0:?}")]
8884
DecryptionFailed(String),
8985

90-
#[error("Error synchronizing: {0}")]
91-
SyncAdapterError(#[from] sync15::Error),
92-
9386
#[error("Error parsing JSON data: {0}")]
9487
JsonError(#[from] serde_json::Error),
9588

@@ -171,24 +164,6 @@ impl GetErrorHandling for Error {
171164
Self::Interrupted(_) => ErrorHandling::convert(LoginsApiError::Interrupted {
172165
reason: self.to_string(),
173166
}),
174-
Self::SyncAdapterError(e) => match e {
175-
Sync15Error::TokenserverHttpError(401) | Sync15Error::BadKeyLength(..) => {
176-
ErrorHandling::convert(LoginsApiError::SyncAuthInvalid {
177-
reason: e.to_string(),
178-
})
179-
.log_warning()
180-
}
181-
Sync15Error::RequestError(_) => {
182-
ErrorHandling::convert(LoginsApiError::UnexpectedLoginsApiError {
183-
reason: e.to_string(),
184-
})
185-
.log_warning()
186-
}
187-
_ => ErrorHandling::convert(LoginsApiError::UnexpectedLoginsApiError {
188-
reason: self.to_string(),
189-
})
190-
.report_error("logins-sync"),
191-
},
192167
Error::SqlError(rusqlite::Error::SqliteFailure(err, _)) => match err.code {
193168
rusqlite::ErrorCode::DatabaseCorrupt => {
194169
ErrorHandling::convert(LoginsApiError::UnexpectedLoginsApiError {

components/logins/src/logins.udl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ interface LoginsApiError {
146146
/// An operation was interrupted at the request of the consuming app.
147147
Interrupted(string reason);
148148

149-
/// Sync reported that authentication failed and the user should re-enter their FxA password.
150-
// TODO: remove this at the same time as remove the sync() method in favour of the SyncManager.
151-
SyncAuthInvalid(string reason);
152-
153149
/// something internal went wrong which doesn't have a public error value
154150
/// because the consuming app can not reasonably take any action to resolve it.
155151
/// The underlying error will have been logged and reported.

components/logins/src/schema.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,9 @@
7878
//! This table was added (by this rust crate) in version 4, and so is not
7979
//! present in firefox-ios.
8080
//!
81-
//! Currently it is used to store two items:
82-
//!
83-
//! 1. The last sync timestamp is stored under [LAST_SYNC_META_KEY], a
81+
//! Currently it is used to store the last sync timestamp, under [LAST_SYNC_META_KEY], a
8482
//! `sync15::ServerTimestamp` stored in integer milliseconds.
8583
//!
86-
//! 2. The persisted sync state machine information is stored under
87-
//! [GLOBAL_STATE_META_KEY]. This is a `sync15::GlobalState` stored as
88-
//! JSON.
89-
//!
9084
9185
use crate::error::*;
9286
use lazy_static::lazy_static;
@@ -197,7 +191,6 @@ const CREATE_DELETED_ORIGIN_INDEX_SQL: &str = "
197191
";
198192

199193
pub(crate) static LAST_SYNC_META_KEY: &str = "last_sync_time";
200-
pub(crate) static GLOBAL_STATE_META_KEY: &str = "global_state_v2";
201194
pub(crate) static GLOBAL_SYNCID_META_KEY: &str = "global_sync_id";
202195
pub(crate) static COLLECTION_SYNCID_META_KEY: &str = "passwords_sync_id";
203196
pub(crate) static CHECKPOINT_KEY: &str = "checkpoint";

components/logins/src/sync/engine.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,6 @@ impl LoginsSyncEngine {
297297
Ok(Some(ServerTimestamp(millis)))
298298
}
299299

300-
pub fn set_global_state(&self, state: &Option<String>) -> Result<()> {
301-
let to_write = match state {
302-
Some(ref s) => s,
303-
None => "",
304-
};
305-
let db = self.store.lock_db()?;
306-
db.put_meta(schema::GLOBAL_STATE_META_KEY, &to_write)
307-
}
308-
309-
pub fn get_global_state(&self) -> Result<Option<String>> {
310-
let db = self.store.lock_db()?;
311-
db.get_meta::<String>(schema::GLOBAL_STATE_META_KEY)
312-
}
313-
314300
fn mark_as_synchronized(&self, guids: &[&str], ts: ServerTimestamp) -> Result<()> {
315301
let db = self.store.lock_db()?;
316302
let tx = db.unchecked_transaction()?;
@@ -378,7 +364,6 @@ impl LoginsSyncEngine {
378364
db.put_meta(schema::COLLECTION_SYNCID_META_KEY, &ids.coll)?;
379365
}
380366
};
381-
db.delete_meta(schema::GLOBAL_STATE_META_KEY)?;
382367
tx.commit()?;
383368
Ok(())
384369
}

components/places/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ exclude = ["/android", "/ios"]
1010
default = []
1111

1212
[dependencies]
13-
# TODO: we've enabled the "standalone-sync" feature - see the description
14-
# of this feature in sync15's Cargo.toml for what we should do instead.
15-
sync15 = { path = "../sync15", features=["standalone-sync"] }
13+
sync15 = { path = "../sync15" }
1614
serde = "1"
1715
serde_derive = "1"
1816
serde_json = "1"

components/places/src/api/places_api.rs

Lines changed: 1 addition & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,19 @@ use crate::bookmark_sync::BookmarksSyncEngine;
66
use crate::db::db::{PlacesDb, SharedPlacesDb};
77
use crate::error::*;
88
use crate::history_sync::HistorySyncEngine;
9-
use crate::storage::{
10-
self, bookmarks::bookmark_sync, delete_meta, get_meta, history::history_sync, put_meta,
11-
};
129
use crate::util::normalize_path;
1310
use error_support::handle_error;
1411
use interrupt_support::register_interrupt;
1512
use lazy_static::lazy_static;
1613
use parking_lot::Mutex;
1714
use rusqlite::OpenFlags;
18-
use std::cell::Cell;
1915
use std::collections::HashMap;
2016
use std::path::{Path, PathBuf};
2117
use std::sync::{
2218
atomic::{AtomicUsize, Ordering},
2319
Arc, Weak,
2420
};
25-
use sync15::client::{sync_multiple, MemoryCachedState, Sync15StorageClientInit, SyncResult};
26-
use sync15::engine::{EngineSyncAssociation, SyncEngine, SyncEngineId};
27-
use sync15::{telemetry, KeyBundle};
28-
29-
// Not clear if this should be here, but this is the "global sync state"
30-
// which is persisted to disk and reused for all engines.
31-
// Note that this is only ever round-tripped, and never changed by, or impacted
32-
// by a store or collection, so it's safe to storage globally rather than
33-
// per collection.
34-
pub const GLOBAL_STATE_META_KEY: &str = "global_sync_state_v2";
21+
use sync15::engine::{SyncEngine, SyncEngineId};
3522

3623
// Our "sync manager" will use whatever is stashed here.
3724
lazy_static::lazy_static! {
@@ -121,11 +108,6 @@ lazy_static! {
121108

122109
static ID_COUNTER: AtomicUsize = AtomicUsize::new(0);
123110

124-
pub struct SyncState {
125-
pub mem_cached_state: Cell<MemoryCachedState>,
126-
pub disk_cached_state: Cell<Option<String>>,
127-
}
128-
129111
/// For uniffi we need to expose our `Arc` returning constructor as a global function :(
130112
/// https://github.com/mozilla/uniffi-rs/pull/1063 would fix this, but got some pushback
131113
/// meaning we are forced into this unfortunate workaround.
@@ -140,7 +122,6 @@ pub fn places_api_new(db_name: impl AsRef<Path>) -> ApiResult<Arc<PlacesApi>> {
140122
pub struct PlacesApi {
141123
db_name: PathBuf,
142124
write_connection: Mutex<Option<PlacesDb>>,
143-
sync_state: Mutex<Option<SyncState>>,
144125
coop_tx_lock: Arc<Mutex<()>>,
145126
// Used for get_sync_connection()
146127
// - The inner mutex synchronizes sync operation (for example one of the [SyncEngine] methods).
@@ -188,7 +169,6 @@ impl PlacesApi {
188169
let new = PlacesApi {
189170
db_name: db_name.clone(),
190171
write_connection: Mutex::new(Some(connection)),
191-
sync_state: Mutex::new(None),
192172
sync_connection: Mutex::new(Weak::new()),
193173
id,
194174
coop_tx_lock,
@@ -275,17 +255,6 @@ impl PlacesApi {
275255
Ok(())
276256
}
277257

278-
fn get_disk_persisted_state(&self, conn: &PlacesDb) -> Result<Option<String>> {
279-
get_meta::<String>(conn, GLOBAL_STATE_META_KEY)
280-
}
281-
282-
fn set_disk_persisted_state(&self, conn: &PlacesDb, state: &Option<String>) -> Result<()> {
283-
match state {
284-
Some(ref s) => put_meta(conn, GLOBAL_STATE_META_KEY, s),
285-
None => delete_meta(conn, GLOBAL_STATE_META_KEY),
286-
}
287-
}
288-
289258
// This allows the embedding app to say "make this instance available to
290259
// the sync manager". The implementation is more like "offer to sync mgr"
291260
// (thereby avoiding us needing to link with the sync manager) but
@@ -294,177 +263,6 @@ impl PlacesApi {
294263
pub fn register_with_sync_manager(self: Arc<Self>) {
295264
*PLACES_API_FOR_SYNC_MANAGER.lock() = Arc::downgrade(&self);
296265
}
297-
298-
// NOTE: These should be deprecated as soon as possible - that will be once
299-
// all consumers have been updated to use the .sync() method below, and/or
300-
// we have implemented the sync manager and migrated consumers to that.
301-
pub fn sync_history(
302-
&self,
303-
client_init: &Sync15StorageClientInit,
304-
key_bundle: &KeyBundle,
305-
) -> Result<telemetry::SyncTelemetryPing> {
306-
self.do_sync_one(
307-
"history",
308-
move |conn, mem_cached_state, disk_cached_state| {
309-
let engine = HistorySyncEngine::new(conn)?;
310-
Ok(sync_multiple(
311-
&[&engine],
312-
disk_cached_state,
313-
mem_cached_state,
314-
client_init,
315-
key_bundle,
316-
&interrupt_support::ShutdownInterruptee,
317-
None,
318-
))
319-
},
320-
)
321-
}
322-
323-
pub fn sync_bookmarks(
324-
&self,
325-
client_init: &Sync15StorageClientInit,
326-
key_bundle: &KeyBundle,
327-
) -> Result<telemetry::SyncTelemetryPing> {
328-
self.do_sync_one(
329-
"bookmarks",
330-
move |conn, mem_cached_state, disk_cached_state| {
331-
let engine = BookmarksSyncEngine::new(conn)?;
332-
Ok(sync_multiple(
333-
&[&engine],
334-
disk_cached_state,
335-
mem_cached_state,
336-
client_init,
337-
key_bundle,
338-
&interrupt_support::ShutdownInterruptee,
339-
None,
340-
))
341-
},
342-
)
343-
}
344-
345-
pub fn do_sync_one<F>(
346-
&self,
347-
name: &'static str,
348-
syncer: F,
349-
) -> Result<telemetry::SyncTelemetryPing>
350-
where
351-
F: FnOnce(
352-
Arc<SharedPlacesDb>,
353-
&mut MemoryCachedState,
354-
&mut Option<String>,
355-
) -> Result<SyncResult>,
356-
{
357-
let mut guard = self.sync_state.lock();
358-
let conn = self.get_sync_connection()?;
359-
if guard.is_none() {
360-
*guard = Some(SyncState {
361-
mem_cached_state: Cell::default(),
362-
disk_cached_state: Cell::new(self.get_disk_persisted_state(&conn.lock())?),
363-
});
364-
}
365-
366-
let sync_state = guard.as_ref().unwrap();
367-
368-
let mut mem_cached_state = sync_state.mem_cached_state.take();
369-
let mut disk_cached_state = sync_state.disk_cached_state.take();
370-
let mut result = syncer(conn.clone(), &mut mem_cached_state, &mut disk_cached_state)?;
371-
// even on failure we set the persisted state - sync itself takes care
372-
// to ensure this has been None'd out if necessary.
373-
self.set_disk_persisted_state(&conn.lock(), &disk_cached_state)?;
374-
sync_state.mem_cached_state.replace(mem_cached_state);
375-
sync_state.disk_cached_state.replace(disk_cached_state);
376-
377-
// for b/w compat reasons, we do some dances with the result.
378-
if let Err(e) = result.result {
379-
return Err(e.into());
380-
}
381-
match result.engine_results.remove(name) {
382-
None | Some(Ok(())) => Ok(result.telemetry),
383-
Some(Err(e)) => Err(e.into()),
384-
}
385-
}
386-
387-
// This is the new sync API until the sync manager lands. It's currently
388-
// not wired up via the FFI - it's possible we'll do declined engines too
389-
// before we do.
390-
// Note we've made a policy decision about the return value - even though
391-
// it is Result<SyncResult>, we will only return an Err() if there's a
392-
// fatal error that prevents us starting a sync, such as failure to open
393-
// the DB. Any errors that happen *after* sync must not escape - ie, once
394-
// we have a SyncResult, we must return it.
395-
pub fn sync(
396-
&self,
397-
client_init: &Sync15StorageClientInit,
398-
key_bundle: &KeyBundle,
399-
) -> Result<SyncResult> {
400-
let mut guard = self.sync_state.lock();
401-
let conn = self.get_sync_connection()?;
402-
if guard.is_none() {
403-
*guard = Some(SyncState {
404-
mem_cached_state: Cell::default(),
405-
disk_cached_state: Cell::new(self.get_disk_persisted_state(&conn.lock())?),
406-
});
407-
}
408-
409-
let sync_state = guard.as_ref().unwrap();
410-
411-
let bm_engine = BookmarksSyncEngine::new(conn.clone())?;
412-
let history_engine = HistorySyncEngine::new(conn.clone())?;
413-
let mut mem_cached_state = sync_state.mem_cached_state.take();
414-
let mut disk_cached_state = sync_state.disk_cached_state.take();
415-
416-
// NOTE: After here we must never return Err()!
417-
let result = sync_multiple(
418-
&[&history_engine, &bm_engine],
419-
&mut disk_cached_state,
420-
&mut mem_cached_state,
421-
client_init,
422-
key_bundle,
423-
&interrupt_support::ShutdownInterruptee,
424-
None,
425-
);
426-
// even on failure we set the persisted state - sync itself takes care
427-
// to ensure this has been None'd out if necessary.
428-
if let Err(e) = self.set_disk_persisted_state(&conn.lock(), &disk_cached_state) {
429-
error_support::report_error!(
430-
"places-sync-persist-failure",
431-
"Failed to persist the sync state: {:?}",
432-
e
433-
);
434-
}
435-
sync_state.mem_cached_state.replace(mem_cached_state);
436-
sync_state.disk_cached_state.replace(disk_cached_state);
437-
438-
Ok(result)
439-
}
440-
441-
pub fn wipe_bookmarks(&self) -> Result<()> {
442-
// Take the lock to prevent syncing while we're doing this.
443-
let _guard = self.sync_state.lock();
444-
let conn = self.get_sync_connection()?;
445-
446-
storage::bookmarks::delete_everything(&conn.lock())?;
447-
Ok(())
448-
}
449-
450-
pub fn reset_bookmarks(&self) -> Result<()> {
451-
// Take the lock to prevent syncing while we're doing this.
452-
let _guard = self.sync_state.lock();
453-
let conn = self.get_sync_connection()?;
454-
455-
bookmark_sync::reset(&conn.lock(), &EngineSyncAssociation::Disconnected)?;
456-
Ok(())
457-
}
458-
459-
#[handle_error(crate::Error)]
460-
pub fn reset_history(&self) -> ApiResult<()> {
461-
// Take the lock to prevent syncing while we're doing this.
462-
let _guard = self.sync_state.lock();
463-
let conn = self.get_sync_connection()?;
464-
465-
history_sync::reset(&conn.lock(), &EngineSyncAssociation::Disconnected)?;
466-
Ok(())
467-
}
468266
}
469267

470268
#[cfg(test)]

0 commit comments

Comments
 (0)