b2g/components/WebappsUpdateTimer.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial