Bug 1889495 - Make FxSuggestStorage respect the Remote Settings server. r=skhan,android-reviewers

This commit wires up Fenix's "use Remote Settings production server"
secret setting to the Suggest component.

Differential Revision: https://phabricator.services.mozilla.com/D207189
This commit is contained in:
Lina Butler 2024-06-23 06:17:01 +00:00
parent 1d4550867d
commit 2dee63ed3c
3 changed files with 17 additions and 6 deletions

View File

@ -46,7 +46,7 @@ tasks.withType(KotlinCompile).configureEach {
}
dependencies {
api ComponentsDependencies.mozilla_appservices_suggest
api ComponentsDependencies.mozilla_remote_settings
implementation project(':browser-state')
implementation project(':concept-awesomebar')
@ -58,6 +58,7 @@ dependencies {
implementation ComponentsDependencies.androidx_work_runtime
implementation ComponentsDependencies.kotlin_coroutines
implementation ComponentsDependencies.mozilla_appservices_suggest
testImplementation project(':support-test')

View File

@ -10,29 +10,30 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.withContext
import mozilla.appservices.remotesettings.RemoteSettingsServer
import mozilla.appservices.suggest.SuggestApiException
import mozilla.appservices.suggest.SuggestIngestionConstraints
import mozilla.appservices.suggest.SuggestStore
import mozilla.appservices.suggest.SuggestStoreBuilder
import mozilla.appservices.suggest.Suggestion
import mozilla.appservices.suggest.SuggestionQuery
import mozilla.components.concept.base.crash.CrashReporting
import mozilla.components.support.base.log.logger.Logger
/**
* A coroutine-aware wrapper around the synchronous [SuggestStore] interface.
*
* @param context The Android application context.
* @param crashReporter An optional [CrashReporting] instance for reporting unexpected caught
* exceptions.
* @param remoteSettingsServer The [RemoteSettingsServer] from which to ingest
* suggestions.
*/
class FxSuggestStorage(context: Context) {
class FxSuggestStorage(context: Context, remoteSettingsServer: RemoteSettingsServer = RemoteSettingsServer.Prod) {
// Lazily initializes the store on first use. `cacheDir` and using the `File` constructor
// does I/O, so `store.value` should only be accessed from the read or write scope.
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal val store: Lazy<SuggestStore> = lazy {
SuggestStoreBuilder()
.dataPath(context.getDatabasePath(DATABASE_NAME).absolutePath)
.remoteSettingsServer(remoteSettingsServer)
.build()
}

View File

@ -5,8 +5,10 @@
package org.mozilla.fenix.components
import android.content.Context
import mozilla.appservices.remotesettings.RemoteSettingsServer
import mozilla.components.feature.fxsuggest.FxSuggestIngestionScheduler
import mozilla.components.feature.fxsuggest.FxSuggestStorage
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.perf.lazyMonitored
/**
@ -16,7 +18,14 @@ import org.mozilla.fenix.perf.lazyMonitored
*/
class FxSuggest(context: Context) {
val storage by lazyMonitored {
FxSuggestStorage(context)
FxSuggestStorage(
context,
remoteSettingsServer = if (context.settings().useProductionRemoteSettingsServer) {
RemoteSettingsServer.Prod
} else {
RemoteSettingsServer.Stage
},
)
}
val ingestionScheduler by lazyMonitored {