diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/chromium/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc b/chromium/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc index 83dae0b5ebb..b74fa162ae0 100644 --- a/chromium/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc +++ b/chromium/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc @@ -36,6 +36,7 @@ #include "third_party/blink/renderer/core/fileapi/blob.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h" +#include "third_party/blink/renderer/modules/peerconnection/adapters/web_rtc_cross_thread_copier.h" #include "third_party/blink/renderer/modules/peerconnection/rtc_error_event.h" #include "third_party/blink/renderer/modules/peerconnection/rtc_peer_connection.h" #include "third_party/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.h" @@ -45,6 +46,17 @@ #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" #include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h" +namespace WTF { + +template <> +struct CrossThreadCopier<scoped_refptr<webrtc::DataChannelInterface>> + : public CrossThreadCopierPassThrough< + scoped_refptr<webrtc::DataChannelInterface>> { + STATIC_ONLY(CrossThreadCopier); +}; + +} // namespace WTF + namespace blink { namespace { @@ -110,6 +122,12 @@ void RecordMessageSent(const webrtc::DataChannelInterface& channel, } } +void SendOnSignalingThread( + const scoped_refptr<webrtc::DataChannelInterface> channel, + const webrtc::DataBuffer data_buffer) { + channel->Send(data_buffer); +} + } // namespace static void ThrowNotOpenException(ExceptionState* exception_state) { @@ -223,10 +241,12 @@ RTCDataChannel::RTCDataChannel( buffered_amount_(0U), stopped_(false), closed_from_owner_(false), + is_rtp_data_channel_(peer_connection_handler->enable_rtp_data_channel()), observer_(base::MakeRefCounted<Observer>( context->GetTaskRunner(TaskType::kNetworking), this, - channel)) { + channel)), + signaling_thread_(peer_connection_handler->signaling_thread()) { DCHECK(peer_connection_handler); // Register observer and get state update to make up for state change updates @@ -364,9 +384,7 @@ void RTCDataChannel::send(const String& data, ExceptionState& exception_state) { } buffered_amount_ += data_buffer.size(); RecordMessageSent(*channel().get(), data_buffer.size()); - if (!channel()->Send(data_buffer)) { - // TODO(https://crbug.com/937848): Don't throw an exception if data is - // queued. + if (!SendDataBuffer(std::move(data_buffer))) { ThrowCouldNotSendDataException(&exception_state); } } @@ -482,7 +500,7 @@ bool RTCDataChannel::HasPendingActivity() const { bufferedAmount() > 0; } -void RTCDataChannel::Trace(Visitor* visitor) { +void RTCDataChannel::Trace(Visitor* visitor) const { visitor->Trace(scheduled_events_); EventTargetWithInlineData::Trace(visitor); ExecutionContextLifecycleObserver::Trace(visitor); @@ -613,7 +631,20 @@ bool RTCDataChannel::SendRawData(const char* data, size_t length) { rtc::CopyOnWriteBuffer buffer(data, length); webrtc::DataBuffer data_buffer(buffer, true); RecordMessageSent(*channel().get(), data_buffer.size()); - return channel()->Send(data_buffer); + return SendDataBuffer(std::move(data_buffer)); +} + +bool RTCDataChannel::SendDataBuffer(webrtc::DataBuffer data_buffer) { + // RTP data channels return false on failure to send. SCTP data channels + // queue the packet on failure and always return true, so Send can be + // called asynchronously for them. + if (is_rtp_data_channel_) { + return channel()->Send(data_buffer); + } + PostCrossThreadTask(*signaling_thread_.get(), FROM_HERE, + CrossThreadBindOnce(&SendOnSignalingThread, channel(), + std::move(data_buffer))); + return true; } } // namespace blink |