1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ipc/mojo/ipc_mojo_message_helper.h"
7 #include "ipc/mojo/ipc_mojo_handle_attachment.h"
12 bool MojoMessageHelper::WriteMessagePipeTo(
14 mojo::ScopedMessagePipeHandle handle
) {
15 message
->WriteAttachment(new internal::MojoHandleAttachment(
16 mojo::ScopedHandle::From(handle
.Pass())));
21 bool MojoMessageHelper::ReadMessagePipeFrom(
22 const Message
* message
,
24 mojo::ScopedMessagePipeHandle
* handle
) {
25 scoped_refptr
<MessageAttachment
> attachment
;
26 if (!message
->ReadAttachment(iter
, &attachment
)) {
27 LOG(ERROR
) << "Failed to read attachment for message pipe.";
31 if (attachment
->GetType() != MessageAttachment::TYPE_MOJO_HANDLE
) {
32 LOG(ERROR
) << "Unxpected attachment type:" << attachment
->GetType();
36 handle
->reset(mojo::MessagePipeHandle(
37 static_cast<internal::MojoHandleAttachment
*>(attachment
.get())
44 MojoMessageHelper::MojoMessageHelper() {