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

Side by Side 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: Use ref counting for pending activity for a async operations. 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return peerConnection.release(); 175 return peerConnection.release();
176 } 176 }
177 177
178 RTCPeerConnection::RTCPeerConnection(ExecutionContext* context, PassRefPtr<RTCCo nfiguration> configuration, blink::WebMediaConstraints constraints, ExceptionSta te& exceptionState) 178 RTCPeerConnection::RTCPeerConnection(ExecutionContext* context, PassRefPtr<RTCCo nfiguration> configuration, blink::WebMediaConstraints constraints, ExceptionSta te& exceptionState)
179 : ActiveDOMObject(context) 179 : ActiveDOMObject(context)
180 , m_signalingState(SignalingStateStable) 180 , m_signalingState(SignalingStateStable)
181 , m_iceGatheringState(ICEGatheringStateNew) 181 , m_iceGatheringState(ICEGatheringStateNew)
182 , m_iceConnectionState(ICEConnectionStateNew) 182 , m_iceConnectionState(ICEConnectionStateNew)
183 , m_dispatchScheduledEventRunner(this, &RTCPeerConnection::dispatchScheduled Event) 183 , m_dispatchScheduledEventRunner(this, &RTCPeerConnection::dispatchScheduled Event)
184 , m_stopped(false) 184 , m_stopped(false)
185 , m_closed(false)
185 { 186 {
186 ScriptWrappable::init(this); 187 ScriptWrappable::init(this);
187 Document* document = toDocument(executionContext()); 188 Document* document = toDocument(executionContext());
188 189
189 if (!document->frame()) { 190 if (!document->frame()) {
190 exceptionState.throwDOMException(NotSupportedError, "PeerConnections may not be created in detached documents."); 191 exceptionState.throwDOMException(NotSupportedError, "PeerConnections may not be created in detached documents.");
191 return; 192 return;
192 } 193 }
193 194
195 // We require a call to close() before the object can be garbage collected.
196 // In close(), stop() is called on |m_peer_handler|, after which no events
197 // are fired on this object (blink::WebRTCPeerConnectionHandlerClient
198 // interface). So we increase the ref count right away, and decrease it
199 // correspondingly in close(). Note that async operations, such as
200 // createOffer or getStats doesn't respond through this object, but through
201 // a request object containing the callback. The request object is handed to
202 // the client. Hence, we don't ref count these operations.
203 setPendingActivity(this);
haraken 2014/06/13 01:23:00 setPendingActivity/unsetPendingActivity are deprec
Henrik Grunell 2014/06/13 07:50:46 Oh, I didn't know that. Maybe a comment should be
204
194 m_peerHandler = adoptPtr(blink::Platform::current()->createRTCPeerConnection Handler(this)); 205 m_peerHandler = adoptPtr(blink::Platform::current()->createRTCPeerConnection Handler(this));
195 if (!m_peerHandler) { 206 if (!m_peerHandler) {
196 exceptionState.throwDOMException(NotSupportedError, "No PeerConnection h andler can be created, perhaps WebRTC is disabled?"); 207 exceptionState.throwDOMException(NotSupportedError, "No PeerConnection h andler can be created, perhaps WebRTC is disabled?");
197 return; 208 return;
198 } 209 }
199 210
200 document->frame()->loader().client()->dispatchWillStartUsingPeerConnectionHa ndler(m_peerHandler.get()); 211 document->frame()->loader().client()->dispatchWillStartUsingPeerConnectionHa ndler(m_peerHandler.get());
201 212
202 if (!m_peerHandler->initialize(configuration, constraints)) { 213 if (!m_peerHandler->initialize(configuration, constraints)) {
203 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ e native PeerConnection."); 214 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ e native PeerConnection.");
204 return; 215 return;
205 } 216 }
206 } 217 }
207 218
208 RTCPeerConnection::~RTCPeerConnection() 219 RTCPeerConnection::~RTCPeerConnection()
209 { 220 {
210 // This checks that stop() is called if necessary before the destructor. 221 // This checks that stop() is called if necessary before the destructor.
211 // We are assuming that a wrapper is always created when RTCPeerConnection i s created 222 // We are assuming that a wrapper is always created when RTCPeerConnection i s created.
223 // TODO - BEFORE COMMIT: We should call stop here.
224 ASSERT(m_closed);
212 ASSERT(m_dataChannels.isEmpty()); 225 ASSERT(m_dataChannels.isEmpty());
213 } 226 }
214 227
215 void RTCPeerConnection::createOffer(PassOwnPtr<RTCSessionDescriptionCallback> su ccessCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& med iaConstraints, ExceptionState& exceptionState) 228 void RTCPeerConnection::createOffer(PassOwnPtr<RTCSessionDescriptionCallback> su ccessCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& med iaConstraints, ExceptionState& exceptionState)
216 { 229 {
217 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 230 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
218 return; 231 return;
219 232
220 ASSERT(successCallback); 233 ASSERT(successCallback);
221 234
222 blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaC onstraints, exceptionState); 235 blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaC onstraints, exceptionState);
223 if (exceptionState.hadException()) 236 if (exceptionState.hadException())
224 return; 237 return;
225 238
226 RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestI mpl::create(executionContext(), successCallback, errorCallback); 239 setPendingActivity(this);
240 RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestI mpl::create(executionContext(), this, successCallback, errorCallback);
227 m_peerHandler->createOffer(request.release(), constraints); 241 m_peerHandler->createOffer(request.release(), constraints);
228 } 242 }
229 243
230 void RTCPeerConnection::createAnswer(PassOwnPtr<RTCSessionDescriptionCallback> s uccessCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& me diaConstraints, ExceptionState& exceptionState) 244 void RTCPeerConnection::createAnswer(PassOwnPtr<RTCSessionDescriptionCallback> s uccessCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& me diaConstraints, ExceptionState& exceptionState)
231 { 245 {
232 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 246 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
233 return; 247 return;
234 248
235 ASSERT(successCallback); 249 ASSERT(successCallback);
236 250
237 blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaC onstraints, exceptionState); 251 blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaC onstraints, exceptionState);
238 if (exceptionState.hadException()) 252 if (exceptionState.hadException())
239 return; 253 return;
240 254
241 RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestI mpl::create(executionContext(), successCallback, errorCallback); 255 setPendingActivity(this);
256 RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestI mpl::create(executionContext(), this, successCallback, errorCallback);
242 m_peerHandler->createAnswer(request.release(), constraints); 257 m_peerHandler->createAnswer(request.release(), constraints);
243 } 258 }
244 259
245 void RTCPeerConnection::setLocalDescription(PassRefPtrWillBeRawPtr<RTCSessionDes cription> prpSessionDescription, PassOwnPtr<VoidCallback> successCallback, PassO wnPtr<RTCErrorCallback> errorCallback, ExceptionState& exceptionState) 260 void RTCPeerConnection::setLocalDescription(PassRefPtrWillBeRawPtr<RTCSessionDes cription> prpSessionDescription, PassOwnPtr<VoidCallback> successCallback, PassO wnPtr<RTCErrorCallback> errorCallback, ExceptionState& exceptionState)
246 { 261 {
247 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 262 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
248 return; 263 return;
249 264
250 RefPtrWillBeRawPtr<RTCSessionDescription> sessionDescription = prpSessionDes cription; 265 RefPtrWillBeRawPtr<RTCSessionDescription> sessionDescription = prpSessionDes cription;
251 if (!sessionDescription) { 266 if (!sessionDescription) {
252 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription")); 267 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription"));
253 return; 268 return;
254 } 269 }
255 270
256 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), successCallback, errorCallback); 271 setPendingActivity(this);
272 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), this, successCallback, errorCallback);
257 m_peerHandler->setLocalDescription(request.release(), sessionDescription->we bSessionDescription()); 273 m_peerHandler->setLocalDescription(request.release(), sessionDescription->we bSessionDescription());
258 } 274 }
259 275
260 PassRefPtrWillBeRawPtr<RTCSessionDescription> RTCPeerConnection::localDescriptio n(ExceptionState& exceptionState) 276 PassRefPtrWillBeRawPtr<RTCSessionDescription> RTCPeerConnection::localDescriptio n(ExceptionState& exceptionState)
261 { 277 {
262 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->local Description(); 278 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->local Description();
263 if (webSessionDescription.isNull()) 279 if (webSessionDescription.isNull())
264 return nullptr; 280 return nullptr;
265 281
266 return RTCSessionDescription::create(webSessionDescription); 282 return RTCSessionDescription::create(webSessionDescription);
267 } 283 }
268 284
269 void RTCPeerConnection::setRemoteDescription(PassRefPtrWillBeRawPtr<RTCSessionDe scription> prpSessionDescription, PassOwnPtr<VoidCallback> successCallback, Pass OwnPtr<RTCErrorCallback> errorCallback, ExceptionState& exceptionState) 285 void RTCPeerConnection::setRemoteDescription(PassRefPtrWillBeRawPtr<RTCSessionDe scription> prpSessionDescription, PassOwnPtr<VoidCallback> successCallback, Pass OwnPtr<RTCErrorCallback> errorCallback, ExceptionState& exceptionState)
270 { 286 {
271 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 287 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
272 return; 288 return;
273 289
274 RefPtrWillBeRawPtr<RTCSessionDescription> sessionDescription = prpSessionDes cription; 290 RefPtrWillBeRawPtr<RTCSessionDescription> sessionDescription = prpSessionDes cription;
275 if (!sessionDescription) { 291 if (!sessionDescription) {
276 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription")); 292 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription"));
277 return; 293 return;
278 } 294 }
279 295
280 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), successCallback, errorCallback); 296 setPendingActivity(this);
297 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), this, successCallback, errorCallback);
281 m_peerHandler->setRemoteDescription(request.release(), sessionDescription->w ebSessionDescription()); 298 m_peerHandler->setRemoteDescription(request.release(), sessionDescription->w ebSessionDescription());
282 } 299 }
283 300
284 PassRefPtrWillBeRawPtr<RTCSessionDescription> RTCPeerConnection::remoteDescripti on(ExceptionState& exceptionState) 301 PassRefPtrWillBeRawPtr<RTCSessionDescription> RTCPeerConnection::remoteDescripti on(ExceptionState& exceptionState)
285 { 302 {
286 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->remot eDescription(); 303 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->remot eDescription();
287 if (webSessionDescription.isNull()) 304 if (webSessionDescription.isNull())
288 return nullptr; 305 return nullptr;
289 306
290 return RTCSessionDescription::create(webSessionDescription); 307 return RTCSessionDescription::create(webSessionDescription);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 345 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
329 return; 346 return;
330 347
331 if (!iceCandidate) { 348 if (!iceCandidate) {
332 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate")); 349 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate"));
333 return; 350 return;
334 } 351 }
335 ASSERT(successCallback); 352 ASSERT(successCallback);
336 ASSERT(errorCallback); 353 ASSERT(errorCallback);
337 354
338 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), successCallback, errorCallback); 355 setPendingActivity(this);
356 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), this, successCallback, errorCallback);
339 357
340 bool implemented = m_peerHandler->addICECandidate(request.release(), iceCand idate->webCandidate()); 358 bool implemented = m_peerHandler->addICECandidate(request.release(), iceCand idate->webCandidate());
341 if (!implemented) 359 if (!implemented) {
360 unsetPendingActivity(this);
342 exceptionState.throwDOMException(NotSupportedError, "This method is not yet implemented."); 361 exceptionState.throwDOMException(NotSupportedError, "This method is not yet implemented.");
362 }
343 } 363 }
344 364
345 String RTCPeerConnection::signalingState() const 365 String RTCPeerConnection::signalingState() const
346 { 366 {
347 switch (m_signalingState) { 367 switch (m_signalingState) {
348 case SignalingStateStable: 368 case SignalingStateStable:
349 return "stable"; 369 return "stable";
350 case SignalingStateHaveLocalOffer: 370 case SignalingStateHaveLocalOffer:
351 return "have-local-offer"; 371 return "have-local-offer";
352 case SignalingStateHaveRemoteOffer: 372 case SignalingStateHaveRemoteOffer:
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 for (MediaStreamVector::iterator iter = m_remoteStreams.begin(); iter != m_r emoteStreams.end(); ++iter) { 487 for (MediaStreamVector::iterator iter = m_remoteStreams.begin(); iter != m_r emoteStreams.end(); ++iter) {
468 if ((*iter)->id() == streamId) 488 if ((*iter)->id() == streamId)
469 return iter->get(); 489 return iter->get();
470 } 490 }
471 491
472 return 0; 492 return 0;
473 } 493 }
474 494
475 void RTCPeerConnection::getStats(PassOwnPtr<RTCStatsCallback> successCallback, P assRefPtr<MediaStreamTrack> selector) 495 void RTCPeerConnection::getStats(PassOwnPtr<RTCStatsCallback> successCallback, P assRefPtr<MediaStreamTrack> selector)
476 { 496 {
477 RefPtr<RTCStatsRequest> statsRequest = RTCStatsRequestImpl::create(execution Context(), successCallback, selector); 497 setPendingActivity(this);
498 RefPtr<RTCStatsRequest> statsRequest = RTCStatsRequestImpl::create(execution Context(), this, successCallback, selector);
478 // FIXME: Add passing selector as part of the statsRequest. 499 // FIXME: Add passing selector as part of the statsRequest.
479 m_peerHandler->getStats(statsRequest.release()); 500 m_peerHandler->getStats(statsRequest.release());
480 } 501 }
481 502
482 PassRefPtrWillBeRawPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(Stri ng label, const Dictionary& options, ExceptionState& exceptionState) 503 PassRefPtrWillBeRawPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(Stri ng label, const Dictionary& options, ExceptionState& exceptionState)
483 { 504 {
484 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 505 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
485 return nullptr; 506 return nullptr;
486 507
487 blink::WebRTCDataChannelInit init; 508 blink::WebRTCDataChannelInit init;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 return dtmfSender.release(); 560 return dtmfSender.release();
540 } 561 }
541 562
542 void RTCPeerConnection::close(ExceptionState& exceptionState) 563 void RTCPeerConnection::close(ExceptionState& exceptionState)
543 { 564 {
544 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 565 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
545 return; 566 return;
546 567
547 m_peerHandler->stop(); 568 m_peerHandler->stop();
548 569
570 m_closed = true;
571
549 changeIceConnectionState(ICEConnectionStateClosed); 572 changeIceConnectionState(ICEConnectionStateClosed);
550 changeIceGatheringState(ICEGatheringStateComplete); 573 changeIceGatheringState(ICEGatheringStateComplete);
551 changeSignalingState(SignalingStateClosed); 574 changeSignalingState(SignalingStateClosed);
575
576 // TODO - BEFORE COMMIT: Stop data channels here?
577
578 m_dispatchScheduledEventRunner.stop();
579
580 unsetPendingActivity(this);
581 }
582
583 bool RTCPeerConnection::requestCompletedCheckIfCallbackShouldFire()
584 {
585 unsetPendingActivity(this);
586 return !m_closed;
552 } 587 }
553 588
554 void RTCPeerConnection::negotiationNeeded() 589 void RTCPeerConnection::negotiationNeeded()
555 { 590 {
591 ASSERT(!m_closed);
556 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded)); 592 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded));
557 } 593 }
558 594
559 void RTCPeerConnection::didGenerateICECandidate(const blink::WebRTCICECandidate& webCandidate) 595 void RTCPeerConnection::didGenerateICECandidate(const blink::WebRTCICECandidate& webCandidate)
560 { 596 {
597 ASSERT(!m_closed);
561 ASSERT(executionContext()->isContextThread()); 598 ASSERT(executionContext()->isContextThread());
562 if (webCandidate.isNull()) 599 if (webCandidate.isNull())
563 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, nullptr )); 600 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, nullptr ));
564 else { 601 else {
565 RefPtrWillBeRawPtr<RTCIceCandidate> iceCandidate = RTCIceCandidate::crea te(webCandidate); 602 RefPtrWillBeRawPtr<RTCIceCandidate> iceCandidate = RTCIceCandidate::crea te(webCandidate);
566 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, iceCand idate.release())); 603 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, iceCand idate.release()));
567 } 604 }
568 } 605 }
569 606
570 void RTCPeerConnection::didChangeSignalingState(SignalingState newState) 607 void RTCPeerConnection::didChangeSignalingState(SignalingState newState)
571 { 608 {
609 ASSERT(!m_closed);
572 ASSERT(executionContext()->isContextThread()); 610 ASSERT(executionContext()->isContextThread());
573 changeSignalingState(newState); 611 changeSignalingState(newState);
574 } 612 }
575 613
576 void RTCPeerConnection::didChangeICEGatheringState(ICEGatheringState newState) 614 void RTCPeerConnection::didChangeICEGatheringState(ICEGatheringState newState)
577 { 615 {
616 ASSERT(!m_closed);
578 ASSERT(executionContext()->isContextThread()); 617 ASSERT(executionContext()->isContextThread());
579 changeIceGatheringState(newState); 618 changeIceGatheringState(newState);
580 } 619 }
581 620
582 void RTCPeerConnection::didChangeICEConnectionState(ICEConnectionState newState) 621 void RTCPeerConnection::didChangeICEConnectionState(ICEConnectionState newState)
583 { 622 {
623 ASSERT(!m_closed);
584 ASSERT(executionContext()->isContextThread()); 624 ASSERT(executionContext()->isContextThread());
585 changeIceConnectionState(newState); 625 changeIceConnectionState(newState);
586 } 626 }
587 627
588 void RTCPeerConnection::didAddRemoteStream(const blink::WebMediaStream& remoteSt ream) 628 void RTCPeerConnection::didAddRemoteStream(const blink::WebMediaStream& remoteSt ream)
589 { 629 {
630 ASSERT(!m_closed);
590 ASSERT(executionContext()->isContextThread()); 631 ASSERT(executionContext()->isContextThread());
591 632
592 if (m_signalingState == SignalingStateClosed) 633 if (m_signalingState == SignalingStateClosed)
593 return; 634 return;
594 635
595 RefPtrWillBeRawPtr<MediaStream> stream = MediaStream::create(executionContex t(), remoteStream); 636 RefPtrWillBeRawPtr<MediaStream> stream = MediaStream::create(executionContex t(), remoteStream);
596 m_remoteStreams.append(stream); 637 m_remoteStreams.append(stream);
597 638
598 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::addstream, fa lse, false, stream.release())); 639 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::addstream, fa lse, false, stream.release()));
599 } 640 }
600 641
601 void RTCPeerConnection::didRemoveRemoteStream(const blink::WebMediaStream& remot eStream) 642 void RTCPeerConnection::didRemoveRemoteStream(const blink::WebMediaStream& remot eStream)
602 { 643 {
644 ASSERT(!m_closed);
603 ASSERT(executionContext()->isContextThread()); 645 ASSERT(executionContext()->isContextThread());
604 646
605 MediaStreamDescriptor* streamDescriptor = remoteStream; 647 MediaStreamDescriptor* streamDescriptor = remoteStream;
606 ASSERT(streamDescriptor->client()); 648 ASSERT(streamDescriptor->client());
607 649
608 RefPtrWillBeRawPtr<MediaStream> stream = static_cast<MediaStream*>(streamDes criptor->client()); 650 RefPtrWillBeRawPtr<MediaStream> stream = static_cast<MediaStream*>(streamDes criptor->client());
609 stream->streamEnded(); 651 stream->streamEnded();
610 652
611 if (m_signalingState == SignalingStateClosed) 653 if (m_signalingState == SignalingStateClosed)
612 return; 654 return;
613 655
614 size_t pos = m_remoteStreams.find(stream); 656 size_t pos = m_remoteStreams.find(stream);
615 ASSERT(pos != kNotFound); 657 ASSERT(pos != kNotFound);
616 m_remoteStreams.remove(pos); 658 m_remoteStreams.remove(pos);
617 659
618 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::removestream, false, false, stream.release())); 660 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::removestream, false, false, stream.release()));
619 } 661 }
620 662
621 void RTCPeerConnection::didAddRemoteDataChannel(blink::WebRTCDataChannelHandler* handler) 663 void RTCPeerConnection::didAddRemoteDataChannel(blink::WebRTCDataChannelHandler* handler)
622 { 664 {
665 ASSERT(!m_closed);
623 ASSERT(executionContext()->isContextThread()); 666 ASSERT(executionContext()->isContextThread());
624 667
625 if (m_signalingState == SignalingStateClosed) 668 if (m_signalingState == SignalingStateClosed)
626 return; 669 return;
627 670
628 RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executio nContext(), adoptPtr(handler)); 671 RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executio nContext(), adoptPtr(handler));
629 m_dataChannels.append(channel); 672 m_dataChannels.append(channel);
630 673
631 scheduleDispatchEvent(RTCDataChannelEvent::create(EventTypeNames::datachanne l, false, false, channel.release())); 674 scheduleDispatchEvent(RTCDataChannelEvent::create(EventTypeNames::datachanne l, false, false, channel.release()));
632 } 675 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 741
699 void RTCPeerConnection::scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event> even t) 742 void RTCPeerConnection::scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event> even t)
700 { 743 {
701 m_scheduledEvents.append(event); 744 m_scheduledEvents.append(event);
702 745
703 m_dispatchScheduledEventRunner.runAsync(); 746 m_dispatchScheduledEventRunner.runAsync();
704 } 747 }
705 748
706 void RTCPeerConnection::dispatchScheduledEvent() 749 void RTCPeerConnection::dispatchScheduledEvent()
707 { 750 {
751 ASSERT(!m_closed);
708 if (m_stopped) 752 if (m_stopped)
709 return; 753 return;
710 754
711 WillBeHeapVector<RefPtrWillBeMember<Event> > events; 755 WillBeHeapVector<RefPtrWillBeMember<Event> > events;
712 events.swap(m_scheduledEvents); 756 events.swap(m_scheduledEvents);
713 757
714 WillBeHeapVector<RefPtrWillBeMember<Event> >::iterator it = events.begin(); 758 WillBeHeapVector<RefPtrWillBeMember<Event> >::iterator it = events.begin();
715 for (; it != events.end(); ++it) 759 for (; it != events.end(); ++it)
716 dispatchEvent((*it).release()); 760 dispatchEvent((*it).release());
717 761
718 events.clear(); 762 events.clear();
719 } 763 }
720 764
721 void RTCPeerConnection::trace(Visitor* visitor) 765 void RTCPeerConnection::trace(Visitor* visitor)
722 { 766 {
723 visitor->trace(m_localStreams); 767 visitor->trace(m_localStreams);
724 visitor->trace(m_remoteStreams); 768 visitor->trace(m_remoteStreams);
725 visitor->trace(m_dataChannels); 769 visitor->trace(m_dataChannels);
726 visitor->trace(m_scheduledEvents); 770 visitor->trace(m_scheduledEvents);
727 EventTargetWithInlineData::trace(visitor); 771 EventTargetWithInlineData::trace(visitor);
728 } 772 }
729 773
730 } // namespace WebCore 774 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698