Chromium Code Reviews| Index: chrome/browser/resources/downloads.html |
| diff --git a/chrome/browser/resources/downloads.html b/chrome/browser/resources/downloads.html |
| index 7aee1a3aec950c89a655debacd42489f79758ae9..3507edb16653b3b19b2211c63cbda9adde683987 100644 |
| --- a/chrome/browser/resources/downloads.html |
| +++ b/chrome/browser/resources/downloads.html |
| @@ -471,6 +471,7 @@ Download.States = { |
| IN_PROGRESS : "IN_PROGRESS", |
| CANCELLED : "CANCELLED", |
| COMPLETE : "COMPLETE", |
| + REMOVED : "REMOVED", |
| PAUSED : "PAUSED", |
| DANGEROUS : "DANGEROUS", |
| INTERRUPTED : "INTERRUPTED", |
| @@ -627,6 +628,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: |
| @@ -711,7 +714,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(); |
| @@ -719,12 +730,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', []); |
| @@ -741,6 +754,7 @@ function downloadsList(results) { |
| if (resultsTimeout) |
| clearTimeout(resultsTimeout); |
| window.console.log('results'); |
| + fifo_results.length = 0; |
| downloads.clear(); |
| downloadUpdated(results); |
| downloads.updateSummary(); |
| @@ -754,13 +768,27 @@ 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() { |
| + // Sometimes this can get called too early. |
| + if (!downloads) |
| + return; |
|
Randy Smith (Not in Mondays)
2011/05/16 20:57:12
Do we still need this comment and the null check f
haraken1
2011/06/07 12:49:18
Done.
|
| + |
| 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; |
| } |
| } |