OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // require: cr.js | 5 // require: cr.js |
6 | 6 |
7 cr.define('chrome.sync', function() { | 7 cr.define('chrome.sync', function() { |
8 var currSearchId = 0; | 8 var currSearchId = 0; |
9 | 9 |
10 var setQueryString = function(queryControl, query) { | 10 var setQueryString = function(queryControl, query) { |
(...skipping 29 matching lines...) Expand all Loading... |
40 * Runs a search with the given query. | 40 * Runs a search with the given query. |
41 * | 41 * |
42 * @param {string} query The regex to do the search with. | 42 * @param {string} query The regex to do the search with. |
43 * @param {function} callback The callback called with the search results; | 43 * @param {function} callback The callback called with the search results; |
44 * not called if doSearch() is called again while the search is running. | 44 * not called if doSearch() is called again while the search is running. |
45 */ | 45 */ |
46 var doSearch = function(query, callback) { | 46 var doSearch = function(query, callback) { |
47 var searchId = ++currSearchId; | 47 var searchId = ++currSearchId; |
48 try { | 48 try { |
49 var regex = new RegExp(query); | 49 var regex = new RegExp(query); |
50 chrome.sync.getAllNodes(query, function(allNodes) { | 50 chrome.sync.getAllNodes(function(node_map) { |
| 51 // Put all nodes into one big list that ignores the type. |
| 52 var nodes = node_map. |
| 53 map(function(x) { return x.nodes; }). |
| 54 reduce(function(a, b) { return a.concat(b); }); |
| 55 |
51 if (currSearchId != searchId) { | 56 if (currSearchId != searchId) { |
52 return; | 57 return; |
53 } | 58 } |
54 callback(allNodes.filter(function(elem) { | 59 callback(nodes.filter(function(elem) { |
55 return regex.test(JSON.stringify(elem, null, 2)); | 60 return regex.test(JSON.stringify(elem, null, 2)); |
56 }), null); | 61 }), null); |
57 }); | 62 }); |
58 } catch (err) { | 63 } catch (err) { |
59 // Sometimes the provided regex is invalid. This and other errors will | 64 // Sometimes the provided regex is invalid. This and other errors will |
60 // be caught and handled here. | 65 // be caught and handled here. |
61 callback([], err); | 66 callback([], err); |
62 } | 67 } |
63 }; | 68 }; |
64 | 69 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 detailsControl.textContent = JSON.stringify(selected, null, 2); | 133 detailsControl.textContent = JSON.stringify(selected, null, 2); |
129 } | 134 } |
130 }); | 135 }); |
131 } | 136 } |
132 | 137 |
133 return { | 138 return { |
134 decorateSearchControls: decorateSearchControls, | 139 decorateSearchControls: decorateSearchControls, |
135 decorateQuickQueryControls: decorateQuickQueryControls | 140 decorateQuickQueryControls: decorateQuickQueryControls |
136 }; | 141 }; |
137 }); | 142 }); |
OLD | NEW |