Index: chrome/browser/resources/sync_internals/sync_search.js |
diff --git a/chrome/browser/resources/sync_internals/sync_search.js b/chrome/browser/resources/sync_internals/sync_search.js |
index 95d27223c6375007222af8fc91fcc9816f914119..62a67985ce447b7195f4bf7665bb60fec54dc4b9 100644 |
--- a/chrome/browser/resources/sync_internals/sync_search.js |
+++ b/chrome/browser/resources/sync_internals/sync_search.js |
@@ -10,25 +10,28 @@ cr.define('chrome.sync', function() { |
/** |
* Runs a search with the given query. |
* |
- * @param {string} query The query to do the search with. |
- * @param {Array.<{id: string, title: string, isFolder: boolean}>} |
+ * @param {string} query The regex to do the search with. |
+ * @param {Array.<NodeSummary>} |
* callback The callback called with the search results; not |
* called if doSearch() is called again while the search is |
* running. |
*/ |
var doSearch = function(query, callback) { |
var searchId = ++currSearchId; |
- chrome.sync.findNodesContainingString(query, function(ids) { |
- if (currSearchId != searchId) { |
- return; |
- } |
- chrome.sync.getNodeSummariesById(ids, function(nodeSummaries) { |
+ try { |
+ var regex = new RegExp(query); |
+ chrome.sync.getAllNodes(query, function(allNodes) { |
if (currSearchId != searchId) { |
return; |
} |
- callback(nodeSummaries); |
+ callback(allNodes.filter(function (elem) { |
akalin
2012/04/03 00:36:08
remove space after 'function'
rlarocque
2012/04/03 19:01:42
Done.
|
+ return JSON.stringify(elem, null, 2).search(regex) != -1; |
akalin
2012/04/03 00:36:08
use regex.test(str) instead?
rlarocque
2012/04/03 19:01:42
Done.
|
+ }), null); |
}); |
- }); |
+ } catch (err) { |
+ // Sometimes the provided regex is invalid. |
akalin
2012/04/03 00:36:08
update comment to indicate that this can also catc
rlarocque
2012/04/03 19:01:42
Done.
|
+ callback([], err); |
+ } |
}; |
/** |
@@ -56,20 +59,28 @@ cr.define('chrome.sync', function() { |
return; |
} |
statusControl.textContent = 'Searching for ' + query + '...'; |
+ queryControl.removeAttribute('error'); |
var timer = chrome.sync.makeTimer(); |
- doSearch(query, function(nodeSummaries) { |
- statusControl.textContent = |
- 'Found ' + nodeSummaries.length + ' nodes in ' |
- + timer.elapsedSeconds + 's'; |
- // TODO(akalin): Write a nicer list display. |
- for (var i = 0; i < nodeSummaries.length; ++i) { |
- nodeSummaries[i].toString = function() { |
- return this.title; |
- }.bind(nodeSummaries[i]); |
+ doSearch(query, function(nodes, error) { |
+ if (error) { |
+ statusControl.textContent = 'Error: ' + error; |
+ queryControl.setAttribute('error'); |
+ } else { |
+ statusControl.textContent = |
+ 'Found ' + nodes.length + ' nodes in ' |
+ + timer.elapsedSeconds + 's'; |
+ queryControl.removeAttribute('error'); |
+ |
+ // TODO(akalin): Write a nicer list display. |
+ for (var i = 0; i < nodes.length; ++i) { |
+ nodes[i].toString = function() { |
+ return this.NON_UNIQUE_NAME; |
+ }.bind(nodes[i]); |
+ } |
+ resultsDataModel.push.apply(resultsDataModel, nodes); |
+ // Workaround for http://crbug.com/83452 . |
+ resultsControl.redraw(); |
} |
- resultsDataModel.push.apply(resultsDataModel, nodeSummaries); |
- // Workaround for http://crbug.com/83452 . |
- resultsControl.redraw(); |
}); |
}; |
queryControl.value = ''; |
@@ -81,13 +92,7 @@ cr.define('chrome.sync', function() { |
detailsControl.textContent = ''; |
var selected = resultsControl.selectedItem; |
if (selected) { |
- chrome.sync.getNodeDetailsById([selected.id], function(nodeDetails) { |
- var selectedNodeDetails = nodeDetails[0] || null; |
- if (selectedNodeDetails) { |
- detailsControl.textContent = |
- JSON.stringify(selectedNodeDetails, null, 2); |
- } |
- }); |
+ detailsControl.textContent = JSON.stringify(selected, null, 2); |
} |
}); |
} |