|
|
|
/* 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.components
|
|
|
|
|
|
|
|
import android.app.Application
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import androidx.core.net.toUri
|
|
|
|
import mozilla.components.feature.addons.AddonManager
|
|
|
|
import mozilla.components.feature.addons.amo.AddonCollectionProvider
|
|
|
|
import mozilla.components.feature.addons.update.AddonUpdater
|
|
|
|
import mozilla.components.feature.addons.update.DefaultAddonUpdater
|
|
|
|
import mozilla.components.feature.addons.migration.SupportedAddonsChecker
|
|
|
|
import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker
|
|
|
|
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
|
|
|
|
import mozilla.components.support.migration.state.MigrationStore
|
|
|
|
import org.mozilla.fenix.BuildConfig
|
|
|
|
import org.mozilla.fenix.HomeActivity
|
|
|
|
import org.mozilla.fenix.utils.Mockable
|
|
|
|
import org.mozilla.fenix.utils.ClipboardHandler
|
|
|
|
import org.mozilla.fenix.wifi.WifiConnectionMonitor
|
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
|
|
|
|
private const val DAY_IN_MINUTES = 24 * 60L
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides access to all components.
|
|
|
|
*/
|
|
|
|
@Mockable
|
|
|
|
class Components(private val context: Context) {
|
|
|
|
val backgroundServices by lazy {
|
|
|
|
BackgroundServices(
|
|
|
|
context,
|
|
|
|
push,
|
|
|
|
analytics.crashReporter,
|
Closes #7450: Lazy storage initialization
Make sure that we actually lazily initialize our storage layers.
With this patch applied, storage layers (history, logins, bookmarks) will be initialized when first
accessed. We will no longer block GeckoEngine init, for example, on waiting for the logins storage
to initialize (which needs to access the costly securePrefStorage).
Similarly, BackgroundServices init will no longer require initialized instances of the storage
components - references to their "lazy wrappers" will suffice.
In practice, this change changes when our storage layers are initialized in the following ways.
Currently, we will initialize everything on startup. This includes loading our megazord, as well.
With this change, init path depends on if the user is signed-into FxA or not.
If user is not an FxA user:
- on startup, none of the storage layers are initialized
- history storage will be initialized once, whenever:
- first non-customTab page is loaded (access to the HistoryDelegate)
- first interaction with the awesomebar
- history UI is accessed
- bookmarks storage will be initialized once, whenever:
- something is bookmarked, or we need to figure out if something's bookmarked
- bookmarks UI is accessed
- logins storage will be initialized once, whenever:
- first page is loaded with a login/password fields that can be autofilled
- (or some other interaction by GV with the autofill/loginStorage delegates)
- logins UI is accessed
- all of these storages will be initialized if the user logs into FxA and starts syncing data
- except, if a storage is not chosen to be synced, it will not be initialized
If user is an FxA user:
- on startup, none of the storage layers are initialized
- sometime shortly after startup is complete, when a sync worker runs in the background, all storage
layers that are enabled to sync will be initialized.
This change also means that we delay loading the megazord until first access (as described above).
5 years ago
|
|
|
core.lazyHistoryStorage,
|
|
|
|
core.lazyBookmarksStorage,
|
|
|
|
core.lazyPasswordsStorage
|
|
|
|
)
|
|
|
|
}
|
|
|
|
val services by lazy { Services(context, backgroundServices.accountManager) }
|
|
|
|
val core by lazy { Core(context) }
|
|
|
|
val search by lazy { Search(context) }
|
|
|
|
val useCases by lazy {
|
|
|
|
UseCases(
|
|
|
|
context,
|
|
|
|
core.sessionManager,
|
|
|
|
core.store,
|
|
|
|
core.engine.settings,
|
|
|
|
search.searchEngineManager,
|
|
|
|
core.webAppShortcutManager
|
|
|
|
)
|
|
|
|
}
|
|
|
|
val intentProcessors by lazy {
|
|
|
|
IntentProcessors(
|
|
|
|
context,
|
|
|
|
core.sessionManager,
|
|
|
|
useCases.sessionUseCases,
|
|
|
|
useCases.searchUseCases,
|
|
|
|
core.client,
|
|
|
|
core.customTabsStore,
|
|
|
|
migrationStore,
|
|
|
|
core.webAppManifestStorage
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
val addonCollectionProvider by lazy {
|
|
|
|
if (!BuildConfig.AMO_COLLECTION.isNullOrEmpty()) {
|
|
|
|
AddonCollectionProvider(
|
|
|
|
context,
|
|
|
|
core.client,
|
|
|
|
collectionName = BuildConfig.AMO_COLLECTION,
|
|
|
|
maxCacheAgeInMinutes = DAY_IN_MINUTES
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
AddonCollectionProvider(context, core.client, maxCacheAgeInMinutes = DAY_IN_MINUTES)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Suppress("MagicNumber")
|
|
|
|
val addonUpdater by lazy {
|
|
|
|
DefaultAddonUpdater(context, AddonUpdater.Frequency(12, TimeUnit.HOURS))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Suppress("MagicNumber")
|
|
|
|
val supportedAddonsChecker by lazy {
|
|
|
|
DefaultSupportedAddonsChecker(context, SupportedAddonsChecker.Frequency(16, TimeUnit.MINUTES),
|
|
|
|
onNotificationClickIntent = Intent(context, HomeActivity::class.java).apply {
|
|
|
|
action = Intent.ACTION_VIEW
|
|
|
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
|
|
data = "fenix://settings_addon_manager".toUri()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
val addonManager by lazy {
|
|
|
|
AddonManager(core.store, core.engine, addonCollectionProvider, addonUpdater)
|
|
|
|
}
|
|
|
|
|
|
|
|
val analytics by lazy { Analytics(context) }
|
|
|
|
val publicSuffixList by lazy { PublicSuffixList(context) }
|
|
|
|
val clipboardHandler by lazy { ClipboardHandler(context) }
|
|
|
|
val migrationStore by lazy { MigrationStore() }
|
|
|
|
val performance by lazy { PerformanceComponent() }
|
|
|
|
val push by lazy { Push(context, analytics.crashReporter) }
|
|
|
|
val wifiConnectionMonitor by lazy { WifiConnectionMonitor(context as Application) }
|
|
|
|
}
|