Index: chrome/browser/resources/sync_internals/chrome_sync.js |
diff --git a/chrome/browser/resources/sync_internals/chrome_sync.js b/chrome/browser/resources/sync_internals/chrome_sync.js |
index f8d9a2f97dda939ee4c278d646e1381d0168edad..7efee0fd4b18544c33fa11e38270d344b0364849 100644 |
--- a/chrome/browser/resources/sync_internals/chrome_sync.js |
+++ b/chrome/browser/resources/sync_internals/chrome_sync.js |
@@ -9,40 +9,6 @@ |
cr.define('chrome.sync', function() { |
'use strict'; |
- function makeSyncFunction(name) { |
- var callbacks = []; |
- |
- // Calls the function, assuming the last argument is a callback to be |
- // called with the return value. |
- var fn = function() { |
- var args = Array.prototype.slice.call(arguments); |
- callbacks.push(args.pop()); |
- chrome.send(name, args); |
- }; |
- |
- // Handle a reply, assuming that messages are processed in FIFO order. |
- // Called by SyncInternalsUI::HandleJsReply(). |
- fn.handleReply = function() { |
- var args = Array.prototype.slice.call(arguments); |
- // Remove the callback before we call it since the callback may |
- // throw. |
- var callback = callbacks.shift(); |
- callback.apply(null, args); |
- }; |
- |
- return fn; |
- } |
- |
- var syncFunctions = [ |
- // Get an array containing a JSON representations of all known sync nodes. |
- 'getAllNodes', |
- ]; |
- |
- for (var i = 0; i < syncFunctions.length; ++i) { |
- var syncFunction = syncFunctions[i]; |
- chrome.sync[syncFunction] = makeSyncFunction(syncFunction); |
- } |
- |
/** |
* A simple timer to measure elapsed time. |
* @constructor |
@@ -103,11 +69,37 @@ cr.define('chrome.sync', function() { |
chrome.send('requestListOfTypes'); |
}; |
Dan Beam
2014/04/04 22:36:31
/** Doc comment of what these do and how they act.
rlarocque
2014/04/05 00:07:27
Done.
|
+ var requestId = 0; |
+ var requestCallbacks = {}; |
+ |
+ /** |
+ * Asks the browser to send us a copy of all existing sync nodes. |
+ * Will eventually invoke the given callback with the results. |
Dan Beam
2014/04/04 22:36:31
@param {function(!Object)} callback A description
rlarocque
2014/04/05 00:07:27
Done.
|
+ */ |
+ var getAllNodes = function(callback) { |
+ requestId++; |
+ requestCallbacks[requestId] = callback; |
+ chrome.send('getAllNodes', [requestId]); |
+ }; |
+ |
+ /** |
+ * Called from C++ with the response to a getAllNodes request. |
+ * @param {number} id The requestId passed in with the request. |
+ * @param {Object} response The response to the request. |
+ */ |
+ var getAllNodesCallback = function(id, response) { |
+ requestCallbacks[id](response); |
+ delete requestCallbacks[id]; |
Dan Beam
2014/04/04 22:36:31
i think technically we don't like delete in webui
rlarocque
2014/04/05 00:07:27
Works for me. I'm just trying to avoid gratuitous
|
+ }; |
+ |
return { |
makeTimer: makeTimer, |
dispatchEvent: dispatchEvent, |
events: new cr.EventTarget(), |
Dan Beam
2014/04/04 22:36:31
nit: remove blank lines
rlarocque
2014/04/05 00:07:27
Done.
|
+ getAllNodes: getAllNodes, |
+ getAllNodesCallback: getAllNodesCallback, |
+ |
registerForEvents: registerForEvents, |
requestUpdatedAboutInfo: requestUpdatedAboutInfo, |
requestListOfTypes: requestListOfTypes, |