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 #include "net/dns/mojo_host_struct_traits.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "net/base/address_list.h" |
| 10 |
| 11 namespace mojo { |
| 12 |
| 13 // static |
| 14 bool EnumTraits<net::interfaces::AddressFamily, net::AddressFamily>::FromMojom( |
| 15 net::interfaces::AddressFamily address_family, |
| 16 net::AddressFamily* out) { |
| 17 using net::interfaces::AddressFamily; |
| 18 switch (address_family) { |
| 19 case AddressFamily::UNSPECIFIED: |
| 20 *out = net::ADDRESS_FAMILY_UNSPECIFIED; |
| 21 return true; |
| 22 case AddressFamily::IPV4: |
| 23 *out = net::ADDRESS_FAMILY_IPV4; |
| 24 return true; |
| 25 case AddressFamily::IPV6: |
| 26 *out = net::ADDRESS_FAMILY_IPV6; |
| 27 return true; |
| 28 } |
| 29 return false; |
| 30 } |
| 31 |
| 32 // static |
| 33 net::interfaces::AddressFamily |
| 34 EnumTraits<net::interfaces::AddressFamily, net::AddressFamily>::ToMojom( |
| 35 net::AddressFamily address_family) { |
| 36 using net::interfaces::AddressFamily; |
| 37 switch (address_family) { |
| 38 case net::ADDRESS_FAMILY_UNSPECIFIED: |
| 39 return AddressFamily::UNSPECIFIED; |
| 40 case net::ADDRESS_FAMILY_IPV4: |
| 41 return AddressFamily::IPV4; |
| 42 case net::ADDRESS_FAMILY_IPV6: |
| 43 return AddressFamily::IPV6; |
| 44 } |
| 45 NOTREACHED(); |
| 46 return AddressFamily::UNSPECIFIED; |
| 47 } |
| 48 |
| 49 // static |
| 50 bool StructTraits<net::interfaces::HostResolverRequestInfoDataView, |
| 51 std::unique_ptr<net::HostResolver::RequestInfo>>:: |
| 52 Read(net::interfaces::HostResolverRequestInfoDataView data, |
| 53 std::unique_ptr<net::HostResolver::RequestInfo>* out) { |
| 54 base::StringPiece host; |
| 55 if (!data.ReadHost(&host)) |
| 56 return false; |
| 57 |
| 58 net::AddressFamily address_family; |
| 59 if (!data.ReadAddressFamily(&address_family)) |
| 60 return false; |
| 61 |
| 62 *out = base::MakeUnique<net::HostResolver::RequestInfo>( |
| 63 net::HostPortPair(host.as_string(), data.port())); |
| 64 net::HostResolver::RequestInfo& request = **out; |
| 65 request.set_address_family(address_family); |
| 66 request.set_is_my_ip_address(data.is_my_ip_address()); |
| 67 return true; |
| 68 } |
| 69 |
| 70 // static |
| 71 bool StructTraits<net::interfaces::IPEndPointDataView, net::IPEndPoint>::Read( |
| 72 net::interfaces::IPEndPointDataView data, |
| 73 net::IPEndPoint* out) { |
| 74 std::vector<uint8_t> bytes; |
| 75 if (!data.ReadAddress(&bytes)) |
| 76 return false; |
| 77 |
| 78 *out = net::IPEndPoint(net::IPAddress(bytes), data.port()); |
| 79 return true; |
| 80 } |
| 81 |
| 82 // static |
| 83 bool StructTraits<net::interfaces::AddressListDataView, net::AddressList>::Read( |
| 84 net::interfaces::AddressListDataView data, |
| 85 net::AddressList* out) { |
| 86 return data.ReadAddresses(&out->endpoints()); |
| 87 } |
| 88 |
| 89 } // namespace mojo |
OLD | NEW |