blob: 6f33f80f11b4e70834b913ccf9ae676a261f93fe [file] [log] [blame]
morrita81b17e02015-02-06 00:58:301// 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.
4
5#include "ipc/mojo/ipc_mojo_message_helper.h"
6
7#include "ipc/mojo/ipc_mojo_handle_attachment.h"
8
9namespace IPC {
10
11// static
12bool MojoMessageHelper::WriteMessagePipeTo(
13 Message* message,
14 mojo::ScopedMessagePipeHandle handle) {
15 message->WriteAttachment(new internal::MojoHandleAttachment(
16 mojo::ScopedHandle::From(handle.Pass())));
17 return true;
18}
19
20// static
21bool MojoMessageHelper::ReadMessagePipeFrom(
22 const Message* message,
brettwbd4d7112015-06-03 04:29:2523 base::PickleIterator* iter,
morrita81b17e02015-02-06 00:58:3024 mojo::ScopedMessagePipeHandle* handle) {
25 scoped_refptr<MessageAttachment> attachment;
26 if (!message->ReadAttachment(iter, &attachment)) {
morritaa3889aa2015-03-16 22:40:5127 LOG(ERROR) << "Failed to read attachment for message pipe.";
morrita81b17e02015-02-06 00:58:3028 return false;
29 }
30
31 if (attachment->GetType() != MessageAttachment::TYPE_MOJO_HANDLE) {
morritaa3889aa2015-03-16 22:40:5132 LOG(ERROR) << "Unxpected attachment type:" << attachment->GetType();
morrita81b17e02015-02-06 00:58:3033 return false;
34 }
35
36 handle->reset(mojo::MessagePipeHandle(
37 static_cast<internal::MojoHandleAttachment*>(attachment.get())
38 ->TakeHandle()
39 .release()
40 .value()));
41 return true;
42}
43
44MojoMessageHelper::MojoMessageHelper() {
45}
46
47} // namespace IPC