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

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

Issue 1428833005: MD Downloads: track downloads in C++, dispatch discrete JS updates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dpapad@ + asanka@ feedback + self-review Created 5 years, 1 month 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
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 f984fe5a14614e3b853993e4dcaad33b70577641..d135fb3666804edb0f502f2f940e1422faf5aa0b 100644
--- a/chrome/browser/resources/md_downloads/action_service.js
+++ b/chrome/browser/resources/md_downloads/action_service.js
@@ -14,6 +14,27 @@ cr.define('downloads', function() {
/** @constructor */
function ActionService() {}
+ /**
+ * @param {string} searchText Input typed by the user into a search box.
+ * @return {Array<string>} A list of terms extracted from |searchText|.
+ */
+ ActionService.splitTerms = function(searchText) {
+ /**
+ * @param {string} s
+ * @return {string} |s| without whitespace at the beginning or end.
+ */
+ function trim(s) { return s.trim(); }
+
+ /**
+ * @param {string} s
+ * @return {boolean} Whether |s| is empty.
+ */
+ function notEmpty(s) { return s.length > 0; }
dpapad 2015/11/25 17:50:47 Nit: We are re-defining the trim() and notEpmty()
Dan Beam 2015/11/25 20:23:23 Done.
+
+ // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']).
+ return searchText.split(/"([^"]*)"/).map(trim).filter(notEmpty);
+ };
+
ActionService.prototype = {
/** @param {string} id ID of the download to cancel. */
cancel: chromeSendWithId('cancel'),
@@ -45,7 +66,7 @@ cr.define('downloads', function() {
* (i.e. has a non-empty search term).
*/
isSearching: function() {
- return this.searchText_.length > 0;
+ return !!this.searchText_;
dpapad 2015/11/25 17:50:47 If you follow the comment above, then you can re-u
Dan Beam 2015/11/25 20:23:23 changed a little, but basically doing this
},
/** Opens the current local destination for downloads. */
@@ -77,10 +98,7 @@ cr.define('downloads', function() {
return;
this.searchText_ = searchText;
-
- // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']).
- function trim(s) { return s.trim(); }
- chrome.send('getDownloads', searchText.split(/"([^"]*)"/).map(trim));
+ chrome.send('getDownloads', ActionService.splitTerms(searchText));
},
/**

Powered by Google App Engine
This is Rietveld 408576698