Make PeerConnectionFactory constructor taking dependency the only constructor

Bug: None
Change-Id: I19e9fab1ecec3799cc7b8573ab3fd6b258114cce
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128601
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27194}
diff --git a/pc/peer_connection_factory.cc b/pc/peer_connection_factory.cc
index 9fd8b73..4c89120 100644
--- a/pc/peer_connection_factory.cc
+++ b/pc/peer_connection_factory.cc
@@ -101,41 +101,19 @@
 }
 
 PeerConnectionFactory::PeerConnectionFactory(
-    rtc::Thread* network_thread,
-    rtc::Thread* worker_thread,
-    rtc::Thread* signaling_thread,
-    std::unique_ptr<cricket::MediaEngineInterface> media_engine,
-    std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
-    std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory)
-    : PeerConnectionFactory(network_thread,
-                            worker_thread,
-                            signaling_thread,
-                            std::move(media_engine),
-                            std::move(call_factory),
-                            std::move(event_log_factory),
-                            nullptr,
-                            nullptr) {}
-
-PeerConnectionFactory::PeerConnectionFactory(
-    rtc::Thread* network_thread,
-    rtc::Thread* worker_thread,
-    rtc::Thread* signaling_thread,
-    std::unique_ptr<cricket::MediaEngineInterface> media_engine,
-    std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
-    std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory,
-    std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
-    std::unique_ptr<NetworkControllerFactoryInterface>
-        network_controller_factory)
+    PeerConnectionFactoryDependencies dependencies)
     : wraps_current_thread_(false),
-      network_thread_(network_thread),
-      worker_thread_(worker_thread),
-      signaling_thread_(signaling_thread),
-      media_engine_(std::move(media_engine)),
-      call_factory_(std::move(call_factory)),
-      event_log_factory_(std::move(event_log_factory)),
-      fec_controller_factory_(std::move(fec_controller_factory)),
+      network_thread_(dependencies.network_thread),
+      worker_thread_(dependencies.worker_thread),
+      signaling_thread_(dependencies.signaling_thread),
+      media_engine_(std::move(dependencies.media_engine)),
+      call_factory_(std::move(dependencies.call_factory)),
+      event_log_factory_(std::move(dependencies.event_log_factory)),
+      fec_controller_factory_(std::move(dependencies.fec_controller_factory)),
       injected_network_controller_factory_(
-          std::move(network_controller_factory)) {
+          std::move(dependencies.network_controller_factory)),
+      media_transport_factory_(
+          std::move(dependencies.media_transport_factory)) {
   if (!network_thread_) {
     owned_network_thread_ = rtc::Thread::CreateWithSocketServer();
     owned_network_thread_->SetName("pc_network_thread", nullptr);
@@ -159,24 +137,6 @@
       wraps_current_thread_ = true;
     }
   }
-
-  // TODO(deadbeef): Currently there is no way to create an external adm in
-  // libjingle source tree. So we can 't currently assert if this is NULL.
-  // RTC_DCHECK(default_adm != NULL);
-}
-
-PeerConnectionFactory::PeerConnectionFactory(
-    PeerConnectionFactoryDependencies dependencies)
-    : PeerConnectionFactory(
-          dependencies.network_thread,
-          dependencies.worker_thread,
-          dependencies.signaling_thread,
-          std::move(dependencies.media_engine),
-          std::move(dependencies.call_factory),
-          std::move(dependencies.event_log_factory),
-          std::move(dependencies.fec_controller_factory),
-          std::move(dependencies.network_controller_factory)) {
-  media_transport_factory_ = std::move(dependencies.media_transport_factory);
 }
 
 PeerConnectionFactory::~PeerConnectionFactory() {
diff --git a/pc/peer_connection_factory.h b/pc/peer_connection_factory.h
index 40706ce..0ea309b 100644
--- a/pc/peer_connection_factory.h
+++ b/pc/peer_connection_factory.h
@@ -92,26 +92,8 @@
   }
 
  protected:
-  PeerConnectionFactory(
-      rtc::Thread* network_thread,
-      rtc::Thread* worker_thread,
-      rtc::Thread* signaling_thread,
-      std::unique_ptr<cricket::MediaEngineInterface> media_engine,
-      std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
-      std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory);
-  PeerConnectionFactory(
-      rtc::Thread* network_thread,
-      rtc::Thread* worker_thread,
-      rtc::Thread* signaling_thread,
-      std::unique_ptr<cricket::MediaEngineInterface> media_engine,
-      std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
-      std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory,
-      std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
-      std::unique_ptr<NetworkControllerFactoryInterface>
-          network_controller_factory);
-  // Use this implementation for all future use. This structure allows simple
-  // management of all new dependencies being added to the
-  // PeerConnectionFactory.
+  // This structure allows simple management of all new dependencies being added
+  // to the PeerConnectionFactory.
   explicit PeerConnectionFactory(
       PeerConnectionFactoryDependencies dependencies);
 
diff --git a/pc/peer_connection_histogram_unittest.cc b/pc/peer_connection_histogram_unittest.cc
index 596f2f5..78b41d5 100644
--- a/pc/peer_connection_histogram_unittest.cc
+++ b/pc/peer_connection_histogram_unittest.cc
@@ -64,13 +64,16 @@
     : public rtc::RefCountedObject<PeerConnectionFactory> {
  public:
   PeerConnectionFactoryForUsageHistogramTest()
-      : rtc::RefCountedObject<PeerConnectionFactory>(
-            rtc::Thread::Current(),
-            rtc::Thread::Current(),
-            rtc::Thread::Current(),
-            absl::make_unique<cricket::FakeMediaEngine>(),
-            CreateCallFactory(),
-            nullptr) {}
+      : rtc::RefCountedObject<PeerConnectionFactory>([] {
+          PeerConnectionFactoryDependencies dependencies;
+          dependencies.network_thread = rtc::Thread::Current();
+          dependencies.worker_thread = rtc::Thread::Current();
+          dependencies.signaling_thread = rtc::Thread::Current();
+          dependencies.media_engine =
+              absl::make_unique<cricket::FakeMediaEngine>();
+          dependencies.call_factory = CreateCallFactory();
+          return dependencies;
+        }()) {}
 
   void ActionsBeforeInitializeForTesting(PeerConnectionInterface* pc) override {
     PeerConnection* internal_pc = static_cast<PeerConnection*>(pc);
diff --git a/pc/peer_connection_interface_unittest.cc b/pc/peer_connection_interface_unittest.cc
index 7cec6ed..90c5208 100644
--- a/pc/peer_connection_interface_unittest.cc
+++ b/pc/peer_connection_interface_unittest.cc
@@ -639,41 +639,30 @@
     auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
     auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
 
+    PeerConnectionFactoryDependencies dependencies;
+    dependencies.worker_thread = rtc::Thread::Current();
+    dependencies.network_thread = rtc::Thread::Current();
+    dependencies.signaling_thread = rtc::Thread::Current();
+
     // Use fake audio device module since we're only testing the interface
     // level, and using a real one could make tests flaky when run in parallel.
-    auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
+    dependencies.media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
         cricket::WebRtcMediaEngineFactory::Create(
             FakeAudioCaptureModule::Create(), audio_encoder_factory,
             audio_decoder_factory, std::move(video_encoder_factory),
             std::move(video_decoder_factory), nullptr,
             webrtc::AudioProcessingBuilder().Create()));
 
-    std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
-        webrtc::CreateCallFactory();
-
-    std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
-        webrtc::CreateRtcEventLogFactory();
+    dependencies.call_factory = webrtc::CreateCallFactory();
+    dependencies.event_log_factory = webrtc::CreateRtcEventLogFactory();
 
     return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
-        rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
-        std::move(media_engine), std::move(call_factory),
-        std::move(event_log_factory));
+        std::move(dependencies));
   }
 
-  PeerConnectionFactoryForTest(
-      rtc::Thread* network_thread,
-      rtc::Thread* worker_thread,
-      rtc::Thread* signaling_thread,
-      std::unique_ptr<cricket::MediaEngineInterface> media_engine,
-      std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
-      std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
-      : webrtc::PeerConnectionFactory(network_thread,
-                                      worker_thread,
-                                      signaling_thread,
-                                      std::move(media_engine),
-                                      std::move(call_factory),
-                                      std::move(event_log_factory)) {}
+  using PeerConnectionFactory::PeerConnectionFactory;
 
+ private:
   rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
 };
 
diff --git a/pc/peer_connection_jsep_unittest.cc b/pc/peer_connection_jsep_unittest.cc
index b2fe86b..868ff67 100644
--- a/pc/peer_connection_jsep_unittest.cc
+++ b/pc/peer_connection_jsep_unittest.cc
@@ -46,20 +46,22 @@
 class PeerConnectionFactoryForJsepTest : public PeerConnectionFactory {
  public:
   PeerConnectionFactoryForJsepTest()
-      : PeerConnectionFactory(rtc::Thread::Current(),
-                              rtc::Thread::Current(),
-                              rtc::Thread::Current(),
-                              cricket::WebRtcMediaEngineFactory::Create(
-                                  rtc::scoped_refptr<AudioDeviceModule>(
-                                      FakeAudioCaptureModule::Create()),
-                                  CreateBuiltinAudioEncoderFactory(),
-                                  CreateBuiltinAudioDecoderFactory(),
-                                  CreateBuiltinVideoEncoderFactory(),
-                                  CreateBuiltinVideoDecoderFactory(),
-                                  nullptr,
-                                  AudioProcessingBuilder().Create()),
-                              CreateCallFactory(),
-                              nullptr) {}
+      : PeerConnectionFactory([] {
+          PeerConnectionFactoryDependencies dependencies;
+          dependencies.worker_thread = rtc::Thread::Current();
+          dependencies.network_thread = rtc::Thread::Current();
+          dependencies.signaling_thread = rtc::Thread::Current();
+          dependencies.media_engine = cricket::WebRtcMediaEngineFactory::Create(
+              rtc::scoped_refptr<AudioDeviceModule>(
+                  FakeAudioCaptureModule::Create()),
+              CreateBuiltinAudioEncoderFactory(),
+              CreateBuiltinAudioDecoderFactory(),
+              CreateBuiltinVideoEncoderFactory(),
+              CreateBuiltinVideoDecoderFactory(), nullptr,
+              AudioProcessingBuilder().Create());
+          dependencies.call_factory = CreateCallFactory();
+          return dependencies;
+        }()) {}
 
   std::unique_ptr<cricket::SctpTransportInternalFactory>
   CreateSctpTransportInternalFactory() {