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

Unified Diff: chrome/browser/resources/md_downloads/action_service.js

Issue 1492273002: MD Downloads: limit the amount of downloads we send (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new-dl-data
Patch Set: asdf Created 5 years 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 | chrome/browser/resources/md_downloads/crisper.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/md_downloads/action_service.js
diff --git a/chrome/browser/resources/md_downloads/action_service.js b/chrome/browser/resources/md_downloads/action_service.js
index ee0a1b4a9fdc7384cfca8c7a120ddc7f6f18bf3b..3294632cb469e660a8dd48be742a21c41370f358 100644
--- a/chrome/browser/resources/md_downloads/action_service.js
+++ b/chrome/browser/resources/md_downloads/action_service.js
@@ -36,6 +36,9 @@ cr.define('downloads', function() {
};
ActionService.prototype = {
+ /** @private {Array<string>} */
+ searchTerms_: [],
esprehn 2015/12/10 21:42:59 this is static, the array is shred between all ins
Dan Beam 2015/12/10 21:51:15 yeah, but this class is a singleton. i understand
+
/** @param {string} id ID of the download to cancel. */
cancel: chromeSendWithId('cancel'),
@@ -61,15 +64,17 @@ cr.define('downloads', function() {
/** @param {string} id ID of the download that the user started dragging. */
drag: chromeSendWithId('drag'),
- /** @private {boolean} */
- isSearching_: false,
+ /** Loads more downloads with the current search terms. */
+ loadMore: function() {
+ chrome.send('getDownloads', this.searchTerms_);
+ },
/**
* @return {boolean} Whether the user is currently searching for downloads
* (i.e. has a non-empty search term).
*/
isSearching: function() {
- return this.isSearching_;
+ return this.searchTerms_.length > 0;
},
/** Opens the current local destination for downloads. */
@@ -97,15 +102,19 @@ cr.define('downloads', function() {
/** @param {string} searchText What to search for. */
search: function(searchText) {
- if (this.searchText_ == searchText)
- return;
+ var searchTerms = ActionService.splitTerms(searchText);
+ var sameTerms = searchTerms.length == this.searchTerms_.length;
- this.searchText_ = searchText;
+ for (var i = 0; sameTerms && i < searchTerms.length; ++i) {
esprehn 2015/12/10 21:42:59 there's no standard library in WebUI like closure?
Dan Beam 2015/12/10 21:51:15 not currently. why isn't there an Array equals...
+ if (searchTerms[i] != this.searchTerms_[i])
+ sameTerms = false;
+ }
- var terms = ActionService.splitTerms(searchText);
- this.isSearching_ = terms.length > 0;
+ if (sameTerms)
+ return;
- chrome.send('getDownloads', terms);
+ this.searchTerms_ = searchTerms;
esprehn 2015/12/10 21:42:59 this is actually shadowing the variable on the pro
Dan Beam 2015/12/10 21:51:15 that's fine for our use-case, but will send a foll
Dan Beam 2015/12/10 22:08:41 followup here: https://codereview.chromium.org/151
+ this.loadMore();
},
/**
« no previous file with comments | « no previous file | chrome/browser/resources/md_downloads/crisper.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698