Commit 0677fc35 authored by Grisha Kruglov's avatar Grisha Kruglov Committed by Grisha Kruglov
Browse files

Part 1: Add 'accountManagerReady' queue to BackgroundServices

This gives us an ability to perform tasks against 'accountManager' without
causing its immediate initialization.
parent be1fa8df
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.test.Mockable
import org.mozilla.fenix.utils.RunWhenReadyQueue

/**
 * Component group for background services. These are the components that need to be accessed from within a
@@ -50,6 +51,9 @@ class BackgroundServices(
    bookmarkStorage: Lazy<PlacesBookmarksStorage>,
    passwordsStorage: Lazy<SyncableLoginsStorage>
) {
    // Allows executing tasks which depend on the account manager, but do not need to eagerly initialize it.
    val accountManagerAvailableQueue = RunWhenReadyQueue()

    fun defaultDeviceName(context: Context): String =
        context.getString(
            R.string.default_device_name,
@@ -98,7 +102,7 @@ class BackgroundServices(

    val accountAbnormalities = AccountAbnormalities(context, crashReporter)

    val accountManager = makeAccountManager(context, serverConfig, deviceConfig, syncConfig)
    val accountManager by lazy { makeAccountManager(context, serverConfig, deviceConfig, syncConfig) }

    @VisibleForTesting(otherwise = PRIVATE)
    fun makeAccountManager(
@@ -148,6 +152,8 @@ class BackgroundServices(
            accountManager,
            accountManager.initAsync()
        )
    }.also {
        accountManagerAvailableQueue.ready()
    }

    /**