Commit e6e2dd94 authored by Grisha Kruglov's avatar Grisha Kruglov Committed by Sebastian Kaspari
Browse files

Closes #7344: Login storage refactor

The a-c side of this work is in https://github.com/mozilla-mobile/android-components/pull/6128

This switches Fenix to use `SyncableLoginsStorage`, which caches a connection internally
on first access, and doesn't expose any lock/unlock APIs at the public boundary.
parent 6a75d822
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -6,10 +6,9 @@ import android.content.Context
import android.os.Bundle
import mozilla.components.browser.engine.gecko.autofill.GeckoLoginDelegateWrapper
import mozilla.components.browser.engine.gecko.glean.GeckoAdapter
import mozilla.components.concept.storage.LoginsStorage
import mozilla.components.lib.crash.handler.CrashHandlerService
import mozilla.components.lib.dataprotect.SecureAbove22Preferences
import mozilla.components.service.experiments.Experiments
import mozilla.components.service.sync.logins.AsyncLoginsStorage
import mozilla.components.service.sync.logins.GeckoLoginStorageDelegate
import org.mozilla.fenix.Config
import org.mozilla.fenix.ext.settings
@@ -24,11 +23,10 @@ object GeckoProvider {
    @Synchronized
    fun getOrCreateRuntime(
        context: Context,
        storage: AsyncLoginsStorage,
        securePreferences: SecureAbove22Preferences
        storage: LoginsStorage
    ): GeckoRuntime {
        if (runtime == null) {
            runtime = createRuntime(context, storage, securePreferences)
            runtime = createRuntime(context, storage)
        }

        return runtime!!
@@ -36,8 +34,7 @@ object GeckoProvider {

    private fun createRuntime(
        context: Context,
        storage: AsyncLoginsStorage,
        securePreferences: SecureAbove22Preferences
        storage: LoginsStorage
    ): GeckoRuntime {
        val builder = GeckoRuntimeSettings.Builder()

@@ -69,7 +66,6 @@ object GeckoProvider {
        val geckoRuntime = GeckoRuntime.create(context, runtimeSettings)
        val loginStorageDelegate = GeckoLoginStorageDelegate(
            storage,
            securePreferences,
            { context.settings().shouldAutofillLogins && context.settings().shouldPromptToSaveLogins }
        )
        geckoRuntime.loginStorageDelegate = GeckoLoginDelegateWrapper(loginStorageDelegate)
+4 −8
Original line number Diff line number Diff line
@@ -6,9 +6,8 @@ import android.content.Context
import android.os.Bundle
import mozilla.components.browser.engine.gecko.autofill.GeckoLoginDelegateWrapper
import mozilla.components.browser.engine.gecko.glean.GeckoAdapter
import mozilla.components.concept.storage.LoginsStorage
import mozilla.components.lib.crash.handler.CrashHandlerService
import mozilla.components.lib.dataprotect.SecureAbove22Preferences
import mozilla.components.service.sync.logins.AsyncLoginsStorage
import mozilla.components.service.sync.logins.GeckoLoginStorageDelegate
import org.mozilla.fenix.Config
import org.mozilla.fenix.ext.settings
@@ -23,11 +22,10 @@ object GeckoProvider {
    @Synchronized
    fun getOrCreateRuntime(
        context: Context,
        storage: AsyncLoginsStorage,
        securePreferences: SecureAbove22Preferences
        storage: LoginsStorage
    ): GeckoRuntime {
        if (runtime == null) {
            runtime = createRuntime(context, storage, securePreferences)
            runtime = createRuntime(context, storage)
        }

        return runtime!!
@@ -35,8 +33,7 @@ object GeckoProvider {

    private fun createRuntime(
        context: Context,
        storage: AsyncLoginsStorage,
        securePreferences: SecureAbove22Preferences
        storage: LoginsStorage
    ): GeckoRuntime {
        val builder = GeckoRuntimeSettings.Builder()

@@ -61,7 +58,6 @@ object GeckoProvider {
        val geckoRuntime = GeckoRuntime.create(context, runtimeSettings)
        val loginStorageDelegate = GeckoLoginStorageDelegate(
            storage,
            securePreferences,
            { context.settings().shouldAutofillLogins && context.settings().shouldPromptToSaveLogins }
        )
        geckoRuntime.loginStorageDelegate = GeckoLoginDelegateWrapper(loginStorageDelegate)
+1 −2
Original line number Diff line number Diff line
@@ -328,8 +328,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
                    customTabId = customTabSessionId,
                    fragmentManager = parentFragmentManager,
                    loginValidationDelegate = DefaultLoginValidationDelegate(
                        context.components.core.asyncPasswordsStorage,
                        context.components.core.getSecureAbove22Preferences()
                        context.components.core.passwordsStorage
                    ),
                    isSaveLoginEnabled = {
                        context.settings().shouldPromptToSaveLogins
+3 −6
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import mozilla.components.feature.accounts.push.SendTabFeature
import mozilla.components.feature.push.AutoPushFeature
import mozilla.components.feature.push.PushConfig
import mozilla.components.lib.crash.CrashReporter
import mozilla.components.lib.dataprotect.SecureAbove22Preferences
import mozilla.components.service.fxa.DeviceConfig
import mozilla.components.service.fxa.ServerConfig
import mozilla.components.service.fxa.SyncConfig
@@ -30,7 +29,7 @@ import mozilla.components.service.fxa.manager.SCOPE_SESSION
import mozilla.components.service.fxa.manager.SCOPE_SYNC
import mozilla.components.service.fxa.manager.SyncEnginesStorage
import mozilla.components.service.fxa.sync.GlobalSyncableStoreProvider
import mozilla.components.service.sync.logins.SyncableLoginsStore
import mozilla.components.service.sync.logins.SyncableLoginsStorage
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
@@ -51,8 +50,7 @@ class BackgroundServices(
    crashReporter: CrashReporter,
    historyStorage: PlacesHistoryStorage,
    bookmarkStorage: PlacesBookmarksStorage,
    passwordsStorage: SyncableLoginsStore,
    secureAbove22Preferences: SecureAbove22Preferences
    passwordsStorage: SyncableLoginsStorage
) {
    fun defaultDeviceName(context: Context): String =
        context.getString(
@@ -88,7 +86,7 @@ class BackgroundServices(
            syncPeriodInMinutes = 240L) // four hours
    }

    val pushService by lazy { FirebasePushService() }
    private val pushService by lazy { FirebasePushService() }

    val push by lazy { makePushConfig()?.let { makePush(it) } }

@@ -97,7 +95,6 @@ class BackgroundServices(
        GlobalSyncableStoreProvider.configureStore(SyncEngine.History to historyStorage)
        GlobalSyncableStoreProvider.configureStore(SyncEngine.Bookmarks to bookmarkStorage)
        GlobalSyncableStoreProvider.configureStore(SyncEngine.Passwords to passwordsStorage)
        GlobalSyncableStoreProvider.configureKeyStorage(secureAbove22Preferences)
    }

    private val telemetryAccountObserver = TelemetryAccountObserver(
+1 −2
Original line number Diff line number Diff line
@@ -29,8 +29,7 @@ class Components(private val context: Context) {
            analytics.crashReporter,
            core.historyStorage,
            core.bookmarksStorage,
            core.syncablePasswordsStorage,
            core.getSecureAbove22Preferences()
            core.passwordsStorage
        )
    }
    val services by lazy { Services(context, backgroundServices.accountManager) }
Loading