michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * This component triggers a periodic webapp update check. michael@0: */ michael@0: michael@0: "use strict"; michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/WebappManager.jsm"); michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: function log(message) { michael@0: // We use *dump* instead of Services.console.logStringMessage so the messages michael@0: // have the INFO level of severity instead of the ERROR level. And we don't michael@0: // append a newline character to the end of the message because *dump* spills michael@0: // into the Android native logging system, which strips newlines from messages michael@0: // and breaks messages into lines automatically at display time (i.e. logcat). michael@0: dump(message); michael@0: } michael@0: michael@0: function WebappsUpdateTimer() {} michael@0: michael@0: WebappsUpdateTimer.prototype = { michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback, michael@0: Ci.nsISupportsWeakReference]), michael@0: classID: Components.ID("{8f7002cb-e959-4f0a-a2e8-563232564385}"), michael@0: michael@0: notify: function(aTimer) { michael@0: if (Services.prefs.getIntPref("browser.webapps.checkForUpdates") == 0) { michael@0: // Do nothing, because updates are disabled. michael@0: log("Webapps update timer invoked in webapp process; ignoring."); michael@0: return; michael@0: } michael@0: michael@0: // If we are offline, wait to be online to start the update check. michael@0: if (Services.io.offline) { michael@0: log("network offline for webapp update check; waiting"); michael@0: Services.obs.addObserver(this, "network:offline-status-changed", true); michael@0: return; michael@0: } michael@0: michael@0: log("periodic check for webapp updates"); michael@0: WebappManager.checkForUpdates(); michael@0: }, michael@0: michael@0: observe: function(aSubject, aTopic, aData) { michael@0: if (aTopic !== "network:offline-status-changed" || aData !== "online") { michael@0: return; michael@0: } michael@0: michael@0: log("network back online for webapp update check; commencing"); michael@0: // TODO: observe pref to do this only on wifi. michael@0: Services.obs.removeObserver(this, "network:offline-status-changed"); michael@0: WebappManager.checkForUpdates(); michael@0: } michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsUpdateTimer]);