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 an app update check even when system updates are michael@0: * disabled to make sure we always check for app updates. 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/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/WebappsUpdater.jsm"); michael@0: michael@0: function debug(aStr) { michael@0: //dump("--*-- WebappsUpdateTimer: " + aStr); michael@0: } michael@0: michael@0: function WebappsUpdateTimer() { michael@0: } michael@0: michael@0: WebappsUpdateTimer.prototype = { michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback]), michael@0: classID: Components.ID("{637b0f77-2429-49a0-915f-abf5d0db8b9a}"), michael@0: michael@0: notify: function(aTimer) { michael@0: try { michael@0: // We want to check app updates if system updates are disabled or michael@0: // if they update frecency is not daily. michael@0: if (Services.prefs.getBoolPref("app.update.enabled") === true && michael@0: Services.prefs.getIntPref("app.update.interval") === 86400) { michael@0: return; michael@0: } michael@0: } catch(e) { michael@0: // That should never happen.. 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: debug("Network is offline. Setting up an offline status observer."); michael@0: Services.obs.addObserver(this, "network:offline-status-changed", false); michael@0: return; michael@0: } michael@0: michael@0: // This will trigger app updates in b2g/components/WebappsUpdater.jsm michael@0: // that also takes care of notifying gaia. michael@0: WebappsUpdater.updateApps(); michael@0: }, michael@0: michael@0: observe: function(aSubject, aTopic, aData) { michael@0: if (aTopic !== "network:offline-status-changed" || michael@0: aData !== "online") { michael@0: return; michael@0: } michael@0: michael@0: debug("Network is online. Checking updates."); michael@0: Services.obs.removeObserver(this, "network:offline-status-changed"); michael@0: WebappsUpdater.updateApps(); michael@0: } michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsUpdateTimer]);