Chromium Code Reviews| Index: ppapi/proxy/ppapi_param_traits.cc |
| diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc |
| index 23d2b727af3ecdd2866613ae70b13765fd5ba350..93501743f6704df5476a2eaf14af21127770c759 100644 |
| --- a/ppapi/proxy/ppapi_param_traits.cc |
| +++ b/ppapi/proxy/ppapi_param_traits.cc |
| @@ -6,12 +6,14 @@ |
| #include <string.h> // For memcpy |
| +#include <limits> |
| + |
| #include "ppapi/c/pp_file_info.h" |
| #include "ppapi/c/pp_resource.h" |
| #include "ppapi/c/private/ppb_flash_tcp_socket.h" |
| #include "ppapi/proxy/ppapi_messages.h" |
| -#include "ppapi/proxy/serialized_var.h" |
| #include "ppapi/proxy/serialized_flash_menu.h" |
| +#include "ppapi/proxy/serialized_var.h" |
| #include "ppapi/shared_impl/host_resource.h" |
| namespace IPC { |
| @@ -137,6 +139,39 @@ bool ParamTraits<PP_FileInfo>::Read(const Message* m, void** iter, |
| void ParamTraits<PP_FileInfo>::Log(const param_type& p, std::string* l) { |
| } |
| +// PP_HostResolver_Private_Hint ------------------------------------------------ |
| +// static |
| +void ParamTraits<PP_HostResolver_Private_Hint>::Write(Message* m, |
| + const param_type& p) { |
| + ParamTraits<int>::Write(m, static_cast<int>(p.family)); |
| + ParamTraits<int>::Write(m, static_cast<int>(p.flags)); |
| +} |
| + |
| +// static |
| +bool ParamTraits<PP_HostResolver_Private_Hint>::Read(const Message* m, |
| + void** iter, |
| + param_type* r) { |
| + int family, flags; |
| + if (!ParamTraits<int>::Read(m, iter, &family) || |
| + !ParamTraits<int>::Read(m, iter, &flags)) { |
| + return false; |
| + } |
| + |
| + if (family != PP_NETADDRESSFAMILY_UNSPECIFIED && |
| + family != PP_NETADDRESSFAMILY_IPV4 && |
| + family != PP_NETADDRESSFAMILY_IPV6) { |
| + return false; |
| + } |
| + r->family = static_cast<PP_NetAddressFamily_Private>(family); |
| + r->flags = static_cast<PP_HostResolver_Private_Flags>(flags); |
| + return true; |
| +} |
| + |
| +// static |
| +void ParamTraits<PP_HostResolver_Private_Hint>::Log(const param_type& p, |
| + std::string* l) { |
| +} |
| + |
| // PP_NetAddress_Private ------------------------------------------------------- |
| // static |
| @@ -372,6 +407,35 @@ void ParamTraits<ppapi::proxy::SerializedFontDescription>::Log( |
| std::string* l) { |
| } |
| +// HostPortPair ---------------------------------------------------------------- |
| + |
| +// static |
| +void ParamTraits<ppapi::HostPortPair>::Write(Message* m, |
| + const param_type& p) { |
| + ParamTraits<std::string>::Write(m, p.host); |
| + ParamTraits<uint32_t>::Write(m, p.port); |
| +} |
| + |
| +// static |
| +bool ParamTraits<ppapi::HostPortPair>::Read(const Message* m, |
| + void** iter, |
| + param_type* r) { |
| + if (!ParamTraits<std::string>::Read(m, iter, &r->host)) |
| + return false; |
| + uint32_t port; |
| + if (!ParamTraits<uint32_t>::Read(m, iter, &port) || |
| + port > std::numeric_limits<uint16_t>::max()) { |
| + return false; |
| + } |
| + r->port = port; |
| + return true; |
| +} |
| + |
| +// static |
| +void ParamTraits<ppapi::HostPortPair>::Log(const param_type& p, |
| + std::string* l) { |
| +} |
| + |
| // HostResource ---------------------------------------------------------------- |
| // static |
| @@ -399,6 +463,61 @@ void ParamTraits<ppapi::HostResource>::Log(const param_type& p, |
| std::string* l) { |
| } |
| +// NameAndAddressPair ---------------------------------------------------------- |
|
yzshen1
2012/02/29 19:11:49
Is it possible to use IPC_STRUCT_TRAITS_*? And I t
ygorshenin1
2012/03/01 09:37:34
Thanks! This is greatly simplified the code.
On 2
|
| + |
| +// static |
| +void ParamTraits<ppapi::NameAndAddressPair>::Write(Message* m, |
| + const param_type& p) { |
| + ParamTraits<std::string>::Write(m, p.canonical_name); |
| + ParamTraits<PP_NetAddress_Private>::Write(m, p.address); |
| +} |
| + |
| +// static |
| +bool ParamTraits<ppapi::NameAndAddressPair>::Read(const Message* m, |
| + void** iter, |
| + param_type* r) { |
| + if (!ParamTraits<std::string>::Read(m, iter, &r->canonical_name) || |
| + !ParamTraits<PP_NetAddress_Private>::Read(m, iter, &r->address)) { |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +// static |
| +void ParamTraits<ppapi::NameAndAddressPair>::Log(const param_type& p, |
| + std::string* l) { |
| +} |
| + |
| +// NetworkList ----------------------------------------------------------------- |
| + |
| +// static |
| +void ParamTraits<ppapi::NetworkList>::Write(Message* m, const param_type& p) { |
| + ParamTraits<int>::Write(m, static_cast<int>(p.size())); |
| + for (ppapi::NetworkList::const_iterator it = p.begin(); it != p.end(); ++it) |
| + ParamTraits<ppapi::NameAndAddressPair>::Write(m, *it); |
| +} |
| + |
| +// static |
| +bool ParamTraits<ppapi::NetworkList>::Read(const Message* m, |
| + void** iter, |
| + param_type* r) { |
| + int size; |
| + if (!ParamTraits<int>::Read(m, iter, &size)) |
| + return false; |
| + |
| + r->resize(size); |
| + for (int i = 0; i < size; ++i) { |
| + if (!ParamTraits<ppapi::NameAndAddressPair>::Read(m, iter, &(*r)[i])) |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +// static |
| +void ParamTraits<ppapi::NetworkList>::Log(const param_type& p, std::string* l) { |
| +} |
| + |
| // SerializedVar --------------------------------------------------------------- |
| // static |