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

Side by Side Diff: Source/modules/mediastream/RTCDataChannel.cpp

Issue 329093002: Allow PeerConnection to be garbage collected after close(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Data channel now has a weak ptr to the peer connection that created it. Stops itself if creator goe… 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 12 matching lines...) Expand all
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "modules/mediastream/RTCDataChannel.h" 26 #include "modules/mediastream/RTCDataChannel.h"
27 27
28 #include "bindings/v8/ExceptionState.h" 28 #include "bindings/v8/ExceptionState.h"
29 #include "core/dom/ExceptionCode.h" 29 #include "core/dom/ExceptionCode.h"
30 #include "core/dom/ExecutionContext.h" 30 #include "core/dom/ExecutionContext.h"
31 #include "core/events/MessageEvent.h" 31 #include "core/events/MessageEvent.h"
32 #include "core/fileapi/Blob.h" 32 #include "core/fileapi/Blob.h"
33 #include "modules/mediastream/RTCPeerConnection.h"
33 #include "public/platform/WebRTCPeerConnectionHandler.h" 34 #include "public/platform/WebRTCPeerConnectionHandler.h"
34 #include "wtf/ArrayBuffer.h" 35 #include "wtf/ArrayBuffer.h"
35 #include "wtf/ArrayBufferView.h" 36 #include "wtf/ArrayBufferView.h"
36 37
37 namespace WebCore { 38 namespace WebCore {
38 39
39 static void throwNotOpenException(ExceptionState& exceptionState) 40 static void throwNotOpenException(ExceptionState& exceptionState)
40 { 41 {
41 exceptionState.throwDOMException(InvalidStateError, "RTCDataChannel.readySta te is not 'open'"); 42 exceptionState.throwDOMException(InvalidStateError, "RTCDataChannel.readySta te is not 'open'");
42 } 43 }
43 44
44 static void throwCouldNotSendDataException(ExceptionState& exceptionState) 45 static void throwCouldNotSendDataException(ExceptionState& exceptionState)
45 { 46 {
46 exceptionState.throwDOMException(NetworkError, "Could not send data"); 47 exceptionState.throwDOMException(NetworkError, "Could not send data");
47 } 48 }
48 49
49 static void throwNoBlobSupportException(ExceptionState& exceptionState) 50 static void throwNoBlobSupportException(ExceptionState& exceptionState)
50 { 51 {
51 exceptionState.throwDOMException(NotSupportedError, "Blob support not implem ented yet"); 52 exceptionState.throwDOMException(NotSupportedError, "Blob support not implem ented yet");
52 } 53 }
53 54
54 PassRefPtrWillBeRawPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, PassOwnPtr<blink::WebRTCDataChannelHandler> handler) 55 PassRefPtrWillBeRawPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, WeakPtrWillBeRawPtr<RTCPeerConnection> creator, PassOwnPtr<blink::WebRT CDataChannelHandler> handler)
55 { 56 {
56 ASSERT(handler); 57 ASSERT(handler);
57 return adoptRefWillBeRefCountedGarbageCollected(new RTCDataChannel(context, handler)); 58 return adoptRefWillBeRefCountedGarbageCollected(new RTCDataChannel(context, creator, handler));
58 } 59 }
59 60
60 PassRefPtrWillBeRawPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, blink::WebRTCPeerConnectionHandler* peerConnectionHandler, const String & label, const blink::WebRTCDataChannelInit& init, ExceptionState& exceptionStat e) 61 PassRefPtrWillBeRawPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, WeakPtrWillBeRawPtr<RTCPeerConnection> creator, blink::WebRTCPeerConnec tionHandler* peerConnectionHandler, const String& label, const blink::WebRTCData ChannelInit& init, ExceptionState& exceptionState)
61 { 62 {
62 OwnPtr<blink::WebRTCDataChannelHandler> handler = adoptPtr(peerConnectionHan dler->createDataChannel(label, init)); 63 OwnPtr<blink::WebRTCDataChannelHandler> handler = adoptPtr(peerConnectionHan dler->createDataChannel(label, init));
63 if (!handler) { 64 if (!handler) {
64 exceptionState.throwDOMException(NotSupportedError, "RTCDataChannel is n ot supported"); 65 exceptionState.throwDOMException(NotSupportedError, "RTCDataChannel is n ot supported");
65 return nullptr; 66 return nullptr;
66 } 67 }
67 return adoptRefWillBeRefCountedGarbageCollected(new RTCDataChannel(context, handler.release())); 68 return adoptRefWillBeRefCountedGarbageCollected(new RTCDataChannel(context, creator, handler.release()));
68 } 69 }
69 70
70 RTCDataChannel::RTCDataChannel(ExecutionContext* context, PassOwnPtr<blink::WebR TCDataChannelHandler> handler) 71 RTCDataChannel::RTCDataChannel(ExecutionContext* context, WeakPtrWillBeRawPtr<RT CPeerConnection> creator, PassOwnPtr<blink::WebRTCDataChannelHandler> handler)
71 : m_executionContext(context) 72 : m_executionContext(context)
72 , m_handler(handler) 73 , m_handler(handler)
73 , m_stopped(false) 74 , m_stopped(false)
74 , m_readyState(ReadyStateConnecting) 75 , m_readyState(ReadyStateConnecting)
75 , m_binaryType(BinaryTypeArrayBuffer) 76 , m_binaryType(BinaryTypeArrayBuffer)
76 , m_scheduledEventTimer(this, &RTCDataChannel::scheduledEventTimerFired) 77 , m_scheduledEventTimer(this, &RTCDataChannel::scheduledEventTimerFired)
78 , m_creator(creator)
77 { 79 {
78 ScriptWrappable::init(this); 80 ScriptWrappable::init(this);
79 m_handler->setClient(this); 81 m_handler->setClient(this);
80 } 82 }
81 83
82 RTCDataChannel::~RTCDataChannel() 84 RTCDataChannel::~RTCDataChannel()
83 { 85 {
84 } 86 }
85 87
86 String RTCDataChannel::label() const 88 String RTCDataChannel::label() const
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 void RTCDataChannel::close() 217 void RTCDataChannel::close()
216 { 218 {
217 if (m_stopped) 219 if (m_stopped)
218 return; 220 return;
219 221
220 m_handler->close(); 222 m_handler->close();
221 } 223 }
222 224
223 void RTCDataChannel::didChangeReadyState(blink::WebRTCDataChannelHandlerClient:: ReadyState newState) 225 void RTCDataChannel::didChangeReadyState(blink::WebRTCDataChannelHandlerClient:: ReadyState newState)
224 { 226 {
227 stopAndFireCloseEventIfCreatorWasDeleted();
225 if (m_stopped || m_readyState == ReadyStateClosed) 228 if (m_stopped || m_readyState == ReadyStateClosed)
226 return; 229 return;
227 230
228 m_readyState = newState; 231 m_readyState = newState;
229 232
230 switch (m_readyState) { 233 switch (m_readyState) {
231 case ReadyStateOpen: 234 case ReadyStateOpen:
232 scheduleDispatchEvent(Event::create(EventTypeNames::open)); 235 scheduleDispatchEvent(Event::create(EventTypeNames::open));
233 break; 236 break;
234 case ReadyStateClosed: 237 case ReadyStateClosed:
235 scheduleDispatchEvent(Event::create(EventTypeNames::close)); 238 scheduleDispatchEvent(Event::create(EventTypeNames::close));
236 break; 239 break;
237 default: 240 default:
238 break; 241 break;
239 } 242 }
240 } 243 }
241 244
242 void RTCDataChannel::didReceiveStringData(const blink::WebString& text) 245 void RTCDataChannel::didReceiveStringData(const blink::WebString& text)
243 { 246 {
247 stopAndFireCloseEventIfCreatorWasDeleted();
244 if (m_stopped) 248 if (m_stopped)
245 return; 249 return;
246 250
247 scheduleDispatchEvent(MessageEvent::create(text)); 251 scheduleDispatchEvent(MessageEvent::create(text));
248 } 252 }
249 253
250 void RTCDataChannel::didReceiveRawData(const char* data, size_t dataLength) 254 void RTCDataChannel::didReceiveRawData(const char* data, size_t dataLength)
251 { 255 {
256 stopAndFireCloseEventIfCreatorWasDeleted();
252 if (m_stopped) 257 if (m_stopped)
253 return; 258 return;
254 259
255 if (m_binaryType == BinaryTypeBlob) { 260 if (m_binaryType == BinaryTypeBlob) {
256 // FIXME: Implement. 261 // FIXME: Implement.
257 return; 262 return;
258 } 263 }
259 if (m_binaryType == BinaryTypeArrayBuffer) { 264 if (m_binaryType == BinaryTypeArrayBuffer) {
260 RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(data, dataLength); 265 RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(data, dataLength);
261 scheduleDispatchEvent(MessageEvent::create(buffer.release())); 266 scheduleDispatchEvent(MessageEvent::create(buffer.release()));
262 return; 267 return;
263 } 268 }
264 ASSERT_NOT_REACHED(); 269 ASSERT_NOT_REACHED();
265 } 270 }
266 271
267 void RTCDataChannel::didDetectError() 272 void RTCDataChannel::didDetectError()
268 { 273 {
274 stopAndFireCloseEventIfCreatorWasDeleted();
269 if (m_stopped) 275 if (m_stopped)
270 return; 276 return;
271 277
272 scheduleDispatchEvent(Event::create(EventTypeNames::error)); 278 scheduleDispatchEvent(Event::create(EventTypeNames::error));
273 } 279 }
274 280
275 const AtomicString& RTCDataChannel::interfaceName() const 281 const AtomicString& RTCDataChannel::interfaceName() const
276 { 282 {
277 return EventTargetNames::RTCDataChannel; 283 return EventTargetNames::RTCDataChannel;
278 } 284 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 318
313 events.clear(); 319 events.clear();
314 } 320 }
315 321
316 void RTCDataChannel::trace(Visitor* visitor) 322 void RTCDataChannel::trace(Visitor* visitor)
317 { 323 {
318 visitor->trace(m_scheduledEvents); 324 visitor->trace(m_scheduledEvents);
319 EventTargetWithInlineData::trace(visitor); 325 EventTargetWithInlineData::trace(visitor);
320 } 326 }
321 327
328 void RTCDataChannel::stopAndFireCloseEventIfCreatorWasDeleted()
329 {
330 if (!m_creator) {
331 // When the RTCPeerConnection creator is gone, we must stop this data
332 // channel and fire a closed event.
333 dispatchEvent(Event::create(EventTypeNames::close));
334 stop();
335 }
336 }
337
322 } // namespace WebCore 338 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698