-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PM-15177: Improve destructive fallback logic (#4373)
- Loading branch information
1 parent
2e18458
commit 8e7ec7a
Showing
11 changed files
with
102 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 4 additions & 9 deletions
13
app/src/main/java/com/x8bit/bitwarden/data/platform/manager/DatabaseSchemeManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,18 @@ | ||
package com.x8bit.bitwarden.data.platform.manager | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import java.time.Instant | ||
|
||
/** | ||
* Manager for tracking changes to database scheme(s). | ||
*/ | ||
interface DatabaseSchemeManager { | ||
|
||
/** | ||
* The instant of the last database schema change performed on the database, if any. | ||
* | ||
* There is only a single scheme change instant tracked for all database schemes. It is expected | ||
* that a scheme change to any database will update this value and trigger a sync. | ||
* Clears the sync state for all users and emits on the [databaseSchemeChangeFlow]. | ||
*/ | ||
var lastDatabaseSchemeChangeInstant: Instant? | ||
fun clearSyncState() | ||
|
||
/** | ||
* A flow of the last database schema change instant. | ||
* Emits whenever the sync state hs been cleared. | ||
*/ | ||
val lastDatabaseSchemeChangeInstantFlow: Flow<Instant?> | ||
val databaseSchemeChangeFlow: Flow<Unit> | ||
} |
33 changes: 13 additions & 20 deletions
33
app/src/main/java/com/x8bit/bitwarden/data/platform/manager/DatabaseSchemeManagerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,27 @@ | ||
package com.x8bit.bitwarden.data.platform.manager | ||
|
||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource | ||
import com.x8bit.bitwarden.data.platform.datasource.disk.SettingsDiskSource | ||
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.stateIn | ||
import java.time.Instant | ||
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
|
||
/** | ||
* Primary implementation of [DatabaseSchemeManager]. | ||
*/ | ||
class DatabaseSchemeManagerImpl( | ||
val authDiskSource: AuthDiskSource, | ||
val settingsDiskSource: SettingsDiskSource, | ||
val dispatcherManager: DispatcherManager, | ||
) : DatabaseSchemeManager { | ||
private val mutableSharedFlow: MutableSharedFlow<Unit> = bufferedMutableSharedFlow() | ||
|
||
private val unconfinedScope = CoroutineScope(dispatcherManager.unconfined) | ||
|
||
override var lastDatabaseSchemeChangeInstant: Instant? | ||
get() = settingsDiskSource.lastDatabaseSchemeChangeInstant | ||
set(value) { | ||
settingsDiskSource.lastDatabaseSchemeChangeInstant = value | ||
override fun clearSyncState() { | ||
authDiskSource.userState?.accounts?.forEach { (userId, _) -> | ||
settingsDiskSource.storeLastSyncTime(userId = userId, lastSyncTime = null) | ||
} | ||
mutableSharedFlow.tryEmit(Unit) | ||
} | ||
|
||
override val lastDatabaseSchemeChangeInstantFlow = | ||
settingsDiskSource | ||
.lastDatabaseSchemeChangeInstantFlow | ||
.stateIn( | ||
scope = unconfinedScope, | ||
started = SharingStarted.Eagerly, | ||
initialValue = settingsDiskSource.lastDatabaseSchemeChangeInstant, | ||
) | ||
override val databaseSchemeChangeFlow: Flow<Unit> = mutableSharedFlow.asSharedFlow() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.