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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('downloads', function() { 5 cr.define('downloads', function() {
6 /** 6 /**
7 * @param {string} chromeSendName 7 * @param {string} chromeSendName
8 * @return {function(string):void} A chrome.send() callback with curried name. 8 * @return {function(string):void} A chrome.send() callback with curried name.
9 */ 9 */
10 function chromeSendWithId(chromeSendName) { 10 function chromeSendWithId(chromeSendName) {
(...skipping 27 matching lines...) Expand all
38 }, 38 },
39 39
40 /** @param {string} id ID of the download that the user started dragging. */ 40 /** @param {string} id ID of the download that the user started dragging. */
41 drag: chromeSendWithId('drag'), 41 drag: chromeSendWithId('drag'),
42 42
43 /** 43 /**
44 * @return {boolean} Whether the user is currently searching for downloads 44 * @return {boolean} Whether the user is currently searching for downloads
45 * (i.e. has a non-empty search term). 45 * (i.e. has a non-empty search term).
46 */ 46 */
47 isSearching: function() { 47 isSearching: function() {
48 return this.searchText_.length > 0; 48 return (this.searchText_ || '').length > 0;
asanka 2015/11/24 22:08:22 !!this.searchText_ or do you folks dislike that e
Dan Beam 2015/11/25 04:06:36 Done.
49 }, 49 },
50 50
51 /** Opens the current local destination for downloads. */ 51 /** Opens the current local destination for downloads. */
52 openDownloadsFolder: chrome.send.bind(chrome, 'openDownloadsFolder'), 52 openDownloadsFolder: chrome.send.bind(chrome, 'openDownloadsFolder'),
53 53
54 /** 54 /**
55 * @param {string} id ID of the download to run locally on the user's box. 55 * @param {string} id ID of the download to run locally on the user's box.
56 */ 56 */
57 openFile: chromeSendWithId('openFile'), 57 openFile: chromeSendWithId('openFile'),
58 58
(...skipping 12 matching lines...) Expand all
71 */ 71 */
72 saveDangerous: chromeSendWithId('saveDangerous'), 72 saveDangerous: chromeSendWithId('saveDangerous'),
73 73
74 /** @param {string} searchText What to search for. */ 74 /** @param {string} searchText What to search for. */
75 search: function(searchText) { 75 search: function(searchText) {
76 if (this.searchText_ == searchText) 76 if (this.searchText_ == searchText)
77 return; 77 return;
78 78
79 this.searchText_ = searchText; 79 this.searchText_ = searchText;
80 80
81 /**
82 * @param {string} s
83 * @return {string} |s| without whitespace at the ends (trimmed).
84 */
85 function trim(s) { return s.trim(); }
86
81 // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']). 87 // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']).
82 function trim(s) { return s.trim(); } 88 var terms = searchText ? searchText.split(/"([^"]*)"/).map(trim) : [];
dpapad 2015/11/24 18:42:33 Is it worth adding tests for the regular expressio
Dan Beam 2015/11/25 04:06:36 Done.
83 chrome.send('getDownloads', searchText.split(/"([^"]*)"/).map(trim)); 89
90 chrome.send('getDownloads', terms);
84 }, 91 },
85 92
86 /** 93 /**
87 * Shows the local folder a finished download resides in. 94 * Shows the local folder a finished download resides in.
88 * @param {string} id ID of the download to show. 95 * @param {string} id ID of the download to show.
89 */ 96 */
90 show: chromeSendWithId('show'), 97 show: chromeSendWithId('show'),
91 98
92 /** Undo download removal. */ 99 /** Undo download removal. */
93 undo: chrome.send.bind(chrome, 'undo'), 100 undo: chrome.send.bind(chrome, 'undo'),
94 }; 101 };
95 102
96 cr.addSingletonGetter(ActionService); 103 cr.addSingletonGetter(ActionService);
97 104
98 return {ActionService: ActionService}; 105 return {ActionService: ActionService};
99 }); 106 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698