Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 #ifndef NET_DNS_MOJO_HOST_STRUCT_TRAITS_H_ | |
| 6 #define NET_DNS_MOJO_HOST_STRUCT_TRAITS_H_ | |
| 7 | |
| 8 #include "base/strings/string_piece.h" | |
| 9 #include "mojo/public/cpp/bindings/enum_traits.h" | |
| 10 #include "mojo/public/cpp/bindings/struct_traits.h" | |
| 11 #include "net/dns/host_resolver.h" | |
| 12 #include "net/interfaces/host_resolver_service.mojom.h" | |
| 13 | |
| 14 namespace mojo { | |
| 15 | |
| 16 template <> | |
| 17 struct EnumTraits<net::interfaces::AddressFamily, net::AddressFamily> { | |
| 18 static net::interfaces::AddressFamily ToMojom( | |
| 19 net::AddressFamily address_family); | |
| 20 static bool FromMojom(net::interfaces::AddressFamily address_family, | |
| 21 net::AddressFamily* out); | |
| 22 }; | |
| 23 | |
| 24 template <> | |
| 25 struct StructTraits<net::interfaces::HostResolverRequestInfo, | |
| 26 std::unique_ptr<net::HostResolver::RequestInfo>> { | |
| 27 static base::StringPiece host( | |
| 28 const std::unique_ptr<net::HostResolver::RequestInfo>& obj) { | |
| 29 return obj->hostname(); | |
| 30 } | |
| 31 | |
| 32 static uint16_t port( | |
| 33 const std::unique_ptr<net::HostResolver::RequestInfo>& obj) { | |
| 34 return obj->port(); | |
| 35 } | |
| 36 | |
| 37 static net::AddressFamily address_family( | |
| 38 const std::unique_ptr<net::HostResolver::RequestInfo>& obj) { | |
| 39 return obj->address_family(); | |
| 40 } | |
| 41 | |
| 42 static bool is_my_ip_address( | |
| 43 const std::unique_ptr<net::HostResolver::RequestInfo>& obj) { | |
| 44 return obj->is_my_ip_address(); | |
| 45 } | |
| 46 | |
| 47 static bool Read(net::interfaces::HostResolverRequestInfoDataView obj, | |
| 48 std::unique_ptr<net::HostResolver::RequestInfo>* output); | |
| 49 }; | |
| 50 | |
| 51 template <> | |
| 52 struct StructTraits<net::interfaces::IPEndPoint, net::IPEndPoint> { | |
| 53 static const std::vector<uint8_t>& address(const net::IPEndPoint& obj) { | |
| 54 return obj.address().bytes(); | |
| 55 } | |
| 56 static uint16_t port(const net::IPEndPoint& obj) { return obj.port(); } | |
| 57 | |
| 58 static bool Read(net::interfaces::IPEndPointDataView obj, | |
| 59 net::IPEndPoint* out); | |
| 60 }; | |
| 61 | |
| 62 template <> | |
| 63 struct StructTraits<net::interfaces::AddressList, net::AddressList> { | |
| 64 static std::vector<net::IPEndPoint> addresses(const net::AddressList& obj) { | |
| 65 std::vector<net::IPEndPoint> address_list(obj.begin(), obj.end()); | |
|
dcheng
2016/06/27 03:50:45
My understanding is this gets called multiple time
Sam McNally
2016/06/29 01:42:07
Done.
| |
| 66 return address_list; | |
| 67 } | |
| 68 | |
| 69 static bool Read(net::interfaces::AddressListDataView data, | |
| 70 net::AddressList* out); | |
| 71 }; | |
| 72 | |
| 73 } // namespace mojo | |
| 74 | |
| 75 #endif // NET_DNS_MOJO_HOST_STRUCT_TRAITS_H_ | |
| OLD | NEW |