OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 // This file is used to define IPC::ParamTraits<> specializations for a number |
| 6 // of types so that they can be serialized over IPC. IPC::ParamTraits<> |
| 7 // specializations for basic types (like int and std::string) and types in the |
| 8 // 'base' project can be found in ipc/ipc_message_utils.h. This file contains |
| 9 // specializations for types that are used by the content code, and which need |
| 10 // manual serialization code. This is usually because they're not structs with |
| 11 // public members, or because the same type is being used in multiple |
| 12 // *_messages.h headers. |
| 13 |
| 14 #ifndef CONTENT_COMMON_INPUT_INPUT_PARAM_TRAITS_H_ |
| 15 #define CONTENT_COMMON_INPUT_INPUT_PARAM_TRAITS_H_ |
| 16 |
| 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "content/common/input/event_packet.h" |
| 19 #include "content/common/input/input_param_traits_macros.h" |
| 20 #include "content/common/input/web_event.h" |
| 21 |
| 22 namespace IPC { |
| 23 |
| 24 // TODO(jdduke): There should be a common copy of this utility somewhere... Move |
| 25 // or remove appropriately. |
| 26 template<class P> |
| 27 struct ParamTraits<scoped_ptr<P> > { |
| 28 typedef scoped_ptr<P> param_type; |
| 29 static void Write(Message* m, const param_type& p) { |
| 30 bool valid = !!p; |
| 31 WriteParam(m, valid); |
| 32 if (valid) |
| 33 WriteParam(m, *p); |
| 34 } |
| 35 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| 36 bool valid = false; |
| 37 if (!ReadParam(m, iter, &valid)) |
| 38 return false; |
| 39 |
| 40 if (!valid) { |
| 41 r->reset(); |
| 42 return true; |
| 43 } |
| 44 |
| 45 param_type temp(new P()); |
| 46 if (!ReadParam(m, iter, temp.get())) |
| 47 return false; |
| 48 |
| 49 r->swap(temp); |
| 50 return true; |
| 51 } |
| 52 static void Log(const param_type& p, std::string* l) { |
| 53 if (p) |
| 54 LogParam(*p, l); |
| 55 } |
| 56 }; |
| 57 |
| 58 template <> |
| 59 struct CONTENT_EXPORT ParamTraits<content::EventPacket> { |
| 60 typedef content::EventPacket param_type; |
| 61 static void Write(Message* m, const param_type& p); |
| 62 static bool Read(const Message* m, PickleIterator* iter, param_type* r); |
| 63 static void Log(const param_type& p, std::string* l); |
| 64 }; |
| 65 |
| 66 template <> |
| 67 struct CONTENT_EXPORT ParamTraits<content::WebEvent> { |
| 68 typedef content::WebEvent param_type; |
| 69 static void Write(Message* m, const param_type& p); |
| 70 static bool Read(const Message* m, PickleIterator* iter, param_type* r); |
| 71 static void Log(const param_type& p, std::string* l); |
| 72 }; |
| 73 |
| 74 } // namespace IPC |
| 75 |
| 76 #endif // CONTENT_COMMON_CONTENT_PARAM_TRAITS_H_ |
OLD | NEW |