Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(742)

Unified Diff: Source/modules/mediastream/RTCPeerConnection.cpp

Issue 329093002: Allow PeerConnection to be garbage collected after close(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Code review. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/mediastream/RTCPeerConnection.cpp
diff --git a/Source/modules/mediastream/RTCPeerConnection.cpp b/Source/modules/mediastream/RTCPeerConnection.cpp
index 5c0d5df96329f78a1d431fb78abaf5ea11cbc42f..2202970dbf63a59f90fa069563995c3a290db45c 100644
--- a/Source/modules/mediastream/RTCPeerConnection.cpp
+++ b/Source/modules/mediastream/RTCPeerConnection.cpp
@@ -181,18 +181,26 @@ RTCPeerConnection::RTCPeerConnection(ExecutionContext* context, PassRefPtr<RTCCo
, m_iceGatheringState(ICEGatheringStateNew)
, m_iceConnectionState(ICEConnectionStateNew)
, m_dispatchScheduledEventRunner(this, &RTCPeerConnection::dispatchScheduledEvent)
+ , m_weakPtrFactory(this)
keishi 2014/06/17 08:16:42 nit: Wrap in #if ENABLE(OILPAN)
, m_stopped(false)
+ , m_closed(false)
{
ScriptWrappable::init(this);
Document* document = toDocument(executionContext());
+ // If we fail, set |m_closed| and |m_stopped| to true, to avoid hitting the assert in the destructor.
+
if (!document->frame()) {
+ m_closed = true;
+ m_stopped = true;
exceptionState.throwDOMException(NotSupportedError, "PeerConnections may not be created in detached documents.");
return;
}
m_peerHandler = adoptPtr(blink::Platform::current()->createRTCPeerConnectionHandler(this));
if (!m_peerHandler) {
+ m_closed = true;
+ m_stopped = true;
exceptionState.throwDOMException(NotSupportedError, "No PeerConnection handler can be created, perhaps WebRTC is disabled?");
return;
}
@@ -200,6 +208,8 @@ RTCPeerConnection::RTCPeerConnection(ExecutionContext* context, PassRefPtr<RTCCo
document->frame()->loader().client()->dispatchWillStartUsingPeerConnectionHandler(m_peerHandler.get());
if (!m_peerHandler->initialize(configuration, constraints)) {
+ m_closed = true;
+ m_stopped = true;
exceptionState.throwDOMException(NotSupportedError, "Failed to initialize native PeerConnection.");
return;
}
@@ -207,9 +217,9 @@ RTCPeerConnection::RTCPeerConnection(ExecutionContext* context, PassRefPtr<RTCCo
RTCPeerConnection::~RTCPeerConnection()
{
- // This checks that stop() is called if necessary before the destructor.
- // We are assuming that a wrapper is always created when RTCPeerConnection is created
- ASSERT(m_dataChannels.isEmpty());
+ // This checks that close() or stop() is called before the destructor.
+ // We are assuming that a wrapper is always created when RTCPeerConnection is created.
+ ASSERT(m_closed || m_stopped);
}
void RTCPeerConnection::createOffer(PassOwnPtr<RTCSessionDescriptionCallback> successCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& mediaConstraints, ExceptionState& exceptionState)
@@ -223,7 +233,7 @@ void RTCPeerConnection::createOffer(PassOwnPtr<RTCSessionDescriptionCallback> su
if (exceptionState.hadException())
return;
- RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestImpl::create(executionContext(), successCallback, errorCallback);
+ RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestImpl::create(executionContext(), this, successCallback, errorCallback);
m_peerHandler->createOffer(request.release(), constraints);
}
@@ -238,7 +248,7 @@ void RTCPeerConnection::createAnswer(PassOwnPtr<RTCSessionDescriptionCallback> s
if (exceptionState.hadException())
return;
- RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestImpl::create(executionContext(), successCallback, errorCallback);
+ RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestImpl::create(executionContext(), this, successCallback, errorCallback);
m_peerHandler->createAnswer(request.release(), constraints);
}
@@ -253,7 +263,7 @@ void RTCPeerConnection::setLocalDescription(PassRefPtrWillBeRawPtr<RTCSessionDes
return;
}
- RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext(), successCallback, errorCallback);
+ RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext(), this, successCallback, errorCallback);
m_peerHandler->setLocalDescription(request.release(), sessionDescription->webSessionDescription());
}
@@ -277,7 +287,7 @@ void RTCPeerConnection::setRemoteDescription(PassRefPtrWillBeRawPtr<RTCSessionDe
return;
}
- RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext(), successCallback, errorCallback);
+ RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext(), this, successCallback, errorCallback);
m_peerHandler->setRemoteDescription(request.release(), sessionDescription->webSessionDescription());
}
@@ -335,11 +345,12 @@ void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, PassOwnPt
ASSERT(successCallback);
ASSERT(errorCallback);
- RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext(), successCallback, errorCallback);
+ RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext(), this, successCallback, errorCallback);
bool implemented = m_peerHandler->addICECandidate(request.release(), iceCandidate->webCandidate());
- if (!implemented)
+ if (!implemented) {
exceptionState.throwDOMException(NotSupportedError, "This method is not yet implemented.");
+ }
}
String RTCPeerConnection::signalingState() const
@@ -474,7 +485,7 @@ MediaStream* RTCPeerConnection::getStreamById(const String& streamId)
void RTCPeerConnection::getStats(PassOwnPtr<RTCStatsCallback> successCallback, PassRefPtr<MediaStreamTrack> selector)
{
- RefPtr<RTCStatsRequest> statsRequest = RTCStatsRequestImpl::create(executionContext(), successCallback, selector);
+ RefPtr<RTCStatsRequest> statsRequest = RTCStatsRequestImpl::create(executionContext(), this, successCallback, selector);
// FIXME: Add passing selector as part of the statsRequest.
m_peerHandler->getStats(statsRequest.release());
}
@@ -500,7 +511,11 @@ PassRefPtrWillBeRawPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(Stri
options.get("protocol", protocolString);
init.protocol = protocolString;
- RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), m_peerHandler.get(), label, init, exceptionState);
+#if ENABLE(OILPAN)
+ RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), this, m_peerHandler.get(), label, init, exceptionState);
+#else
+ RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), m_weakPtrFactory.createWeakPtr(), m_peerHandler.get(), label, init, exceptionState);
+#endif
if (exceptionState.hadException())
return nullptr;
m_dataChannels.append(channel);
@@ -545,6 +560,7 @@ void RTCPeerConnection::close(ExceptionState& exceptionState)
return;
m_peerHandler->stop();
+ m_closed = true;
changeIceConnectionState(ICEConnectionStateClosed);
changeIceGatheringState(ICEGatheringStateComplete);
@@ -553,11 +569,13 @@ void RTCPeerConnection::close(ExceptionState& exceptionState)
void RTCPeerConnection::negotiationNeeded()
{
+ ASSERT(!m_closed);
scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded));
}
void RTCPeerConnection::didGenerateICECandidate(const blink::WebRTCICECandidate& webCandidate)
{
+ ASSERT(!m_closed);
ASSERT(executionContext()->isContextThread());
if (webCandidate.isNull())
scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, nullptr));
@@ -569,24 +587,28 @@ void RTCPeerConnection::didGenerateICECandidate(const blink::WebRTCICECandidate&
void RTCPeerConnection::didChangeSignalingState(SignalingState newState)
{
+ ASSERT(!m_closed);
ASSERT(executionContext()->isContextThread());
changeSignalingState(newState);
}
void RTCPeerConnection::didChangeICEGatheringState(ICEGatheringState newState)
{
+ ASSERT(!m_closed);
ASSERT(executionContext()->isContextThread());
changeIceGatheringState(newState);
}
void RTCPeerConnection::didChangeICEConnectionState(ICEConnectionState newState)
{
+ ASSERT(!m_closed);
ASSERT(executionContext()->isContextThread());
changeIceConnectionState(newState);
}
void RTCPeerConnection::didAddRemoteStream(const blink::WebMediaStream& remoteStream)
{
+ ASSERT(!m_closed);
ASSERT(executionContext()->isContextThread());
if (m_signalingState == SignalingStateClosed)
@@ -600,6 +622,7 @@ void RTCPeerConnection::didAddRemoteStream(const blink::WebMediaStream& remoteSt
void RTCPeerConnection::didRemoveRemoteStream(const blink::WebMediaStream& remoteStream)
{
+ ASSERT(!m_closed);
ASSERT(executionContext()->isContextThread());
MediaStreamDescriptor* streamDescriptor = remoteStream;
@@ -620,12 +643,17 @@ void RTCPeerConnection::didRemoveRemoteStream(const blink::WebMediaStream& remot
void RTCPeerConnection::didAddRemoteDataChannel(blink::WebRTCDataChannelHandler* handler)
{
+ ASSERT(!m_closed);
ASSERT(executionContext()->isContextThread());
if (m_signalingState == SignalingStateClosed)
return;
- RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), adoptPtr(handler));
+#if ENABLE(OILPAN)
+ RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), this, adoptPtr(handler));
+#else
+ RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), m_weakPtrFactory.createWeakPtr(), adoptPtr(handler));
+#endif
m_dataChannels.append(channel);
scheduleDispatchEvent(RTCDataChannelEvent::create(EventTypeNames::datachannel, false, false, channel.release()));

Powered by Google App Engine
This is Rietveld 408576698