Reland "Mojo C++ bindings: Serialize handles during message allocation"

This is a reland of ecf30db27d06ac0c6c61e24e811acfba32e34977

This reland changes the StructTraits for gfx::NativePixmapHandle to
behave properly. Previously the traits relied on the |fds| accessor
being called twice, returning an empty vector for sizing the first time,
and the real vector for serialization the second time. The correct thing
to do is return a reference to the vector both times, so that's what we
do now. This allows the traits to play nicely with the earlier handle
serialization behavior introduced here.

Original change's description:
> Mojo C++ bindings: Serialize handles during message allocation
> 
> This changes C++ bindings to collect handles during the message sizing
> phase of serialization so that a single Message object can be allocated
> prior to full serialization.
> 
> This reduces the cost of sending messages with attached handles. It also
> fulfills a necessary precondition for C++ bindings supporting lazy
> serialization, as it would not be possible to re-allocate a message
> object (as we do now) once a deferred serialization operation has been
> coerced by Mojo internals.
> 
> In order to support this a few changes to serialization semantics are
> applied here:
> 
>   - Handle and interface accessors on StructTraits must return lvalue
>     references as they will be called twice: once during sizing and
>     once during serialization.
>   - SetUpContext and TearDownContext are always called even for nullable
>     custom types which report themselves as null
>   - IsNull supports being called with context so that e.g. traits can
>     move or otherwise store handle and interface types in the context
>     object at context creation, and these objects may in turn need to be
>     used for nullability testing.
> 
> BUG=725321
> R=yzshen@chromium.org
> 
> Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
> Change-Id: I7056651222641220301e9adfce5028dc3501884f
> Reviewed-on: https://chromium-review.googlesource.com/546957
> Reviewed-by: Yuzhu Shen <yzshen@chromium.org>
> Commit-Queue: Ken Rockot <rockot@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#482773}

Bug: 725321
Change-Id: I8eb077324450ba6b42ac64acdd8f9d8f3c9fab38
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel

TBR=yzshen@chromium.org

Change-Id: I8eb077324450ba6b42ac64acdd8f9d8f3c9fab38
Reviewed-on: https://chromium-review.googlesource.com/552741
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Ken Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#483098}

CrOS-Libchrome-Original-Commit: 11be895df47331de2498478f18079696ae43529d
15 files changed
tree: d7189d0d9801373777ade2bac923e41a54124258
  1. base/
  2. build/
  3. components/
  4. dbus/
  5. device/
  6. ipc/
  7. mojo/
  8. testing/
  9. third_party/
  10. ui/