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

Unified Diff: chrome/browser/resources/sync_internals/chrome_sync.js

Issue 224563004: sync: Re-implement getAllNodes WebUI function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Many updates Created 6 years, 9 months 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 side-by-side diff with in-line comments
Download patch
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..e6e5d7d45a3ddb40ef1975296ff5cd23b381031b 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,46 @@ cr.define('chrome.sync', function() {
chrome.send('requestListOfTypes');
};
+ /**
+ * Counter to uniquely identify requests while they're in progress.
+ * Used in the implementation of GetAllNodes.
+ */
+ var requestId = 0;
+
+ /**
+ * A map from counter values to asynchronous request callbacks.
+ * Used in the implementation of GetAllNodes.
Dan Beam 2014/04/05 00:19:25 nit: @type {{number: !Function}} (though technical
rlarocque 2014/04/05 00:27:29 Done.
+ */
+ var requestCallbacks = {};
+
+ /**
+ * Asks the browser to send us a copy of all existing sync nodes.
+ * Will eventually invoke the given callback with the results.
+ *
+ * @param {function(!Object)} callback The function to call with the response.
+ */
+ 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);
+ requestCallbacks[id] = undefined;
+ };
+
return {
makeTimer: makeTimer,
dispatchEvent: dispatchEvent,
events: new cr.EventTarget(),
-
+ getAllNodes: getAllNodes,
+ getAllNodesCallback: getAllNodesCallback,
registerForEvents: registerForEvents,
requestUpdatedAboutInfo: requestUpdatedAboutInfo,
requestListOfTypes: requestListOfTypes,

Powered by Google App Engine
This is Rietveld 408576698