Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/downloader.js

Issue 29715555: Issue 6447 - Switch to Harmony modules in lib/* (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created March 6, 2018, 7:42 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 /** 20 /**
21 * @fileOverview Downloads a set of URLs in regular time intervals. 21 * @fileOverview Downloads a set of URLs in regular time intervals.
22 */ 22 */
23 23
24 const {Utils} = require("utils"); 24 import {Utils} from "utils";
25 25
26 const MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; 26 export const MILLIS_IN_SECOND = 1000;
27 const MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; 27 export const MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND;
28 const MILLIS_IN_HOUR = exports.MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE; 28 export const MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE;
29 const MILLIS_IN_DAY = exports.MILLIS_IN_DAY = 24 * MILLIS_IN_HOUR; 29 export const MILLIS_IN_DAY = 24 * MILLIS_IN_HOUR;
30 30
31 let Downloader =
32 /** 31 /**
33 * Creates a new downloader instance. 32 * Creates a new downloader instance.
34 * @param {Function} dataSource 33 * @param {Function} dataSource
35 * Function that will yield downloadable objects on each check 34 * Function that will yield downloadable objects on each check
36 * @param {number} initialDelay 35 * @param {number} initialDelay
37 * Number of milliseconds to wait before the first check 36 * Number of milliseconds to wait before the first check
38 * @param {number} checkInterval 37 * @param {number} checkInterval
39 * Interval between the checks 38 * Interval between the checks
40 * @constructor 39 * @constructor
41 */ 40 */
42 exports.Downloader = function(dataSource, initialDelay, checkInterval) 41 export function Downloader(dataSource, initialDelay, checkInterval)
43 { 42 {
44 this.dataSource = dataSource; 43 this.dataSource = dataSource;
45 this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); 44 this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
46 this._timer.initWithCallback(() => 45 this._timer.initWithCallback(() =>
47 { 46 {
48 this._timer.delay = checkInterval; 47 this._timer.delay = checkInterval;
49 this._doCheck(); 48 this._doCheck();
50 }, initialDelay, Ci.nsITimer.TYPE_REPEATING_SLACK); 49 }, initialDelay, Ci.nsITimer.TYPE_REPEATING_SLACK);
51 this._downloading = Object.create(null); 50 this._downloading = Object.create(null);
52 }; 51 }
52
53 Downloader.prototype = 53 Downloader.prototype =
54 { 54 {
55 /** 55 /**
56 * Timer triggering the downloads. 56 * Timer triggering the downloads.
57 * @type {nsITimer} 57 * @type {nsITimer}
58 */ 58 */
59 _timer: null, 59 _timer: null,
60 60
61 /** 61 /**
62 * Map containing the URLs of objects currently being downloaded as its keys. 62 * Map containing the URLs of objects currently being downloaded as its keys.
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 let now = Date.now(); 357 let now = Date.now();
358 return [now + soft, now + hard]; 358 return [now + soft, now + hard];
359 } 359 }
360 }; 360 };
361 361
362 /** 362 /**
363 * An object that can be downloaded by the downloadable 363 * An object that can be downloaded by the downloadable
364 * @param {string} url URL that has to be requested for the object 364 * @param {string} url URL that has to be requested for the object
365 * @constructor 365 * @constructor
366 */ 366 */
367 let Downloadable = exports.Downloadable = function Downloadable(url) 367 export function Downloadable(url)
368 { 368 {
369 this.url = url; 369 this.url = url;
370 }; 370 }
371
371 Downloadable.prototype = 372 Downloadable.prototype =
372 { 373 {
373 /** 374 /**
374 * URL that has to be requested for the object. 375 * URL that has to be requested for the object.
375 * @type {string} 376 * @type {string}
376 */ 377 */
377 url: null, 378 url: null,
378 379
379 /** 380 /**
380 * URL that the download was redirected to if any. 381 * URL that the download was redirected to if any.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 * @type {number} 413 * @type {number}
413 */ 414 */
414 hardExpiration: 0, 415 hardExpiration: 0,
415 416
416 /** 417 /**
417 * Number indicating how often the object was downloaded. 418 * Number indicating how often the object was downloaded.
418 * @type {number} 419 * @type {number}
419 */ 420 */
420 downloadCount: 0 421 downloadCount: 0
421 }; 422 };
OLDNEW
« lib/common.js ('K') | « lib/coreUtils.js ('k') | lib/elemHide.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld