Skip to content

Commit

Permalink
4373801: Use rtc::scoped_refptr for webrtc::DataChannel objects
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Aug 2, 2023
1 parent af84144 commit 2df593a
Showing 1 changed file with 10 additions and 38 deletions.
48 changes: 10 additions & 38 deletions patches/chromium/cherry-pick-b03973561862.patch
Expand Up @@ -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(
Expand Down Expand Up @@ -58,7 +58,7 @@ index 78d28d60822f4ce206d869846235352224378076..f5fc9fc01397d46a1262d7747925f425
RTCDataChannel::RTCDataChannel(
ExecutionContext* context,
- scoped_refptr<webrtc::DataChannelInterface> channel,
+ rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel,
+ scoped_refptr<webrtc::DataChannelInterface> data_channel,
RTCPeerConnectionHandler* peer_connection_handler)
: ExecutionContextLifecycleObserver(context),
state_(webrtc::DataChannelInterface::kConnecting),
Expand All @@ -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<RTCDataChannel::Observer> observer,
+ [](scoped_refptr<RTCDataChannel::Observer> observer_,
webrtc::DataChannelInterface::DataState current_state) {
scoped_refptr<webrtc::DataChannelInterface> 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;
Expand All @@ -108,35 +92,23 @@ 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

const scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
WeakPersistent<RTCDataChannel> blink_channel_;
- scoped_refptr<webrtc::DataChannelInterface> webrtc_channel_;
+ const rtc::scoped_refptr<webrtc::DataChannelInterface> webrtc_channel_;
+ const scoped_refptr<webrtc::DataChannelInterface> 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> 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<uint16_t> 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
Expand Down

0 comments on commit 2df593a

Please sign in to comment.