Make ICE transports injectable.

Bug: chromium:1024965
Change-Id: I4961f50aee34c82701299f59a95cb90d231db6f5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/158820
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Honghai Zhang <honghaiz@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29807}
diff --git a/api/ice_transport_interface.h b/api/ice_transport_interface.h
index 6e63045..d2f1edc 100644
--- a/api/ice_transport_interface.h
+++ b/api/ice_transport_interface.h
@@ -11,12 +11,17 @@
 #ifndef API_ICE_TRANSPORT_INTERFACE_H_
 #define API_ICE_TRANSPORT_INTERFACE_H_
 
+#include <string>
+
+#include "api/async_resolver_factory.h"
 #include "api/rtc_error.h"
+#include "api/rtc_event_log/rtc_event_log.h"
 #include "api/scoped_refptr.h"
 #include "rtc_base/ref_count.h"
 
 namespace cricket {
 class IceTransportInternal;
+class PortAllocator;
 }  // namespace cricket
 
 namespace webrtc {
@@ -34,5 +39,57 @@
   virtual cricket::IceTransportInternal* internal() = 0;
 };
 
+struct IceTransportInit final {
+ public:
+  IceTransportInit() = default;
+  IceTransportInit(const IceTransportInit&) = delete;
+  IceTransportInit(IceTransportInit&&) = default;
+  IceTransportInit& operator=(const IceTransportInit&) = delete;
+  IceTransportInit& operator=(IceTransportInit&&) = default;
+
+  cricket::PortAllocator* port_allocator() { return port_allocator_; }
+  void set_port_allocator(cricket::PortAllocator* port_allocator) {
+    port_allocator_ = port_allocator;
+  }
+
+  AsyncResolverFactory* async_resolver_factory() {
+    return async_resolver_factory_;
+  }
+  void set_async_resolver_factory(
+      AsyncResolverFactory* async_resolver_factory) {
+    async_resolver_factory_ = async_resolver_factory;
+  }
+
+  RtcEventLog* event_log() { return event_log_; }
+  void set_event_log(RtcEventLog* event_log) { event_log_ = event_log; }
+
+ private:
+  cricket::PortAllocator* port_allocator_ = nullptr;
+  AsyncResolverFactory* async_resolver_factory_ = nullptr;
+  RtcEventLog* event_log_ = nullptr;
+};
+
+// TODO(qingsi): The factory interface is defined in this file instead of its
+// namesake file ice_transport_factory.h to avoid the extra dependency on p2p/
+// introduced there by the p2p/-dependent factory methods. Move the factory
+// methods to a different file or rename it.
+class IceTransportFactory {
+ public:
+  virtual ~IceTransportFactory() = default;
+  // As a refcounted object, the returned ICE transport may outlive the host
+  // construct into which its reference is given, e.g. a peer connection. As a
+  // result, the returned ICE transport should not hold references to any object
+  // that the transport does not own and that has a lifetime bound to the host
+  // construct. Also, assumptions on the thread safety of the returned transport
+  // should be clarified by implementations. For example, a peer connection
+  // requires the returned transport to be constructed and destroyed on the
+  // network thread and an ICE transport factory that intends to work with a
+  // peer connection should offer transports compatible with these assumptions.
+  virtual rtc::scoped_refptr<IceTransportInterface> CreateIceTransport(
+      const std::string& transport_name,
+      int component,
+      IceTransportInit init) = 0;
+};
+
 }  // namespace webrtc
 #endif  // API_ICE_TRANSPORT_INTERFACE_H_