| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // This file is used to define IPC::ParamTraits<> specializations for a number | 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<> | 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 | 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 | 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 | 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 | 10 // manual serialization code. This is usually because they're not structs with |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 class HostPortPair; | 40 class HostPortPair; |
| 41 class IPAddress; | 41 class IPAddress; |
| 42 class IPEndPoint; | 42 class IPEndPoint; |
| 43 } | 43 } |
| 44 | 44 |
| 45 namespace IPC { | 45 namespace IPC { |
| 46 | 46 |
| 47 template <> | 47 template <> |
| 48 struct CONTENT_EXPORT ParamTraits<GURL> { | 48 struct CONTENT_EXPORT ParamTraits<GURL> { |
| 49 typedef GURL param_type; | 49 typedef GURL param_type; |
| 50 static void Write(Message* m, const param_type& p); | 50 static void Write(base::Pickle* m, const param_type& p); |
| 51 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); | 51 static bool Read(const base::Pickle* m, |
| 52 base::PickleIterator* iter, |
| 53 param_type* p); |
| 52 static void Log(const param_type& p, std::string* l); | 54 static void Log(const param_type& p, std::string* l); |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 template <> | 57 template <> |
| 56 struct CONTENT_EXPORT ParamTraits<url::Origin> { | 58 struct CONTENT_EXPORT ParamTraits<url::Origin> { |
| 57 typedef url::Origin param_type; | 59 typedef url::Origin param_type; |
| 58 static void Write(Message* m, const param_type& p); | 60 static void Write(base::Pickle* m, const param_type& p); |
| 59 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); | 61 static bool Read(const base::Pickle* m, |
| 62 base::PickleIterator* iter, |
| 63 param_type* p); |
| 60 static void Log(const param_type& p, std::string* l); | 64 static void Log(const param_type& p, std::string* l); |
| 61 }; | 65 }; |
| 62 | 66 |
| 63 template<> | 67 template<> |
| 64 struct CONTENT_EXPORT ParamTraits<net::HostPortPair> { | 68 struct CONTENT_EXPORT ParamTraits<net::HostPortPair> { |
| 65 typedef net::HostPortPair param_type; | 69 typedef net::HostPortPair param_type; |
| 66 static void Write(Message* m, const param_type& p); | 70 static void Write(base::Pickle* m, const param_type& p); |
| 67 static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); | 71 static bool Read(const base::Pickle* m, |
| 72 base::PickleIterator* iter, |
| 73 param_type* r); |
| 68 static void Log(const param_type& p, std::string* l); | 74 static void Log(const param_type& p, std::string* l); |
| 69 }; | 75 }; |
| 70 | 76 |
| 71 template <> | 77 template <> |
| 72 struct CONTENT_EXPORT ParamTraits<net::IPEndPoint> { | 78 struct CONTENT_EXPORT ParamTraits<net::IPEndPoint> { |
| 73 typedef net::IPEndPoint param_type; | 79 typedef net::IPEndPoint param_type; |
| 74 static void Write(Message* m, const param_type& p); | 80 static void Write(base::Pickle* m, const param_type& p); |
| 75 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); | 81 static bool Read(const base::Pickle* m, |
| 82 base::PickleIterator* iter, |
| 83 param_type* p); |
| 76 static void Log(const param_type& p, std::string* l); | 84 static void Log(const param_type& p, std::string* l); |
| 77 }; | 85 }; |
| 78 | 86 |
| 79 template <> | 87 template <> |
| 80 struct CONTENT_EXPORT ParamTraits<net::IPAddress> { | 88 struct CONTENT_EXPORT ParamTraits<net::IPAddress> { |
| 81 typedef net::IPAddress param_type; | 89 typedef net::IPAddress param_type; |
| 82 static void Write(Message* m, const param_type& p); | 90 static void Write(base::Pickle* m, const param_type& p); |
| 83 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); | 91 static bool Read(const base::Pickle* m, |
| 92 base::PickleIterator* iter, |
| 93 param_type* p); |
| 84 static void Log(const param_type& p, std::string* l); | 94 static void Log(const param_type& p, std::string* l); |
| 85 }; | 95 }; |
| 86 | 96 |
| 87 template <> | 97 template <> |
| 88 struct CONTENT_EXPORT ParamTraits<content::PageState> { | 98 struct CONTENT_EXPORT ParamTraits<content::PageState> { |
| 89 typedef content::PageState param_type; | 99 typedef content::PageState param_type; |
| 90 static void Write(Message* m, const param_type& p); | 100 static void Write(base::Pickle* m, const param_type& p); |
| 91 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); | 101 static bool Read(const base::Pickle* m, |
| 102 base::PickleIterator* iter, |
| 103 param_type* p); |
| 92 static void Log(const param_type& p, std::string* l); | 104 static void Log(const param_type& p, std::string* l); |
| 93 }; | 105 }; |
| 94 | 106 |
| 95 template <> | 107 template <> |
| 96 struct ParamTraits<gfx::NativeWindow> { | 108 struct ParamTraits<gfx::NativeWindow> { |
| 97 typedef gfx::NativeWindow param_type; | 109 typedef gfx::NativeWindow param_type; |
| 98 static void Write(Message* m, const param_type& p) { | 110 static void Write(base::Pickle* m, const param_type& p) { |
| 99 #if defined(OS_WIN) | 111 #if defined(OS_WIN) |
| 100 m->WriteUInt32(base::win::HandleToUint32(p)); | 112 m->WriteUInt32(base::win::HandleToUint32(p)); |
| 101 #else | 113 #else |
| 102 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p)); | 114 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p)); |
| 103 #endif | 115 #endif |
| 104 } | 116 } |
| 105 static bool Read(const Message* m, base::PickleIterator* iter, | 117 static bool Read(const base::Pickle* m, |
| 118 base::PickleIterator* iter, |
| 106 param_type* r) { | 119 param_type* r) { |
| 107 #if defined(OS_WIN) | 120 #if defined(OS_WIN) |
| 108 return iter->ReadUInt32(reinterpret_cast<uint32_t*>(r)); | 121 return iter->ReadUInt32(reinterpret_cast<uint32_t*>(r)); |
| 109 #else | 122 #else |
| 110 const char *data; | 123 const char *data; |
| 111 int data_size = 0; | 124 int data_size = 0; |
| 112 bool result = iter->ReadData(&data, &data_size); | 125 bool result = iter->ReadData(&data, &data_size); |
| 113 if (result && data_size == sizeof(gfx::NativeWindow)) { | 126 if (result && data_size == sizeof(gfx::NativeWindow)) { |
| 114 memcpy(r, data, sizeof(gfx::NativeWindow)); | 127 memcpy(r, data, sizeof(gfx::NativeWindow)); |
| 115 } else { | 128 } else { |
| 116 result = false; | 129 result = false; |
| 117 NOTREACHED(); | 130 NOTREACHED(); |
| 118 } | 131 } |
| 119 return result; | 132 return result; |
| 120 #endif | 133 #endif |
| 121 } | 134 } |
| 122 static void Log(const param_type& p, std::string* l) { | 135 static void Log(const param_type& p, std::string* l) { |
| 123 l->append("<gfx::NativeWindow>"); | 136 l->append("<gfx::NativeWindow>"); |
| 124 } | 137 } |
| 125 }; | 138 }; |
| 126 | 139 |
| 127 } // namespace IPC | 140 } // namespace IPC |
| 128 | 141 |
| 129 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ | 142 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ |
| OLD | NEW |