Bug 830463 - Download/update notification is showing up late on a weak connection in some cases. r=fabrice, a=lsblakk

This commit is contained in:
Julien Wajsberg 2013-02-11 09:38:51 +01:00
Родитель 0ce76f916d
Коммит 1b5b9e173e
1 изменённых файлов: 32 добавлений и 9 удалений

Просмотреть файл

@ -1171,6 +1171,9 @@ this.DOMApplicationRegistry = {
? updateSvc.scheduleCustomProfileUpdate(appcacheURI, docURI, aProfileDir)
: updateSvc.scheduleAppUpdate(appcacheURI, docURI, aApp.localId, false);
// initialize the progress to 0 right now
aApp.progress = 0;
// We save the download details for potential further usage like cancelling
// it.
let download = {
@ -2038,6 +2041,13 @@ this.DOMApplicationRegistry = {
AppDownloadManager.remove(aApp.manifestURL);
}
function sendProgressEvent() {
self.broadcastMessage("Webapps:PackageEvent",
{ type: "progress",
manifestURL: aApp.manifestURL,
app: app });
}
function download() {
debug("About to download " + aManifest.fullPackagePath());
@ -2058,6 +2068,7 @@ this.DOMApplicationRegistry = {
);
let lastProgressTime = 0;
requestChannel.notificationCallbacks = {
QueryInterface: function notifQI(aIID) {
if (aIID.equals(Ci.nsISupports) ||
@ -2076,10 +2087,7 @@ this.DOMApplicationRegistry = {
let now = Date.now();
if (now - lastProgressTime > MIN_PROGRESS_EVENT_DELAY) {
debug("onProgress: " + aProgress + "/" + aProgressMax);
self.broadcastMessage("Webapps:PackageEvent",
{ type: "progress",
manifestURL: aApp.manifestURL,
app: app });
sendProgressEvent();
lastProgressTime = now;
self._saveApps();
}
@ -2105,6 +2113,9 @@ this.DOMApplicationRegistry = {
// installed apps should morph to 'updating'.
app.installState = aIsUpdate ? "updating" : "pending";
// initialize the progress to 0 right now
app.progress = 0;
// Staging the zip in TmpD until all the checks are done.
let zipFile = FileUtils.getFile("TmpD",
["webapps", id, "application.zip"], true);
@ -2315,6 +2326,9 @@ this.DOMApplicationRegistry = {
});
requestChannel.asyncOpen(listener, null);
// send a first progress event to correctly set the DOM object's properties
sendProgressEvent();
};
let deviceStorage = Services.wm.getMostRecentWindow("navigator:browser")
@ -2799,18 +2813,30 @@ let AppcacheObserver = function(aApp) {
this.app = aApp;
this.startStatus = aApp.installState;
this.lastProgressTime = 0;
// send a first progress event to correctly set the DOM object's properties
this._sendProgressEvent();
};
AppcacheObserver.prototype = {
// nsIOfflineCacheUpdateObserver implementation
_sendProgressEvent: function() {
let app = this.app;
DOMApplicationRegistry.broadcastMessage("Webapps:OfflineCache",
{ manifest: app.manifestURL,
installState: app.installState,
progress: app.progress });
},
updateStateChanged: function appObs_Update(aUpdate, aState) {
let mustSave = false;
let app = this.app;
debug("Offline cache state change for " + app.origin + " : " + aState);
var self = this;
let setStatus = function appObs_setStatus(aStatus, aProgress) {
debug("Offlinecache setStatus to " + aStatus + " for " + app.origin);
debug("Offlinecache setStatus to " + aStatus + " with progress " +
aProgress + " for " + app.origin);
mustSave = (app.installState != aStatus);
app.installState = aStatus;
app.progress = aProgress;
@ -2818,10 +2844,7 @@ AppcacheObserver.prototype = {
app.downloading = false;
app.downloadAvailable = false;
}
DOMApplicationRegistry.broadcastMessage("Webapps:OfflineCache",
{ manifest: app.manifestURL,
installState: app.installState,
progress: app.progress });
self._sendProgressEvent();
}
let setError = function appObs_setError(aError) {