Convert P2PtransportChannel.GatheringState to CallbackList
Earlier attempts have shown that this signal is multiply listened to.
Bug: webrtc:11943
Change-Id: I382df9a554925d214872d788c5d7a36f2f7c7b7e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/348661
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42139}
diff --git a/p2p/base/ice_transport_internal.h b/p2p/base/ice_transport_internal.h
index 38b6bfe..32e913d 100644
--- a/p2p/base/ice_transport_internal.h
+++ b/p2p/base/ice_transport_internal.h
@@ -306,10 +306,14 @@
// Signal Exposed for backwards compatibility.
sigslot::signal1<IceTransportInternal*> SignalGatheringState;
- void SetGatheringStateCallback(
+ void AddGatheringStateCallback(
+ const void* removal_tag,
absl::AnyInvocable<void(IceTransportInternal*)> callback) {
- RTC_DCHECK(!gathering_state_callback_);
- gathering_state_callback_ = std::move(callback);
+ gathering_state_callback_list_.AddReceiver(removal_tag,
+ std::move(callback));
+ }
+ void RemoveGatheringStateCallback(const void* removal_tag) {
+ gathering_state_callback_list_.RemoveReceivers(removal_tag);
}
// Handles sending and receiving of candidates.
@@ -393,7 +397,7 @@
webrtc::CallbackList<IceTransportInternal*, const StunDictionaryWriter&>
dictionary_writer_synced_callback_list_;
- absl::AnyInvocable<void(IceTransportInternal*)> gathering_state_callback_;
+ webrtc::CallbackList<IceTransportInternal*> gathering_state_callback_list_;
absl::AnyInvocable<void(IceTransportInternal*, const IceCandidateErrorEvent&)>
candidate_error_callback_;
@@ -407,9 +411,7 @@
private:
// TODO(bugs.webrtc.org/11943): remove when removing Signal
void SignalGatheringStateFired(IceTransportInternal* transport) {
- if (gathering_state_callback_) {
- gathering_state_callback_(transport);
- }
+ gathering_state_callback_list_.Send(transport);
}
};
diff --git a/pc/jsep_transport_controller.cc b/pc/jsep_transport_controller.cc
index dae7060..7152826 100644
--- a/pc/jsep_transport_controller.cc
+++ b/pc/jsep_transport_controller.cc
@@ -439,8 +439,8 @@
this, &JsepTransportController::OnTransportWritableState_n);
dtls->SignalReceivingState.connect(
this, &JsepTransportController::OnTransportReceivingState_n);
- dtls->ice_transport()->SetGatheringStateCallback(
- [this](cricket::IceTransportInternal* transport) {
+ dtls->ice_transport()->AddGatheringStateCallback(
+ this, [this](cricket::IceTransportInternal* transport) {
RTC_DCHECK_RUN_ON(network_thread_);
OnTransportGatheringState_n(transport);
});