172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenOverview of chrome://sync-internals
272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen-----------------------------------
372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenThis note explains how chrome://sync-internals (also known as
572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenabout:sync) interacts with the sync service/backend.
672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenBasically, chrome://sync-internals sends asynchronous messages to the
872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsensync backend and the sync backend asynchronously raises events to
972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenchrome://sync-internals, either when replying to messages or when
1072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsensomething interesting happens.
1172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
1272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenBoth messages and events have a name and a list of arguments, the
1372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenlatter of which is represented by a JsArgList (js_arg_list.h) object,
1472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenwhich is basically a wrapper around an immutable ListValue.
1572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
1672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenTODO(akalin): Move all the js_* files into a js/ subdirectory.
1772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
1872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenMessage/event flow
1972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen------------------
2072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
2172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenchrome://sync-internals is represented by SyncInternalsUI
22dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen(chrome/browser/web_ui/sync_internals_ui.h).  SyncInternalsUI
2372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monseninteracts with the sync service via a JsFrontend (js_frontend.h)
2472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenobject, which has a ProcessMessage() method.  The JsFrontend can
2572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenhandle some messages itself, but it can also delegate the rest to a
2672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenJsBackend instance (js_backend.h), which also has a ProcessMessage()
2772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenmethod.  A JsBackend can in turn handle some messages itself and
2872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsendelegate to other JsBackend instances.
2972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
3072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenEssentially, there is a tree with a JsFrontend as the root and
3172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenJsBackend as non-root internal nodes and leaf nodes (although
3272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsencurrently, the tree is more like a simple list).  The sets of messages
3372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenhandled by the JsBackends and the JsFrontend are disjoint, which means
3472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenthat at most one node handles a given message type.  Also, the
3572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenJsBackends may live on different threads, but JsArgList is thread-safe
3672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenso that's okay.
3772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
3872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenSyncInternalsUI is a JsEventHandler (js_event_handler.h), which means
3972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenthat it has a HandleJsEvent() method, but JsBackends cannot easily
4072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenaccess those objects.  Instead, each JsBackend keeps track of its
4172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenparent router, which is a JsEventRouter object (js_event_router.h).
4272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenBasically, a JsEventRouter is another JsBackend object or a JsFrontend
4372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenobject.  So an event travels up through the JsEventRouter until it
4472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenreaches the JsFrontend, which knows about the existing JsEventHandlers
4572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen(via AddHandler()/RemoveHandler()) and so can delegate to the right
4672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenone.
4772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
4872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenA diagram of the flow of a message and its reply:
4972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
5072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenmsg(args) -> F -> B -> B -> B
5172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen             |    |    |
5272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen        H <- R <- R <- R <- reply-event(args)
5372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
5472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenF = JsFrontend, B = JsBackend, R = JsEventRouter, H = JsEventHandler
5572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
5672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian MonsenNon-reply events are percolated up similarly.
57