Bug 912612 - Add a timer dedicated to apps update when system updates are disabled. r=etienne,vingtetun

This commit is contained in:
Fabrice Desré 2013-09-11 05:00:48 -07:00
parent 37ee2a9708
commit 7f0553997a
9 changed files with 179 additions and 57 deletions

View File

@ -523,6 +523,9 @@ pref("app.update.log", true);
pref("shutdown.watchdog.timeoutSecs", -1);
#endif
// Check daily for apps updates.
pref("webapps.update.interval", 86400);
// Extensions preferences
pref("extensions.update.enabled", false);
pref("extensions.getAddons.cache.enabled", false);

View File

@ -318,7 +318,7 @@ let AdbController = {
// Check if we have a remote debugging session going on. If so, we won't
// disable adb even if the screen is locked.
let isDebugging = Object.keys(DebuggerServer._connections).length > 0;
debug("isDebugging=" + isDebugging);
this.debug("isDebugging=" + isDebugging);
let enableAdb = this.remoteDebuggerEnabled &&
(!(this.lockEnabled && this.locked) || isDebugging);

View File

@ -1135,6 +1135,9 @@ window.addEventListener('ContentStart', function cr_onContentStart() {
});
window.addEventListener('ContentStart', function update_onContentStart() {
Cu.import('resource://gre/modules/WebappsUpdater.jsm');
WebappsUpdater.handleContentStart(shell);
let promptCc = Cc["@mozilla.org/updates/update-prompt;1"];
if (!promptCc) {
return;

View File

@ -73,3 +73,8 @@ contract @mozilla.org/network/protocol/about;1?what=certerror {920400b1-cf8f-476
# FilePicker.js
component {436ff8f9-0acc-4b11-8ec7-e293efba3141} FilePicker.js
contract @mozilla.org/filepicker;1 {436ff8f9-0acc-4b11-8ec7-e293efba3141}
# WebappsUpdateTimer.js
component {637b0f77-2429-49a0-915f-abf5d0db8b9a} WebappsUpdateTimer.js
contract @mozilla.org/b2g/webapps-update-timer;1 {637b0f77-2429-49a0-915f-abf5d0db8b9a}
category update-timer WebappsUpdateTimer @mozilla.org/b2g/webapps-update-timer;1,getService,background-update-timer,webapps.update.interval,86400

View File

@ -12,6 +12,7 @@ const Cr = Components.results;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/WebappsUpdater.jsm");
const VERBOSE = 1;
let log =
@ -449,61 +450,6 @@ UpdatePrompt.prototype = {
}
},
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() {
log("onUpdateCheckStart (" + this._checkingApps + ")");
// 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() {
if (aApp.downloadAvailable) {
appsToUpdate.push(aApp.manifestURL);
}
appsChecked += 1;
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) {
@ -517,7 +463,7 @@ UpdatePrompt.prototype = {
Services.obs.removeObserver(this, "quit-application");
break;
case "update-check-start":
this.onUpdateCheckStart();
WebappsUpdater.updateApps();
break;
}
},

View File

@ -0,0 +1,67 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* This component triggers an app update check even when system updates are
* disabled to make sure we always check for app updates.
*/
"use strict";
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/WebappsUpdater.jsm");
function debug(aStr) {
//dump("--*-- WebappsUpdateTimer: " + aStr);
}
function WebappsUpdateTimer() {
}
WebappsUpdateTimer.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback]),
classID: Components.ID("{637b0f77-2429-49a0-915f-abf5d0db8b9a}"),
notify: function(aTimer) {
try {
// We want to check app updates if system updates are disabled or
// if they update frecency is not daily.
if (Services.prefs.getBoolPref("app.update.enabled") === true &&
Services.prefs.getIntPref("app.update.interval") === 86400) {
return;
}
} catch(e) {
// That should never happen..
}
// If we are offline, wait to be online to start the update check.
if (Services.io.offline) {
debug("Network is offline. Setting up an offline status observer.");
Services.obs.addObserver(this, "network:offline-status-changed", false);
return;
}
// This will trigger app updates in b2g/components/WebappsUpdater.jsm
// that also takes care of notifying gaia.
WebappsUpdater.updateApps();
},
observe: function(aSubject, aTopic, aData) {
if (aTopic !== "network:offline-status-changed" ||
aData !== "online") {
return;
}
debug("Network is online. Checking updates.");
Services.obs.removeObserver(this, "network:offline-status-changed");
WebappsUpdater.updateApps();
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsUpdateTimer]);

View File

@ -0,0 +1,95 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
this.EXPORTED_SYMBOLS = ["WebappsUpdater"];
const Cc = Components.classes;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
this.WebappsUpdater = {
_checkingApps: false,
_pendingEvents: [],
handleContentStart: function(aShell) {
let content = aShell.contentBrowser.contentWindow;
this._pendingEvents.forEach(aShell.sendChromeEvent);
this._pendingEvents.length = 0;
},
sendChromeEvent: function(aType, aDetail) {
let detail = aDetail || {};
detail.type = aType;
let browser = Services.wm.getMostRecentWindow("navigator:browser");
if (!browser) {
this._pendingEvents.push(detail);
dump("Warning: Couldn't send update event " + aType +
": no content browser. Will send again when content becomes available.");
return false;
}
browser.shell.sendChromeEvent(detail);
return true;
},
_appsUpdated: function(aApps) {
dump("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.
updateApps: function() {
dump("updateApps (" + this._checkingApps + ")");
// 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() {
if (aApp.downloadAvailable) {
appsToUpdate.push(aApp.manifestURL);
}
appsChecked += 1;
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([]);
}
}
};

View File

@ -25,6 +25,7 @@ EXTRA_COMPONENTS += [
'ProcessGlobal.js',
'SmsProtocolHandler.js',
'TelProtocolHandler.js',
'WebappsUpdateTimer.js',
'YoutubeProtocolHandler.js',
]
@ -44,4 +45,5 @@ EXTRA_JS_MODULES += [
'Keyboard.jsm',
'SignInToWebsite.jsm',
'TelURIParser.jsm',
'WebappsUpdater.jsm',
]

View File

@ -733,6 +733,7 @@ bin/components/@DLL_PREFIX@nkgnomevfs@DLL_SUFFIX@
#ifdef MOZ_UPDATER
@BINPATH@/components/UpdatePrompt.js
#endif
@BINPATH@/components/WebappsUpdateTimer.js
@BINPATH@/components/MozKeyboard.js
@BINPATH@/components/DirectoryProvider.js
@BINPATH@/components/ActivitiesGlue.js