From 0677fc35dee39d5de01cad404a90db3079f51d60 Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Thu, 26 Mar 2020 23:16:52 -0700 Subject: [PATCH] Part 1: Add 'accountManagerReady' queue to BackgroundServices This gives us an ability to perform tasks against 'accountManager' without causing its immediate initialization. --- .../org/mozilla/fenix/components/BackgroundServices.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt b/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt index 7700788e5..9b5c515f2 100644 --- a/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt +++ b/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt @@ -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, passwordsStorage: Lazy ) { + // 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() } /**