Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Unified Diff: net/dns/mojo_host_type_converters.cc

Issue 2083463002: Replace //net TypeConverters with StructTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@type-converter-cleanup--gurl
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/dns/mojo_host_type_converters.cc
diff --git a/net/dns/mojo_host_type_converters.cc b/net/dns/mojo_host_type_converters.cc
deleted file mode 100644
index 760ee3ba1642a6d374e15d92d21db7c8f17d4505..0000000000000000000000000000000000000000
--- a/net/dns/mojo_host_type_converters.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/dns/mojo_host_type_converters.h"
-
-#include <utility>
-
-#include "mojo/public/cpp/bindings/type_converter.h"
-#include "net/base/address_list.h"
-
-namespace net {
-namespace {
-
-AddressFamily AddressFamilyFromMojo(interfaces::AddressFamily address_family) {
- switch (address_family) {
- case interfaces::AddressFamily::UNSPECIFIED:
- return ADDRESS_FAMILY_UNSPECIFIED;
- case interfaces::AddressFamily::IPV4:
- return ADDRESS_FAMILY_IPV4;
- case interfaces::AddressFamily::IPV6:
- return ADDRESS_FAMILY_IPV6;
- }
- NOTREACHED();
- return ADDRESS_FAMILY_UNSPECIFIED;
-}
-
-interfaces::AddressFamily AddressFamilyToMojo(AddressFamily address_family) {
- switch (address_family) {
- case ADDRESS_FAMILY_UNSPECIFIED:
- return interfaces::AddressFamily::UNSPECIFIED;
- case ADDRESS_FAMILY_IPV4:
- return interfaces::AddressFamily::IPV4;
- case ADDRESS_FAMILY_IPV6:
- return interfaces::AddressFamily::IPV6;
- }
- NOTREACHED();
- return interfaces::AddressFamily::UNSPECIFIED;
-}
-
-} // namespace
-} // namespace net
-
-namespace mojo {
-
-// static
-net::HostResolver::RequestInfo
-TypeConverter<net::HostResolver::RequestInfo,
- net::interfaces::HostResolverRequestInfo>::
- Convert(const net::interfaces::HostResolverRequestInfo& obj) {
- net::HostResolver::RequestInfo result(net::HostPortPair(obj.host, obj.port));
- result.set_address_family(net::AddressFamilyFromMojo(obj.address_family));
- result.set_is_my_ip_address(obj.is_my_ip_address);
- return result;
-}
-
-// static
-net::interfaces::HostResolverRequestInfoPtr
-TypeConverter<net::interfaces::HostResolverRequestInfoPtr,
- net::HostResolver::RequestInfo>::
- Convert(const net::HostResolver::RequestInfo& obj) {
- net::interfaces::HostResolverRequestInfoPtr result(
- net::interfaces::HostResolverRequestInfo::New());
- result->host = obj.hostname();
- result->port = obj.port();
- result->address_family = net::AddressFamilyToMojo(obj.address_family());
- result->is_my_ip_address = obj.is_my_ip_address();
- return result;
-}
-
-// static
-net::interfaces::AddressListPtr
-TypeConverter<net::interfaces::AddressListPtr, net::AddressList>::Convert(
- const net::AddressList& obj) {
- net::interfaces::AddressListPtr result(net::interfaces::AddressList::New());
- for (const auto& endpoint : obj) {
- net::interfaces::IPEndPointPtr ep(net::interfaces::IPEndPoint::New());
- ep->port = endpoint.port();
- ep->address = mojo::Array<uint8_t>::From(endpoint.address().bytes());
- result->addresses.push_back(std::move(ep));
- }
- return result;
-}
-
-// static
-net::AddressList
-TypeConverter<net::AddressList, net::interfaces::AddressList>::Convert(
- const net::interfaces::AddressList& obj) {
- net::AddressList address_list;
- for (size_t i = 0; i < obj.addresses.size(); i++) {
- const net::interfaces::IPEndPointPtr& ep = obj.addresses[i];
- net::IPAddress ip_address(ep->address.To<std::vector<uint8_t>>());
- address_list.push_back(net::IPEndPoint(ip_address, ep->port));
- }
- return address_list;
-}
-
-} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698