From 7527702f5ffc5e31256646d9aaa82d5359368552 Mon Sep 17 00:00:00 2001 From: "ben%bengoodger.com" Date: Wed, 8 Jun 2005 22:39:45 +0000 Subject: [PATCH] add support for restarting downloads at different priority levels (background vs. foreground), separate out update and extensions jar manifests for faster development turnaround --- toolkit/mozapps/extensions/jar.mn | 13 +++++ toolkit/mozapps/jar.mn | 18 ------- toolkit/mozapps/update/content/updates.js | 6 +-- toolkit/mozapps/update/jar.mn | 9 ++++ .../update/public/nsIUpdateService.idl | 2 +- .../mozapps/update/src/nsUpdateService.js.in | 52 ++++++++++++++----- 6 files changed, 66 insertions(+), 34 deletions(-) create mode 100755 toolkit/mozapps/extensions/jar.mn create mode 100755 toolkit/mozapps/update/jar.mn diff --git a/toolkit/mozapps/extensions/jar.mn b/toolkit/mozapps/extensions/jar.mn new file mode 100755 index 00000000000..40996065759 --- /dev/null +++ b/toolkit/mozapps/extensions/jar.mn @@ -0,0 +1,13 @@ +toolkit.jar: +% content mozapps %content/mozapps/ xpcnativewrappers=yes +* content/mozapps/extensions/extensions.xul (content/extensions.xul) +* content/mozapps/extensions/extensions.js (content/extensions.js) +* content/mozapps/extensions/extensions.xml (content/extensions.xml) +* content/mozapps/extensions/extensions.css (content/extensions.css) +* content/mozapps/extensions/update.xul (content/update.xul) +* content/mozapps/extensions/update.xml (content/update.xml) +* content/mozapps/extensions/update.js (content/update.js) + content/mozapps/extensions/update.css (content/update.css) +* content/mozapps/extensions/about.xul (content/about.xul) +* content/mozapps/extensions/about.js (content/about.js) +* content/mozapps/extensions/finalize.xul (content/finalize.xul) diff --git a/toolkit/mozapps/jar.mn b/toolkit/mozapps/jar.mn index c77c3168dee..99e30802f4b 100755 --- a/toolkit/mozapps/jar.mn +++ b/toolkit/mozapps/jar.mn @@ -12,17 +12,6 @@ toolkit.jar: * content/mozapps/downloads/download.xml (downloads/content/download.xml) * content/mozapps/downloads/downloadProperties.xul (downloads/content/downloadProperties.xul) * content/mozapps/downloads/downloadProperties.js (downloads/content/downloadProperties.js) -* content/mozapps/extensions/extensions.xul (extensions/content/extensions.xul) -* content/mozapps/extensions/extensions.js (extensions/content/extensions.js) -* content/mozapps/extensions/extensions.xml (extensions/content/extensions.xml) -* content/mozapps/extensions/extensions.css (extensions/content/extensions.css) -* content/mozapps/extensions/update.xul (extensions/content/update.xul) -* content/mozapps/extensions/update.xml (extensions/content/update.xml) -* content/mozapps/extensions/update.js (extensions/content/update.js) - content/mozapps/extensions/update.css (extensions/content/update.css) -* content/mozapps/extensions/about.xul (extensions/content/about.xul) -* content/mozapps/extensions/about.js (extensions/content/about.js) -* content/mozapps/extensions/finalize.xul (extensions/content/finalize.xul) * content/mozapps/preferences/actionsshared.js (preferences/actionsshared.js) * content/mozapps/preferences/ocsp.js (preferences/ocsp.js) * content/mozapps/preferences/ocsp.xul (preferences/ocsp.xul) @@ -35,13 +24,6 @@ toolkit.jar: * content/mozapps/preferences/removemp.xul (preferences/removemp.xul) * content/mozapps/preferences/preferences.css (preferences/preferences.css) * content/mozapps/preferences/preferences.xml (preferences/preferences.xml) - content/mozapps/update/updates.css (update/content/updates.css) -* content/mozapps/update/updates.xul (update/content/updates.xul) -* content/mozapps/update/updates.js (update/content/updates.js) -* content/mozapps/update/updates.xml (update/content/updates.xml) -* content/mozapps/update/incompatible.xul (update/content/incompatible.xul) -* content/mozapps/update/incompatible.js (update/content/incompatible.js) -* content/mozapps/update/errors.xul (update/content/errors.xul) * content/mozapps/shared/richview.xml (shared/content/richview.xml) content/mozapps/plugins/pluginInstallerWizard.xul (plugins/content/pluginInstallerWizard.xul) content/mozapps/plugins/pluginInstallerWizard.js (plugins/content/pluginInstallerWizard.js) diff --git a/toolkit/mozapps/update/content/updates.js b/toolkit/mozapps/update/content/updates.js index 1d69b74e278..2ebd0a049d8 100755 --- a/toolkit/mozapps/update/content/updates.js +++ b/toolkit/mozapps/update/content/updates.js @@ -86,7 +86,7 @@ var gCheckingPage = { * See nsIUpdateCheckListener.idl */ onError: function() { - dump("*** UpdateCheckListener: ERROR\n"); + LOG("UpdateCheckListener: ERROR"); }, /** @@ -112,7 +112,6 @@ var gUpdatesAvailablePage = { [brandName, gUpdates.update.version]); var updateNameElement = document.getElementById("updateName"); updateNameElement.value = updateName; - dump("*** update = " + gUpdates.update.version + "\n"); var displayType = updateStrings.getString("updateType_" + gUpdates.update.type); var updateTypeElement = document.getElementById("updateType"); updateTypeElement.setAttribute("type", gUpdates.update.type); @@ -164,7 +163,8 @@ var gDownloadingPage = { var updates = Components.classes["@mozilla.org/updates/update-service;1"] .getService(Components.interfaces.nsIApplicationUpdateService); - updates.downloadUpdate(gUpdates.update); + LOG("goats"); + updates.downloadUpdate(gUpdates.update, false); updates.addDownloadListener(this); // Build the UI for previously installed updates diff --git a/toolkit/mozapps/update/jar.mn b/toolkit/mozapps/update/jar.mn new file mode 100755 index 00000000000..e071902a492 --- /dev/null +++ b/toolkit/mozapps/update/jar.mn @@ -0,0 +1,9 @@ +toolkit.jar: +% content mozapps %content/mozapps/ xpcnativewrappers=yes + content/mozapps/update/updates.css (content/updates.css) +* content/mozapps/update/updates.xul (content/updates.xul) +* content/mozapps/update/updates.js (content/updates.js) +* content/mozapps/update/updates.xml (content/updates.xml) +* content/mozapps/update/incompatible.xul (content/incompatible.xul) +* content/mozapps/update/incompatible.js (content/incompatible.js) +* content/mozapps/update/errors.xul (content/errors.xul) diff --git a/toolkit/mozapps/update/public/nsIUpdateService.idl b/toolkit/mozapps/update/public/nsIUpdateService.idl index 4a7fd42699a..3aa68c950e9 100644 --- a/toolkit/mozapps/update/public/nsIUpdateService.idl +++ b/toolkit/mozapps/update/public/nsIUpdateService.idl @@ -186,7 +186,7 @@ interface nsIApplicationUpdateService : nsISupports /** * */ - void downloadUpdate(in nsIUpdate update); + void downloadUpdate(in nsIUpdate update, in boolean background); }; [scriptable, uuid(0765c92c-6145-4253-9db4-594d8023087e)] diff --git a/toolkit/mozapps/update/src/nsUpdateService.js.in b/toolkit/mozapps/update/src/nsUpdateService.js.in index 8bf26b54285..0c03d54d1f5 100644 --- a/toolkit/mozapps/update/src/nsUpdateService.js.in +++ b/toolkit/mozapps/update/src/nsUpdateService.js.in @@ -77,8 +77,9 @@ const STATE_APPLYING = "applying"; const STATE_SUCCEEDED = "succeeded"; const STATE_FAILED = "failed"; -const DOWNLOAD_CHUNK_SIZE = 65536; -const DOWNLOAD_INTERVAL = 1; +const DOWNLOAD_CHUNK_SIZE = 65536; +const DOWNLOAD_BACKGROUND_INTERVAL = 1; +const DOWNLOAD_FOREGROUND_INTERVAL = 0; const nsILocalFile = Components.interfaces.nsILocalFile; const nsIUpdateService = Components.interfaces.nsIUpdateService; @@ -376,14 +377,15 @@ UpdateService.prototype = { switch (topic) { case "app-startup": // Resume fetching... - this.downloadUpdate(null); + this.downloadUpdate(null, true); break; case "profile-after-change": gOS.removeObserver(this, "profile-after-change"); // Register a background update check timer - var tm = Components.classes["@mozilla.org/updates/timer-manager;1"] - .getService(Components.interfaces.nsIUpdateTimerManager); + var tm = + Components.classes["@mozilla.org/updates/timer-manager;1"] + .getService(Components.interfaces.nsIUpdateTimerManager); var interval = getPref("getIntPref", PREF_APP_UPDATE_INTERVAL, 86400000); tm.registerTimer("background-update-timer", this, interval, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK); @@ -518,7 +520,7 @@ UpdateService.prototype = { prompter.showUpdateAvailable(update); } else - this.downloadUpdate(update); + this.downloadUpdate(update, true); }, /** @@ -555,14 +557,17 @@ UpdateService.prototype = { /** * */ - downloadUpdate: function(update) { + downloadUpdate: function(update, background) { LOG("downloadUpdate"); if (this._downloader && this._downloader.isBusy) { - LOG("no support for downloading more than one update at a time"); - return; + if (background == this._downloader.background) { + LOG("no support for downloading more than one update at a time"); + return; + } + this._downloader.cancel(); } - this._downloader = new Downloader(); + this._downloader = new Downloader(background); this._downloader.downloadUpdate(update); }, @@ -791,12 +796,31 @@ Checker.prototype = { } }; -function Downloader() { +/** + * Manages the download of updates + * @param background + * Whether or not this downloader is operating in background + * update mode. + * @constructor + */ +function Downloader(background) { + this.background = background; } Downloader.prototype = { _patch: null, // UpdatePatch _request: null, // nsIIncrementalDownload + /** + * + */ + cancel: function() { + if (this._request && + this._request instanceof Components.interfaces.nsIRequest) { + const NS_BINDING_ABORTED = 0x804b0002; + this._request.cancel(NS_BINDING_ABORTED); + } + }, + /** * */ @@ -1010,6 +1034,7 @@ Downloader.prototype = { * attempt to resume downloading what it was previously downloading. */ downloadUpdate: function(update) { + LOG("downloadUpdate"); var updateDir = this._getUpdatesDir(); // This function may return null, which indicates that there are no patches @@ -1034,7 +1059,9 @@ Downloader.prototype = { LOG("Downloader.downloadUpdate: Downloading from " + uri.spec + " to " + patchFile.path); - this._request.init(uri, patchFile, DOWNLOAD_CHUNK_SIZE, DOWNLOAD_INTERVAL); + var interval = this.background ? DOWNLOAD_BACKGROUND_INTERVAL + : DOWNLOAD_FOREGROUND_INTERVAL; + this._request.init(uri, patchFile, DOWNLOAD_CHUNK_SIZE, interval); this._request.start(this, null); this._writeStatusFile(updateDir, STATE_DOWNLOADING); @@ -1074,6 +1101,7 @@ Downloader.prototype = { }, onProgress: function(request, context, progress, maxProgress) { + LOG("MODE: " + (this.background ? "BACKGROUND" : "FOREGROUND")); request.QueryInterface(nsIIncrementalDownload); LOG("Downloader.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress); var listenerCount = this._listeners.length;