Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4367)

Unified Diff: chrome/browser/resources/downloads/downloads.js

Issue 977473002: downloads: break downloads.js into more classes/files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/downloads/downloads.js
diff --git a/chrome/browser/resources/downloads/downloads.js b/chrome/browser/resources/downloads/downloads.js
index 0a074b7bf28f290c4615c3195488864ef9ee92f1..c8697755222bf7da57c62c2d3c43e3c293799157 100644
--- a/chrome/browser/resources/downloads/downloads.js
+++ b/chrome/browser/resources/downloads/downloads.js
@@ -172,10 +172,6 @@ function Downloads() {
this.searchText_ = '';
this.focusGrid_ = new cr.ui.FocusGrid();
- // Keep track of the dates of the newest and oldest downloads so that we
- // know where to insert them.
- this.newestTime_ = -1;
-
// Icon load request queue.
this.iconLoadQueue_ = [];
this.isIconLoading_ = false;
@@ -202,17 +198,21 @@ Downloads.prototype.updated = function(download) {
this.downloads_[id].update(download);
} else {
this.downloads_[id] = new Download(download);
- // We get downloads in display order, so we don't have to worry about
- // maintaining correct order - we can assume that any downloads not in
- // display order are new ones and so we can add them to the top of the
- // list.
- if (download.started > this.newestTime_) {
- this.node_.insertBefore(this.downloads_[id].node, this.node_.firstChild);
- this.newestTime_ = download.started;
- } else {
- this.node_.appendChild(this.downloads_[id].node);
+
+ // Sort downloads by start time and insert the new one in the right place.
+ var startSorted = [];
+ for (var sortedId in this.downloads_) {
+ startSorted.push(this.downloads_[sortedId]);
}
+ startSorted.sort(function(d1, d2) { return d2.started_ - d1.started_; });
+
+ var indexOfNewDownload = startSorted.indexOf(this.downloads_[id]);
+ var before = startSorted[indexOfNewDownload + 1];
+
+ // If !before, insertBefore() acts like appendChild() and adds at the end.
+ this.node_.insertBefore(this.downloads_[id].node, before && before.node);
Dan Beam 2015/03/03 19:31:05 i could possibly do this: if (startSorted.lengt
asanka 2015/03/03 20:45:56 Yeah. For undo operations that affect multiple dow
Dan Beam 2015/03/04 00:46:20 the problem with rebuilding DOM is that it messes
}
+
// Download.prototype.update may change its nodeSince_ and nodeDate_, so
// update all the date displays.
// TODO(benjhayden) Only do this if its nodeSince_ or nodeDate_ actually did
@@ -373,10 +373,7 @@ Downloads.prototype.scheduleIconLoad = function(elem, iconURL) {
* @return {boolean} Returns true if the displayed list is to be updated.
*/
Downloads.prototype.isUpdateNeeded = function(downloads) {
- var size = 0;
- for (var i in this.downloads_)
- size++;
- if (size != downloads.length)
+ if (this.size() != downloads.length)
return true;
// Since there are the same number of items in the incoming list as
// |this.downloads_|, there won't be any removed downloads without some
@@ -633,6 +630,7 @@ Download.prototype.update = function(download) {
this.fileUrl_ = download.file_url;
this.fileName_ = download.file_name;
this.url_ = download.url;
+ this.started_ = download.started;
this.state_ = download.state;
this.fileExternallyRemoved_ = download.file_externally_removed;
this.dangerType_ = download.danger_type;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698