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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ipc/mojo/ipc_mojo_handle_attachment.h" | 9 #include "ipc/mojo/ipc_mojo_handle_attachment.h" |
10 | 10 |
11 namespace IPC { | 11 namespace IPC { |
12 | 12 |
13 // static | 13 // static |
14 bool MojoMessageHelper::WriteMessagePipeTo( | 14 bool MojoMessageHelper::WriteMessagePipeTo( |
15 Message* message, | 15 base::Pickle* message, |
16 mojo::ScopedMessagePipeHandle handle) { | 16 mojo::ScopedMessagePipeHandle handle) { |
17 message->WriteAttachment(new internal::MojoHandleAttachment( | 17 message->WriteAttachment(new internal::MojoHandleAttachment( |
18 mojo::ScopedHandle::From(std::move(handle)))); | 18 mojo::ScopedHandle::From(std::move(handle)))); |
19 return true; | 19 return true; |
20 } | 20 } |
21 | 21 |
22 // static | 22 // static |
23 bool MojoMessageHelper::ReadMessagePipeFrom( | 23 bool MojoMessageHelper::ReadMessagePipeFrom( |
24 const Message* message, | 24 const base::Pickle* message, |
25 base::PickleIterator* iter, | 25 base::PickleIterator* iter, |
26 mojo::ScopedMessagePipeHandle* handle) { | 26 mojo::ScopedMessagePipeHandle* handle) { |
27 scoped_refptr<MessageAttachment> attachment; | 27 scoped_refptr<base::Pickle::Attachment> attachment; |
28 if (!message->ReadAttachment(iter, &attachment)) { | 28 if (!message->ReadAttachment(iter, &attachment)) { |
29 LOG(ERROR) << "Failed to read attachment for message pipe."; | 29 LOG(ERROR) << "Failed to read attachment for message pipe."; |
30 return false; | 30 return false; |
31 } | 31 } |
32 | 32 |
33 if (attachment->GetType() != MessageAttachment::TYPE_MOJO_HANDLE) { | 33 MessageAttachment::Type type = |
34 LOG(ERROR) << "Unxpected attachment type:" << attachment->GetType(); | 34 static_cast<MessageAttachment*>(attachment.get())->GetType(); |
| 35 if (type != MessageAttachment::TYPE_MOJO_HANDLE) { |
| 36 LOG(ERROR) << "Unxpected attachment type:" << type; |
35 return false; | 37 return false; |
36 } | 38 } |
37 | 39 |
38 handle->reset(mojo::MessagePipeHandle( | 40 handle->reset(mojo::MessagePipeHandle( |
39 static_cast<internal::MojoHandleAttachment*>(attachment.get()) | 41 static_cast<internal::MojoHandleAttachment*>(attachment.get()) |
40 ->TakeHandle() | 42 ->TakeHandle() |
41 .release() | 43 .release() |
42 .value())); | 44 .value())); |
43 return true; | 45 return true; |
44 } | 46 } |
45 | 47 |
46 MojoMessageHelper::MojoMessageHelper() { | 48 MojoMessageHelper::MojoMessageHelper() { |
47 } | 49 } |
48 | 50 |
49 } // namespace IPC | 51 } // namespace IPC |
OLD | NEW |