For #15279: replace lazy with lazyMonitored in component groups.

By component groups, I mean I applied this to any class with the
class kdoc, "Component group for...".

There are a few instances of lazy we had to keep using the old API to
avoid having to update constructor arguments.
This commit is contained in:
Michael Comella 2020-10-30 11:29:09 -07:00 committed by Michael Comella
parent f37ace0630
commit 901c78684c
10 changed files with 87 additions and 75 deletions

View File

@ -23,6 +23,7 @@ import org.mozilla.fenix.components.metrics.GleanMetricsService
import org.mozilla.fenix.components.metrics.LeanplumMetricsService
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.utils.Mockable
import org.mozilla.geckoview.BuildConfig.MOZ_APP_BUILDID
import org.mozilla.geckoview.BuildConfig.MOZ_APP_VENDOR
@ -36,7 +37,7 @@ import org.mozilla.geckoview.BuildConfig.MOZ_UPDATE_CHANNEL
class Analytics(
private val context: Context
) {
val crashReporter: CrashReporter by lazy {
val crashReporter: CrashReporter by lazyMonitored {
val services = mutableListOf<CrashReporterService>()
if (isSentryEnabled()) {
@ -84,9 +85,9 @@ class Analytics(
)
}
val leanplumMetricsService by lazy { LeanplumMetricsService(context as Application) }
val leanplumMetricsService by lazyMonitored { LeanplumMetricsService(context as Application) }
val metrics: MetricController by lazy {
val metrics: MetricController by lazyMonitored {
MetricController.create(
listOf(
GleanMetricsService(context),

View File

@ -41,6 +41,7 @@ import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.sync.SyncedTabsIntegration
import org.mozilla.fenix.utils.Mockable
import org.mozilla.fenix.utils.Settings
@ -109,9 +110,11 @@ class BackgroundServices(
val accountAbnormalities = AccountAbnormalities(context, crashReporter, strictMode)
val accountManager by lazy { makeAccountManager(context, serverConfig, deviceConfig, syncConfig, crashReporter) }
val accountManager by lazyMonitored {
makeAccountManager(context, serverConfig, deviceConfig, syncConfig, crashReporter)
}
val syncedTabsStorage by lazy {
val syncedTabsStorage by lazyMonitored {
SyncedTabsStorage(accountManager, context.components.core.store, remoteTabsStorage.value)
}
@ -174,7 +177,7 @@ class BackgroundServices(
/**
* Provides notification functionality, manages notification channels.
*/
private val notificationManager by lazy {
private val notificationManager by lazyMonitored {
NotificationManager(context)
}
}

View File

@ -22,6 +22,7 @@ import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.StrictModeManager
import org.mozilla.fenix.components.metrics.AppStartupTelemetry
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.utils.ClipboardHandler
import org.mozilla.fenix.utils.Mockable
import org.mozilla.fenix.utils.Settings
@ -39,7 +40,7 @@ private const val DAY_IN_MINUTES = 24 * 60L
*/
@Mockable
class Components(private val context: Context) {
val backgroundServices by lazy {
val backgroundServices by lazyMonitored {
BackgroundServices(
context,
push,
@ -51,10 +52,10 @@ class Components(private val context: Context) {
strictMode
)
}
val services by lazy { Services(context, backgroundServices.accountManager) }
val core by lazy { Core(context, analytics.crashReporter, strictMode) }
val search by lazy { Search(context) }
val useCases by lazy {
val services by lazyMonitored { Services(context, backgroundServices.accountManager) }
val core by lazyMonitored { Core(context, analytics.crashReporter, strictMode) }
val search by lazyMonitored { Search(context) }
val useCases by lazyMonitored {
UseCases(
context,
core.engine,
@ -65,7 +66,7 @@ class Components(private val context: Context) {
core.topSitesStorage
)
}
val intentProcessors by lazy {
val intentProcessors by lazyMonitored {
IntentProcessors(
context,
core.sessionManager,
@ -78,7 +79,7 @@ class Components(private val context: Context) {
)
}
val addonCollectionProvider by lazy {
val addonCollectionProvider by lazyMonitored {
// Check if we have a customized (overridden) AMO collection (only supported in Nightly)
if (Config.channel.isNightlyOrDebug && context.settings().amoCollectionOverrideConfigured()) {
AddonCollectionProvider(
@ -103,15 +104,15 @@ class Components(private val context: Context) {
}
}
val appStartupTelemetry by lazy { AppStartupTelemetry(analytics.metrics) }
val appStartupTelemetry by lazyMonitored { AppStartupTelemetry(analytics.metrics) }
@Suppress("MagicNumber")
val addonUpdater by lazy {
val addonUpdater by lazyMonitored {
DefaultAddonUpdater(context, AddonUpdater.Frequency(12, TimeUnit.HOURS))
}
@Suppress("MagicNumber")
val supportedAddonsChecker by lazy {
val supportedAddonsChecker by lazyMonitored {
DefaultSupportedAddonsChecker(context, SupportedAddonsChecker.Frequency(12, TimeUnit.HOURS),
onNotificationClickIntent = Intent(context, HomeActivity::class.java).apply {
action = Intent.ACTION_VIEW
@ -121,22 +122,22 @@ class Components(private val context: Context) {
)
}
val addonManager by lazy {
val addonManager by lazyMonitored {
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) }
val strictMode by lazy { StrictModeManager(Config, this) }
val analytics by lazyMonitored { Analytics(context) }
val publicSuffixList by lazyMonitored { PublicSuffixList(context) }
val clipboardHandler by lazyMonitored { ClipboardHandler(context) }
val migrationStore by lazyMonitored { MigrationStore() }
val performance by lazyMonitored { PerformanceComponent() }
val push by lazyMonitored { Push(context, analytics.crashReporter) }
val wifiConnectionMonitor by lazyMonitored { WifiConnectionMonitor(context as Application) }
val strictMode by lazyMonitored { StrictModeManager(Config, this) }
val settings by lazy { Settings(context) }
val settings by lazyMonitored { Settings(context) }
val reviewPromptController by lazy {
val reviewPromptController by lazyMonitored {
ReviewPromptController(
context,
FenixReviewSettings(settings)

View File

@ -68,6 +68,7 @@ import org.mozilla.fenix.TelemetryMiddleware
import org.mozilla.fenix.downloads.DownloadService
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.media.MediaService
import org.mozilla.fenix.search.telemetry.ads.AdsTelemetry
import org.mozilla.fenix.search.telemetry.incontent.InContentTelemetry
@ -91,7 +92,7 @@ class Core(
* The browser engine component initialized based on the build
* configuration (see build variants).
*/
val engine: Engine by lazy {
val engine: Engine by lazyMonitored {
val defaultSettings = DefaultSettings(
requestInterceptor = AppRequestInterceptor(context),
remoteDebuggingEnabled = context.settings().isRemoteDebuggingEnabled &&
@ -137,7 +138,7 @@ class Core(
/**
* [Client] implementation to be used for code depending on `concept-fetch``
*/
val client: Client by lazy {
val client: Client by lazyMonitored {
GeckoViewFetchClient(
context,
GeckoProvider.getOrCreateRuntime(
@ -148,14 +149,14 @@ class Core(
)
}
private val sessionStorage: SessionStorage by lazy {
private val sessionStorage: SessionStorage by lazyMonitored {
SessionStorage(context, engine = engine)
}
/**
* The [BrowserStore] holds the global [BrowserState].
*/
val store by lazy {
val store by lazyMonitored {
BrowserStore(
middleware = listOf(
RecentlyClosedMiddleware(context, RECENTLY_CLOSED_MAX, engine),
@ -186,12 +187,12 @@ class Core(
/**
* The [CustomTabsServiceStore] holds global custom tabs related data.
*/
val customTabsStore by lazy { CustomTabsServiceStore() }
val customTabsStore by lazyMonitored { CustomTabsServiceStore() }
/**
* The [RelationChecker] checks Digital Asset Links relationships for Trusted Web Activities.
*/
val relationChecker: RelationChecker by lazy {
val relationChecker: RelationChecker by lazyMonitored {
StatementRelationChecker(StatementApi(client))
}
@ -201,7 +202,7 @@ class Core(
* sessions from the [SessionStorage], and with a default session (about:blank) in
* case all sessions/tabs are closed.
*/
val sessionManager by lazy {
val sessionManager by lazyMonitored {
SessionManager(engine, store).also { sessionManager ->
// Install the "icons" WebExtension to automatically load icons for every visited website.
icons.install(engine, store)
@ -260,26 +261,26 @@ class Core(
/**
* Icons component for loading, caching and processing website icons.
*/
val icons by lazy {
val icons by lazyMonitored {
BrowserIcons(context, client)
}
val metrics by lazy {
val metrics by lazyMonitored {
context.components.analytics.metrics
}
val adsTelemetry by lazy {
val adsTelemetry by lazyMonitored {
AdsTelemetry(metrics)
}
val searchTelemetry by lazy {
val searchTelemetry by lazyMonitored {
InContentTelemetry(metrics)
}
/**
* Shortcut component for managing shortcuts on the device home screen.
*/
val webAppShortcutManager by lazy {
val webAppShortcutManager by lazyMonitored {
WebAppShortcutManager(
context,
client,
@ -302,11 +303,11 @@ class Core(
val lazyRemoteTabsStorage = lazy { RemoteTabsStorage() }
// For most other application code (non-startup), these wrappers are perfectly fine and more ergonomic.
val historyStorage by lazy { lazyHistoryStorage.value }
val bookmarksStorage by lazy { lazyBookmarksStorage.value }
val passwordsStorage by lazy { lazyPasswordsStorage.value }
val historyStorage by lazyMonitored { lazyHistoryStorage.value }
val bookmarksStorage by lazyMonitored { lazyBookmarksStorage.value }
val passwordsStorage by lazyMonitored { lazyPasswordsStorage.value }
val tabCollectionStorage by lazy {
val tabCollectionStorage by lazyMonitored {
TabCollectionStorage(
context,
sessionManager,
@ -317,11 +318,11 @@ class Core(
/**
* A storage component for persisting thumbnail images of tabs.
*/
val thumbnailStorage by lazy { ThumbnailStorage(context) }
val thumbnailStorage by lazyMonitored { ThumbnailStorage(context) }
val pinnedSiteStorage by lazy { PinnedSiteStorage(context) }
val pinnedSiteStorage by lazyMonitored { PinnedSiteStorage(context) }
val topSitesStorage by lazy {
val topSitesStorage by lazyMonitored {
val defaultTopSites = mutableListOf<Pair<String, String>>()
strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
@ -360,11 +361,11 @@ class Core(
)
}
val permissionStorage by lazy { PermissionStorage(context) }
val permissionStorage by lazyMonitored { PermissionStorage(context) }
val webAppManifestStorage by lazy { ManifestStorage(context) }
val webAppManifestStorage by lazyMonitored { ManifestStorage(context) }
val loginExceptionStorage by lazy { LoginExceptionStorage(context) }
val loginExceptionStorage by lazyMonitored { LoginExceptionStorage(context) }
/**
* Shared Preferences that encrypt/decrypt using Android KeyStore and lib-dataprotect for 23+
@ -378,7 +379,7 @@ class Core(
forceInsecure = !Config.channel.isNightlyOrDebug
)
private val passwordsEncryptionKey by lazy {
private val passwordsEncryptionKey by lazyMonitored {
getSecureAbove22Preferences().getString(PASSWORDS_KEY)
?: generateEncryptionKey(KEY_STRENGTH).also {
if (context.settings().passwordsEncryptionKeyGenerated &&

View File

@ -19,6 +19,7 @@ import mozilla.components.support.migration.MigrationIntentProcessor
import mozilla.components.support.migration.state.MigrationStore
import org.mozilla.fenix.customtabs.FennecWebAppIntentProcessor
import org.mozilla.fenix.home.intent.FennecBookmarkShortcutsIntentProcessor
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.utils.Mockable
/**
@ -39,26 +40,26 @@ class IntentProcessors(
/**
* Provides intent processing functionality for ACTION_VIEW and ACTION_SEND intents.
*/
val intentProcessor by lazy {
val intentProcessor by lazyMonitored {
TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch, isPrivate = false)
}
/**
* Provides intent processing functionality for ACTION_VIEW and ACTION_SEND intents in private tabs.
*/
val privateIntentProcessor by lazy {
val privateIntentProcessor by lazyMonitored {
TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch, isPrivate = true)
}
val customTabIntentProcessor by lazy {
val customTabIntentProcessor by lazyMonitored {
CustomTabIntentProcessor(sessionManager, sessionUseCases.loadUrl, context.resources, isPrivate = false)
}
val privateCustomTabIntentProcessor by lazy {
val privateCustomTabIntentProcessor by lazyMonitored {
CustomTabIntentProcessor(sessionManager, sessionUseCases.loadUrl, context.resources, isPrivate = true)
}
val externalAppIntentProcessors by lazy {
val externalAppIntentProcessors by lazyMonitored {
listOf(
TrustedWebActivityIntentProcessor(
sessionManager = sessionManager,
@ -72,11 +73,11 @@ class IntentProcessors(
)
}
val fennecPageShortcutIntentProcessor by lazy {
val fennecPageShortcutIntentProcessor by lazyMonitored {
FennecBookmarkShortcutsIntentProcessor(sessionManager, sessionUseCases.loadUrl)
}
val migrationIntentProcessor by lazy {
val migrationIntentProcessor by lazyMonitored {
MigrationIntentProcessor(migrationStore)
}
}

View File

@ -6,10 +6,11 @@ package org.mozilla.fenix.components
import mozilla.components.support.utils.RunWhenReadyQueue
import org.mozilla.fenix.perf.VisualCompletenessQueue
import org.mozilla.fenix.perf.lazyMonitored
/**
* Component group for all functionality related to performance.
*/
class PerformanceComponent {
val visualCompletenessQueue by lazy { VisualCompletenessQueue(RunWhenReadyQueue()) }
val visualCompletenessQueue by lazyMonitored { VisualCompletenessQueue(RunWhenReadyQueue()) }
}

View File

@ -10,6 +10,7 @@ import mozilla.components.feature.push.PushConfig
import mozilla.components.lib.crash.CrashReporter
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.R
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.push.FirebasePushService
/**
@ -17,7 +18,7 @@ import org.mozilla.fenix.push.FirebasePushService
* push messaging (e.g. WebPush, SendTab).
*/
class Push(context: Context, crashReporter: CrashReporter) {
val feature by lazy {
val feature by lazyMonitored {
pushConfig?.let { config ->
AutoPushFeature(
context = context,
@ -28,13 +29,13 @@ class Push(context: Context, crashReporter: CrashReporter) {
}
}
private val pushConfig: PushConfig? by lazy {
private val pushConfig: PushConfig? by lazyMonitored {
val logger = Logger("PushConfig")
val projectIdKey = context.getString(R.string.pref_key_push_project_id)
val resId = context.resources.getIdentifier(projectIdKey, "string", context.packageName)
if (resId == 0) {
logger.warn("No firebase configuration found; cannot support push service.")
return@lazy null
return@lazyMonitored null
}
logger.debug("Creating push configuration for autopush.")
@ -42,5 +43,5 @@ class Push(context: Context, crashReporter: CrashReporter) {
PushConfig(projectId)
}
private val pushService by lazy { FirebasePushService() }
private val pushService by lazyMonitored { FirebasePushService() }
}

View File

@ -10,6 +10,7 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import mozilla.components.browser.search.SearchEngineManager
import org.mozilla.fenix.components.searchengine.FenixSearchEngineProvider
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.utils.Mockable
/**
@ -22,7 +23,7 @@ class Search(private val context: Context) {
/**
* This component provides access to a centralized registry of search engines.
*/
val searchEngineManager by lazy {
val searchEngineManager by lazyMonitored {
SearchEngineManager(
coroutineContext = IO,
providers = listOf(provider)

View File

@ -14,6 +14,7 @@ import mozilla.components.feature.app.links.AppLinksInterceptor
import mozilla.components.service.fxa.manager.FxaAccountManager
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.utils.Mockable
@ -25,7 +26,7 @@ class Services(
private val context: Context,
private val accountManager: FxaAccountManager
) {
val accountsAuthFeature by lazy {
val accountsAuthFeature by lazyMonitored {
FirefoxAccountsAuthFeature(accountManager, FxaServer.REDIRECT_URL) { context, authUrl ->
CoroutineScope(Dispatchers.Main).launch {
val intent = SupportUtils.createAuthCustomTabIntent(context, authUrl)
@ -34,7 +35,7 @@ class Services(
}
}
val appLinksInterceptor by lazy {
val appLinksInterceptor by lazyMonitored {
AppLinksInterceptor(
context,
interceptLinkClicks = true,

View File

@ -22,6 +22,7 @@ import mozilla.components.feature.session.TrackingProtectionUseCases
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.feature.top.sites.TopSitesStorage
import mozilla.components.feature.top.sites.TopSitesUseCases
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.utils.Mockable
/**
@ -42,17 +43,17 @@ class UseCases(
/**
* Use cases that provide engine interactions for a given browser session.
*/
val sessionUseCases by lazy { SessionUseCases(store, sessionManager) }
val sessionUseCases by lazyMonitored { SessionUseCases(store, sessionManager) }
/**
* Use cases that provide tab management.
*/
val tabsUseCases: TabsUseCases by lazy { TabsUseCases(store, sessionManager) }
val tabsUseCases: TabsUseCases by lazyMonitored { TabsUseCases(store, sessionManager) }
/**
* Use cases that provide search engine integration.
*/
val searchUseCases by lazy {
val searchUseCases by lazyMonitored {
SearchUseCases(
context,
store,
@ -64,22 +65,22 @@ class UseCases(
/**
* Use cases that provide settings management.
*/
val settingsUseCases by lazy { SettingsUseCases(engine, store) }
val settingsUseCases by lazyMonitored { SettingsUseCases(engine, store) }
val appLinksUseCases by lazy { AppLinksUseCases(context.applicationContext) }
val appLinksUseCases by lazyMonitored { AppLinksUseCases(context.applicationContext) }
val webAppUseCases by lazy {
val webAppUseCases by lazyMonitored {
WebAppUseCases(context, sessionManager, shortcutManager)
}
val downloadUseCases by lazy { DownloadsUseCases(store) }
val downloadUseCases by lazyMonitored { DownloadsUseCases(store) }
val contextMenuUseCases by lazy { ContextMenuUseCases(store) }
val contextMenuUseCases by lazyMonitored { ContextMenuUseCases(store) }
val trackingProtectionUseCases by lazy { TrackingProtectionUseCases(store, engine) }
val trackingProtectionUseCases by lazyMonitored { TrackingProtectionUseCases(store, engine) }
/**
* Use cases that provide top sites management.
*/
val topSitesUseCase by lazy { TopSitesUseCases(topSitesStorage) }
val topSitesUseCase by lazyMonitored { TopSitesUseCases(topSitesStorage) }
}