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

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: Style fixes + comments 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..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,
« no previous file with comments | « no previous file | chrome/browser/resources/sync_internals/data.js » ('j') | chrome/browser/resources/sync_internals/data.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698