Reland "Use the new DNS resolver API in PeerConnection"

This reverts commit 5a40b3710545edfd8a634341df3de26f57d79281.

Reason for revert: Fixed the bug and ran layout tests.

Original change's description:
> Revert "Use the new DNS resolver API in PeerConnection"
>
> This reverts commit acf8ccb3c9f001b0ed749aca52b2d436d66f9586.
>
> Reason for revert: Speculative revert for https://ci.chromium.org/ui/p/chromium/builders/try/win10_chromium_x64_rel_ng/b8851745102358680592/overview.
>
> Original change's description:
> > Use the new DNS resolver API in PeerConnection
> >
> > Bug: webrtc:12598
> > Change-Id: I5a14058e7f28c993ed927749df7357c715ba83fb
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/212961
> > Reviewed-by: Niels Moller <nisse@webrtc.org>
> > Commit-Queue: Harald Alvestrand <hta@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#33561}
>
> # Not skipping CQ checks because original CL landed > 1 day ago.
>
> TBR=hta@webrtc.org
>
> Bug: webrtc:12598
> Change-Id: Idc9853cb569849c49052f9cbd865614710fff979
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213188
> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#33591}

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: webrtc:12598
Change-Id: Ief7867f2f23de66504877cdab1b23a11df2d5de4
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214120
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33647}
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc
index aaf7232..97dca34 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -12,6 +12,7 @@
 
 #include <limits.h>
 #include <stddef.h>
+
 #include <algorithm>
 #include <memory>
 #include <set>
@@ -33,6 +34,7 @@
 #include "media/base/rid_description.h"
 #include "media/base/stream_params.h"
 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
+#include "p2p/base/basic_async_resolver_factory.h"
 #include "p2p/base/connection.h"
 #include "p2p/base/connection_info.h"
 #include "p2p/base/dtls_transport_internal.h"
@@ -435,6 +437,30 @@
   bool is_unified_plan =
       configuration.sdp_semantics == SdpSemantics::kUnifiedPlan;
   bool dtls_enabled = DtlsEnabled(configuration, options, dependencies);
+
+  // Interim code: If an AsyncResolverFactory is given, but not an
+  // AsyncDnsResolverFactory, wrap it in a WrappingAsyncDnsResolverFactory
+  // If neither is given, create a WrappingAsyncDnsResolverFactory wrapping
+  // a BasicAsyncResolver.
+  // TODO(bugs.webrtc.org/12598): Remove code once all callers pass a
+  // AsyncDnsResolverFactory.
+  if (dependencies.async_dns_resolver_factory &&
+      dependencies.async_resolver_factory) {
+    RTC_LOG(LS_ERROR)
+        << "Attempt to set both old and new type of DNS resolver factory";
+    return RTCError(RTCErrorType::INVALID_PARAMETER,
+                    "Both old and new type of DNS resolver given");
+  }
+  if (dependencies.async_resolver_factory) {
+    dependencies.async_dns_resolver_factory =
+        std::make_unique<WrappingAsyncDnsResolverFactory>(
+            std::move(dependencies.async_resolver_factory));
+  } else {
+    dependencies.async_dns_resolver_factory =
+        std::make_unique<WrappingAsyncDnsResolverFactory>(
+            std::make_unique<BasicAsyncResolverFactory>());
+  }
+
   // The PeerConnection constructor consumes some, but not all, dependencies.
   rtc::scoped_refptr<PeerConnection> pc(
       new rtc::RefCountedObject<PeerConnection>(
@@ -462,7 +488,8 @@
       is_unified_plan_(is_unified_plan),
       event_log_(std::move(event_log)),
       event_log_ptr_(event_log_.get()),
-      async_resolver_factory_(std::move(dependencies.async_resolver_factory)),
+      async_dns_resolver_factory_(
+          std::move(dependencies.async_dns_resolver_factory)),
       port_allocator_(std::move(dependencies.allocator)),
       ice_transport_factory_(std::move(dependencies.ice_transport_factory)),
       tls_cert_verifier_(std::move(dependencies.tls_cert_verifier)),
@@ -672,7 +699,7 @@
 
   transport_controller_.reset(
       new JsepTransportController(network_thread(), port_allocator_.get(),
-                                  async_resolver_factory_.get(), config));
+                                  async_dns_resolver_factory_.get(), config));
 
   transport_controller_->SubscribeIceConnectionState(
       [this](cricket::IceConnectionState s) {