blob: 8b8344ec766c514d2a4a1c8bce92f5ca05739c66 [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
dchenge48600452015-12-28 02:24:507#include <utility>
8
morrita81b17e02015-02-06 00:58:309#include "ipc/mojo/ipc_mojo_handle_attachment.h"
10
11namespace IPC {
12
13// static
14bool MojoMessageHelper::WriteMessagePipeTo(
15 Message* message,
16 mojo::ScopedMessagePipeHandle handle) {
17 message->WriteAttachment(new internal::MojoHandleAttachment(
dchenge48600452015-12-28 02:24:5018 mojo::ScopedHandle::From(std::move(handle))));
morrita81b17e02015-02-06 00:58:3019 return true;
20}
21
22// static
23bool MojoMessageHelper::ReadMessagePipeFrom(
24 const Message* message,
brettwbd4d7112015-06-03 04:29:2525 base::PickleIterator* iter,
morrita81b17e02015-02-06 00:58:3026 mojo::ScopedMessagePipeHandle* handle) {
27 scoped_refptr<MessageAttachment> attachment;
28 if (!message->ReadAttachment(iter, &attachment)) {
morritaa3889aa2015-03-16 22:40:5129 LOG(ERROR) << "Failed to read attachment for message pipe.";
morrita81b17e02015-02-06 00:58:3030 return false;
31 }
32
33 if (attachment->GetType() != MessageAttachment::TYPE_MOJO_HANDLE) {
morritaa3889aa2015-03-16 22:40:5134 LOG(ERROR) << "Unxpected attachment type:" << attachment->GetType();
morrita81b17e02015-02-06 00:58:3035 return false;
36 }
37
38 handle->reset(mojo::MessagePipeHandle(
39 static_cast<internal::MojoHandleAttachment*>(attachment.get())
40 ->TakeHandle()
41 .release()
42 .value()));
43 return true;
44}
45
46MojoMessageHelper::MojoMessageHelper() {
47}
48
49} // namespace IPC