1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 * This component triggers an app update check even when system updates are
7 * disabled to make sure we always check for app updates.
12 const Cc = Components.classes;
13 const Ci = Components.interfaces;
14 const Cu = Components.utils;
16 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
17 Cu.import("resource://gre/modules/Services.jsm");
18 Cu.import("resource://gre/modules/WebappsUpdater.jsm");
20 function debug(aStr) {
21 //dump("--*-- WebappsUpdateTimer: " + aStr);
24 function WebappsUpdateTimer() {
27 WebappsUpdateTimer.prototype = {
28 QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback]),
29 classID: Components.ID("{637b0f77-2429-49a0-915f-abf5d0db8b9a}"),
31 notify: function(aTimer) {
33 // We want to check app updates if system updates are disabled or
34 // if they update frecency is not daily.
35 if (Services.prefs.getBoolPref("app.update.enabled") === true &&
36 Services.prefs.getIntPref("app.update.interval") === 86400) {
40 // That should never happen..
43 // If we are offline, wait to be online to start the update check.
44 if (Services.io.offline) {
45 debug("Network is offline. Setting up an offline status observer.");
46 Services.obs.addObserver(this, "network:offline-status-changed", false);
50 // This will trigger app updates in b2g/components/WebappsUpdater.jsm
51 // that also takes care of notifying gaia.
52 WebappsUpdater.updateApps();
55 observe: function(aSubject, aTopic, aData) {
56 if (aTopic !== "network:offline-status-changed" ||
61 debug("Network is online. Checking updates.");
62 Services.obs.removeObserver(this, "network:offline-status-changed");
63 WebappsUpdater.updateApps();
67 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsUpdateTimer]);