b2g/components/WebappsUpdateTimer.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     5 /**
     6  * This component triggers an app update check even when system updates are
     7  * disabled to make sure we always check for app updates.
     8  */
    10 "use strict";
    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);
    22 }
    24 function WebappsUpdateTimer() {
    25 }
    27 WebappsUpdateTimer.prototype = {
    28   QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback]),
    29   classID: Components.ID("{637b0f77-2429-49a0-915f-abf5d0db8b9a}"),
    31   notify: function(aTimer) {
    32     try {
    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) {
    37         return;
    38       }
    39     } catch(e) {
    40       // That should never happen..
    41     }
    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);
    47       return;
    48     }
    50     // This will trigger app updates in b2g/components/WebappsUpdater.jsm
    51     // that also takes care of notifying gaia.
    52     WebappsUpdater.updateApps();
    53   },
    55   observe: function(aSubject, aTopic, aData) {
    56     if (aTopic !== "network:offline-status-changed" ||
    57         aData !== "online") {
    58       return;
    59     }
    61     debug("Network is online. Checking updates.");
    62     Services.obs.removeObserver(this, "network:offline-status-changed");
    63     WebappsUpdater.updateApps();
    64   }
    65 };
    67 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsUpdateTimer]);

mercurial