Bug 1853309 - Expose Creating Shopping Analysis and Status API

This commit is contained in:
Cathy Lu
2023-09-18 18:17:27 -05:00
committed by mergify[bot]
parent c8992d4fb4
commit 7d655590f3
6 changed files with 151 additions and 6 deletions

View File

@@ -766,6 +766,62 @@ class GeckoEngineSession(
})
}
/**
* See [EngineSession.reanalyzeProduct]
*/
override fun reanalyzeProduct(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {
geckoSession.requestCreateAnalysis(url).then({
response ->
val errorMessage = "Invalid value: unable to reanalyze product from Gecko Engine."
if (response == null) {
logger.error(errorMessage)
onException(
java.lang.IllegalStateException(errorMessage),
)
return@then GeckoResult()
}
onResult(response)
GeckoResult<String>()
}, {
throwable ->
logger.error("Request to reanalyze product failed.", throwable)
onException(throwable)
GeckoResult()
})
}
/**
* See [EngineSession.requestAnalysisStatus]
*/
override fun requestAnalysisStatus(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {
geckoSession.requestAnalysisCreationStatus(url).then({
response ->
val errorMessage = "Invalid value: unable to request analysis status from Gecko Engine."
if (response == null) {
logger.error(errorMessage)
onException(
java.lang.IllegalStateException(errorMessage),
)
return@then GeckoResult()
}
onResult(response)
GeckoResult<String>()
}, {
throwable ->
logger.error("Request for product analysis status failed.", throwable)
onException(throwable)
GeckoResult()
})
}
/**
* Purges the history for the session (back and forward history).
*/

View File

@@ -446,6 +446,28 @@ class SystemEngineSession(
throw UnsupportedOperationException("Analysis of product reviews for shopping is not available in this engine")
}
/**
* See [EngineSession.reanalyzeProduct]
*/
override fun reanalyzeProduct(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {
throw UnsupportedOperationException("Reanalyzing product reviews for shopping is not available in this engine")
}
/**
* See [EngineSession.requestAnalysisStatus]
*/
override fun requestAnalysisStatus(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {
throw UnsupportedOperationException("Requesting product analysis status is not available in this engine")
}
override fun hasCookieBannerRuleForSession(
onResult: (Boolean) -> Unit,
onException: (Throwable) -> Unit,

View File

@@ -91,7 +91,16 @@ class EngineObserverTest {
onResult: (List<ProductRecommendation>) -> Unit,
onException: (Throwable) -> Unit,
) {}
override fun reanalyzeProduct(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {}
override fun requestAnalysisStatus(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {}
override fun findAll(text: String) {}
override fun findNext(forward: Boolean) {}
override fun clearFindMatches() {}
@@ -168,7 +177,16 @@ class EngineObserverTest {
onResult: (List<ProductRecommendation>) -> Unit,
onException: (Throwable) -> Unit,
) {}
override fun reanalyzeProduct(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {}
override fun requestAnalysisStatus(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {}
override fun findAll(text: String) {}
override fun findNext(forward: Boolean) {}
override fun clearFindMatches() {}
@@ -242,7 +260,16 @@ class EngineObserverTest {
onResult: (ProductAnalysis) -> Unit,
onException: (Throwable) -> Unit,
) {}
override fun reanalyzeProduct(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {}
override fun requestAnalysisStatus(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {}
override fun loadUrl(
url: String,
parent: EngineSession?,

View File

@@ -852,7 +852,7 @@ abstract class EngineSession(
* @param onResult callback invoked if the engine API returned a valid response. Please note
* that the response can be null - which can indicate a bug, a miscommunication
* or other unexpected failure.
* @param onError callback invoked if there was an error getting the response.
* @param onException callback invoked if there was an error getting the response.
*/
abstract fun requestProductRecommendations(
url: String,
@@ -863,8 +863,8 @@ abstract class EngineSession(
/**
* Requests the analysis results for a given product page URL.
*
* @param onSuccess callback invoked if the engine API returns a valid response.
* @param onError callback invoked if there was an error getting the response.
* @param onResult callback invoked if the engine API returns a valid response.
* @param onException callback invoked if there was an error getting the response.
*/
abstract fun requestProductAnalysis(
url: String,
@@ -872,6 +872,30 @@ abstract class EngineSession(
onException: (Throwable) -> Unit,
)
/**
* Requests the reanalysis of a product for a given product page URL.
*
* @param onResult callback invoked if the engine API returns a valid response.
* @param onException callback invoked if there was an error getting the response.
*/
abstract fun reanalyzeProduct(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
)
/**
* Requests the status of a product analysis for a given product page URL.
*
* @param onResult callback invoked if the engine API returns a valid response.
* @param onException callback invoked if there was an error getting the response.
*/
abstract fun requestAnalysisStatus(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
)
/**
* Finds and highlights all occurrences of the provided String and highlights them asynchronously.
*

View File

@@ -1019,6 +1019,18 @@ open class DummyEngineSession : EngineSession() {
onException: (Throwable) -> Unit,
) {}
override fun reanalyzeProduct(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {}
override fun requestAnalysisStatus(
url: String,
onResult: (String) -> Unit,
onException: (Throwable) -> Unit,
) {}
override fun findAll(text: String) {}
override fun findNext(forward: Boolean) {}

View File

@@ -39,6 +39,10 @@ permalink: /changelog/
* ⚠️ **This is a breaking change**: Renamed `WebExtensionPopupFeature` to `WebExtensionPopupObserver` [bug #1852335](https://bugzilla.mozilla.org/show_bug.cgi?id=1852335)
* Added `ExtensionProcessDisabledPopupObserver` to display to the user a dialog when the extensions process spawning has been disabled. [bug #1846979](https://bugzilla.mozilla.org/show_bug.cgi?id=1846979)
* **concept-engine**
* 🌟️️ Add `reanalyzeProduct` API to `EngineSession` to allow reanalyzing product from the engine. See more on [Bug 1853309](https://bugzilla.mozilla.org/show_bug.cgi?id=1853309).
* 🌟️️ Add `requestAnalysisStatus` API to `EngineSession` to allow request product analysis status from the engine. See more on [Bug 1853309](https://bugzilla.mozilla.org/show_bug.cgi?id=1853309).
# 118.0
* [Commits](https://github.com/mozilla-mobile/firefox-android/compare/releases_v117..releases_v118)
* [Dependencies](https://github.com/mozilla-mobile/firefox-android/blob/releases_v118/android-components/plugins/dependencies/src/main/java/DependenciesPlugin.kt)