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..35b55c9958c6c2e107eb10da5f13306ae2dc3634 100644 |
| --- a/chrome/browser/resources/downloads.js |
| +++ b/chrome/browser/resources/downloads.js |
| @@ -292,6 +292,7 @@ Download.States = { |
| IN_PROGRESS : "IN_PROGRESS", |
| CANCELLED : "CANCELLED", |
| COMPLETE : "COMPLETE", |
| + REMOVED : "REMOVED", |
|
hendrickson_a
2011/06/07 15:38:52
I don't like this mismatch between the states in D
Randy Smith (Not in Mondays)
2011/06/07 18:51:10
I'm sorry if this was covered earlier and the stat
haraken1
2011/06/08 05:11:49
I got it. I removed REMOVED state from Download.St
|
| PAUSED : "PAUSED", |
| DANGEROUS : "DANGEROUS", |
| INTERRUPTED : "INTERRUPTED", |
| @@ -448,6 +449,8 @@ Download.prototype.getStatusText_ = function() { |
| return this.progressStatusText_; |
| case Download.States.CANCELLED: |
| return localStrings.getString('status_cancelled'); |
| + case Download.States.REMOVED: |
| + return localStrings.getString('status_removed'); |
| case Download.States.PAUSED: |
| return localStrings.getString('status_paused'); |
| case Download.States.DANGEROUS: |
| @@ -532,7 +535,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 +551,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 +575,7 @@ function downloadsList(results) { |
| if (resultsTimeout) |
| clearTimeout(resultsTimeout); |
| window.console.log('results'); |
| + fifo_results.length = 0; |
| downloads.clear(); |
| downloadUpdated(results); |
| downloads.updateSummary(); |
| @@ -575,13 +589,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; |
| } |
| } |