OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ipc/mojo/ipc_mojo_message_helper.h" | 5 #include "ipc/mojo/ipc_mojo_message_helper.h" |
6 | 6 |
7 #include "ipc/mojo/ipc_mojo_handle_attachment.h" | 7 #include "ipc/mojo/ipc_mojo_handle_attachment.h" |
8 | 8 |
9 namespace IPC { | 9 namespace IPC { |
10 | 10 |
11 // static | 11 // static |
12 bool MojoMessageHelper::WriteMessagePipeTo( | 12 bool MojoMessageHelper::WriteMessagePipeTo( |
13 Message* message, | 13 Message* message, |
14 mojo::ScopedMessagePipeHandle handle) { | 14 mojo::ScopedMessagePipeHandle handle) { |
15 message->WriteAttachment(new internal::MojoHandleAttachment( | 15 message->WriteAttachment(new internal::MojoHandleAttachment( |
16 mojo::ScopedHandle::From(handle.Pass()))); | 16 mojo::ScopedHandle::From(handle.Pass()))); |
17 return true; | 17 return true; |
18 } | 18 } |
19 | 19 |
20 // static | 20 // static |
21 bool MojoMessageHelper::ReadMessagePipeFrom( | 21 bool MojoMessageHelper::ReadMessagePipeFrom( |
22 const Message* message, | 22 const Message* message, |
23 PickleIterator* iter, | 23 base::PickleIterator* iter, |
24 mojo::ScopedMessagePipeHandle* handle) { | 24 mojo::ScopedMessagePipeHandle* handle) { |
25 scoped_refptr<MessageAttachment> attachment; | 25 scoped_refptr<MessageAttachment> attachment; |
26 if (!message->ReadAttachment(iter, &attachment)) { | 26 if (!message->ReadAttachment(iter, &attachment)) { |
27 LOG(ERROR) << "Failed to read attachment for message pipe."; | 27 LOG(ERROR) << "Failed to read attachment for message pipe."; |
28 return false; | 28 return false; |
29 } | 29 } |
30 | 30 |
31 if (attachment->GetType() != MessageAttachment::TYPE_MOJO_HANDLE) { | 31 if (attachment->GetType() != MessageAttachment::TYPE_MOJO_HANDLE) { |
32 LOG(ERROR) << "Unxpected attachment type:" << attachment->GetType(); | 32 LOG(ERROR) << "Unxpected attachment type:" << attachment->GetType(); |
33 return false; | 33 return false; |
34 } | 34 } |
35 | 35 |
36 handle->reset(mojo::MessagePipeHandle( | 36 handle->reset(mojo::MessagePipeHandle( |
37 static_cast<internal::MojoHandleAttachment*>(attachment.get()) | 37 static_cast<internal::MojoHandleAttachment*>(attachment.get()) |
38 ->TakeHandle() | 38 ->TakeHandle() |
39 .release() | 39 .release() |
40 .value())); | 40 .value())); |
41 return true; | 41 return true; |
42 } | 42 } |
43 | 43 |
44 MojoMessageHelper::MojoMessageHelper() { | 44 MojoMessageHelper::MojoMessageHelper() { |
45 } | 45 } |
46 | 46 |
47 } // namespace IPC | 47 } // namespace IPC |
OLD | NEW |