For #15279: LazyMonitored implement Lazy + update built-in API use.
By having LazyMonitored implement Lazy, we can continue to pass these values directly into the ac APIs that require Lazy references. For some reason, implementing `Lazy.value` can replace `operator fun getValue` required for delegates.
This commit is contained in:
parent
901c78684c
commit
89541a17f7
|
@ -293,14 +293,14 @@ class Core(
|
|||
// Use these for startup-path code, where we don't want to do any work that's not strictly necessary.
|
||||
// For example, this is how the GeckoEngine delegates (history, logins) are configured.
|
||||
// We can fully initialize GeckoEngine without initialized our storage.
|
||||
val lazyHistoryStorage = lazy { PlacesHistoryStorage(context, crashReporter) }
|
||||
val lazyBookmarksStorage = lazy { PlacesBookmarksStorage(context) }
|
||||
val lazyPasswordsStorage = lazy { SyncableLoginsStorage(context, passwordsEncryptionKey) }
|
||||
val lazyHistoryStorage = lazyMonitored { PlacesHistoryStorage(context, crashReporter) }
|
||||
val lazyBookmarksStorage = lazyMonitored { PlacesBookmarksStorage(context) }
|
||||
val lazyPasswordsStorage = lazyMonitored { SyncableLoginsStorage(context, passwordsEncryptionKey) }
|
||||
|
||||
/**
|
||||
* The storage component to sync and persist tabs in a Firefox Sync account.
|
||||
*/
|
||||
val lazyRemoteTabsStorage = lazy { RemoteTabsStorage() }
|
||||
val lazyRemoteTabsStorage = lazyMonitored { RemoteTabsStorage() }
|
||||
|
||||
// For most other application code (non-startup), these wrappers are perfectly fine and more ergonomic.
|
||||
val historyStorage by lazyMonitored { lazyHistoryStorage.value }
|
||||
|
|
|
@ -27,7 +27,7 @@ fun <T> lazyMonitored(initializer: () -> T) = LazyMonitored(initializer)
|
|||
* For example, we can count the number of components initialized to see how the number of
|
||||
* components initialized on start up impacts start up time.
|
||||
*/
|
||||
class LazyMonitored<T>(initializer: () -> T) {
|
||||
class LazyMonitored<T>(initializer: () -> T) : Lazy<T> {
|
||||
// Lazy is thread safe.
|
||||
private val lazyValue = lazy {
|
||||
// We're unlikely to have 4 billion components so we don't handle overflow.
|
||||
|
@ -40,5 +40,6 @@ class LazyMonitored<T>(initializer: () -> T) {
|
|||
}
|
||||
}
|
||||
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = lazyValue.value
|
||||
override val value: T get() = lazyValue.value
|
||||
override fun isInitialized(): Boolean = lazyValue.isInitialized()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user