Bug 801742: Pass updater errors and status to Gaia in B2G. r=fabrice

--HG--
extra : rebase_source : 1cb52325daa904a8b0fad9f1bb57bdc058188e1c
This commit is contained in:
Marshall Culpepper 2012-10-16 14:15:37 -05:00
parent 3f36060b9d
commit 08e2eba20e

View File

@ -26,16 +26,24 @@ const SELF_DESTRUCT_TIMEOUT =
Services.prefs.getIntPref("b2g.update.self-destruct-timeout");
const APPLY_IDLE_TIMEOUT_SECONDS = APPLY_IDLE_TIMEOUT / 1000;
const NETWORK_ERROR_OFFLINE = 111;
XPCOMUtils.defineLazyServiceGetter(Services, "aus",
"@mozilla.org/updates/update-service;1",
"nsIApplicationUpdateService");
XPCOMUtils.defineLazyServiceGetter(Services, "um",
"@mozilla.org/updates/update-manager;1",
"nsIUpdateManager");
XPCOMUtils.defineLazyServiceGetter(Services, "idle",
"@mozilla.org/widget/idleservice;1",
"nsIIdleService");
XPCOMUtils.defineLazyServiceGetter(Services, "settings",
"@mozilla.org/settingsService;1",
"nsISettingsService");
function UpdatePrompt() {
this.wrappedJSObject = this;
}
@ -43,6 +51,7 @@ function UpdatePrompt() {
UpdatePrompt.prototype = {
classID: Components.ID("{88b3eb21-d072-4e3b-886d-f89d8c49fe59}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdatePrompt,
Ci.nsIUpdateCheckListener,
Ci.nsIRequestObserver,
Ci.nsIProgressEventSink,
Ci.nsIObserver]),
@ -88,14 +97,52 @@ UpdatePrompt.prototype = {
},
showUpdateError: function UP_showUpdateError(aUpdate) {
if (aUpdate.state == "failed") {
log("Failed to download update, errorCode: " + aUpdate.errorCode);
}
log("Update error, state: " + aUpdate.state + ", errorCode: " +
aUpdate.errorCode);
this.sendUpdateEvent("update-error", aUpdate);
this.setUpdateStatus(aUpdate.statusText);
},
showUpdateHistory: function UP_showUpdateHistory(aParent) { },
showUpdateInstalled: function UP_showUpdateInstalled() { },
// nsIUpdateCheckListener
onCheckComplete: function UP_onCheckComplete(request, updates, updateCount) {
if (Services.um.activeUpdate) {
return;
}
if (updateCount == 0) {
this.setUpdateStatus("no-updates");
return;
}
let update = Services.aus.selectUpdate(updates, updateCount);
if (!update) {
this.setUpdateStatus("already-latest-version");
return;
}
this.setUpdateStatus("check-complete");
this.showUpdateAvailable(update);
},
onError: function UP_onError(request, update) {
if (update.errorCode == NETWORK_ERROR_OFFLINE) {
this.setUpdateStatus("retry-when-online");
}
Services.aus.QueryInterface(Ci.nsIUpdateCheckListener);
Services.aus.onError(request, update);
},
onProgress: function UP_onProgress(request, position, totalSize) {
Services.aus.QueryInterface(Ci.nsIUpdateCheckListener);
Services.aus.onProgress(request, position, totalSize);
},
// Custom functions
waitForIdle: function UP_waitForIdle() {
@ -108,6 +155,13 @@ UpdatePrompt.prototype = {
Services.obs.addObserver(this, "quit-application", false);
},
setUpdateStatus: function UP_setUpdateStatus(aStatus) {
log("Setting gecko.updateStatus: " + aStatus);
let lock = Services.settings.createLock();
lock.set("gecko.updateStatus", aStatus, null);
},
showApplyPrompt: function UP_showApplyPrompt(aUpdate) {
if (!this.sendUpdateEvent("update-prompt-apply", aUpdate)) {
log("Unable to prompt, forcing restart");
@ -123,22 +177,26 @@ UpdatePrompt.prototype = {
sendUpdateEvent: function UP_sendUpdateEvent(aType, aUpdate) {
let detail = {
displayVersion: aUpdate.displayVersion,
detailsURL: aUpdate.detailsURL
detailsURL: aUpdate.detailsURL,
statusText: aUpdate.statusText,
state: aUpdate.state,
errorCode: aUpdate.errorCode,
isOSUpdate: aUpdate.isOSUpdate
};
let patch = aUpdate.selectedPatch;
if (!patch) {
if (!patch && aUpdate.patchCount > 0) {
// For now we just check the first patch to get size information if a
// patch hasn't been selected yet.
if (aUpdate.patchCount == 0) {
log("Warning: no patches available in update");
return false;
}
patch = aUpdate.getPatchAt(0);
}
detail.size = patch.size;
detail.updateType = patch.type;
if (patch) {
detail.size = patch.size;
detail.updateType = patch.type;
} else {
log("Warning: no patches available in update");
}
this._update = aUpdate;
return this.sendChromeEvent(aType, detail);
@ -254,9 +312,7 @@ UpdatePrompt.prototype = {
let checker = Cc["@mozilla.org/updates/update-checker;1"]
.createInstance(Ci.nsIUpdateChecker);
Services.aus.QueryInterface(Ci.nsIUpdateCheckListener);
checker.checkForUpdates(Services.aus, true);
checker.checkForUpdates(this, true);
},
handleEvent: function UP_handleEvent(evt) {