Commit 0ac4adeb authored by MozLando's avatar MozLando
Browse files

Merge #6395

6395: Closes #6354 - Take Lazy references to storage in FennecMigrator r=jonalmeida a=grigoryk

This is a follow-up to https://github.com/mozilla-mobile/android-components/issues/6304

, in which I forget that FennecMigrator exists.
Co-authored-by: default avatarGrisha Kruglov <gkruglov@mozilla.com>
parents 3d18d874 d10c9e21
......@@ -210,12 +210,12 @@ class FennecMigrator private constructor(
private val context: Context,
private val crashReporter: CrashReporter,
private val migrations: List<VersionedMigration>,
private val historyStorage: PlacesHistoryStorage?,
private val bookmarksStorage: PlacesBookmarksStorage?,
private val loginsStorage: SyncableLoginsStorage?,
private val historyStorage: Lazy<PlacesHistoryStorage>?,
private val bookmarksStorage: Lazy<PlacesBookmarksStorage>?,
private val loginsStorage: Lazy<SyncableLoginsStorage>?,
private val sessionManager: SessionManager?,
private val searchEngineManager: SearchEngineManager?,
private val accountManager: FxaAccountManager?,
private val accountManager: Lazy<FxaAccountManager>?,
private val engine: Engine?,
private val addonCollectionProvider: AddonCollectionProvider?,
private val addonUpdater: AddonUpdater?,
......@@ -232,13 +232,13 @@ class FennecMigrator private constructor(
*/
@Suppress("TooManyFunctions")
class Builder(private val context: Context, private val crashReporter: CrashReporter) {
private var historyStorage: PlacesHistoryStorage? = null
private var bookmarksStorage: PlacesBookmarksStorage? = null
private var loginsStorage: SyncableLoginsStorage? = null
private var historyStorage: Lazy<PlacesHistoryStorage>? = null
private var bookmarksStorage: Lazy<PlacesBookmarksStorage>? = null
private var loginsStorage: Lazy<SyncableLoginsStorage>? = null
private var loginsStorageKey: String? = null
private var sessionManager: SessionManager? = null
private var searchEngineManager: SearchEngineManager? = null
private var accountManager: FxaAccountManager? = null
private var accountManager: Lazy<FxaAccountManager>? = null
private var engine: Engine? = null
private var addonCollectionProvider: AddonCollectionProvider? = null
private var addonUpdater: AddonUpdater? = null
......@@ -262,7 +262,10 @@ class FennecMigrator private constructor(
* @param storage An instance of [PlacesHistoryStorage], used for storing data.
* @param version Version of the migration; defaults to the current version.
*/
fun migrateHistory(storage: PlacesHistoryStorage, version: Int = Migration.History.currentVersion): Builder {
fun migrateHistory(
storage: Lazy<PlacesHistoryStorage>,
version: Int = Migration.History.currentVersion
): Builder {
check(migrations.find { it.migration is Migration.FxA } == null) {
"FxA migration, if desired, must run after history"
}
......@@ -281,7 +284,7 @@ class FennecMigrator private constructor(
* @param version Version of the migration; defaults to the current version.
*/
fun migrateBookmarks(
storage: PlacesBookmarksStorage,
storage: Lazy<PlacesBookmarksStorage>,
topSiteStorage: TopSiteStorage? = null,
version: Int = Migration.Bookmarks.currentVersion
): Builder {
......@@ -311,7 +314,7 @@ class FennecMigrator private constructor(
* @param storage An instance of [AsyncLoginsStorage], used for storing data.
*/
fun migrateLogins(
storage: SyncableLoginsStorage,
storage: Lazy<SyncableLoginsStorage>,
version: Int = Migration.Logins.currentVersion
): Builder {
check(migrations.find { it.migration is Migration.FxA } == null) {
......@@ -366,7 +369,7 @@ class FennecMigrator private constructor(
* @param accountManager An instance of [FxaAccountManager] used for authenticating using a migrated account.
* @param version Version of the migration; defaults to the current version.
*/
fun migrateFxa(accountManager: FxaAccountManager, version: Int = Migration.FxA.currentVersion): Builder {
fun migrateFxa(accountManager: Lazy<FxaAccountManager>, version: Int = Migration.FxA.currentVersion): Builder {
this.accountManager = accountManager
migrations.add(VersionedMigration(Migration.FxA, version))
return this
......@@ -657,7 +660,7 @@ class FennecMigrator private constructor(
val migrationMetrics = try {
logger.debug("Migrating history...")
historyStorage.importFromFennec(browserDbPath)
historyStorage.value.importFromFennec(browserDbPath)
} catch (e: Exception) {
crashReporter.submitCaughtException(FennecMigratorException.MigrateHistoryException(e))
MigrationHistory.failureReason.add(FailureReasonTelemetryCodes.HISTORY_RUST_EXCEPTION.code)
......@@ -702,7 +705,7 @@ class FennecMigrator private constructor(
val migrationMetrics = try {
logger.debug("Migrating bookmarks...")
bookmarksStorage.importFromFennec(browserDbPath)
bookmarksStorage.value.importFromFennec(browserDbPath)
} catch (e: Exception) {
crashReporter.submitCaughtException(
FennecMigratorException.MigrateBookmarksException(e)
......@@ -746,7 +749,7 @@ class FennecMigrator private constructor(
crashReporter,
signonsDbPath = "${profile.path}/$signonsDbName",
key4DbPath = "${profile.path}/$key4DbName",
loginsStorage = loginsStorage!!
loginsStorage = loginsStorage!!.value
)
} catch (e: Exception) {
crashReporter.submitCaughtException(FennecMigratorException.MigrateLoginsException(e))
......@@ -864,7 +867,7 @@ class FennecMigrator private constructor(
@Suppress("ComplexMethod", "LongMethod")
private suspend fun migrateFxA(): Result<FxaMigrationResult> {
val result = FennecFxaMigration.migrate(fxaState!!, context, accountManager!!)
val result = FennecFxaMigration.migrate(fxaState!!, context, accountManager!!.value)
if (result is Result.Failure<FxaMigrationResult>) {
val migrationFailureWrapper = result.throwables.first() as FxaMigrationException
......@@ -1169,7 +1172,7 @@ class FennecMigrator private constructor(
}
val importedPinnedSites = try {
bookmarksStorage.readPinnedSitesFromFennec(browserDbPath)
bookmarksStorage.value.readPinnedSitesFromFennec(browserDbPath)
} catch (e: Exception) {
crashReporter.submitCaughtException(
FennecMigratorException.MigratePinnedSitesException(e)
......
......@@ -135,7 +135,7 @@ class FennecMigratorTest {
val migrator1 = FennecMigrator.Builder(testContext, mock())
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
.migrateHistory(historyStore)
.migrateHistory(lazy { historyStore })
.build()
assertTrue(migrator1.isFennecInstallation())
......@@ -146,7 +146,7 @@ class FennecMigratorTest {
val migrator2 = FennecMigrator.Builder(testContext, mock())
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/no-browser.db").absolutePath)
.migrateHistory(historyStore)
.migrateHistory(lazy { historyStore })
.build()
assertFalse(migrator2.isFennecInstallation())
......@@ -172,8 +172,8 @@ class FennecMigratorTest {
.setProfile(FennecProfile(
"test", File(getTestPath("combined"), "basic").absolutePath, true)
)
.migrateHistory(historyStore)
.migrateBookmarks(bookmarksStore, topSiteStorage)
.migrateHistory(lazy { historyStore })
.migrateBookmarks(lazy { bookmarksStore }, topSiteStorage)
.build()
assertEquals(listOf<String>(), historyStore.getVisited())
......@@ -229,8 +229,8 @@ class FennecMigratorTest {
).absolutePath,
true
))
.migrateHistory(historyStore)
.migrateBookmarks(bookmarksStore, topSiteStorage)
.migrateHistory(lazy { historyStore })
.migrateBookmarks(lazy { bookmarksStore }, topSiteStorage)
.migrateOpenTabs(sessionManager)
.build()
......@@ -263,8 +263,8 @@ class FennecMigratorTest {
.setProfile(FennecProfile(
"test", File(getTestPath("combined"), "basic").absolutePath, true)
)
.migrateHistory(historyStore)
.migrateBookmarks(bookmarksStore, topSiteStorage)
.migrateHistory(lazy { historyStore })
.migrateBookmarks(lazy { bookmarksStore }, topSiteStorage)
.setBrowserDbPath(File(getTestPath("databases/v39-basic"), "pinnedSites-v39.db").absolutePath)
.build()
......@@ -316,7 +316,7 @@ class FennecMigratorTest {
// DB path is set, but db is corrupt.
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateHistory(historyStorage)
.migrateHistory(lazy { historyStorage })
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/corrupt.db").absolutePath)
.build()
......@@ -341,7 +341,7 @@ class FennecMigratorTest {
`when`(historyStorage.importFromFennec(any())).thenThrow(PlacesException("test exception"))
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateHistory(historyStorage)
.migrateHistory(lazy { historyStorage })
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
.setProfile(FennecProfile(
......@@ -375,8 +375,8 @@ class FennecMigratorTest {
// DB path is configured, partial success (only history failed).
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateHistory(historyStorage)
.migrateBookmarks(bookmarkStorage)
.migrateHistory(lazy { historyStorage })
.migrateBookmarks(lazy { bookmarkStorage })
.setCoroutineContext(this.coroutineContext)
.setProfile(FennecProfile(
"test",
......@@ -411,8 +411,8 @@ class FennecMigratorTest {
`when`(bookmarkStorage.importFromFennec(any())).thenThrow(PlacesException("test exception"))
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateHistory(historyStorage)
.migrateBookmarks(bookmarkStorage)
.migrateHistory(lazy { historyStorage })
.migrateBookmarks(lazy { bookmarkStorage })
.setCoroutineContext(this.coroutineContext)
.setProfile(FennecProfile(
"test",
......@@ -457,7 +457,7 @@ class FennecMigratorTest {
fun `failing migrations are reported - case 7, corrupt fxa state`() = runBlocking {
val accountManager: FxaAccountManager = mock()
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateFxa(accountManager)
.migrateFxa(lazy { accountManager })
.setFxaState(File(getTestPath("fxa"), "corrupt-married-v4.json"))
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
......@@ -476,7 +476,7 @@ class FennecMigratorTest {
fun `failing migrations are reported - case 8, unsupported pickle version`() = runBlocking {
val accountManager: FxaAccountManager = mock()
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateFxa(accountManager)
.migrateFxa(lazy { accountManager })
.setFxaState(File(getTestPath("fxa"), "separated-bad-pickle-version-v4.json"))
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
......@@ -495,7 +495,7 @@ class FennecMigratorTest {
fun `failing migrations are reported - case 8, unsupported state version`() = runBlocking {
val accountManager: FxaAccountManager = mock()
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateFxa(accountManager)
.migrateFxa(lazy { accountManager })
.setFxaState(File(getTestPath("fxa"), "separated-bad-state-version-v10.json"))
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
......@@ -515,7 +515,7 @@ class FennecMigratorTest {
// FxA migration without configured path to pickle file (test environment path isn't the same as real path).
val accountManager: FxaAccountManager = mock()
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateFxa(accountManager)
.migrateFxa(lazy { accountManager })
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
.build()
......@@ -541,7 +541,7 @@ class FennecMigratorTest {
// FxA migration without configured path to pickle file (test environment path isn't the same as real path).
val accountManager: FxaAccountManager = mock()
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateFxa(accountManager)
.migrateFxa(lazy { accountManager })
.setFxaState(File(getTestPath("fxa"), "separated-v4.json"))
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
......@@ -567,7 +567,7 @@ class FennecMigratorTest {
fun `fxa migration - authenticated account, sign-in succeeded`() = runBlocking {
val accountManager: FxaAccountManager = mock()
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateFxa(accountManager)
.migrateFxa(lazy { accountManager })
.setFxaState(File(getTestPath("fxa"), "married-v4.json"))
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
......@@ -606,7 +606,7 @@ class FennecMigratorTest {
fun `fxa migration - authenticated account, sign-in will retry`() = runBlocking {
val accountManager: FxaAccountManager = mock()
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateFxa(accountManager)
.migrateFxa(lazy { accountManager })
.setFxaState(File(getTestPath("fxa"), "married-v4.json"))
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
......@@ -645,7 +645,7 @@ class FennecMigratorTest {
fun `fxa migration - authenticated account, sign-in failed`() = runBlocking {
val accountManager: FxaAccountManager = mock()
val migrator = FennecMigrator.Builder(testContext, mock())
.migrateFxa(accountManager)
.migrateFxa(lazy { accountManager })
.setFxaState(File(getTestPath("fxa"), "cohabiting-v4.json"))
.setCoroutineContext(this.coroutineContext)
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
......@@ -688,7 +688,7 @@ class FennecMigratorTest {
it.wipeLocal()
}
val migrator = FennecMigrator.Builder(testContext, crashReporter)
.migrateLogins(loginStorage)
.migrateLogins(lazy { loginStorage })
.setProfile(FennecProfile(
"test", File(getTestPath("logins"), "basic").absolutePath, true)
)
......@@ -739,7 +739,7 @@ class FennecMigratorTest {
val crashReporter: CrashReporter = mock()
val loginStorage = SyncableLoginsStorage(testContext, "test key")
val migrator = FennecMigrator.Builder(testContext, crashReporter)
.migrateLogins(loginStorage)
.migrateLogins(lazy { loginStorage })
.setProfile(FennecProfile(
"test", File(getTestPath("logins"), "with-mp").absolutePath, true)
)
......@@ -767,7 +767,7 @@ class FennecMigratorTest {
it.wipeLocal()
}
val migrator = FennecMigrator.Builder(testContext, crashReporter)
.migrateLogins(loginStorage)
.migrateLogins(lazy { loginStorage })
.setProfile(FennecProfile(
"test", File(getTestPath("logins"), "with-mp").absolutePath, true)
)
......@@ -791,7 +791,7 @@ class FennecMigratorTest {
val crashReporter: CrashReporter = mock()
val loginStorage = SyncableLoginsStorage(testContext, "test key")
val migrator = FennecMigrator.Builder(testContext, crashReporter)
.migrateLogins(loginStorage)
.migrateLogins(lazy { loginStorage })
.setProfile(FennecProfile(
"test", File(getTestPath("logins"), "with-mp").absolutePath, true)
)
......@@ -818,7 +818,7 @@ class FennecMigratorTest {
it.wipeLocal()
}
val migrator = FennecMigrator.Builder(testContext, crashReporter)
.migrateLogins(loginStorage)
.migrateLogins(lazy { loginStorage })
.setKey4DbName("noNss-key4.db")
.setSignonsDbName("signons.sqlite")
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
......@@ -840,7 +840,7 @@ class FennecMigratorTest {
val crashReporter: CrashReporter = mock()
val loginStorage = SyncableLoginsStorage(testContext, "test key")
val migrator = FennecMigrator.Builder(testContext, crashReporter)
.migrateLogins(loginStorage)
.migrateLogins(lazy { loginStorage })
.setProfile(FennecProfile(
"test", File(getTestPath("logins"), "with-mp").absolutePath, true)
)
......@@ -864,7 +864,7 @@ class FennecMigratorTest {
val crashReporter: CrashReporter = mock()
val loginStorage = SyncableLoginsStorage(testContext, "test key")
val migrator = FennecMigrator.Builder(testContext, crashReporter)
.migrateLogins(loginStorage)
.migrateLogins(lazy { loginStorage })
.setProfile(FennecProfile(
"test", File(getTestPath("logins"), "basic").absolutePath, true)
)
......
......@@ -21,6 +21,9 @@ permalink: /changelog/
* **feature-accounts-push**
* Re-subscribe for Sync push support when notified by `onSubscriptionChanged` events.
* **support-migration**
* ⚠️ **This is a breaking change**: `FennecMigrator` now takes `Lazy` references to storage layers.
# 37.0.0
* [Commits](https://github.com/mozilla-mobile/android-components/compare/v36.0.0...v37.0.0)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment