Skip to content

Commit

Permalink
Run migration in background service.
Browse files Browse the repository at this point in the history
In order to avoid a half done migration we are moving the migration to a background service (that is
running in the "foreground").

This is the Fenix part of:
mozilla-mobile/android-components#4879
  • Loading branch information
pocmo committed Dec 10, 2019
1 parent 3f7205e commit 0db75a1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/src/migration/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<application
android:name="org.mozilla.fenix.MigratingFenixApplication"
tools:replace="android:name">
<service android:name="org.mozilla.fenix.MigrationService" />
</application>
</manifest>

Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,33 @@

package org.mozilla.fenix

import android.content.Context
import kotlinx.coroutines.runBlocking
import mozilla.components.support.migration.FennecMigrator

/**
* An application class which knows how to migrate Fennec data.
*/
class MigratingFenixApplication : FenixApplication() {
val migrator by lazy {
FennecMigrator.Builder(this, this.components.analytics.crashReporter)
.migrateOpenTabs(this.components.core.sessionManager)
.migrateHistory(this.components.core.historyStorage)
.migrateBookmarks(this.components.core.bookmarksStorage)
.migrateLogins(
this.components.core.passwordsStorage.store,
this.components.core.passwordsEncryptionKey
)
.migrateFxa(this.components.backgroundServices.accountManager)
.build()
}

override fun setupInMainProcessOnly() {
migrateGeckoBlocking()

super.setupInMainProcessOnly()

migrateDataAsynchronously()
migrator.startMigrationServiceIfNeeded(MigrationService::class.java)
}

private fun migrateGeckoBlocking() {
Expand All @@ -28,19 +42,8 @@ class MigratingFenixApplication : FenixApplication() {
migrator.migrateAsync().await()
}
}
}

private fun migrateDataAsynchronously() {
val migrator = FennecMigrator.Builder(this, this.components.analytics.crashReporter)
.migrateOpenTabs(this.components.core.sessionManager)
.migrateHistory(this.components.core.historyStorage)
.migrateBookmarks(this.components.core.bookmarksStorage)
.migrateLogins(
this.components.core.passwordsStorage.store,
this.components.core.passwordsEncryptionKey
)
.migrateFxa(this.components.backgroundServices.accountManager)
.build()

migrator.migrateAsync()
}
fun Context.getMigratorFromApplication(): FennecMigrator {
return (applicationContext as MigratingFenixApplication).migrator
}
14 changes: 14 additions & 0 deletions app/src/migration/java/org/mozilla/fenix/MigrationService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix

import mozilla.components.support.migration.AbstractMigrationService

/**
* Background service for running the migration from legacy Firefox for Android (Fennec).
*/
class MigrationService : AbstractMigrationService() {
override val migrator by lazy { getMigratorFromApplication() }
}

0 comments on commit 0db75a1

Please sign in to comment.