Skip to content

Commit

Permalink
Closes issue mozilla-mobile#8681: Do not retry to update an extension
Browse files Browse the repository at this point in the history
 when an UnRecoverableError happens
  • Loading branch information
Amejia481 committed Oct 15, 2020
1 parent 05dfb09 commit cbcd597
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.GeckoRuntime
import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.GeckoWebExecutor
import org.mozilla.geckoview.WebExtension.InstallException
import org.mozilla.geckoview.WebExtension.InstallException.ErrorCodes.ERROR_NETWORK_FAILURE
import org.mozilla.geckoview.WebExtensionController

/**
Expand Down Expand Up @@ -267,7 +269,13 @@ class GeckoEngine(
onSuccess(updatedExtension)
GeckoResult<Void>()
}, { throwable ->
onError(extension.id, throwable)

val exception = if (throwable is InstallException && throwable.code != ERROR_NETWORK_FAILURE) {
WebExtension.UnRecoverableError(throwable)
} else {
throwable
}
onError(extension.id, exception)
GeckoResult<Void>()
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.graphics.Bitmap
import android.net.Uri
import mozilla.components.concept.engine.EngineSession
import org.json.JSONObject
import java.lang.Error

/**
* Represents a browser extension based on the WebExtension API:
Expand Down Expand Up @@ -180,6 +181,13 @@ abstract class WebExtension(
* available icon to the provided size.
*/
abstract suspend fun loadIcon(size: Int): Bitmap?

/**
* An error that occur trying to perform an action like installing, removing or updating
* an [WebExtension] that is not recoverable.
*/
class UnRecoverableError(throwable: Throwable) : Error(throwable)

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ internal class AddonUpdaterWorker(
"Unable to update extension $extensionId, re-schedule ${status.message}",
status.exception
)
Result.retry()
retryIfRecoverable(status.exception)
}
}
saveUpdateAttempt(extensionId, status)
Expand All @@ -599,11 +599,19 @@ internal class AddonUpdaterWorker(
if (exception.shouldReport()) {
GlobalAddonDependencyProvider.onCrash?.invoke(exception)
}
continuation.resume(Result.retry())
continuation.resume(retryIfRecoverable(exception))
}
}
}

private fun retryIfRecoverable(throwable: Throwable): Result {
return if (throwable !is WebExtension.UnRecoverableError) {
Result.retry()
} else {
Result.success()
}
}

private fun saveUpdateAttempt(extensionId: String, status: AddonUpdater.Status) {
CoroutineScope((Dispatchers.IO)).launch {
updateAttemptStorage.saveOrUpdate(AddonUpdater.UpdateAttempt(extensionId, Date(), status))
Expand Down

0 comments on commit cbcd597

Please sign in to comment.