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

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: 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 * 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
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_weakPtrFactory(this)
184 , m_stopped(false) 185 , m_stopped(false)
186 , m_closed(false)
185 { 187 {
186 ScriptWrappable::init(this); 188 ScriptWrappable::init(this);
187 Document* document = toDocument(executionContext()); 189 Document* document = toDocument(executionContext());
188 190
191 // If we fail, set |m_closed| and |m_stopped| to true, to avoid hitting the assert in the destructor.
192
189 if (!document->frame()) { 193 if (!document->frame()) {
194 m_closed = true;
195 m_stopped = true;
190 exceptionState.throwDOMException(NotSupportedError, "PeerConnections may not be created in detached documents."); 196 exceptionState.throwDOMException(NotSupportedError, "PeerConnections may not be created in detached documents.");
191 return; 197 return;
192 } 198 }
193 199
194 m_peerHandler = adoptPtr(blink::Platform::current()->createRTCPeerConnection Handler(this)); 200 m_peerHandler = adoptPtr(blink::Platform::current()->createRTCPeerConnection Handler(this));
195 if (!m_peerHandler) { 201 if (!m_peerHandler) {
202 m_closed = true;
203 m_stopped = true;
196 exceptionState.throwDOMException(NotSupportedError, "No PeerConnection h andler can be created, perhaps WebRTC is disabled?"); 204 exceptionState.throwDOMException(NotSupportedError, "No PeerConnection h andler can be created, perhaps WebRTC is disabled?");
197 return; 205 return;
198 } 206 }
199 207
200 document->frame()->loader().client()->dispatchWillStartUsingPeerConnectionHa ndler(m_peerHandler.get()); 208 document->frame()->loader().client()->dispatchWillStartUsingPeerConnectionHa ndler(m_peerHandler.get());
201 209
202 if (!m_peerHandler->initialize(configuration, constraints)) { 210 if (!m_peerHandler->initialize(configuration, constraints)) {
211 m_closed = true;
212 m_stopped = true;
203 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ e native PeerConnection."); 213 exceptionState.throwDOMException(NotSupportedError, "Failed to initializ e native PeerConnection.");
204 return; 214 return;
205 } 215 }
206 } 216 }
207 217
208 RTCPeerConnection::~RTCPeerConnection() 218 RTCPeerConnection::~RTCPeerConnection()
209 { 219 {
210 // This checks that stop() is called if necessary before the destructor. 220 // This checks that close() or stop() is called before the destructor.
211 // We are assuming that a wrapper is always created when RTCPeerConnection i s created 221 // We are assuming that a wrapper is always created when RTCPeerConnection i s created.
212 ASSERT(m_dataChannels.isEmpty()); 222 ASSERT(m_closed || m_stopped);
223 stop();
keishi 2014/06/17 07:53:10 We should remove this now.
Henrik Grunell 2014/06/17 08:08:27 Done.
213 } 224 }
214 225
215 void RTCPeerConnection::createOffer(PassOwnPtr<RTCSessionDescriptionCallback> su ccessCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& med iaConstraints, ExceptionState& exceptionState) 226 void RTCPeerConnection::createOffer(PassOwnPtr<RTCSessionDescriptionCallback> su ccessCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& med iaConstraints, ExceptionState& exceptionState)
216 { 227 {
217 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 228 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
218 return; 229 return;
219 230
220 ASSERT(successCallback); 231 ASSERT(successCallback);
221 232
222 blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaC onstraints, exceptionState); 233 blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaC onstraints, exceptionState);
223 if (exceptionState.hadException()) 234 if (exceptionState.hadException())
224 return; 235 return;
225 236
226 RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestI mpl::create(executionContext(), successCallback, errorCallback); 237 RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestI mpl::create(executionContext(), this, successCallback, errorCallback);
227 m_peerHandler->createOffer(request.release(), constraints); 238 m_peerHandler->createOffer(request.release(), constraints);
228 } 239 }
229 240
230 void RTCPeerConnection::createAnswer(PassOwnPtr<RTCSessionDescriptionCallback> s uccessCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& me diaConstraints, ExceptionState& exceptionState) 241 void RTCPeerConnection::createAnswer(PassOwnPtr<RTCSessionDescriptionCallback> s uccessCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& me diaConstraints, ExceptionState& exceptionState)
231 { 242 {
232 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 243 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
233 return; 244 return;
234 245
235 ASSERT(successCallback); 246 ASSERT(successCallback);
236 247
237 blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaC onstraints, exceptionState); 248 blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaC onstraints, exceptionState);
238 if (exceptionState.hadException()) 249 if (exceptionState.hadException())
239 return; 250 return;
240 251
241 RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestI mpl::create(executionContext(), successCallback, errorCallback); 252 RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestI mpl::create(executionContext(), this, successCallback, errorCallback);
242 m_peerHandler->createAnswer(request.release(), constraints); 253 m_peerHandler->createAnswer(request.release(), constraints);
243 } 254 }
244 255
245 void RTCPeerConnection::setLocalDescription(PassRefPtrWillBeRawPtr<RTCSessionDes cription> prpSessionDescription, PassOwnPtr<VoidCallback> successCallback, PassO wnPtr<RTCErrorCallback> errorCallback, ExceptionState& exceptionState) 256 void RTCPeerConnection::setLocalDescription(PassRefPtrWillBeRawPtr<RTCSessionDes cription> prpSessionDescription, PassOwnPtr<VoidCallback> successCallback, PassO wnPtr<RTCErrorCallback> errorCallback, ExceptionState& exceptionState)
246 { 257 {
247 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 258 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
248 return; 259 return;
249 260
250 RefPtrWillBeRawPtr<RTCSessionDescription> sessionDescription = prpSessionDes cription; 261 RefPtrWillBeRawPtr<RTCSessionDescription> sessionDescription = prpSessionDes cription;
251 if (!sessionDescription) { 262 if (!sessionDescription) {
252 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription")); 263 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription"));
253 return; 264 return;
254 } 265 }
255 266
256 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), successCallback, errorCallback); 267 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), this, successCallback, errorCallback);
257 m_peerHandler->setLocalDescription(request.release(), sessionDescription->we bSessionDescription()); 268 m_peerHandler->setLocalDescription(request.release(), sessionDescription->we bSessionDescription());
258 } 269 }
259 270
260 PassRefPtrWillBeRawPtr<RTCSessionDescription> RTCPeerConnection::localDescriptio n(ExceptionState& exceptionState) 271 PassRefPtrWillBeRawPtr<RTCSessionDescription> RTCPeerConnection::localDescriptio n(ExceptionState& exceptionState)
261 { 272 {
262 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->local Description(); 273 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->local Description();
263 if (webSessionDescription.isNull()) 274 if (webSessionDescription.isNull())
264 return nullptr; 275 return nullptr;
265 276
266 return RTCSessionDescription::create(webSessionDescription); 277 return RTCSessionDescription::create(webSessionDescription);
267 } 278 }
268 279
269 void RTCPeerConnection::setRemoteDescription(PassRefPtrWillBeRawPtr<RTCSessionDe scription> prpSessionDescription, PassOwnPtr<VoidCallback> successCallback, Pass OwnPtr<RTCErrorCallback> errorCallback, ExceptionState& exceptionState) 280 void RTCPeerConnection::setRemoteDescription(PassRefPtrWillBeRawPtr<RTCSessionDe scription> prpSessionDescription, PassOwnPtr<VoidCallback> successCallback, Pass OwnPtr<RTCErrorCallback> errorCallback, ExceptionState& exceptionState)
270 { 281 {
271 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 282 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
272 return; 283 return;
273 284
274 RefPtrWillBeRawPtr<RTCSessionDescription> sessionDescription = prpSessionDes cription; 285 RefPtrWillBeRawPtr<RTCSessionDescription> sessionDescription = prpSessionDes cription;
275 if (!sessionDescription) { 286 if (!sessionDescription) {
276 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription")); 287 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCSessionDescription"));
277 return; 288 return;
278 } 289 }
279 290
280 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), successCallback, errorCallback); 291 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), this, successCallback, errorCallback);
281 m_peerHandler->setRemoteDescription(request.release(), sessionDescription->w ebSessionDescription()); 292 m_peerHandler->setRemoteDescription(request.release(), sessionDescription->w ebSessionDescription());
282 } 293 }
283 294
284 PassRefPtrWillBeRawPtr<RTCSessionDescription> RTCPeerConnection::remoteDescripti on(ExceptionState& exceptionState) 295 PassRefPtrWillBeRawPtr<RTCSessionDescription> RTCPeerConnection::remoteDescripti on(ExceptionState& exceptionState)
285 { 296 {
286 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->remot eDescription(); 297 blink::WebRTCSessionDescription webSessionDescription = m_peerHandler->remot eDescription();
287 if (webSessionDescription.isNull()) 298 if (webSessionDescription.isNull())
288 return nullptr; 299 return nullptr;
289 300
290 return RTCSessionDescription::create(webSessionDescription); 301 return RTCSessionDescription::create(webSessionDescription);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 339 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
329 return; 340 return;
330 341
331 if (!iceCandidate) { 342 if (!iceCandidate) {
332 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate")); 343 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "RTCIceCandidate"));
333 return; 344 return;
334 } 345 }
335 ASSERT(successCallback); 346 ASSERT(successCallback);
336 ASSERT(errorCallback); 347 ASSERT(errorCallback);
337 348
338 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), successCallback, errorCallback); 349 RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext (), this, successCallback, errorCallback);
339 350
340 bool implemented = m_peerHandler->addICECandidate(request.release(), iceCand idate->webCandidate()); 351 bool implemented = m_peerHandler->addICECandidate(request.release(), iceCand idate->webCandidate());
341 if (!implemented) 352 if (!implemented) {
342 exceptionState.throwDOMException(NotSupportedError, "This method is not yet implemented."); 353 exceptionState.throwDOMException(NotSupportedError, "This method is not yet implemented.");
354 }
343 } 355 }
344 356
345 String RTCPeerConnection::signalingState() const 357 String RTCPeerConnection::signalingState() const
346 { 358 {
347 switch (m_signalingState) { 359 switch (m_signalingState) {
348 case SignalingStateStable: 360 case SignalingStateStable:
349 return "stable"; 361 return "stable";
350 case SignalingStateHaveLocalOffer: 362 case SignalingStateHaveLocalOffer:
351 return "have-local-offer"; 363 return "have-local-offer";
352 case SignalingStateHaveRemoteOffer: 364 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) { 479 for (MediaStreamVector::iterator iter = m_remoteStreams.begin(); iter != m_r emoteStreams.end(); ++iter) {
468 if ((*iter)->id() == streamId) 480 if ((*iter)->id() == streamId)
469 return iter->get(); 481 return iter->get();
470 } 482 }
471 483
472 return 0; 484 return 0;
473 } 485 }
474 486
475 void RTCPeerConnection::getStats(PassOwnPtr<RTCStatsCallback> successCallback, P assRefPtr<MediaStreamTrack> selector) 487 void RTCPeerConnection::getStats(PassOwnPtr<RTCStatsCallback> successCallback, P assRefPtr<MediaStreamTrack> selector)
476 { 488 {
477 RefPtr<RTCStatsRequest> statsRequest = RTCStatsRequestImpl::create(execution Context(), successCallback, selector); 489 RefPtr<RTCStatsRequest> statsRequest = RTCStatsRequestImpl::create(execution Context(), this, successCallback, selector);
478 // FIXME: Add passing selector as part of the statsRequest. 490 // FIXME: Add passing selector as part of the statsRequest.
479 m_peerHandler->getStats(statsRequest.release()); 491 m_peerHandler->getStats(statsRequest.release());
480 } 492 }
481 493
482 PassRefPtrWillBeRawPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(Stri ng label, const Dictionary& options, ExceptionState& exceptionState) 494 PassRefPtrWillBeRawPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(Stri ng label, const Dictionary& options, ExceptionState& exceptionState)
483 { 495 {
484 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 496 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
485 return nullptr; 497 return nullptr;
486 498
487 blink::WebRTCDataChannelInit init; 499 blink::WebRTCDataChannelInit init;
488 options.get("ordered", init.ordered); 500 options.get("ordered", init.ordered);
489 options.get("negotiated", init.negotiated); 501 options.get("negotiated", init.negotiated);
490 502
491 unsigned short value = 0; 503 unsigned short value = 0;
492 if (options.get("id", value)) 504 if (options.get("id", value))
493 init.id = value; 505 init.id = value;
494 if (options.get("maxRetransmits", value)) 506 if (options.get("maxRetransmits", value))
495 init.maxRetransmits = value; 507 init.maxRetransmits = value;
496 if (options.get("maxRetransmitTime", value)) 508 if (options.get("maxRetransmitTime", value))
497 init.maxRetransmitTime = value; 509 init.maxRetransmitTime = value;
498 510
499 String protocolString; 511 String protocolString;
500 options.get("protocol", protocolString); 512 options.get("protocol", protocolString);
501 init.protocol = protocolString; 513 init.protocol = protocolString;
502 514
503 RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executio nContext(), m_peerHandler.get(), label, init, exceptionState); 515 RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executio nContext(), m_weakPtrFactory.createWeakPtr(), m_peerHandler.get(), label, init, exceptionState);
keishi 2014/06/17 07:58:21 We need to pass m_weakPtrFactory.createWeakPtr() f
Henrik Grunell 2014/06/17 08:08:27 Done.
504 if (exceptionState.hadException()) 516 if (exceptionState.hadException())
505 return nullptr; 517 return nullptr;
506 m_dataChannels.append(channel); 518 m_dataChannels.append(channel);
507 return channel.release(); 519 return channel.release();
508 } 520 }
509 521
510 bool RTCPeerConnection::hasLocalStreamWithTrackId(const String& trackId) 522 bool RTCPeerConnection::hasLocalStreamWithTrackId(const String& trackId)
511 { 523 {
512 for (MediaStreamVector::iterator iter = m_localStreams.begin(); iter != m_lo calStreams.end(); ++iter) { 524 for (MediaStreamVector::iterator iter = m_localStreams.begin(); iter != m_lo calStreams.end(); ++iter) {
513 if ((*iter)->getTrackById(trackId)) 525 if ((*iter)->getTrackById(trackId))
(...skipping 24 matching lines...) Expand all
538 return nullptr; 550 return nullptr;
539 return dtmfSender.release(); 551 return dtmfSender.release();
540 } 552 }
541 553
542 void RTCPeerConnection::close(ExceptionState& exceptionState) 554 void RTCPeerConnection::close(ExceptionState& exceptionState)
543 { 555 {
544 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 556 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
545 return; 557 return;
546 558
547 m_peerHandler->stop(); 559 m_peerHandler->stop();
560 m_closed = true;
548 561
549 changeIceConnectionState(ICEConnectionStateClosed); 562 changeIceConnectionState(ICEConnectionStateClosed);
550 changeIceGatheringState(ICEGatheringStateComplete); 563 changeIceGatheringState(ICEGatheringStateComplete);
551 changeSignalingState(SignalingStateClosed); 564 changeSignalingState(SignalingStateClosed);
552 } 565 }
553 566
554 void RTCPeerConnection::negotiationNeeded() 567 void RTCPeerConnection::negotiationNeeded()
555 { 568 {
569 ASSERT(!m_closed);
556 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded)); 570 scheduleDispatchEvent(Event::create(EventTypeNames::negotiationneeded));
557 } 571 }
558 572
559 void RTCPeerConnection::didGenerateICECandidate(const blink::WebRTCICECandidate& webCandidate) 573 void RTCPeerConnection::didGenerateICECandidate(const blink::WebRTCICECandidate& webCandidate)
560 { 574 {
575 ASSERT(!m_closed);
561 ASSERT(executionContext()->isContextThread()); 576 ASSERT(executionContext()->isContextThread());
562 if (webCandidate.isNull()) 577 if (webCandidate.isNull())
563 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, nullptr )); 578 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, nullptr ));
564 else { 579 else {
565 RefPtrWillBeRawPtr<RTCIceCandidate> iceCandidate = RTCIceCandidate::crea te(webCandidate); 580 RefPtrWillBeRawPtr<RTCIceCandidate> iceCandidate = RTCIceCandidate::crea te(webCandidate);
566 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, iceCand idate.release())); 581 scheduleDispatchEvent(RTCIceCandidateEvent::create(false, false, iceCand idate.release()));
567 } 582 }
568 } 583 }
569 584
570 void RTCPeerConnection::didChangeSignalingState(SignalingState newState) 585 void RTCPeerConnection::didChangeSignalingState(SignalingState newState)
571 { 586 {
587 ASSERT(!m_closed);
572 ASSERT(executionContext()->isContextThread()); 588 ASSERT(executionContext()->isContextThread());
573 changeSignalingState(newState); 589 changeSignalingState(newState);
574 } 590 }
575 591
576 void RTCPeerConnection::didChangeICEGatheringState(ICEGatheringState newState) 592 void RTCPeerConnection::didChangeICEGatheringState(ICEGatheringState newState)
577 { 593 {
594 ASSERT(!m_closed);
578 ASSERT(executionContext()->isContextThread()); 595 ASSERT(executionContext()->isContextThread());
579 changeIceGatheringState(newState); 596 changeIceGatheringState(newState);
580 } 597 }
581 598
582 void RTCPeerConnection::didChangeICEConnectionState(ICEConnectionState newState) 599 void RTCPeerConnection::didChangeICEConnectionState(ICEConnectionState newState)
583 { 600 {
601 ASSERT(!m_closed);
584 ASSERT(executionContext()->isContextThread()); 602 ASSERT(executionContext()->isContextThread());
585 changeIceConnectionState(newState); 603 changeIceConnectionState(newState);
586 } 604 }
587 605
588 void RTCPeerConnection::didAddRemoteStream(const blink::WebMediaStream& remoteSt ream) 606 void RTCPeerConnection::didAddRemoteStream(const blink::WebMediaStream& remoteSt ream)
589 { 607 {
608 ASSERT(!m_closed);
590 ASSERT(executionContext()->isContextThread()); 609 ASSERT(executionContext()->isContextThread());
591 610
592 if (m_signalingState == SignalingStateClosed) 611 if (m_signalingState == SignalingStateClosed)
593 return; 612 return;
594 613
595 RefPtrWillBeRawPtr<MediaStream> stream = MediaStream::create(executionContex t(), remoteStream); 614 RefPtrWillBeRawPtr<MediaStream> stream = MediaStream::create(executionContex t(), remoteStream);
596 m_remoteStreams.append(stream); 615 m_remoteStreams.append(stream);
597 616
598 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::addstream, fa lse, false, stream.release())); 617 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::addstream, fa lse, false, stream.release()));
599 } 618 }
600 619
601 void RTCPeerConnection::didRemoveRemoteStream(const blink::WebMediaStream& remot eStream) 620 void RTCPeerConnection::didRemoveRemoteStream(const blink::WebMediaStream& remot eStream)
602 { 621 {
622 ASSERT(!m_closed);
603 ASSERT(executionContext()->isContextThread()); 623 ASSERT(executionContext()->isContextThread());
604 624
605 MediaStreamDescriptor* streamDescriptor = remoteStream; 625 MediaStreamDescriptor* streamDescriptor = remoteStream;
606 ASSERT(streamDescriptor->client()); 626 ASSERT(streamDescriptor->client());
607 627
608 RefPtrWillBeRawPtr<MediaStream> stream = static_cast<MediaStream*>(streamDes criptor->client()); 628 RefPtrWillBeRawPtr<MediaStream> stream = static_cast<MediaStream*>(streamDes criptor->client());
609 stream->streamEnded(); 629 stream->streamEnded();
610 630
611 if (m_signalingState == SignalingStateClosed) 631 if (m_signalingState == SignalingStateClosed)
612 return; 632 return;
613 633
614 size_t pos = m_remoteStreams.find(stream); 634 size_t pos = m_remoteStreams.find(stream);
615 ASSERT(pos != kNotFound); 635 ASSERT(pos != kNotFound);
616 m_remoteStreams.remove(pos); 636 m_remoteStreams.remove(pos);
617 637
618 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::removestream, false, false, stream.release())); 638 scheduleDispatchEvent(MediaStreamEvent::create(EventTypeNames::removestream, false, false, stream.release()));
619 } 639 }
620 640
621 void RTCPeerConnection::didAddRemoteDataChannel(blink::WebRTCDataChannelHandler* handler) 641 void RTCPeerConnection::didAddRemoteDataChannel(blink::WebRTCDataChannelHandler* handler)
622 { 642 {
643 ASSERT(!m_closed);
623 ASSERT(executionContext()->isContextThread()); 644 ASSERT(executionContext()->isContextThread());
624 645
625 if (m_signalingState == SignalingStateClosed) 646 if (m_signalingState == SignalingStateClosed)
626 return; 647 return;
627 648
628 RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executio nContext(), adoptPtr(handler)); 649 RefPtrWillBeRawPtr<RTCDataChannel> channel = RTCDataChannel::create(executio nContext(), m_weakPtrFactory.createWeakPtr(), adoptPtr(handler));
keishi 2014/06/17 07:58:21 Ditto.
Henrik Grunell 2014/06/17 08:08:27 Done.
629 m_dataChannels.append(channel); 650 m_dataChannels.append(channel);
630 651
631 scheduleDispatchEvent(RTCDataChannelEvent::create(EventTypeNames::datachanne l, false, false, channel.release())); 652 scheduleDispatchEvent(RTCDataChannelEvent::create(EventTypeNames::datachanne l, false, false, channel.release()));
632 } 653 }
633 654
634 void RTCPeerConnection::releasePeerConnectionHandler() 655 void RTCPeerConnection::releasePeerConnectionHandler()
635 { 656 {
636 stop(); 657 stop();
637 } 658 }
638 659
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 void RTCPeerConnection::trace(Visitor* visitor) 742 void RTCPeerConnection::trace(Visitor* visitor)
722 { 743 {
723 visitor->trace(m_localStreams); 744 visitor->trace(m_localStreams);
724 visitor->trace(m_remoteStreams); 745 visitor->trace(m_remoteStreams);
725 visitor->trace(m_dataChannels); 746 visitor->trace(m_dataChannels);
726 visitor->trace(m_scheduledEvents); 747 visitor->trace(m_scheduledEvents);
727 EventTargetWithInlineData::trace(visitor); 748 EventTargetWithInlineData::trace(visitor);
728 } 749 }
729 750
730 } // namespace WebCore 751 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698