Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ipc_mojo_param_traits.h" | 5 #include "ipc/ipc_mojo_param_traits.h" |
| 6 | 6 |
| 7 #include "ipc/ipc_message_utils.h" | 7 #include "ipc/ipc_message_utils.h" |
| 8 #include "ipc/ipc_mojo_handle_attachment.h" | |
| 8 #include "ipc/ipc_mojo_message_helper.h" | 9 #include "ipc/ipc_mojo_message_helper.h" |
| 9 | 10 |
| 10 namespace IPC { | 11 namespace IPC { |
| 11 | 12 |
| 12 void ParamTraits<mojo::MessagePipeHandle>::GetSize(base::PickleSizer* sizer, | 13 void ParamTraits<mojo::MessagePipeHandle>::GetSize(base::PickleSizer* sizer, |
| 13 const param_type& p) { | 14 const param_type& p) { |
| 14 GetParamSize(sizer, p.is_valid()); | 15 GetParamSize(sizer, p.is_valid()); |
| 15 if (p.is_valid()) | 16 if (p.is_valid()) |
| 16 sizer->AddAttachment(); | 17 sizer->AddAttachment(); |
| 17 } | 18 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 40 return true; | 41 return true; |
| 41 } | 42 } |
| 42 | 43 |
| 43 void ParamTraits<mojo::MessagePipeHandle>::Log(const param_type& p, | 44 void ParamTraits<mojo::MessagePipeHandle>::Log(const param_type& p, |
| 44 std::string* l) { | 45 std::string* l) { |
| 45 l->append("mojo::MessagePipeHandle("); | 46 l->append("mojo::MessagePipeHandle("); |
| 46 LogParam(p.value(), l); | 47 LogParam(p.value(), l); |
| 47 l->append(")"); | 48 l->append(")"); |
| 48 } | 49 } |
| 49 | 50 |
| 51 void ParamTraits<mojo::DataPipeConsumerHandle>::GetSize( | |
| 52 base::PickleSizer* sizer, | |
| 53 const param_type& p) { | |
| 54 GetParamSize(sizer, p.is_valid()); | |
| 55 if (p.is_valid()) | |
| 56 sizer->AddAttachment(); | |
| 57 } | |
| 58 | |
| 59 void ParamTraits<mojo::DataPipeConsumerHandle>::Write(base::Pickle* m, | |
| 60 const param_type& p) { | |
| 61 WriteParam(m, p.is_valid()); | |
| 62 if (!p.is_valid()) | |
| 63 return; | |
| 64 | |
| 65 m->WriteAttachment(new internal::MojoHandleAttachment( | |
| 66 mojo::ScopedHandle::From(mojo::ScopedDataPipeConsumerHandle(p)))); | |
| 67 } | |
| 68 | |
| 69 bool ParamTraits<mojo::DataPipeConsumerHandle>::Read(const base::Pickle* m, | |
| 70 base::PickleIterator* iter, | |
| 71 param_type* r) { | |
| 72 bool is_valid; | |
| 73 if (!ReadParam(m, iter, &is_valid)) | |
| 74 return false; | |
| 75 if (!is_valid) | |
| 76 return true; | |
| 77 | |
| 78 scoped_refptr<base::Pickle::Attachment> attachment; | |
| 79 if (!m->ReadAttachment(iter, &attachment)) { | |
| 80 LOG(ERROR) << "Failed to read attachment for message pipe."; | |
|
dcheng
2017/04/12 21:18:16
Nit: DLOG(ERROR) here and 87
scottmg
2017/04/12 21:28:51
Done.
| |
| 81 return false; | |
| 82 } | |
| 83 | |
| 84 MessageAttachment::Type type = | |
| 85 static_cast<MessageAttachment*>(attachment.get())->GetType(); | |
| 86 if (type != MessageAttachment::Type::MOJO_HANDLE) { | |
| 87 LOG(ERROR) << "Unxpected attachment type:" << type; | |
| 88 return false; | |
| 89 } | |
| 90 | |
| 91 mojo::ScopedDataPipeConsumerHandle handle; | |
| 92 handle.reset(mojo::DataPipeConsumerHandle( | |
| 93 static_cast<internal::MojoHandleAttachment*>(attachment.get()) | |
| 94 ->TakeHandle() | |
| 95 .release() | |
| 96 .value())); | |
| 97 DCHECK(handle.is_valid()); | |
| 98 *r = handle.release(); | |
| 99 return true; | |
| 100 } | |
| 101 | |
| 102 void ParamTraits<mojo::DataPipeConsumerHandle>::Log(const param_type& p, | |
| 103 std::string* l) { | |
| 104 l->append("mojo::DataPipeConsumerHandle("); | |
| 105 LogParam(p.value(), l); | |
| 106 l->append(")"); | |
| 107 } | |
| 108 | |
| 50 } // namespace IPC | 109 } // namespace IPC |
| OLD | NEW |