From 3b7eea02114faa2820e69b04378bb23cfe407afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabrice=20Desr=C3=A9?= Date: Wed, 30 Jan 2013 22:50:28 -0800 Subject: [PATCH] Bug 834371 - Applying a packaged app update and immediately losing power to the phone - app update is lost r=julienw --- dom/apps/src/Webapps.jsm | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/dom/apps/src/Webapps.jsm b/dom/apps/src/Webapps.jsm index e71bd2b9562f..5417902c8639 100644 --- a/dom/apps/src/Webapps.jsm +++ b/dom/apps/src/Webapps.jsm @@ -110,40 +110,48 @@ this.DOMApplicationRegistry = { this.webapps = aData; let appDir = FileUtils.getDir(DIRECTORY_NAME, ["webapps"], false); for (let id in this.webapps) { + let app = this.webapps[id]; - this.webapps[id].id = id; + app.id = id; // Make sure we have a localId - if (this.webapps[id].localId === undefined) { - this.webapps[id].localId = this._nextLocalId(); + if (app.localId === undefined) { + app.localId = this._nextLocalId(); } - if (this.webapps[id].basePath === undefined) { - this.webapps[id].basePath = appDir.path; + if (app.basePath === undefined) { + app.basePath = appDir.path; } // Default to removable apps. - if (this.webapps[id].removable === undefined) { - this.webapps[id].removable = true; + if (app.removable === undefined) { + app.removable = true; } // Default to a non privileged status. - if (this.webapps[id].appStatus === undefined) { - this.webapps[id].appStatus = Ci.nsIPrincipal.APP_STATUS_INSTALLED; + if (app.appStatus === undefined) { + app.appStatus = Ci.nsIPrincipal.APP_STATUS_INSTALLED; } // Default to NO_APP_ID and not in browser. - if (this.webapps[id].installerAppId === undefined) { - this.webapps[id].installerAppId = Ci.nsIScriptSecurityManager.NO_APP_ID; + if (app.installerAppId === undefined) { + app.installerAppId = Ci.nsIScriptSecurityManager.NO_APP_ID; } - if (this.webapps[id].installerIsBrowser === undefined) { - this.webapps[id].installerIsBrowser = false; + if (app.installerIsBrowser === undefined) { + app.installerIsBrowser = false; } - // Default installState to "installed". - if (this.webapps[id].installState === undefined) { - this.webapps[id].installState = "installed"; + // Default installState to "installed", and reset if we shutdown + // during an update. + if (app.installState === undefined || + app.installState === "updating") { + app.installState = "installed"; } + + // At startup we can't be downloading, and the $TMP directory + // will be empty so we can't just apply a staged update. + app.downloading = false; + app.readyToApplyDownload = false; }; } aNext();