Create PeerConnectionFactoryDependencies to prevent new function overloads.

To address this, this CL introduces a PeerConnectionFactoryDependencies
structure to encapsulate all mandatory and optional dependencies (where a
dependency is defined as non trivial executable code that an API user may want
to provide to the native API). This allows adding a new injectable dependency
by simply adding a new field to the struct, avoiding the hassle described above.

Bug: webrtc:7913
Change-Id: Ice58fa72e8c578b250084a1629499fabda66dabf
Reviewed-on: https://webrtc-review.googlesource.com/79720
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Benjamin Wright <benwright@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23480}
diff --git a/api/peerconnectioninterface.h b/api/peerconnectioninterface.h
index fa94093..5397969 100644
--- a/api/peerconnectioninterface.h
+++ b/api/peerconnectioninterface.h
@@ -1205,6 +1205,36 @@
   std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier;
 };
 
+// PeerConnectionFactoryDependencies holds all of the PeerConnectionFactory
+// dependencies. All new dependencies should be added here instead of
+// overloading the function. This simplifies dependency injection and makes it
+// clear which are mandatory and optional. If possible please allow the peer
+// connection factory to take ownership of the dependency by adding a unique_ptr
+// to this structure.
+struct PeerConnectionFactoryDependencies final {
+  PeerConnectionFactoryDependencies() = default;
+  // This object is not copyable or assignable.
+  PeerConnectionFactoryDependencies(const PeerConnectionFactoryDependencies&) =
+      delete;
+  PeerConnectionFactoryDependencies& operator=(
+      const PeerConnectionFactoryDependencies&) = delete;
+  // This object is only moveable.
+  PeerConnectionFactoryDependencies(PeerConnectionFactoryDependencies&&) =
+      default;
+  PeerConnectionFactoryDependencies& operator=(
+      PeerConnectionFactoryDependencies&&) = default;
+
+  // Optional dependencies
+  rtc::Thread* network_thread = nullptr;
+  rtc::Thread* worker_thread = nullptr;
+  rtc::Thread* signaling_thread = nullptr;
+  std::unique_ptr<cricket::MediaEngineInterface> media_engine;
+  std::unique_ptr<CallFactoryInterface> call_factory;
+  std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory;
+  std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory;
+  std::unique_ptr<NetworkControllerFactoryInterface> network_controller_factory;
+};
+
 // PeerConnectionFactoryInterface is the factory interface used for creating
 // PeerConnection, MediaStream and MediaStreamTrack objects.
 //
@@ -1555,6 +1585,10 @@
     std::unique_ptr<NetworkControllerFactoryInterface>
         network_controller_factory = nullptr);
 
+rtc::scoped_refptr<PeerConnectionFactoryInterface>
+CreateModularPeerConnectionFactory(
+    PeerConnectionFactoryDependencies dependencies);
+
 }  // namespace webrtc
 
 #endif  // API_PEERCONNECTIONINTERFACE_H_