[PALEMOON] Bug 1115379 - Streamline DownloadsViewItemController construction and remove now unneeded identifiers

This commit is contained in:
janekptacijarabaci 2018-07-29 09:59:35 +02:00 • committed by Roy Tam
commit a8622a0a10
2 changed files with 29 additions and 39 deletions

View file

@ -647,12 +647,8 @@ XPCOMUtils.defineLazyGetter(DownloadsCommon, "useJSTransfer", function () {
function DownloadsDataCtor(aPrivate) {
this._isPrivate = aPrivate;
// This Object contains all the available DownloadsDataItem objects, indexed by
// their globally unique identifier. The identifiers of downloads that have
// been removed from the Download Manager data are still present, however the
// associated objects are replaced with the value "null". This is required to
// prevent race conditions when populating the list asynchronously.
this.dataItems = {};
// Contains all the available DownloadsDataItem objects.
this.dataItems = new Set();
// Array of view objects that should be notified when the available download
// data changes.
@ -690,8 +686,8 @@ DownloadsDataCtor.prototype = {
*/
get canRemoveFinished()
{
for (let [, dataItem] of Iterator(this.dataItems)) {
if (dataItem && !dataItem.inProgress) {
for (let dataItem of this.dataItems) {
if (!dataItem.inProgress) {
return true;
}
}
@ -716,7 +712,7 @@ DownloadsDataCtor.prototype = {
{
let dataItem = new DownloadsDataItem(aDownload);
this._downloadToDataItemMap.set(aDownload, dataItem);
this.dataItems[dataItem.downloadGuid] = dataItem;
this.dataItems.add(dataItem);
for (let view of this._views) {
view.onDataItemAdded(dataItem, true);
@ -745,7 +741,7 @@ DownloadsDataCtor.prototype = {
}
this._downloadToDataItemMap.delete(aDownload);
this.dataItems[dataItem.downloadGuid] = null;
this.dataItems.delete(dataItem);
for (let view of this._views) {
view.onDataItemRemoved(dataItem);
}
@ -861,14 +857,7 @@ DownloadsDataCtor.prototype = {
//let loadedItemsArray = [dataItem
// for each (dataItem in this.dataItems)
// if (dataItem)];
let loadedItemsArray = [];
for each (let dataItem in this.dataItems) {
if (dataItem) {
loadedItemsArray.push(dataItem);
}
}
let loadedItemsArray = [...this.dataItems];
loadedItemsArray.sort(function(a, b) b.download.startTime - a.download.startTime);
loadedItemsArray.forEach(
@ -1344,13 +1333,6 @@ function DownloadsDataItem(aSource)
}
DownloadsDataItem.prototype = {
/**
* The JavaScript API does not need identifiers for Download objects, so they
* are generated sequentially for the corresponding DownloadDataItem.
*/
get _autoIncrementId() ++DownloadsDataItem.prototype.__lastId,
__lastId: 0,
/**
* Initializes this object from the JavaScript API for downloads.
*
@ -1362,8 +1344,6 @@ DownloadsDataItem.prototype = {
_initFromJSDownload: function (aDownload)
{
this.download = aDownload;
this.downloadGuid = "id:" + this._autoIncrementId;
this.endTime = Date.now();
this.updateFromJSDownload();
@ -2029,7 +2009,7 @@ DownloadsIndicatorDataCtor.prototype = {
{
let dataItems = this._isPrivate ? PrivateDownloadsData.dataItems
: DownloadsData.dataItems;
for each (let dataItem in dataItems) {
for (let dataItem of dataItems) {
if (dataItem && dataItem.inProgress) {
yield dataItem;
}