Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
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 a periodic webapp update check.
7 */
9 "use strict";
11 const Cc = Components.classes;
12 const Ci = Components.interfaces;
13 const Cu = Components.utils;
15 Cu.import("resource://gre/modules/Services.jsm");
16 Cu.import("resource://gre/modules/WebappManager.jsm");
17 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
19 function log(message) {
20 // We use *dump* instead of Services.console.logStringMessage so the messages
21 // have the INFO level of severity instead of the ERROR level. And we don't
22 // append a newline character to the end of the message because *dump* spills
23 // into the Android native logging system, which strips newlines from messages
24 // and breaks messages into lines automatically at display time (i.e. logcat).
25 dump(message);
26 }
28 function WebappsUpdateTimer() {}
30 WebappsUpdateTimer.prototype = {
31 QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback,
32 Ci.nsISupportsWeakReference]),
33 classID: Components.ID("{8f7002cb-e959-4f0a-a2e8-563232564385}"),
35 notify: function(aTimer) {
36 if (Services.prefs.getIntPref("browser.webapps.checkForUpdates") == 0) {
37 // Do nothing, because updates are disabled.
38 log("Webapps update timer invoked in webapp process; ignoring.");
39 return;
40 }
42 // If we are offline, wait to be online to start the update check.
43 if (Services.io.offline) {
44 log("network offline for webapp update check; waiting");
45 Services.obs.addObserver(this, "network:offline-status-changed", true);
46 return;
47 }
49 log("periodic check for webapp updates");
50 WebappManager.checkForUpdates();
51 },
53 observe: function(aSubject, aTopic, aData) {
54 if (aTopic !== "network:offline-status-changed" || aData !== "online") {
55 return;
56 }
58 log("network back online for webapp update check; commencing");
59 // TODO: observe pref to do this only on wifi.
60 Services.obs.removeObserver(this, "network:offline-status-changed");
61 WebappManager.checkForUpdates();
62 }
63 };
65 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsUpdateTimer]);