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

Unified Diff: lib/downloader.js

Issue 29336735: Issue 394 - hit statistics tool data collection (core) (Closed)
Patch Set: Include modules conditionally update Downloader to accept callback for download event Created March 17, 2016, 6:09 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/filterListener.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/downloader.js
===================================================================
--- a/lib/downloader.js
+++ b/lib/downloader.js
@@ -31,11 +31,13 @@
* @param {Function} dataSource Function that will yield downloadable objects on each check
* @param {Integer} initialDelay Number of milliseconds to wait before the first check
* @param {Integer} checkInterval Interval between the checks
+ * @param {function} downloadCallback optional function that's being called when something needs to be downloaded
* @constructor
*/
-let Downloader = exports.Downloader = function Downloader(dataSource, initialDelay, checkInterval)
+let Downloader = exports.Downloader = function Downloader(dataSource, initialDelay, checkInterval, downloadCallback)
saroyanm 2016/03/18 18:24:48 Maybe this changes will be reverted if you agree w
Wladimir Palant 2016/03/23 11:06:01 You are still duplicating quite a bit of the logic
saroyanm 2016/04/06 15:12:49 Thanks for detailed explanation, Done.
{
this.dataSource = dataSource;
+ this.downloadCallback = downloadCallback || this._download;
this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
this._timer.initWithCallback(function()
{
@@ -64,6 +66,12 @@
dataSource: null,
/**
+ * Function that's being called when something needs to be downloaded.
+ * @type Function
+ */
+ downloadCallback: null,
+
+ /**
* Maximal time interval that the checks can be left out until the soft
* expiration interval increases.
* @type Integer
@@ -150,7 +158,7 @@
if (downloadable.lastError && now - downloadable.lastError < this.minRetryInterval)
continue;
- this._download(downloadable, 0);
+ this.downloadCallback(downloadable, 0);
}
},
« no previous file with comments | « no previous file | lib/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld