|
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 an app update check even when system updates are |
|
7 * disabled to make sure we always check for app updates. |
|
8 */ |
|
9 |
|
10 "use strict"; |
|
11 |
|
12 const Cc = Components.classes; |
|
13 const Ci = Components.interfaces; |
|
14 const Cu = Components.utils; |
|
15 |
|
16 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
17 Cu.import("resource://gre/modules/Services.jsm"); |
|
18 Cu.import("resource://gre/modules/WebappsUpdater.jsm"); |
|
19 |
|
20 function debug(aStr) { |
|
21 //dump("--*-- WebappsUpdateTimer: " + aStr); |
|
22 } |
|
23 |
|
24 function WebappsUpdateTimer() { |
|
25 } |
|
26 |
|
27 WebappsUpdateTimer.prototype = { |
|
28 QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback]), |
|
29 classID: Components.ID("{637b0f77-2429-49a0-915f-abf5d0db8b9a}"), |
|
30 |
|
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 } |
|
42 |
|
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 } |
|
49 |
|
50 // This will trigger app updates in b2g/components/WebappsUpdater.jsm |
|
51 // that also takes care of notifying gaia. |
|
52 WebappsUpdater.updateApps(); |
|
53 }, |
|
54 |
|
55 observe: function(aSubject, aTopic, aData) { |
|
56 if (aTopic !== "network:offline-status-changed" || |
|
57 aData !== "online") { |
|
58 return; |
|
59 } |
|
60 |
|
61 debug("Network is online. Checking updates."); |
|
62 Services.obs.removeObserver(this, "network:offline-status-changed"); |
|
63 WebappsUpdater.updateApps(); |
|
64 } |
|
65 }; |
|
66 |
|
67 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsUpdateTimer]); |