|
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/. */ |
|
4 |
|
5 /** |
|
6 * This component triggers a periodic webapp update check. |
|
7 */ |
|
8 |
|
9 "use strict"; |
|
10 |
|
11 const Cc = Components.classes; |
|
12 const Ci = Components.interfaces; |
|
13 const Cu = Components.utils; |
|
14 |
|
15 Cu.import("resource://gre/modules/Services.jsm"); |
|
16 Cu.import("resource://gre/modules/WebappManager.jsm"); |
|
17 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
18 |
|
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 } |
|
27 |
|
28 function WebappsUpdateTimer() {} |
|
29 |
|
30 WebappsUpdateTimer.prototype = { |
|
31 QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback, |
|
32 Ci.nsISupportsWeakReference]), |
|
33 classID: Components.ID("{8f7002cb-e959-4f0a-a2e8-563232564385}"), |
|
34 |
|
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 } |
|
41 |
|
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 } |
|
48 |
|
49 log("periodic check for webapp updates"); |
|
50 WebappManager.checkForUpdates(); |
|
51 }, |
|
52 |
|
53 observe: function(aSubject, aTopic, aData) { |
|
54 if (aTopic !== "network:offline-status-changed" || aData !== "online") { |
|
55 return; |
|
56 } |
|
57 |
|
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 }; |
|
64 |
|
65 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsUpdateTimer]); |