Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owlishDeveloper/57f00a86f9841c8cc5bca88735cba2ae to your computer and use it in GitHub Desktop.
Save owlishDeveloper/57f00a86f9841c8cc5bca88735cba2ae to your computer and use it in GitHub Desktop.
Downloads API proposal - Example 2 - separating concerns
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