Chromium Code Reviews| Index: chrome/browser/resources/downloads.js |
| diff --git a/chrome/browser/resources/downloads.js b/chrome/browser/resources/downloads.js |
| index ddfdb40c813338fe0b5f61134fe6c2e8cd085f8d..65cd8c5cad2f0a86f237fc3b9df98dd84710801c 100644 |
| --- a/chrome/browser/resources/downloads.js |
| +++ b/chrome/browser/resources/downloads.js |
| @@ -187,7 +187,7 @@ function Download(download) { |
| this.safe_.ondragstart = this.drag_.bind(this); |
| this.node.appendChild(this.safe_); |
| - if (download.state != Download.States.COMPLETE) { |
| + if (this.state_ != Download.States.COMPLETE || this.fileExternallyRemoved_) { |
|
Randy Smith (Not in Mondays)
2011/06/08 22:07:54
It may be my lack of javascript, but it doesn't lo
haraken1
2011/06/09 05:25:55
My mistake. I fixed it.
|
| this.nodeProgressBackground_ = |
| createElementWithClassName('div', 'progress background'); |
| this.safe_.appendChild(this.nodeProgressBackground_); |
| @@ -329,6 +329,7 @@ Download.prototype.update = function(download) { |
| this.fileName_ = download.file_name; |
| this.url_ = download.url; |
| this.state_ = download.state; |
| + this.fileExternallyRemoved_ = download.file_externally_removed; |
| this.dangerType_ = download.danger_type; |
| this.since_ = download.since_string; |
| @@ -351,19 +352,24 @@ Download.prototype.update = function(download) { |
| } else { |
| this.nodeImg_.src = 'chrome://fileicon/' + this.filePath_; |
| - if (this.state_ == Download.States.COMPLETE) { |
| + if (this.state_ == Download.States.COMPLETE && |
| + !this.fileExternallyRemoved_) { |
| this.nodeFileLink_.innerHTML = this.fileName_; |
| this.nodeFileLink_.href = this.filePath_; |
| } else { |
| this.nodeFileName_.innerHTML = this.fileName_; |
| } |
| - showInline(this.nodeFileLink_, this.state_ == Download.States.COMPLETE); |
| + showInline(this.nodeFileLink_, |
| + this.state_ == Download.States.COMPLETE && |
| + !this.fileExternallyRemoved_); |
| // nodeFileName_ has to be inline-block to avoid the 'interaction' with |
| // nodeStatus_. If both are inline, it appears that their text contents |
| // are merged before the bidi algorithm is applied leading to an |
| // undesirable reordering. http://crbug.com/13216 |
| - showInlineBlock(this.nodeFileName_, this.state_ != Download.States.COMPLETE); |
| + showInlineBlock(this.nodeFileName_, |
| + this.state_ != Download.States.COMPLETE || |
| + this.fileExternallyRemoved_); |
| if (this.state_ == Download.States.IN_PROGRESS) { |
| this.nodeProgressForeground_.style.display = 'block'; |
| @@ -396,7 +402,9 @@ Download.prototype.update = function(download) { |
| } |
| if (this.controlShow_) { |
| - showInline(this.controlShow_, this.state_ == Download.States.COMPLETE); |
| + showInline(this.controlShow_, |
| + this.state_ == Download.States.COMPLETE && |
| + !this.fileExternallyRemoved_); |
| } |
| showInline(this.controlRetry_, this.state_ == Download.States.CANCELLED); |
| this.controlRetry_.href = this.url_; |
| @@ -457,7 +465,8 @@ Download.prototype.getStatusText_ = function() { |
| case Download.States.INTERRUPTED: |
| return localStrings.getString('status_interrupted'); |
| case Download.States.COMPLETE: |
| - return ''; |
| + return this.fileExternallyRemoved_ ? |
| + localStrings.getString('status_removed') : ''; |
| } |
| } |
| @@ -532,7 +541,15 @@ Download.prototype.cancel_ = function() { |
| // Page: |
| var downloads, localStrings, resultsTimeout; |
| +/** |
| + * The FIFO array that stores updates of download files to be appeared |
| + * on the download page. It is guaranteed that the updates in this array |
| + * are reflected to the download page in a FIFO order. |
| +*/ |
| +var fifo_results; |
| + |
| function load() { |
| + fifo_results = new Array(); |
| localStrings = new LocalStrings(); |
| downloads = new Downloads(); |
| $('term').focus(); |
| @@ -540,12 +557,14 @@ function load() { |
| } |
| function setSearch(searchText) { |
| + fifo_results.length = 0; |
| downloads.clear(); |
| downloads.setSearchText(searchText); |
| chrome.send('getDownloads', [searchText.toString()]); |
| } |
| function clearAll() { |
| + fifo_results.length = 0; |
| downloads.clear(); |
| downloads.setSearchText(''); |
| chrome.send('clearAll', []); |
| @@ -562,6 +581,7 @@ function downloadsList(results) { |
| if (resultsTimeout) |
| clearTimeout(resultsTimeout); |
| window.console.log('results'); |
| + fifo_results.length = 0; |
| downloads.clear(); |
| downloadUpdated(results); |
| downloads.updateSummary(); |
| @@ -575,13 +595,23 @@ function downloadUpdated(results) { |
| if (!downloads) |
| return; |
| + fifo_results = fifo_results.concat(results); |
| + tryDownloadUpdatedPeriodically(); |
| +} |
| + |
| +/** |
| + * Try to reflect as much updates as possible within 50ms. |
| + * This function is scheduled again and again until all updates are reflected. |
| + */ |
| +function tryDownloadUpdatedPeriodically() { |
| var start = Date.now(); |
| - for (var i = 0; i < results.length; i++) { |
| - downloads.updated(results[i]); |
| + while (fifo_results.length) { |
| + var result = fifo_results.shift(); |
| + downloads.updated(result); |
| // Do as much as we can in 50ms. |
| if (Date.now() - start > 50) { |
| clearTimeout(resultsTimeout); |
| - resultsTimeout = setTimeout(downloadUpdated, 5, results.slice(i + 1)); |
| + resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5); |
| break; |
| } |
| } |