author | Fabrice Desré <fabrice@mozilla.com> |
Thu, 15 Nov 2012 12:52:19 -0800 | |
changeset 113410 | 52596d2fa339d948ea652d362b8e5d94f5764a09 |
parent 113409 | 495192ed8589fe54ce165998ec01104986b6ed43 |
child 113411 | d129d66a6491616aed3b09a0c918709b5866f98a |
push id | 18135 |
push user | fdesre@mozilla.com |
push date | Thu, 15 Nov 2012 20:52:28 +0000 |
treeherder | mozilla-inbound@52596d2fa339 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | marshall |
bugs | 802228 |
milestone | 19.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
b2g/components/UpdatePrompt.js | file | annotate | diff | comparison | revisions | |
toolkit/mozapps/update/nsUpdateService.js | file | annotate | diff | comparison | revisions |
--- a/b2g/components/UpdatePrompt.js +++ b/b2g/components/UpdatePrompt.js @@ -86,16 +86,17 @@ UpdateCheckListener.prototype = { Services.aus.QueryInterface(Ci.nsIUpdateCheckListener); Services.aus.onProgress(request, position, totalSize); } }; function UpdatePrompt() { this.wrappedJSObject = this; this._updateCheckListener = new UpdateCheckListener(this); + Services.obs.addObserver(this, "update-check-start", false); } UpdatePrompt.prototype = { classID: Components.ID("{88b3eb21-d072-4e3b-886d-f89d8c49fe59}"), QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdatePrompt, Ci.nsIUpdateCheckListener, Ci.nsIRequestObserver, Ci.nsIProgressEventSink, @@ -352,28 +353,82 @@ UpdatePrompt.prototype = { this._update = null; break; case "update-prompt-apply-result": this.handleApplyPromptResult(detail); break; } }, + appsUpdated: function UP_appsUpdated(aApps) { + log("appsUpdated: " + aApps.length + " apps to update"); + let lock = Services.settings.createLock(); + lock.set("apps.updateStatus", "check-complete", null); + this.sendChromeEvent("apps-update-check", { apps: aApps }); + this._checkingApps = false; + }, + + // Trigger apps update check and wait for all to be done before + // notifying gaia. + onUpdateCheckStart: function UP_onUpdateCheckStart() { + // Don't start twice. + if (this._checkingApps) { + return; + } + + this._checkingApps = true; + + let self = this; + + let window = Services.wm.getMostRecentWindow("navigator:browser"); + let all = window.navigator.mozApps.mgmt.getAll(); + + all.onsuccess = function() { + let appsCount = this.result.length; + let appsChecked = 0; + let appsToUpdate = []; + this.result.forEach(function updateApp(aApp) { + let update = aApp.checkForUpdate(); + update.onsuccess = function() { + appsChecked += 1; + appsToUpdate.push(aApp.manifestURL); + if (appsChecked == appsCount) { + self.appsUpdated(appsToUpdate); + } + } + update.onerror = function() { + appsChecked += 1; + if (appsChecked == appsCount) { + self.appsUpdated(appsToUpdate); + } + } + }); + } + + all.onerror = function() { + // Could not get the app list, just notify to update nothing. + self.appsUpdated([]); + } + }, + // nsIObserver observe: function UP_observe(aSubject, aTopic, aData) { switch (aTopic) { case "idle": this._waitingForIdle = false; this.showApplyPrompt(this._update); // Fall through case "quit-application": Services.idle.removeIdleObserver(this, APPLY_IDLE_TIMEOUT_SECONDS); Services.obs.removeObserver(this, "quit-application"); break; + case "update-check-start": + this.onUpdateCheckStart(); + break; } }, // nsITimerCallback notify: function UP_notify(aTimer) { if (aTimer == this._applyPromptTimer) { log("Timed out waiting for result, restarting");
--- a/toolkit/mozapps/update/nsUpdateService.js +++ b/toolkit/mozapps/update/nsUpdateService.js @@ -2856,16 +2856,18 @@ Checker.prototype = { /** * See nsIUpdateService.idl */ checkForUpdates: function UC_checkForUpdates(listener, force) { LOG("Checker: checkForUpdates, force: " + force); if (!listener) throw Cr.NS_ERROR_NULL_POINTER; + Services.obs.notifyObservers(null, "update-check-start", null); + var url = this.getUpdateURL(force); if (!url || (!this.enabled && !force)) return; this._request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. createInstance(Ci.nsISupports); // This is here to let unit test code override XHR if (this._request.wrappedJSObject) {