From 2df593a78df963320b1c7e517a60b34e392742c6 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 2 Aug 2023 10:22:06 +0200 Subject: [PATCH] 4373801: Use rtc::scoped_refptr for webrtc::DataChannel objects https://chromium-review.googlesource.com/c/chromium/src/+/4373801 --- .../chromium/cherry-pick-b03973561862.patch | 48 ++++--------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/patches/chromium/cherry-pick-b03973561862.patch b/patches/chromium/cherry-pick-b03973561862.patch index d577b82560050..87b92b8ea574d 100644 --- a/patches/chromium/cherry-pick-b03973561862.patch +++ b/patches/chromium/cherry-pick-b03973561862.patch @@ -20,7 +20,7 @@ Cr-Commit-Position: refs/branch-heads/5845@{#300} Cr-Branched-From: 5a5dff63a4a4c63b9b18589819bebb2566c85443-refs/heads/main@{#1160321} diff --git a/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc b/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc -index 78d28d60822f4ce206d869846235352224378076..f5fc9fc01397d46a1262d7747925f425c0677af2 100644 +index 78d28d60822f4ce206d869846235352224378076..91c20cbcc5042373964d57545177ff06074db564 100644 --- a/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc +++ b/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc @@ -228,11 +228,12 @@ RTCDataChannel::Observer::Observer( @@ -58,7 +58,7 @@ index 78d28d60822f4ce206d869846235352224378076..f5fc9fc01397d46a1262d7747925f425 RTCDataChannel::RTCDataChannel( ExecutionContext* context, - scoped_refptr channel, -+ rtc::scoped_refptr data_channel, ++ scoped_refptr data_channel, RTCPeerConnectionHandler* peer_connection_handler) : ExecutionContextLifecycleObserver(context), state_(webrtc::DataChannelInterface::kConnecting), @@ -71,28 +71,12 @@ index 78d28d60822f4ce206d869846235352224378076..f5fc9fc01397d46a1262d7747925f425 signaling_thread_(peer_connection_handler->signaling_thread()) { DCHECK(peer_connection_handler); -@@ -328,19 +324,19 @@ RTCDataChannel::RTCDataChannel( - // channel state consistency. - peer_connection_handler->RunSynchronousOnceClosureOnSignalingThread( - CrossThreadBindOnce( -- [](scoped_refptr observer, -+ [](scoped_refptr observer_, - webrtc::DataChannelInterface::DataState current_state) { - scoped_refptr channel = - observer->channel(); -- channel->RegisterObserver(observer.get()); -- if (channel->state() != current_state) { -- observer->OnStateChange(); -+ channel()->RegisterObserver(observer_.get()); -+ if (channel()->state() != state_) { -+ observer_->OnStateChange(); - } - }, +@@ -340,7 +336,7 @@ RTCDataChannel::RTCDataChannel( observer_, state_), "RegisterObserverAndGetStateUpdate"); - IncrementCounters(*channel.get()); -+ IncrementCounters(*channel().get()); ++ IncrementCounters(*(observer_->channel()).get()); } RTCDataChannel::~RTCDataChannel() = default; @@ -108,7 +92,7 @@ index 78d28d60822f4ce206d869846235352224378076..f5fc9fc01397d46a1262d7747925f425 void RTCDataChannel::ScheduleDispatchEvent(Event* event) { diff --git a/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.h b/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.h -index 21bb39382ac0c6acbf984ffbda5f6a4e6c863432..e48c049cc2820b16a8496f08ef6e4b206d5a4cd0 100644 +index 21bb39382ac0c6acbf984ffbda5f6a4e6c863432..6959b8b1e3a0b586be68cb4a8d0389b7926b98fe 100644 --- a/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.h +++ b/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.h @@ -152,7 +152,7 @@ class MODULES_EXPORT RTCDataChannel final @@ -116,27 +100,15 @@ index 21bb39382ac0c6acbf984ffbda5f6a4e6c863432..e48c049cc2820b16a8496f08ef6e4b20 const scoped_refptr main_thread_; WeakPersistent blink_channel_; - scoped_refptr webrtc_channel_; -+ const rtc::scoped_refptr webrtc_channel_; ++ const scoped_refptr webrtc_channel_; }; void OnStateChange(webrtc::DataChannelInterface::DataState state); -@@ -191,11 +191,19 @@ class MODULES_EXPORT RTCDataChannel final - FrameScheduler::SchedulingAffectingFeatureHandle - feature_handle_for_scheduler_; - -- unsigned buffered_amount_low_threshold_; -- unsigned buffered_amount_; -- bool stopped_; -- bool closed_from_owner_; +@@ -195,7 +195,11 @@ class MODULES_EXPORT RTCDataChannel final + unsigned buffered_amount_; + bool stopped_; + bool closed_from_owner_; - scoped_refptr observer_; -+ // Once an id has been assigned, we'll set this value and use it instead -+ // of querying the channel (which requires thread hop). This is a cached -+ // value to optimize a const getter, and therefore `mutable`. -+ mutable absl::optional id_; -+ unsigned buffered_amount_low_threshold_ = 0u; -+ unsigned buffered_amount_ = 0u; -+ bool stopped_ = false; -+ bool closed_from_owner_ = false; + // Keep the `observer_` reference const to make it clear that we don't want + // to free the underlying channel (or callback observer) until the + // `RTCDataChannel` instance goes away. This allows properties to be queried