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 <deadbeef@webrtc.org>
Commit-Queue: Benjamin Wright <benwright@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23130}
This commit is contained in:
Benjamin Wright 2018-05-02 15:12:47 -07:00 committed by Commit Bot
parent c816ffc0a5
commit cab58888ad
3 changed files with 11 additions and 19 deletions

View File

@ -882,9 +882,7 @@ void PeerConnection::DestroyAllChannels() {
bool PeerConnection::Initialize(
const PeerConnectionInterface::RTCConfiguration& configuration,
std::unique_ptr<cricket::PortAllocator> allocator,
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> 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);

View File

@ -61,9 +61,7 @@ class PeerConnection : public PeerConnectionInternal,
bool Initialize(
const PeerConnectionInterface::RTCConfiguration& configuration,
std::unique_ptr<cricket::PortAllocator> allocator,
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
PeerConnectionObserver* observer);
PeerConnectionDependencies dependencies);
rtc::scoped_refptr<StreamCollectionInterface> local_streams() override;
rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override;

View File

@ -307,11 +307,7 @@ PeerConnectionFactory::CreatePeerConnection(
new rtc::RefCountedObject<PeerConnection>(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);