Index: lib/downloader.js |
=================================================================== |
--- a/lib/downloader.js |
+++ b/lib/downloader.js |
@@ -63,17 +63,17 @@ Downloader.prototype = |
*/ |
dataSource: null, |
/** |
* Maximal time interval that the checks can be left out until the soft |
* expiration interval increases. |
* @type Integer |
*/ |
- maxAbsenseInterval: 1 * MILLIS_IN_DAY, |
+ maxAbsenceInterval: 1 * MILLIS_IN_DAY, |
/** |
* Minimal time interval before retrying a download after an error. |
* @type Integer |
*/ |
minRetryInterval: 1 * MILLIS_IN_DAY, |
/** |
@@ -117,17 +117,17 @@ Downloader.prototype = |
/** |
* Checks whether anything needs downloading. |
*/ |
_doCheck: function() |
{ |
let now = Date.now(); |
for each (let downloadable in this.dataSource()) |
{ |
- if (downloadable.lastCheck && now - downloadable.lastCheck > this.maxAbsenseInterval) |
+ if (downloadable.lastCheck && now - downloadable.lastCheck > this.maxAbsenceInterval) |
{ |
// No checks for a long time interval - user must have been offline, e.g. |
// during a weekend. Increase soft expiration to prevent load peaks on the |
// server. |
downloadable.softExpiration += now - downloadable.lastCheck; |
} |
downloadable.lastCheck = now; |
@@ -166,20 +166,19 @@ Downloader.prototype = |
* Checks whether an address is currently being downloaded. |
*/ |
isDownloading: function(/**String*/ url) /**Boolean*/ |
{ |
return url in this._downloading; |
}, |
/** |
- * Starts a download. |
- * @param {Downloadable} url the object to be downloaded |
+ * Starts downloading for an object. |
*/ |
- download: function(downloadable) |
+ download: function(/**Downloadable*/ downloadable) |
{ |
// Make sure to detach download from the current execution context |
Utils.runAsync(this._download.bind(this, downloadable, 0)); |
}, |
/** |
* Generates the real download URL for an object by appending various |
* parameters. |
@@ -199,59 +198,59 @@ Downloader.prototype = |
"&platform=" + encodeURIComponent(platform) + |
"&platformVersion=" + encodeURIComponent(platformVersion) + |
"&lastVersion=" + encodeURIComponent(downloadable.lastVersion); |
return url; |
}, |
_download: function(downloadable, redirects) |
{ |
- if (downloadable.url in this._downloading) |
+ if (this.isDownloading(downloadable.url)) |
return; |
- let downloadURL = this.getDownloadUrl(downloadable); |
+ let downloadUrl = this.getDownloadUrl(downloadable); |
let request = null; |
let errorCallback = function errorCallback(error) |
{ |
let channelStatus = -1; |
try |
{ |
channelStatus = request.channel.status; |
} catch (e) {} |
let responseStatus = request.status; |
Cu.reportError("Adblock Plus: Downloading URL " + downloadable.url + " failed (" + error + ")\n" + |
- "Download address: " + downloadURL + "\n" + |
+ "Download address: " + downloadUrl + "\n" + |
"Channel status: " + channelStatus + "\n" + |
"Server response: " + responseStatus); |
if (this.onDownloadError) |
{ |
// Allow one extra redirect if the error handler gives us a redirect URL |
let redirectCallback = null; |
if (redirects <= this.maxRedirects) |
{ |
redirectCallback = function redirectCallback(url) |
{ |
downloadable.redirectURL = url; |
this._download(downloadable, redirects + 1); |
}.bind(this); |
} |
- this.onDownloadError(downloadable, downloadURL, error, channelStatus, responseStatus, redirectCallback); |
+ this.onDownloadError(downloadable, downloadUrl, error, channelStatus, responseStatus, redirectCallback); |
} |
}.bind(this); |
try |
{ |
request = new XMLHttpRequest(); |
request.mozBackgroundRequest = true; |
- request.open("GET", downloadURL); |
+ request.open("GET", downloadUrl); |
} |
catch (e) |
{ |
errorCallback("synchronize_invalid_url"); |
return; |
} |
try { |
@@ -299,20 +298,21 @@ Downloader.prototype = |
else |
{ |
downloadable.redirectURL = url; |
this._download(downloadable, redirects + 1); |
} |
}.bind(this)); |
}.bind(this), false); |
+ request.send(null); |
+ |
this._downloading[downloadable.url] = true; |
if (this.onDownloadStarted) |
this.onDownloadStarted(downloadable); |
- request.send(null); |
}, |
/** |
* Produces a soft and a hard expiration interval for a given supplied |
* expiration interval. |
* @return {Array} soft and hard expiration interval |
*/ |
processExpirationInterval: function(/**Integer*/ interval) |