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/. */
7 this.EXPORTED_SYMBOLS = ['RequestSyncTask'];
10 //dump('DEBUG RequestSyncTask: ' + s + '\n');
13 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
15 Cu.import('resource://gre/modules/XPCOMUtils.jsm');
17 this.RequestSyncTask = function(aManager, aWindow, aApp, aData) {
20 this._manager = aManager;
21 this._window = aWindow;
24 let keys = [ 'task', 'lastSync', 'oneShot', 'minInterval', 'wakeUpPage',
25 'wifiOnly', 'data', 'state', 'overwrittenMinInterval' ];
26 for (let i = 0; i < keys.length; ++i) {
27 if (!(keys[i] in aData)) {
28 dump("ERROR - RequestSyncTask must receive a fully app object: " + keys[i] + " missing.");
32 this["_" + keys[i]] = aData[keys[i]];
36 this.RequestSyncTask.prototype = {
37 classDescription: 'RequestSyncTask XPCOM Component',
38 classID: Components.ID('{a1e1c9c6-ce42-49d4-b8b4-fbd686d8fdd9}'),
39 contractID: '@mozilla.org/dom/request-sync-manager;1',
40 QueryInterface: XPCOMUtils.generateQI([]),
50 get overwrittenMinInterval() {
51 return this._overwrittenMinInterval;
59 return this._lastSync;
63 return this._wakeUpPage;
71 return this._minInterval;
75 return this._wifiOnly;
82 setPolicy: function(aState, aOverwrittenMinInterval) {
86 return new this._window.Promise(function(aResolve, aReject) {
87 let p = self._manager.setPolicy(self._task, self._app.origin,
88 self._app.manifestURL,
89 self._app.isInBrowserElement,
91 aOverwrittenMinInterval);
93 // Set the new value only when the promise is resolved.
96 self._overwrittenMinInterval = aOverwrittenMinInterval;
104 return this._manager.runTask(this._task, this._app.origin,
105 this._app.manifestURL,
106 this._app.isInBrowserElement);