Loading components/service/sync-logins/src/main/java/mozilla/components/service/sync/logins/DefaultLoginValidationDelegate.kt +5 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,11 @@ class DefaultLoginValidationDelegate( override fun validateCanPersist(login: Login): Deferred<Result> { return scope.async { try { storage.ensureValid(login) // We're setting guid=null here in order to trigger de-duping logic properly. // Internally, the library ensures to not dupe records against themselves // (via a `guid <> :guid` check), which means we need to "pretend" this is a new record, // in order for `ensureValid` to actually throw `DUPLICATE_LOGIN`. storage.ensureValid(login.copy(guid = null)) Result.CanBeCreated } catch (e: InvalidRecordException) { when (e.reason) { Loading components/service/sync-logins/src/main/java/mozilla/components/service/sync/logins/GeckoLoginStorageDelegate.kt +5 −5 Original line number Diff line number Diff line Loading @@ -88,15 +88,15 @@ class GeckoLoginStorageDelegate( Operation.CREATE -> { // If an existing Login was autofilled, we want to clear its guid to // avoid updating its record loginStorage.add(login.copy(guid = "")) loginStorage.add(login.copy(guid = null)) } } } } /** * Returns whether an existing login record should be [UPDATE]d or a new one [CREATE]d, based * on the saved [ServerPassword] and new [Login]. * Returns whether an existing login record should be UPDATED or a new one [CREATE]d, based * on the saved [Login] and new [Login]. */ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) fun getPersistenceOperation(newLogin: Login, savedLogin: Login?): Operation = when { Loading Loading @@ -146,8 +146,8 @@ fun Login.mergeWithLogin(login: Login): Login { * Converts an Android Components [Login] to an Application Services [ServerPassword] */ fun Login.toServerPassword() = ServerPassword( // Underlying Rust code will generate a new GUID id = "", // Underlying Rust code will generate a new GUID if `guid` is missing. id = guid ?: "", username = username, password = password, hostname = origin, Loading components/service/sync-logins/src/main/java/mozilla/components/service/sync/logins/SyncableLoginsStorage.kt +1 −0 Original line number Diff line number Diff line Loading @@ -183,6 +183,7 @@ class SyncableLoginsStorage( */ @Throws(IdCollisionException::class, InvalidRecordException::class, LoginsStorageException::class) override suspend fun add(login: Login): String = withContext(coroutineContext) { check(login.guid == null) { "'guid' for a new login must be `null`" } conn.getStorage().add(login.toServerPassword()) } Loading Loading
components/service/sync-logins/src/main/java/mozilla/components/service/sync/logins/DefaultLoginValidationDelegate.kt +5 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,11 @@ class DefaultLoginValidationDelegate( override fun validateCanPersist(login: Login): Deferred<Result> { return scope.async { try { storage.ensureValid(login) // We're setting guid=null here in order to trigger de-duping logic properly. // Internally, the library ensures to not dupe records against themselves // (via a `guid <> :guid` check), which means we need to "pretend" this is a new record, // in order for `ensureValid` to actually throw `DUPLICATE_LOGIN`. storage.ensureValid(login.copy(guid = null)) Result.CanBeCreated } catch (e: InvalidRecordException) { when (e.reason) { Loading
components/service/sync-logins/src/main/java/mozilla/components/service/sync/logins/GeckoLoginStorageDelegate.kt +5 −5 Original line number Diff line number Diff line Loading @@ -88,15 +88,15 @@ class GeckoLoginStorageDelegate( Operation.CREATE -> { // If an existing Login was autofilled, we want to clear its guid to // avoid updating its record loginStorage.add(login.copy(guid = "")) loginStorage.add(login.copy(guid = null)) } } } } /** * Returns whether an existing login record should be [UPDATE]d or a new one [CREATE]d, based * on the saved [ServerPassword] and new [Login]. * Returns whether an existing login record should be UPDATED or a new one [CREATE]d, based * on the saved [Login] and new [Login]. */ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) fun getPersistenceOperation(newLogin: Login, savedLogin: Login?): Operation = when { Loading Loading @@ -146,8 +146,8 @@ fun Login.mergeWithLogin(login: Login): Login { * Converts an Android Components [Login] to an Application Services [ServerPassword] */ fun Login.toServerPassword() = ServerPassword( // Underlying Rust code will generate a new GUID id = "", // Underlying Rust code will generate a new GUID if `guid` is missing. id = guid ?: "", username = username, password = password, hostname = origin, Loading
components/service/sync-logins/src/main/java/mozilla/components/service/sync/logins/SyncableLoginsStorage.kt +1 −0 Original line number Diff line number Diff line Loading @@ -183,6 +183,7 @@ class SyncableLoginsStorage( */ @Throws(IdCollisionException::class, InvalidRecordException::class, LoginsStorageException::class) override suspend fun add(login: Login): String = withContext(coroutineContext) { check(login.guid == null) { "'guid' for a new login must be `null`" } conn.getStorage().add(login.toServerPassword()) } Loading