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

Issue 198343002: Mojo: request/response bindings (Closed)

Created:
6 years, 9 months ago by darin (slow to review)
Modified:
6 years, 9 months ago
Reviewers:
viettrungluu
CC:
chromium-reviews, Aaron Boodman, viettrungluu+watch_chromium.org, ben+mojo_chromium.org, abarth-chromium
Visibility:
Public.

Description

Mojo: request/response C++ bindings Introduces mojo::Callback<Sig> in the generated C++ bindings, which is used to handle asynchronous responses. base::Callback<Sig> can be adapted to mojo::Callback<Sig>, allowing for convenient use in Chromium. mojo::Callback<Sig> also defines an inner type named Runnable that can be subclassed and passed to the mojo::Callback<Sig> on construction. This is a lower-level way of initializing a mojo::Callback<Sig>. (pump.py from gtest/scripts is likewise used to generate mojo::Callback<Sig>.) In the C++ bindings, two new class types are introduced: {{class_name}}_{{method.name}}_ForwardToCallback and {{class_name}}_{{method.name}}_ProxyToResponder. *ForwardToCallback is a MessageReceiver that lives on the client side to deserialize a response Message and invoke a callback. *ProxyToResponder lives on the server side and is a Callback<Sig>::Runnable that serializes the response parameters to a Message and forwards them to a MessageReceiver (responder). In other words, the response flow starts with parameters passed to a Callback bound to a *ProxyToResponder instance, which serializes those parameters, and passes the message to the Router's MessageReceiver. This Message then appears on the client-side, and is passed to *ForwardToCallback, which was set on the client-side's Router. That *ForwardToCallback instance deserializes the message and forwards the parameters on to the client's mojo::Callback<Sig> instance. Existing jinja2 templates for proxies and stubs were refactored so that parts of them could be shared with the implementations of *ForwardToCallback and *ProxyToResponder. In addition to {{class_name}}_{{method.name}}_Params_Data, we now also have {{class_name}}_{{method.name}}_ResponseParams_Data when appropriate. Suppression of clang's -Wunused-private-field was broadened to include all of module.cc.tmpl since empty interfaces can end up with unused member variables. This seemed better than trying to avoid the member variables. public/bindings/lib/callback_internal.h resembles base/callback_internal.h a little bit. It was necessary to use unique names for some of these types though as otherwise we'd end up with conflicts when code in mojo/ uses base::Callback since it might see two classes named "internal::CallbackParamTraits", etc. This was a bit unfortunate. I inserted "_" in the mojo::internal:: names (e.g., Callback_ParamTraits) to deal with this issue. Also, unlike base::internal::CallbackParamTraits, it was necessary for mojo::internal::Callback_ParamTraits::ForwardType to be a non-reference type for primitives (e.g., int32_t). This way the signature of Callback<Sig>::Runnable::Run(...) would match the signature of our generated C++ bindings. This was a bit subtle to get right, but thanks to some template specialization based on mojo::internal::TypeTraits<T>::kIsObject, it all seems to work. Modify view_manager.mojom and command_buffer.mojom to take advantage of callbacks. R=viettrungluu@chromium.org Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=257462

Patch Set 1 #

Patch Set 2 : getting closer #

Patch Set 3 : it works #

Patch Set 4 : now, with handle passing #

Patch Set 5 : updates #

Patch Set 6 : cleanup #

Patch Set 7 : CommandBuffer::Echo() => () #

Patch Set 8 : fix compiler bustage #

Patch Set 9 : rebase #

Patch Set 10 : cleanup #

Patch Set 11 : avoid empty switch statements #

Patch Set 12 : more cleanups #

Patch Set 13 : make clang happy #

Patch Set 14 : remove unnecessary SharedPtr::reset method #

Patch Set 15 : rebase #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1153 lines, -128 lines) Patch
M mojo/examples/view_manager/view_manager.cc View 1 2 3 3 chunks +8 lines, -6 lines 0 comments Download
M mojo/examples/view_manager/view_manager.mojom View 1 2 3 1 chunk +2 lines, -4 lines 0 comments Download
M mojo/gles2/command_buffer_client_impl.h View 1 2 3 4 5 6 3 chunks +0 lines, -3 lines 0 comments Download
M mojo/gles2/command_buffer_client_impl.cc View 1 2 3 4 5 6 2 chunks +1 line, -8 lines 0 comments Download
M mojo/mojo_public.gypi View 1 2 3 4 5 6 7 8 9 4 chunks +5 lines, -0 lines 0 comments Download
A mojo/public/bindings/callback.h View 1 2 3 4 5 6 7 8 9 1 chunk +461 lines, -0 lines 0 comments Download
A mojo/public/bindings/callback.h.pump View 1 2 3 4 5 6 7 8 9 1 chunk +79 lines, -0 lines 0 comments Download
M mojo/public/bindings/generators/cpp_templates/interface_declaration.tmpl View 1 2 2 chunks +3 lines, -7 lines 0 comments Download
M mojo/public/bindings/generators/cpp_templates/interface_definition.tmpl View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 2 chunks +170 lines, -50 lines 0 comments Download
A mojo/public/bindings/generators/cpp_templates/interface_macros.tmpl View 1 2 3 4 5 6 1 chunk +23 lines, -0 lines 0 comments Download
M mojo/public/bindings/generators/cpp_templates/interface_proxy_declaration.tmpl View 1 2 1 chunk +2 lines, -4 lines 0 comments Download
M mojo/public/bindings/generators/cpp_templates/module.cc.tmpl View 1 2 3 4 5 6 7 8 9 10 11 12 3 chunks +18 lines, -8 lines 0 comments Download
M mojo/public/bindings/generators/cpp_templates/module.h.tmpl View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M mojo/public/bindings/generators/cpp_templates/params_definition.tmpl View 1 chunk +0 lines, -2 lines 0 comments Download
M mojo/public/bindings/generators/mojom_cpp_generator.py View 1 2 3 3 chunks +21 lines, -0 lines 0 comments Download
A mojo/public/bindings/lib/callback_internal.h View 1 2 3 4 1 chunk +55 lines, -0 lines 0 comments Download
M mojo/public/bindings/lib/router.cc View 1 2 3 4 4 chunks +7 lines, -4 lines 0 comments Download
M mojo/public/bindings/lib/shared_data.h View 1 2 chunks +16 lines, -2 lines 0 comments Download
A mojo/public/bindings/lib/shared_ptr.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +63 lines, -0 lines 0 comments Download
M mojo/public/bindings/message.h View 1 2 3 4 5 1 chunk +11 lines, -4 lines 0 comments Download
M mojo/public/bindings/mojom_bindings_generator.gypi View 1 2 3 4 1 chunk +1 line, -0 lines 0 comments Download
M mojo/public/bindings/pylib/generate/mojom_data.py View 1 chunk +1 line, -1 line 0 comments Download
M mojo/public/bindings/pylib/generate/mojom_generator.py View 1 chunk +9 lines, -0 lines 0 comments Download
A mojo/public/bindings/tests/request_response_unittest.cc View 1 2 3 1 chunk +140 lines, -0 lines 0 comments Download
M mojo/public/bindings/tests/router_unittest.cc View 1 2 3 4 5 6 7 6 chunks +24 lines, -21 lines 0 comments Download
A mojo/public/bindings/tests/sample_interfaces.mojom View 1 2 3 1 chunk +27 lines, -0 lines 0 comments Download
M mojo/services/gles2/command_buffer.mojom View 1 2 3 4 5 6 2 chunks +1 line, -2 lines 0 comments Download
M mojo/services/gles2/command_buffer_impl.h View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download
M mojo/services/gles2/command_buffer_impl.cc View 1 2 3 4 5 6 1 chunk +3 lines, -1 line 0 comments Download

Messages

Total messages: 5 (0 generated)
darin (slow to review)
Sorry for not breaking this up into smaller patches. There's a lot going on in ...
6 years, 9 months ago (2014-03-15 23:52:52 UTC) #1
viettrungluu
LGTM. Are you also going to update the JS generator?
6 years, 9 months ago (2014-03-17 17:02:44 UTC) #2
darin (slow to review)
The CQ bit was checked by darin@chromium.org
6 years, 9 months ago (2014-03-17 17:15:46 UTC) #3
darin (slow to review)
The CQ bit was unchecked by darin@chromium.org
6 years, 9 months ago (2014-03-17 17:15:51 UTC) #4
darin (slow to review)
6 years, 9 months ago (2014-03-17 17:44:07 UTC) #5
Message was sent while issue was closed.
Committed patchset #15 manually as r257462 (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698