Index: talk/app/webrtc/peerconnection.cc |
diff --git a/talk/app/webrtc/peerconnection.cc b/talk/app/webrtc/peerconnection.cc |
index dba77da219df45c8c47709ceed5c7cc71a805d94..08e31ab1a6e968aa7cdd1434d39dd9d1d555bdad 100644 |
--- a/talk/app/webrtc/peerconnection.cc |
+++ b/talk/app/webrtc/peerconnection.cc |
@@ -351,6 +351,55 @@ bool PeerConnection::Initialize( |
PortAllocatorFactoryInterface* allocator_factory, |
DTLSIdentityServiceInterface* dtls_identity_service, |
PeerConnectionObserver* observer) { |
+ if (!InitializeCommon(configuration, constraints, allocator_factory, |
+ observer)) { |
+ if (dtls_identity_service) { |
+ // Since we have the ownership of |dtls_identity_service| and will not |
+ // pass it to WebRtcSession::Initialize it is our job to delete it. |
+ delete dtls_identity_service; |
+ } |
+ return false; |
+ } |
+ |
+ // Initialize the WebRtcSession with our optional |dtls_identity_service|. |
+ // It creates transport channels etc. |
+ // Note: |session_| takes ownership of |dtls_identity_service|. |
+ if (!session_->Initialize(factory_->options(), constraints, |
+ dtls_identity_service, configuration)) { |
+ return false; |
+ } |
+ InitializeSessionAfterInit(); |
+ return true; |
+} |
+ |
+bool PeerConnection::Initialize( |
+ const PeerConnectionInterface::RTCConfiguration& configuration, |
+ const MediaConstraintsInterface* constraints, |
+ PortAllocatorFactoryInterface* allocator_factory, |
+ rtc::scoped_refptr<DtlsCertificate> certificate, |
+ PeerConnectionObserver* observer) { |
+ DCHECK(certificate.get()); |
+ |
+ if (!InitializeCommon(configuration, constraints, allocator_factory, |
+ observer)) { |
+ return false; |
+ } |
+ |
+ // Initialize the WebRtcSession with our |certificate|. |
+ // It creates transport channels etc. |
+ if (!session_->Initialize(factory_->options(), constraints, |
+ certificate, configuration)) { |
+ return false; |
+ } |
+ InitializeSessionAfterInit(); |
+ return true; |
+} |
+ |
+bool PeerConnection::InitializeCommon( |
+ const PeerConnectionInterface::RTCConfiguration& configuration, |
+ const MediaConstraintsInterface* constraints, |
+ PortAllocatorFactoryInterface* allocator_factory, |
+ PeerConnectionObserver* observer) { |
ASSERT(observer != NULL); |
if (!observer) |
return false; |
@@ -402,17 +451,14 @@ bool PeerConnection::Initialize( |
stream_handler_container_.reset(new MediaStreamHandlerContainer( |
session_.get(), session_.get())); |
stats_.reset(new StatsCollector(session_.get())); |
+ return true; |
+} |
- // Initialize the WebRtcSession. It creates transport channels etc. |
- if (!session_->Initialize(factory_->options(), constraints, |
- dtls_identity_service, configuration)) |
- return false; |
- |
+void PeerConnection::InitializeSessionAfterInit() { |
// Register PeerConnection as receiver of local ice candidates. |
// All the callbacks will be posted to the application from PeerConnection. |
session_->RegisterIceObserver(this); |
session_->SignalState.connect(this, &PeerConnection::OnSessionStateChange); |
- return true; |
} |
rtc::scoped_refptr<StreamCollectionInterface> |