Created
July 6, 2020 00:13
-
-
Save owlishDeveloper/57f00a86f9841c8cc5bca88735cba2ae to your computer and use it in GitHub Desktop.
Downloads API proposal - Example 2 - separating concerns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppDownload { | |
WebExtension.DownloadItem mExtensionDownload; | |
// Cancels the download | |
GeckoResult<Void> cancel() { | |
// Actually cancel the download | |
} | |
GeckoResult<DownloadItemUpdate> notifyExtension() { | |
// Notifies extension | |
mExtensionDownload.updateCanceled(true).commit(); | |
} | |
void setDownloadItem(DownloadItem item) { | |
mExtensionDownload = item; | |
} | |
} | |
class AppDownloadController { | |
// stuff ... | |
@Override | |
GeckoResult<DownloadItemUpdate> onCancel(DownloadItem item, WebExtension extension) { | |
AppDownload download = mDownloads.byDownloadItem(item); | |
// Update the download item in case it's out of date | |
download.setDownloadItem(item); | |
download.cancel(); | |
return download.notifyExtension(); | |
} | |
} | |
// UI Code | |
onClick() { | |
mDownload.cancel(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment