Closed Bug 1612097 Opened 6 years ago Closed 5 years ago

Provide API to cancel WebExtensionController.install

Categories

(GeckoView :: Extensions, enhancement, P1)

Unspecified
All
enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: csadilek, Assigned: twisniewski)

References

Details

(Whiteboard: [geckoview:m75][geckoview:m76])

Attachments

(2 files, 1 obsolete file)

This is so Fenix can display a cancel option while installing add-ons.

Priority: -- → P1
Whiteboard: [geckoview:m75]

There are a couple ways to do this, but I think perhaps the most generally useful way would be to introduce a new GeckoCancelableResult, and return that from install(). It would look something like:

public abstract class GeckoCancelableResult extends GeckoResult {
    public GeckoResult<boolean> cancel();
}

The semantics are where things get tricky, but I think we should try to be close to CompletableFuture here. After all, we'd probably be using that directly if we could. CompletableFuture#cancel()[1] causes the future to be completed with a CancelationException if it has not already been completed. So a more complete impl would look like:

public abstract class GeckoCancelableResult extends GeckoResult {
    public GeckoResult<boolean> cancel() {
        completeExceptionally(new CancelationException());
        return GeckoResult.fromValue(true);
    }
}

I think we should keep this class abstract so we don't have cancel() methods that are noops that appear to succeed. We'll then need subclasses for individual cancelable operations, and the subclass would return super.cancel() once they had completed the work necessary to cancel the operation. Nothing stops someone from doing super.cancel() directly, I guess, but at least they will feel bad.

[1] https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html#cancel-boolean-

Assignee: nobody → twisniewski

Unfortunately, the subclass approach in comment 1 won't be pretty, because GeckoResult internally instantiates GeckoResults (not the correct subclass) when calling methods like then. As such, snorp and I decided to just add a cancel method to GeckoResult for now and prevent that mess.

After quite a bit of back-and-forth with snorp, we've decided that using GeckoResult in this way just isn't tenable right now; it's not really designed to be used this way. For now, we'll just add a WebExtensionController.cancelInstall method which accepts the GeckoResults returned by .install(). A try-run of this approach seems fine: https://treeherder.mozilla.org/#/jobs?repo=try&revision=a948dbf2bfd9c6d73d56984b685b2074583e54b0

Attachment #9129560 - Attachment is obsolete: true

add WebExtensionController.cancelInstall(GeckoResult<WebExtension>), accepting the GeckoResults returned by .install()

Attachment #9130136 - Attachment description: Bug 1612097 - add WebExtensionController.cancelInstall(GeckoResult<WebExtension>); r?snorp → Bug 1612097 - change WebExtensionController.install to pass back a WebExtensionInstall object allowing cancelation; r?snorp
Whiteboard: [geckoview:m75] → [geckoview:m75][geckoview:m76]
Pushed by jwillcox@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/48d5409e907b Add GeckoResult.cancel() r=geckoview-reviewers,agi,esawin

Only part of this has landed, so adding leave-open

Keywords: leave-open
Attachment #9130136 - Attachment description: Bug 1612097 - change WebExtensionController.install to pass back a WebExtensionInstall object allowing cancelation; r?snorp → Bug 1612097 - Add ability to cancel the GeckoResult returned by WebExtensionControll.install(BuiltIn); r?snorp,r?agi!
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Pushed by twisniewski@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/79c33a0692de Add ability to cancel the GeckoResult returned by WebExtensionControll.install(BuiltIn); r=snorp,agi
Status: REOPENED → RESOLVED
Closed: 5 years ago5 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: