Commit 348b02c7 authored by Gabriel Luong's avatar Gabriel Luong
Browse files

Issue #7978: Part 1 - Rename TopSiteStorage to PinnedSitesStorage

parent 5713f81b
...@@ -30,9 +30,9 @@ import java.util.concurrent.Executors ...@@ -30,9 +30,9 @@ import java.util.concurrent.Executors
private const val MIGRATION_TEST_DB = "migration-test" private const val MIGRATION_TEST_DB = "migration-test"
@Suppress("LargeClass") @Suppress("LargeClass")
class TopSiteStorageTest { class PinnedSitesStorageTest {
private lateinit var context: Context private lateinit var context: Context
private lateinit var storage: TopSiteStorage private lateinit var storage: PinnedSiteStorage
private lateinit var executor: ExecutorService private lateinit var executor: ExecutorService
@get:Rule @get:Rule
...@@ -52,7 +52,7 @@ class TopSiteStorageTest { ...@@ -52,7 +52,7 @@ class TopSiteStorageTest {
context = ApplicationProvider.getApplicationContext() context = ApplicationProvider.getApplicationContext()
val database = Room.inMemoryDatabaseBuilder(context, TopSiteDatabase::class.java).build() val database = Room.inMemoryDatabaseBuilder(context, TopSiteDatabase::class.java).build()
storage = TopSiteStorage(context) storage = PinnedSiteStorage(context)
storage.database = lazy { database } storage.database = lazy { database }
} }
......
...@@ -15,7 +15,7 @@ import mozilla.components.feature.top.sites.db.TopSiteEntity ...@@ -15,7 +15,7 @@ import mozilla.components.feature.top.sites.db.TopSiteEntity
/** /**
* A storage implementation for organizing top sites. * A storage implementation for organizing top sites.
*/ */
class TopSiteStorage( class PinnedSiteStorage(
context: Context context: Context
) { ) {
internal var database: Lazy<TopSiteDatabase> = lazy { TopSiteDatabase.get(context) } internal var database: Lazy<TopSiteDatabase> = lazy { TopSiteDatabase.get(context) }
......
...@@ -23,7 +23,7 @@ import mozilla.components.browser.storage.sync.PlacesHistoryStorage ...@@ -23,7 +23,7 @@ import mozilla.components.browser.storage.sync.PlacesHistoryStorage
import mozilla.components.concept.engine.Engine import mozilla.components.concept.engine.Engine
import mozilla.components.feature.addons.amo.AddonCollectionProvider import mozilla.components.feature.addons.amo.AddonCollectionProvider
import mozilla.components.feature.addons.update.AddonUpdater import mozilla.components.feature.addons.update.AddonUpdater
import mozilla.components.feature.top.sites.TopSiteStorage import mozilla.components.feature.top.sites.PinnedSiteStorage
import mozilla.components.service.fxa.manager.FxaAccountManager import mozilla.components.service.fxa.manager.FxaAccountManager
import mozilla.components.service.glean.Glean import mozilla.components.service.glean.Glean
import mozilla.components.service.sync.logins.SyncableLoginsStorage import mozilla.components.service.sync.logins.SyncableLoginsStorage
...@@ -217,7 +217,7 @@ sealed class FennecMigratorException(cause: Exception) : Exception(cause) { ...@@ -217,7 +217,7 @@ sealed class FennecMigratorException(cause: Exception) : Exception(cause) {
* @param bookmarksStorage An optional instance of [PlacesBookmarksStorage] used to store migrated bookmarks data. * @param bookmarksStorage An optional instance of [PlacesBookmarksStorage] used to store migrated bookmarks data.
* @param coroutineContext An instance of [CoroutineContext] used for executing async migration tasks. * @param coroutineContext An instance of [CoroutineContext] used for executing async migration tasks.
*/ */
@Suppress("LargeClass", "TooManyFunctions") @Suppress("LargeClass", "TooManyFunctions", "LongParameterList")
class FennecMigrator private constructor( class FennecMigrator private constructor(
private val context: Context, private val context: Context,
private val crashReporter: CrashReporting, private val crashReporter: CrashReporting,
...@@ -237,7 +237,7 @@ class FennecMigrator private constructor( ...@@ -237,7 +237,7 @@ class FennecMigrator private constructor(
private val signonsDbName: String, private val signonsDbName: String,
private val key4DbName: String, private val key4DbName: String,
private val coroutineContext: CoroutineContext, private val coroutineContext: CoroutineContext,
private val topSiteStorage: TopSiteStorage? private val pinnedSitesStorage: PinnedSiteStorage?
) { ) {
/** /**
* Data migration builder. Allows configuring which migrations to run, their versions and relative order. * Data migration builder. Allows configuring which migrations to run, their versions and relative order.
...@@ -266,7 +266,7 @@ class FennecMigrator private constructor( ...@@ -266,7 +266,7 @@ class FennecMigrator private constructor(
private var signonsDbName = "signons.sqlite" private var signonsDbName = "signons.sqlite"
private var key4DbName = "key4.db" private var key4DbName = "key4.db"
private var masterPassword = FennecLoginsMigration.DEFAULT_MASTER_PASSWORD private var masterPassword = FennecLoginsMigration.DEFAULT_MASTER_PASSWORD
private var topSiteStorage: TopSiteStorage? = null private var pinnedSitesStorage: PinnedSiteStorage? = null
/** /**
* Enable history migration. * Enable history migration.
...@@ -288,16 +288,16 @@ class FennecMigrator private constructor( ...@@ -288,16 +288,16 @@ class FennecMigrator private constructor(
/** /**
* Enable bookmarks migration. Must be called after [migrateHistory]. * Enable bookmarks migration. Must be called after [migrateHistory].
* Optionally, enable top sites migration, if [topSiteStorage] is specified. * Optionally, enable top sites migration, if [pinnedSitesStorage] is specified.
* In Fennec, pinned sites are stored as special type of a bookmark, hence this coupling. * In Fennec, pinned sites are stored as special type of a bookmark, hence this coupling.
* *
* @param storage An instance of [PlacesBookmarksStorage], used for storing data. * @param storage An instance of [PlacesBookmarksStorage], used for storing data.
* @param topSiteStorage An instance of [TopSiteStorage], used for storing pinned sites. * @param pinnedSitesStorage An instance of [PinnedSiteStorage], used for storing pinned sites.
* @param version Version of the migration; defaults to the current version. * @param version Version of the migration; defaults to the current version.
*/ */
fun migrateBookmarks( fun migrateBookmarks(
storage: Lazy<PlacesBookmarksStorage>, storage: Lazy<PlacesBookmarksStorage>,
topSiteStorage: TopSiteStorage? = null, pinnedSitesStorage: PinnedSiteStorage? = null,
version: Int = Migration.Bookmarks.currentVersion version: Int = Migration.Bookmarks.currentVersion
): Builder { ): Builder {
check(migrations.find { it.migration is Migration.FxA } == null) { check(migrations.find { it.migration is Migration.FxA } == null) {
...@@ -312,8 +312,8 @@ class FennecMigrator private constructor( ...@@ -312,8 +312,8 @@ class FennecMigrator private constructor(
// Allowing enabling pinned sites migration only when bookmarks migration is enabled is a conscious // Allowing enabling pinned sites migration only when bookmarks migration is enabled is a conscious
// choice. We currently don't have a requirement to only migrate pinned sites, and not bookmarks, // choice. We currently don't have a requirement to only migrate pinned sites, and not bookmarks,
// and so this is done to keep things a bit simpler. // and so this is done to keep things a bit simpler.
topSiteStorage?.let { pinnedSitesStorage?.let {
this.topSiteStorage = it this.pinnedSitesStorage = it
migrations.add(VersionedMigration(Migration.PinnedSites, version)) migrations.add(VersionedMigration(Migration.PinnedSites, version))
} }
...@@ -448,7 +448,7 @@ class FennecMigrator private constructor( ...@@ -448,7 +448,7 @@ class FennecMigrator private constructor(
signonsDbName, signonsDbName,
key4DbName, key4DbName,
coroutineContext, coroutineContext,
topSiteStorage pinnedSitesStorage
) )
} }
...@@ -1263,7 +1263,7 @@ class FennecMigrator private constructor( ...@@ -1263,7 +1263,7 @@ class FennecMigrator private constructor(
@Suppress("ComplexMethod", "TooGenericExceptionCaught", "ReturnCount", "NestedBlockDepth") @Suppress("ComplexMethod", "TooGenericExceptionCaught", "ReturnCount", "NestedBlockDepth")
private fun migratePinnedSites(): Result<Unit> { private fun migratePinnedSites(): Result<Unit> {
checkNotNull(bookmarksStorage) { "Bookmarks storage must be configured to migrate pinned sites" } checkNotNull(bookmarksStorage) { "Bookmarks storage must be configured to migrate pinned sites" }
checkNotNull(topSiteStorage) { "TopSiteStorage must be configured to migrate pinned sites" } checkNotNull(pinnedSitesStorage) { "PinnedSiteStorage must be configured to migrate pinned sites" }
// There's no dbPath without a profile, but if a profile is present we expect dbPath to be also present. // There's no dbPath without a profile, but if a profile is present we expect dbPath to be also present.
if (profile != null && browserDbPath == null) { if (profile != null && browserDbPath == null) {
...@@ -1305,7 +1305,7 @@ class FennecMigrator private constructor( ...@@ -1305,7 +1305,7 @@ class FennecMigrator private constructor(
// Reversed, so that first pinned site in Fennec ends up as the first one in Fenix, as well. // Reversed, so that first pinned site in Fennec ends up as the first one in Fenix, as well.
pinnedSitesWithUrl.reversed().forEach { pinnedSite -> pinnedSitesWithUrl.reversed().forEach { pinnedSite ->
try { try {
topSiteStorage.addTopSite(pinnedSite.title ?: "", pinnedSite.url!!) pinnedSitesStorage.addTopSite(pinnedSite.title ?: "", pinnedSite.url!!)
} catch (e: Exception) { } catch (e: Exception) {
failedToImport++ failedToImport++
// Let's not spam Sentry and submit the same exception multiple times // Let's not spam Sentry and submit the same exception multiple times
......
...@@ -34,7 +34,7 @@ import mozilla.components.concept.engine.Engine ...@@ -34,7 +34,7 @@ import mozilla.components.concept.engine.Engine
import mozilla.components.concept.engine.webextension.WebExtension import mozilla.components.concept.engine.webextension.WebExtension
import mozilla.components.feature.addons.amo.AddonCollectionProvider import mozilla.components.feature.addons.amo.AddonCollectionProvider
import mozilla.components.feature.addons.update.AddonUpdater import mozilla.components.feature.addons.update.AddonUpdater
import mozilla.components.feature.top.sites.TopSiteStorage import mozilla.components.feature.top.sites.PinnedSiteStorage
import mozilla.components.service.fxa.manager.SignInWithShareableAccountResult import mozilla.components.service.fxa.manager.SignInWithShareableAccountResult
import mozilla.components.service.fxa.sharing.ShareableAccount import mozilla.components.service.fxa.sharing.ShareableAccount
import mozilla.components.service.sync.logins.SyncableLoginsStorage import mozilla.components.service.sync.logins.SyncableLoginsStorage
...@@ -160,7 +160,7 @@ class FennecMigratorTest { ...@@ -160,7 +160,7 @@ class FennecMigratorTest {
fun `migrations versioning basics`() = runBlocking { fun `migrations versioning basics`() = runBlocking {
val historyStore = PlacesHistoryStorage(testContext) val historyStore = PlacesHistoryStorage(testContext)
val bookmarksStore = PlacesBookmarksStorage(testContext) val bookmarksStore = PlacesBookmarksStorage(testContext)
val topSiteStorage = mock<TopSiteStorage>() val topSiteStorage = mock<PinnedSiteStorage>()
// Clear-up storage layers between test runs. // Clear-up storage layers between test runs.
historyStore.deleteEverything() historyStore.deleteEverything()
...@@ -257,7 +257,7 @@ class FennecMigratorTest { ...@@ -257,7 +257,7 @@ class FennecMigratorTest {
fun `pinned sites migration`() = runBlocking { fun `pinned sites migration`() = runBlocking {
val historyStore = PlacesHistoryStorage(testContext) val historyStore = PlacesHistoryStorage(testContext)
val bookmarksStore = PlacesBookmarksStorage(testContext) val bookmarksStore = PlacesBookmarksStorage(testContext)
val topSiteStorage = mock<TopSiteStorage>() val topSiteStorage = mock<PinnedSiteStorage>()
val migrator = FennecMigrator.Builder(testContext, mock()) val migrator = FennecMigrator.Builder(testContext, mock())
.setCoroutineContext(this.coroutineContext) .setCoroutineContext(this.coroutineContext)
......
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