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 
5 #include "ipc/ipc_mojo_param_traits.h"
6 
7 #include "ipc/ipc_message_utils.h"
8 #include "ipc/ipc_mojo_message_helper.h"
9 
10 namespace IPC {
11 
GetSize(base::PickleSizer * sizer,const param_type & p)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 
Write(base::Pickle * m,const param_type & p)19 void ParamTraits<mojo::MessagePipeHandle>::Write(base::Pickle* m,
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 
Read(const base::Pickle * m,base::PickleIterator * iter,param_type * r)26 bool ParamTraits<mojo::MessagePipeHandle>::Read(const base::Pickle* m,
27                                                 base::PickleIterator* iter,
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 
Log(const param_type & p,std::string * l)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
51