From cab58888ad62031db9f92aff45e9189fd7c4105a Mon Sep 17 00:00:00 2001 From: Benjamin Wright Date: Wed, 2 May 2018 15:12:47 -0700 Subject: [PATCH] Integrated PeerConnectionDependencies into PeerConnection::Initialize Integrates the new PeerConnectionDependencies structure into PeerConnection::Initialize to simplify future injections. Bug: webrtc:7913 Change-Id: Ida1feae8b81819dfbfe5b79ed7807a63b091e73f Reviewed-on: https://webrtc-review.googlesource.com/73960 Reviewed-by: Taylor Brandstetter Commit-Queue: Benjamin Wright Cr-Commit-Position: refs/heads/master@{#23130} --- pc/peerconnection.cc | 20 +++++++++----------- pc/peerconnection.h | 4 +--- pc/peerconnectionfactory.cc | 6 +----- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc index 454746f40e..ea76e3da44 100644 --- a/pc/peerconnection.cc +++ b/pc/peerconnection.cc @@ -882,9 +882,7 @@ void PeerConnection::DestroyAllChannels() { bool PeerConnection::Initialize( const PeerConnectionInterface::RTCConfiguration& configuration, - std::unique_ptr allocator, - std::unique_ptr cert_generator, - PeerConnectionObserver* observer) { + PeerConnectionDependencies dependencies) { TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); RTCError config_error = ValidateConfiguration(configuration); @@ -893,21 +891,21 @@ bool PeerConnection::Initialize( return false; } - if (!allocator) { + if (!dependencies.allocator) { RTC_LOG(LS_ERROR) << "PeerConnection initialized without a PortAllocator? " "This shouldn't happen if using PeerConnectionFactory."; return false; } - if (!observer) { + if (!dependencies.observer) { // TODO(deadbeef): Why do we do this? RTC_LOG(LS_ERROR) << "PeerConnection initialized without a " "PeerConnectionObserver"; return false; } - observer_ = observer; - port_allocator_ = std::move(allocator); + observer_ = dependencies.observer; + port_allocator_ = std::move(dependencies.allocator); // The port allocator lives on the network thread and should be initialized // there. @@ -971,7 +969,7 @@ bool PeerConnection::Initialize( dtls_enabled_ = false; } else { // Enable DTLS by default if we have an identity store or a certificate. - dtls_enabled_ = (cert_generator || certificate); + dtls_enabled_ = (dependencies.cert_generator || certificate); // |configuration| can override the default |dtls_enabled_| value. if (configuration.enable_dtls_srtp) { dtls_enabled_ = *(configuration.enable_dtls_srtp); @@ -1005,16 +1003,16 @@ bool PeerConnection::Initialize( // what PeerConnectionDescriptionFactory will do, so make sure that we give it // the right instructions by clearing the variables if needed. if (!dtls_enabled_) { - cert_generator.reset(); + dependencies.cert_generator.reset(); certificate = nullptr; } else if (certificate) { // Favor generated certificate over the certificate generator. - cert_generator.reset(); + dependencies.cert_generator.reset(); } webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( signaling_thread(), channel_manager(), this, session_id(), - std::move(cert_generator), certificate)); + std::move(dependencies.cert_generator), certificate)); webrtc_session_desc_factory_->SignalCertificateReady.connect( this, &PeerConnection::OnCertificateReady); diff --git a/pc/peerconnection.h b/pc/peerconnection.h index eaebc1d75b..a03e9522d8 100644 --- a/pc/peerconnection.h +++ b/pc/peerconnection.h @@ -61,9 +61,7 @@ class PeerConnection : public PeerConnectionInternal, bool Initialize( const PeerConnectionInterface::RTCConfiguration& configuration, - std::unique_ptr allocator, - std::unique_ptr cert_generator, - PeerConnectionObserver* observer); + PeerConnectionDependencies dependencies); rtc::scoped_refptr local_streams() override; rtc::scoped_refptr remote_streams() override; diff --git a/pc/peerconnectionfactory.cc b/pc/peerconnectionfactory.cc index b6865ceff2..4889723174 100644 --- a/pc/peerconnectionfactory.cc +++ b/pc/peerconnectionfactory.cc @@ -307,11 +307,7 @@ PeerConnectionFactory::CreatePeerConnection( new rtc::RefCountedObject(this, std::move(event_log), std::move(call))); - // TODO(benwright) Update initialize to take the entire dependencies - // structure. - if (!pc->Initialize(configuration, std::move(dependencies.allocator), - std::move(dependencies.cert_generator), - dependencies.observer)) { + if (!pc->Initialize(configuration, std::move(dependencies))) { return nullptr; } return PeerConnectionProxy::Create(signaling_thread(), pc);