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}
This commit is contained in:
Harald Alvestrand 2024-04-22 10:22:08 +00:00 committed by WebRTC LUCI CQ
parent 5bd0a32859
commit 6f170a05dc
2 changed files with 11 additions and 9 deletions

View file

@ -306,10 +306,14 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal {
// Signal Exposed for backwards compatibility. // Signal Exposed for backwards compatibility.
sigslot::signal1<IceTransportInternal*> SignalGatheringState; sigslot::signal1<IceTransportInternal*> SignalGatheringState;
void SetGatheringStateCallback( void AddGatheringStateCallback(
const void* removal_tag,
absl::AnyInvocable<void(IceTransportInternal*)> callback) { absl::AnyInvocable<void(IceTransportInternal*)> callback) {
RTC_DCHECK(!gathering_state_callback_); gathering_state_callback_list_.AddReceiver(removal_tag,
gathering_state_callback_ = std::move(callback); std::move(callback));
}
void RemoveGatheringStateCallback(const void* removal_tag) {
gathering_state_callback_list_.RemoveReceivers(removal_tag);
} }
// Handles sending and receiving of candidates. // Handles sending and receiving of candidates.
@ -393,7 +397,7 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal {
webrtc::CallbackList<IceTransportInternal*, const StunDictionaryWriter&> webrtc::CallbackList<IceTransportInternal*, const StunDictionaryWriter&>
dictionary_writer_synced_callback_list_; 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&)> absl::AnyInvocable<void(IceTransportInternal*, const IceCandidateErrorEvent&)>
candidate_error_callback_; candidate_error_callback_;
@ -407,9 +411,7 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal {
private: private:
// TODO(bugs.webrtc.org/11943): remove when removing Signal // TODO(bugs.webrtc.org/11943): remove when removing Signal
void SignalGatheringStateFired(IceTransportInternal* transport) { void SignalGatheringStateFired(IceTransportInternal* transport) {
if (gathering_state_callback_) { gathering_state_callback_list_.Send(transport);
gathering_state_callback_(transport);
}
} }
}; };

View file

@ -439,8 +439,8 @@ JsepTransportController::CreateDtlsTransport(
this, &JsepTransportController::OnTransportWritableState_n); this, &JsepTransportController::OnTransportWritableState_n);
dtls->SignalReceivingState.connect( dtls->SignalReceivingState.connect(
this, &JsepTransportController::OnTransportReceivingState_n); this, &JsepTransportController::OnTransportReceivingState_n);
dtls->ice_transport()->SetGatheringStateCallback( dtls->ice_transport()->AddGatheringStateCallback(
[this](cricket::IceTransportInternal* transport) { this, [this](cricket::IceTransportInternal* transport) {
RTC_DCHECK_RUN_ON(network_thread_); RTC_DCHECK_RUN_ON(network_thread_);
OnTransportGatheringState_n(transport); OnTransportGatheringState_n(transport);
}); });