Commit e02c3f95 authored by keishi@chromium.org's avatar keishi@chromium.org

Oilpan: Use weak processing to stop a closed RTCPeerConnection

BUG=373690

Review URL: https://codereview.chromium.org/342683002

git-svn-id: svn://svn.chromium.org/blink/trunk@176481 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 89a4a39b
......@@ -51,29 +51,32 @@ static void throwNoBlobSupportException(ExceptionState& exceptionState)
exceptionState.throwDOMException(NotSupportedError, "Blob support not implemented yet");
}
PassRefPtrWillBeRawPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, PassOwnPtr<blink::WebRTCDataChannelHandler> handler)
PassRefPtrWillBeRawPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, RTCPeerConnection* connection, PassOwnPtr<blink::WebRTCDataChannelHandler> handler)
{
ASSERT(handler);
return adoptRefWillBeRefCountedGarbageCollected(new RTCDataChannel(context, handler));
return adoptRefWillBeRefCountedGarbageCollected(new RTCDataChannel(context, connection, handler));
}
PassRefPtrWillBeRawPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, blink::WebRTCPeerConnectionHandler* peerConnectionHandler, const String& label, const blink::WebRTCDataChannelInit& init, ExceptionState& exceptionState)
PassRefPtrWillBeRawPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, RTCPeerConnection* connection, blink::WebRTCPeerConnectionHandler* peerConnectionHandler, const String& label, const blink::WebRTCDataChannelInit& init, ExceptionState& exceptionState)
{
OwnPtr<blink::WebRTCDataChannelHandler> handler = adoptPtr(peerConnectionHandler->createDataChannel(label, init));
if (!handler) {
exceptionState.throwDOMException(NotSupportedError, "RTCDataChannel is not supported");
return nullptr;
}
return adoptRefWillBeRefCountedGarbageCollected(new RTCDataChannel(context, handler.release()));
return adoptRefWillBeRefCountedGarbageCollected(new RTCDataChannel(context, connection, handler.release()));
}
RTCDataChannel::RTCDataChannel(ExecutionContext* context, PassOwnPtr<blink::WebRTCDataChannelHandler> handler)
RTCDataChannel::RTCDataChannel(ExecutionContext* context, RTCPeerConnection* connection, PassOwnPtr<blink::WebRTCDataChannelHandler> handler)
: m_executionContext(context)
, m_handler(handler)
, m_stopped(false)
, m_readyState(ReadyStateConnecting)
, m_binaryType(BinaryTypeArrayBuffer)
, m_scheduledEventTimer(this, &RTCDataChannel::scheduledEventTimerFired)
#if ENABLE(OILPAN)
, m_connection(connection)
#endif
{
ScriptWrappable::init(this);
m_handler->setClient(this);
......@@ -81,6 +84,15 @@ RTCDataChannel::RTCDataChannel(ExecutionContext* context, PassOwnPtr<blink::WebR
RTCDataChannel::~RTCDataChannel()
{
#if ENABLE(OILPAN)
// If the peer connection and the data channel die in the same
// GC cycle stop has not been called and we need to notify the
// client that the channel is gone.
if (!m_stopped)
m_handler->setClient(0);
#else
ASSERT(m_stopped);
#endif
}
String RTCDataChannel::label() const
......@@ -313,9 +325,22 @@ void RTCDataChannel::scheduledEventTimerFired(Timer<RTCDataChannel>*)
events.clear();
}
#if ENABLE(OILPAN)
void RTCDataChannel::clearWeakMembers(Visitor* visitor)
{
if (visitor->isAlive(m_connection))
return;
stop();
m_connection = nullptr;
}
#endif
void RTCDataChannel::trace(Visitor* visitor)
{
#if ENABLE(OILPAN)
visitor->trace(m_scheduledEvents);
visitor->registerWeakMembers<RTCDataChannel, &RTCDataChannel::clearWeakMembers>(this);
#endif
EventTargetWithInlineData::trace(visitor);
}
......
......@@ -43,13 +43,14 @@ namespace WebCore {
class Blob;
class ExceptionState;
class RTCPeerConnection;
class RTCDataChannel FINAL : public RefCountedWillBeRefCountedGarbageCollected<RTCDataChannel>, public ScriptWrappable, public EventTargetWithInlineData, public blink::WebRTCDataChannelHandlerClient {
REFCOUNTED_EVENT_TARGET(RTCDataChannel);
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(RTCDataChannel);
public:
static PassRefPtrWillBeRawPtr<RTCDataChannel> create(ExecutionContext*, PassOwnPtr<blink::WebRTCDataChannelHandler>);
static PassRefPtrWillBeRawPtr<RTCDataChannel> create(ExecutionContext*, blink::WebRTCPeerConnectionHandler*, const String& label, const blink::WebRTCDataChannelInit&, ExceptionState&);
static PassRefPtrWillBeRawPtr<RTCDataChannel> create(ExecutionContext*, RTCPeerConnection*, PassOwnPtr<blink::WebRTCDataChannelHandler>);
static PassRefPtrWillBeRawPtr<RTCDataChannel> create(ExecutionContext*, RTCPeerConnection*, blink::WebRTCPeerConnectionHandler*, const String& label, const blink::WebRTCDataChannelInit&, ExceptionState&);
virtual ~RTCDataChannel();
String label() const;
......@@ -87,10 +88,14 @@ public:
virtual const AtomicString& interfaceName() const OVERRIDE;
virtual ExecutionContext* executionContext() const OVERRIDE;
#if ENABLE(OILPAN)
void clearWeakMembers(Visitor*);
#endif
virtual void trace(Visitor*) OVERRIDE;
private:
RTCDataChannel(ExecutionContext*, PassOwnPtr<blink::WebRTCDataChannelHandler>);
RTCDataChannel(ExecutionContext*, RTCPeerConnection*, PassOwnPtr<blink::WebRTCDataChannelHandler>);
void scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event>);
void scheduledEventTimerFired(Timer<RTCDataChannel>*);
......@@ -117,6 +122,10 @@ private:
Timer<RTCDataChannel> m_scheduledEventTimer;
WillBeHeapVector<RefPtrWillBeMember<Event> > m_scheduledEvents;
#if ENABLE(OILPAN)
WeakMember<RTCPeerConnection> m_connection;
#endif
};
} // namespace WebCore
......
......@@ -220,10 +220,9 @@ RTCPeerConnection::~RTCPeerConnection()
// We are assuming that a wrapper is always created when RTCPeerConnection is created.
ASSERT(m_closed || m_stopped);
// FIXME: Oilpan: We can't call stop here since it touches m_dataChannels.
// Another way to ensure that data channels are stopped at RTCPeerConnection
// destruction is needed.
#if !ENABLE(OILPAN)
stop();
#endif
}
void RTCPeerConnection::createOffer(PassOwnPtr<RTCSessionDescriptionCallback> successCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& mediaConstraints, ExceptionState& exceptionState)
......@@ -515,7 +514,7 @@ PassRefPtrWillBeRawPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(Stri
options.get("protocol", protocolString);
init.protocol = protocolString;
RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), m_peerHandler.get(), label, init, exceptionState);
RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), this, m_peerHandler.get(), label, init, exceptionState);
if (exceptionState.hadException())
return nullptr;
m_dataChannels.append(channel);
......@@ -649,7 +648,7 @@ void RTCPeerConnection::didAddRemoteDataChannel(blink::WebRTCDataChannelHandler*
if (m_signalingState == SignalingStateClosed)
return;
RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), adoptPtr(handler));
RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), this, adoptPtr(handler));
m_dataChannels.append(channel);
scheduleDispatchEvent(RTCDataChannelEvent::create(EventTypeNames::datachannel, false, false, channel.release()));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment