morrita | 76a6992 | 2015-04-03 14:28:21 +0900 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
amistry | 6555e69 | 2016-06-23 16:52:37 +0900 | [diff] [blame] | 5 | #include "ipc/ipc_mojo_param_traits.h" |
morrita | 76a6992 | 2015-04-03 14:28:21 +0900 | [diff] [blame] | 6 | |
| 7 | #include "ipc/ipc_message_utils.h" |
amistry | 6555e69 | 2016-06-23 16:52:37 +0900 | [diff] [blame] | 8 | #include "ipc/ipc_mojo_message_helper.h" |
morrita | 76a6992 | 2015-04-03 14:28:21 +0900 | [diff] [blame] | 9 | |
| 10 | namespace IPC { |
| 11 | |
amistry | 70d6357 | 2016-06-27 15:34:42 +0900 | [diff] [blame] | 12 | void ParamTraits<mojo::MessagePipeHandle>::GetSize(base::PickleSizer* sizer, |
| 13 | const param_type& p) { |
| 14 | GetParamSize(sizer, p.is_valid()); |
| 15 | if (p.is_valid()) |
| 16 | sizer->AddAttachment(); |
| 17 | } |
| 18 | |
| 19 | void ParamTraits<mojo::MessagePipeHandle>::Write(base::Pickle* m, |
morrita | 76a6992 | 2015-04-03 14:28:21 +0900 | [diff] [blame] | 20 | const param_type& p) { |
| 21 | WriteParam(m, p.is_valid()); |
| 22 | if (p.is_valid()) |
| 23 | MojoMessageHelper::WriteMessagePipeTo(m, mojo::ScopedMessagePipeHandle(p)); |
| 24 | } |
| 25 | |
amistry | 70d6357 | 2016-06-27 15:34:42 +0900 | [diff] [blame] | 26 | bool ParamTraits<mojo::MessagePipeHandle>::Read(const base::Pickle* m, |
brettw | f314620 | 2015-06-03 13:29:25 +0900 | [diff] [blame] | 27 | base::PickleIterator* iter, |
morrita | 76a6992 | 2015-04-03 14:28:21 +0900 | [diff] [blame] | 28 | param_type* r) { |
| 29 | bool is_valid; |
| 30 | if (!ReadParam(m, iter, &is_valid)) |
| 31 | return false; |
| 32 | if (!is_valid) |
| 33 | return true; |
| 34 | |
| 35 | mojo::ScopedMessagePipeHandle handle; |
| 36 | if (!MojoMessageHelper::ReadMessagePipeFrom(m, iter, &handle)) |
| 37 | return false; |
| 38 | DCHECK(handle.is_valid()); |
| 39 | *r = handle.release(); |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | void ParamTraits<mojo::MessagePipeHandle>::Log(const param_type& p, |
| 44 | std::string* l) { |
| 45 | l->append("mojo::MessagePipeHandle("); |
| 46 | LogParam(p.value(), l); |
| 47 | l->append(")"); |
| 48 | } |
| 49 | |
| 50 | } // namespace IPC |