| OLD | NEW |
| 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) { |
| 11 return function(id) { chrome.send(chromeSendName, [id]); }; | 11 return function(id) { |
| 12 chrome.send(chromeSendName, [id]); |
| 13 }; |
| 12 } | 14 } |
| 13 | 15 |
| 14 /** @constructor */ | 16 /** @constructor */ |
| 15 function ActionService() { | 17 function ActionService() { |
| 16 /** @private {Array<string>} */ | 18 /** @private {Array<string>} */ |
| 17 this.searchTerms_ = []; | 19 this.searchTerms_ = []; |
| 18 } | 20 } |
| 19 | 21 |
| 20 /** | 22 /** |
| 21 * @param {string} s | 23 * @param {string} s |
| 22 * @return {string} |s| without whitespace at the beginning or end. | 24 * @return {string} |s| without whitespace at the beginning or end. |
| 23 */ | 25 */ |
| 24 function trim(s) { return s.trim(); } | 26 function trim(s) { |
| 27 return s.trim(); |
| 28 } |
| 25 | 29 |
| 26 /** | 30 /** |
| 27 * @param {string|undefined} value | 31 * @param {string|undefined} value |
| 28 * @return {boolean} Whether |value| is truthy. | 32 * @return {boolean} Whether |value| is truthy. |
| 29 */ | 33 */ |
| 30 function truthy(value) { return !!value; } | 34 function truthy(value) { |
| 35 return !!value; |
| 36 } |
| 31 | 37 |
| 32 /** | 38 /** |
| 33 * @param {string} searchText Input typed by the user into a search box. | 39 * @param {string} searchText Input typed by the user into a search box. |
| 34 * @return {Array<string>} A list of terms extracted from |searchText|. | 40 * @return {Array<string>} A list of terms extracted from |searchText|. |
| 35 */ | 41 */ |
| 36 ActionService.splitTerms = function(searchText) { | 42 ActionService.splitTerms = function(searchText) { |
| 37 // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']). | 43 // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']). |
| 38 return searchText.split(/"([^"]*)"/).map(trim).filter(truthy); | 44 return searchText.split(/"([^"]*)"/).map(trim).filter(truthy); |
| 39 }; | 45 }; |
| 40 | 46 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 show: chromeSendWithId('show'), | 136 show: chromeSendWithId('show'), |
| 131 | 137 |
| 132 /** Undo download removal. */ | 138 /** Undo download removal. */ |
| 133 undo: chrome.send.bind(chrome, 'undo'), | 139 undo: chrome.send.bind(chrome, 'undo'), |
| 134 }; | 140 }; |
| 135 | 141 |
| 136 cr.addSingletonGetter(ActionService); | 142 cr.addSingletonGetter(ActionService); |
| 137 | 143 |
| 138 return {ActionService: ActionService}; | 144 return {ActionService: ActionService}; |
| 139 }); | 145 }); |
| OLD | NEW |