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) ...@@ -51,29 +51,32 @@ static void throwNoBlobSupportException(ExceptionState& exceptionState)
exceptionState.throwDOMException(NotSupportedError, "Blob support not implemented yet"); 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); 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)); OwnPtr<blink::WebRTCDataChannelHandler> handler = adoptPtr(peerConnectionHandler->createDataChannel(label, init));
if (!handler) { if (!handler) {
exceptionState.throwDOMException(NotSupportedError, "RTCDataChannel is not supported"); exceptionState.throwDOMException(NotSupportedError, "RTCDataChannel is not supported");
return nullptr; 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_executionContext(context)
, m_handler(handler) , m_handler(handler)
, m_stopped(false) , m_stopped(false)
, m_readyState(ReadyStateConnecting) , m_readyState(ReadyStateConnecting)
, m_binaryType(BinaryTypeArrayBuffer) , m_binaryType(BinaryTypeArrayBuffer)
, m_scheduledEventTimer(this, &RTCDataChannel::scheduledEventTimerFired) , m_scheduledEventTimer(this, &RTCDataChannel::scheduledEventTimerFired)
#if ENABLE(OILPAN)
, m_connection(connection)
#endif
{ {
ScriptWrappable::init(this); ScriptWrappable::init(this);
m_handler->setClient(this); m_handler->setClient(this);
...@@ -81,6 +84,15 @@ RTCDataChannel::RTCDataChannel(ExecutionContext* context, PassOwnPtr<blink::WebR ...@@ -81,6 +84,15 @@ RTCDataChannel::RTCDataChannel(ExecutionContext* context, PassOwnPtr<blink::WebR
RTCDataChannel::~RTCDataChannel() 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 String RTCDataChannel::label() const
...@@ -313,9 +325,22 @@ void RTCDataChannel::scheduledEventTimerFired(Timer<RTCDataChannel>*) ...@@ -313,9 +325,22 @@ void RTCDataChannel::scheduledEventTimerFired(Timer<RTCDataChannel>*)
events.clear(); 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) void RTCDataChannel::trace(Visitor* visitor)
{ {
#if ENABLE(OILPAN)
visitor->trace(m_scheduledEvents); visitor->trace(m_scheduledEvents);
visitor->registerWeakMembers<RTCDataChannel, &RTCDataChannel::clearWeakMembers>(this);
#endif
EventTargetWithInlineData::trace(visitor); EventTargetWithInlineData::trace(visitor);
} }
......
...@@ -43,13 +43,14 @@ namespace WebCore { ...@@ -43,13 +43,14 @@ namespace WebCore {
class Blob; class Blob;
class ExceptionState; class ExceptionState;
class RTCPeerConnection;
class RTCDataChannel FINAL : public RefCountedWillBeRefCountedGarbageCollected<RTCDataChannel>, public ScriptWrappable, public EventTargetWithInlineData, public blink::WebRTCDataChannelHandlerClient { class RTCDataChannel FINAL : public RefCountedWillBeRefCountedGarbageCollected<RTCDataChannel>, public ScriptWrappable, public EventTargetWithInlineData, public blink::WebRTCDataChannelHandlerClient {
REFCOUNTED_EVENT_TARGET(RTCDataChannel); REFCOUNTED_EVENT_TARGET(RTCDataChannel);
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(RTCDataChannel); WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(RTCDataChannel);
public: public:
static PassRefPtrWillBeRawPtr<RTCDataChannel> create(ExecutionContext*, PassOwnPtr<blink::WebRTCDataChannelHandler>); static PassRefPtrWillBeRawPtr<RTCDataChannel> create(ExecutionContext*, RTCPeerConnection*, PassOwnPtr<blink::WebRTCDataChannelHandler>);
static PassRefPtrWillBeRawPtr<RTCDataChannel> create(ExecutionContext*, blink::WebRTCPeerConnectionHandler*, const String& label, const blink::WebRTCDataChannelInit&, ExceptionState&); static PassRefPtrWillBeRawPtr<RTCDataChannel> create(ExecutionContext*, RTCPeerConnection*, blink::WebRTCPeerConnectionHandler*, const String& label, const blink::WebRTCDataChannelInit&, ExceptionState&);
virtual ~RTCDataChannel(); virtual ~RTCDataChannel();
String label() const; String label() const;
...@@ -87,10 +88,14 @@ public: ...@@ -87,10 +88,14 @@ public:
virtual const AtomicString& interfaceName() const OVERRIDE; virtual const AtomicString& interfaceName() const OVERRIDE;
virtual ExecutionContext* executionContext() const OVERRIDE; virtual ExecutionContext* executionContext() const OVERRIDE;
#if ENABLE(OILPAN)
void clearWeakMembers(Visitor*);
#endif
virtual void trace(Visitor*) OVERRIDE; virtual void trace(Visitor*) OVERRIDE;
private: private:
RTCDataChannel(ExecutionContext*, PassOwnPtr<blink::WebRTCDataChannelHandler>); RTCDataChannel(ExecutionContext*, RTCPeerConnection*, PassOwnPtr<blink::WebRTCDataChannelHandler>);
void scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event>); void scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event>);
void scheduledEventTimerFired(Timer<RTCDataChannel>*); void scheduledEventTimerFired(Timer<RTCDataChannel>*);
...@@ -117,6 +122,10 @@ private: ...@@ -117,6 +122,10 @@ private:
Timer<RTCDataChannel> m_scheduledEventTimer; Timer<RTCDataChannel> m_scheduledEventTimer;
WillBeHeapVector<RefPtrWillBeMember<Event> > m_scheduledEvents; WillBeHeapVector<RefPtrWillBeMember<Event> > m_scheduledEvents;
#if ENABLE(OILPAN)
WeakMember<RTCPeerConnection> m_connection;
#endif
}; };
} // namespace WebCore } // namespace WebCore
......
...@@ -220,10 +220,9 @@ RTCPeerConnection::~RTCPeerConnection() ...@@ -220,10 +220,9 @@ RTCPeerConnection::~RTCPeerConnection()
// We are assuming that a wrapper is always created when RTCPeerConnection is created. // We are assuming that a wrapper is always created when RTCPeerConnection is created.
ASSERT(m_closed || m_stopped); ASSERT(m_closed || m_stopped);
// FIXME: Oilpan: We can't call stop here since it touches m_dataChannels. #if !ENABLE(OILPAN)
// Another way to ensure that data channels are stopped at RTCPeerConnection
// destruction is needed.
stop(); stop();
#endif
} }
void RTCPeerConnection::createOffer(PassOwnPtr<RTCSessionDescriptionCallback> successCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& mediaConstraints, ExceptionState& exceptionState) void RTCPeerConnection::createOffer(PassOwnPtr<RTCSessionDescriptionCallback> successCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& mediaConstraints, ExceptionState& exceptionState)
...@@ -515,7 +514,7 @@ PassRefPtrWillBeRawPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(Stri ...@@ -515,7 +514,7 @@ PassRefPtrWillBeRawPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(Stri
options.get("protocol", protocolString); options.get("protocol", protocolString);
init.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()) if (exceptionState.hadException())
return nullptr; return nullptr;
m_dataChannels.append(channel); m_dataChannels.append(channel);
...@@ -649,7 +648,7 @@ void RTCPeerConnection::didAddRemoteDataChannel(blink::WebRTCDataChannelHandler* ...@@ -649,7 +648,7 @@ void RTCPeerConnection::didAddRemoteDataChannel(blink::WebRTCDataChannelHandler*
if (m_signalingState == SignalingStateClosed) if (m_signalingState == SignalingStateClosed)
return; return;
RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), adoptPtr(handler)); RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), this, adoptPtr(handler));
m_dataChannels.append(channel); m_dataChannels.append(channel);
scheduleDispatchEvent(RTCDataChannelEvent::create(EventTypeNames::datachannel, false, false, channel.release())); 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