tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 9c285be04e86374fdf812b1d6d7634b282e0b88b
parent 02112e2b30efe7dd22204b91636fe66f05fe32ae
Author: Michael Froman <mfroman@mozilla.com>
Date:   Wed,  8 Oct 2025 22:03:30 -0500

Bug 1993083 - Vendor libwebrtc from 90ea14188f

Upstream commit: https://webrtc.googlesource.com/src/+/90ea14188ff81146ad9767e596a85fa4c43afa7e
    Remove PeerConnectionInternal::Observer and instead add RunWithObserver

    This is a NOP refactoring,
    that will in subsequent patches allow for checking of re-entrace.
    I.e. Adding asserts to functions that are unsafe to call while being in
    an callback.

    Bug: webrtc:429335703
    Change-Id: I669572fd02b11a91546c69f976717d22fe1f6fb3
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/399040
    Reviewed-by: Harald Alvestrand <hta@webrtc.org>
    Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#45094}

Diffstat:
Mthird_party/libwebrtc/README.mozilla.last-vendor | 4++--
Mthird_party/libwebrtc/moz-patch-stack/s0103.patch | 2+-
Mthird_party/libwebrtc/pc/BUILD.gn | 5+++++
Mthird_party/libwebrtc/pc/data_channel_controller.cc | 4++--
Mthird_party/libwebrtc/pc/peer_connection.cc | 58+++++++++++++++++++++++++++++++++++++++++++++-------------
Mthird_party/libwebrtc/pc/peer_connection.h | 12++++++++++--
Mthird_party/libwebrtc/pc/peer_connection_internal.h | 7+++++--
Mthird_party/libwebrtc/pc/rtp_transmission_manager.cc | 17++++++++++-------
Mthird_party/libwebrtc/pc/rtp_transmission_manager.h | 5++++-
Mthird_party/libwebrtc/pc/sdp_offer_answer.cc | 128++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Mthird_party/libwebrtc/pc/test/fake_peer_connection_base.h | 7++++++-
Mthird_party/libwebrtc/pc/test/mock_peer_connection_internal.h | 6+++++-
12 files changed, 169 insertions(+), 86 deletions(-)

diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor @@ -1,4 +1,4 @@ # ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc -libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-09T03:02:06.197963+00:00. +libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-09T03:03:20.552903+00:00. # base of lastest vendoring -5004d269dc +90ea14188f diff --git a/third_party/libwebrtc/moz-patch-stack/s0103.patch b/third_party/libwebrtc/moz-patch-stack/s0103.patch @@ -601,7 +601,7 @@ index f79625d651..fe09ff6f5b 100644 import("../../webrtc.gni") diff --git a/pc/BUILD.gn b/pc/BUILD.gn -index 1af9f2efb0..0086730835 100644 +index 605b9bb84a..278e312c85 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -30,8 +30,8 @@ diff --git a/third_party/libwebrtc/pc/BUILD.gn b/third_party/libwebrtc/pc/BUILD.gn @@ -928,6 +928,7 @@ rtc_library("data_channel_controller") { "../rtc_base:timeutils", "../rtc_base:weak_ptr", "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/functional:any_invocable", ] } @@ -959,6 +960,7 @@ rtc_source_set("peer_connection_internal") { "../rtc_base:ssl", "../rtc_base:ssl_adapter", "../rtc_base:threading", + "//third_party/abseil-cpp/absl/functional:any_invocable", "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -1153,6 +1155,7 @@ rtc_library("sdp_offer_answer") { "../rtc_base:weak_ptr", "../system_wrappers:metrics", "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/functional:any_invocable", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/strings:string_view", @@ -1279,6 +1282,7 @@ rtc_library("peer_connection") { "../rtc_base:weak_ptr", "../system_wrappers:metrics", "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/functional:any_invocable", "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/strings:string_view", ] @@ -1699,6 +1703,7 @@ rtc_library("rtp_transmission_manager") { "../rtc_base:threading", "../rtc_base:unique_id_generator", "../rtc_base:weak_ptr", + "//third_party/abseil-cpp/absl/functional:any_invocable", ] } diff --git a/third_party/libwebrtc/pc/data_channel_controller.cc b/third_party/libwebrtc/pc/data_channel_controller.cc @@ -19,10 +19,10 @@ #include <vector> #include "absl/algorithm/container.h" +#include "absl/functional/any_invocable.h" #include "api/array_view.h" #include "api/data_channel_event_observer_interface.h" #include "api/data_channel_interface.h" -#include "api/peer_connection_interface.h" #include "api/priority.h" #include "api/rtc_error.h" #include "api/scoped_refptr.h" @@ -330,7 +330,7 @@ void DataChannelController::OnDataChannelOpenMessage( channel_usage_ = DataChannelUsage::kInUse; auto proxy = SctpDataChannel::CreateProxy(channel, signaling_safety_.flag()); - pc_->Observer()->OnDataChannel(proxy); + pc_->RunWithObserver([&](auto observer) { observer->OnDataChannel(proxy); }); pc_->NoteDataAddedEvent(); if (ready_to_send) { diff --git a/third_party/libwebrtc/pc/peer_connection.cc b/third_party/libwebrtc/pc/peer_connection.cc @@ -24,6 +24,7 @@ #include <vector> #include "absl/algorithm/container.h" +#include "absl/functional/any_invocable.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -1774,11 +1775,17 @@ void PeerConnection::Close() { legacy_stats_->UpdateStats(kStatsOutputLevelStandard); ice_connection_state_ = PeerConnectionInterface::kIceConnectionClosed; - Observer()->OnIceConnectionChange(ice_connection_state_); + RunWithObserver([&](auto observer) { + RTC_DCHECK_RUN_ON(signaling_thread()); + observer->OnIceConnectionChange(ice_connection_state_); + }); standardized_ice_connection_state_ = PeerConnectionInterface::IceConnectionState::kIceConnectionClosed; connection_state_ = PeerConnectionInterface::PeerConnectionState::kClosed; - Observer()->OnConnectionChange(connection_state_); + RunWithObserver([&](auto observer) { + RTC_DCHECK_RUN_ON(signaling_thread()); + observer->OnConnectionChange(connection_state_); + }); sdp_handler_->Close(); @@ -1866,7 +1873,10 @@ void PeerConnection::SetIceConnectionState(IceConnectionState new_state) { PeerConnectionInterface::kIceConnectionClosed); ice_connection_state_ = new_state; - Observer()->OnIceConnectionChange(ice_connection_state_); + RunWithObserver([&](auto observer) { + RTC_DCHECK_RUN_ON(signaling_thread()); + observer->OnIceConnectionChange(ice_connection_state_); + }); } void PeerConnection::SetStandardizedIceConnectionState( @@ -1883,7 +1893,9 @@ void PeerConnection::SetStandardizedIceConnectionState( << standardized_ice_connection_state_ << " => " << new_state; standardized_ice_connection_state_ = new_state; - Observer()->OnStandardizedIceConnectionChange(new_state); + RunWithObserver([&](auto observer) { + observer->OnStandardizedIceConnectionChange(new_state); + }); } void PeerConnection::SetConnectionState( @@ -1893,7 +1905,8 @@ void PeerConnection::SetConnectionState( if (IsClosed()) return; connection_state_ = new_state; - Observer()->OnConnectionChange(new_state); + RunWithObserver( + [&](auto observer) { observer->OnConnectionChange(new_state); }); // The first connection state change to connected happens once per // connection which makes it a good point to report metrics. @@ -2029,7 +2042,10 @@ void PeerConnection::OnIceGatheringChange( return; } ice_gathering_state_ = new_state; - Observer()->OnIceGatheringChange(ice_gathering_state_); + RunWithObserver([&](auto observer) { + RTC_DCHECK_RUN_ON(signaling_thread()); + observer->OnIceGatheringChange(ice_gathering_state_); + }); } void PeerConnection::OnIceCandidate(std::unique_ptr<IceCandidate> candidate) { @@ -2038,7 +2054,8 @@ void PeerConnection::OnIceCandidate(std::unique_ptr<IceCandidate> candidate) { } ReportIceCandidateCollected(candidate->candidate()); ClearStatsCache(); - Observer()->OnIceCandidate(candidate.get()); + RunWithObserver( + [&](auto observer) { observer->OnIceCandidate(candidate.get()); }); } void PeerConnection::OnIceCandidateError(const std::string& address, @@ -2049,7 +2066,9 @@ void PeerConnection::OnIceCandidateError(const std::string& address, if (IsClosed()) { return; } - Observer()->OnIceCandidateError(address, port, url, error_code, error_text); + RunWithObserver([&](auto observer) { + observer->OnIceCandidateError(address, port, url, error_code, error_text); + }); } void PeerConnection::OnIceCandidatesRemoved( @@ -2057,7 +2076,8 @@ void PeerConnection::OnIceCandidatesRemoved( if (IsClosed()) { return; } - Observer()->OnIceCandidatesRemoved(candidates); + RunWithObserver( + [&](auto observer) { observer->OnIceCandidatesRemoved(candidates); }); } void PeerConnection::OnSelectedCandidatePairChanged( @@ -2071,7 +2091,9 @@ void PeerConnection::OnSelectedCandidatePairChanged( NoteUsageEvent(UsageEvent::DIRECT_CONNECTION_SELECTED); } - Observer()->OnIceSelectedCandidatePairChanged(event); + RunWithObserver([&](auto observer) { + observer->OnIceSelectedCandidatePairChanged(event); + }); } bool PeerConnection::CreateDataChannelTransport(absl::string_view mid) { @@ -2684,7 +2706,10 @@ void PeerConnection::AddRemoteCandidate(absl::string_view mid, } void PeerConnection::ReportUsagePattern() const { - usage_pattern_.ReportUsagePattern(observer_); + RunWithMaybeNullObserver([&](auto observer) { + RTC_DCHECK_RUN_ON(signaling_thread()); + usage_pattern_.ReportUsagePattern(observer); + }); } void PeerConnection::ReportRemoteIceCandidateAdded(const Candidate& candidate) { @@ -2908,10 +2933,17 @@ bool PeerConnection::OnTransportChanged( return ret; } -PeerConnectionObserver* PeerConnection::Observer() const { +void PeerConnection::RunWithObserver( + absl::AnyInvocable<void(webrtc::PeerConnectionObserver*) &&> task) { RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK(observer_); - return observer_; + std::move(task)(observer_); +} + +void PeerConnection::RunWithMaybeNullObserver( + absl::AnyInvocable<void(webrtc::PeerConnectionObserver*) &&> task) const { + RTC_DCHECK_RUN_ON(signaling_thread()); + std::move(task)(observer_); } RTCError PeerConnection::StartSctpTransport(const SctpOptions& options) { diff --git a/third_party/libwebrtc/pc/peer_connection.h b/third_party/libwebrtc/pc/peer_connection.h @@ -21,6 +21,7 @@ #include <string> #include <vector> +#include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" #include "api/adaptation/resource.h" #include "api/async_dns_resolver.h" @@ -308,8 +309,15 @@ class PeerConnection : public PeerConnectionInternal, // Functions needed by DataChannelController void NoteDataAddedEvent() override { NoteUsageEvent(UsageEvent::DATA_ADDED); } - // Returns the observer. Will crash on CHECK if the observer is removed. - PeerConnectionObserver* Observer() const override; + + void RunWithObserver( + absl::AnyInvocable<void(webrtc::PeerConnectionObserver*) &&>) override + RTC_RUN_ON(signaling_thread()); + + void RunWithMaybeNullObserver( + absl::AnyInvocable<void(webrtc::PeerConnectionObserver*) &&>) const + RTC_RUN_ON(signaling_thread()); + bool IsClosed() const override { RTC_DCHECK_RUN_ON(signaling_thread()); return !sdp_handler_ || diff --git a/third_party/libwebrtc/pc/peer_connection_internal.h b/third_party/libwebrtc/pc/peer_connection_internal.h @@ -18,6 +18,7 @@ #include <string> #include <vector> +#include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" #include "api/audio/audio_device.h" #include "api/candidate.h" @@ -96,8 +97,10 @@ class PeerConnectionSdpMethods { virtual DataChannelController* data_channel_controller() = 0; virtual PortAllocator* port_allocator() = 0; virtual LegacyStatsCollector* legacy_stats() = 0; - // Returns the observer. Will crash on CHECK if the observer is removed. - virtual PeerConnectionObserver* Observer() const = 0; + // Run lambda on the PeerConnectionObserver. Will crash on CHECK if the + // observer is removed. + virtual void RunWithObserver( + absl::AnyInvocable<void(webrtc::PeerConnectionObserver*) &&>) = 0; virtual std::optional<SSLRole> GetSctpSslRole_n() = 0; virtual PeerConnectionInterface::IceConnectionState ice_connection_state_internal() = 0; diff --git a/third_party/libwebrtc/pc/rtp_transmission_manager.cc b/third_party/libwebrtc/pc/rtp_transmission_manager.cc @@ -17,6 +17,7 @@ #include <utility> #include <vector> +#include "absl/functional/any_invocable.h" #include "api/environment/environment.h" #include "api/make_ref_counted.h" #include "api/media_stream_interface.h" @@ -92,11 +93,11 @@ void RtpTransmissionManager::OnNegotiationNeeded() { on_negotiation_needed_(); } -// Function that returns the currently valid observer -PeerConnectionObserver* RtpTransmissionManager::Observer() const { - RTC_DCHECK(!closed_); +void RtpTransmissionManager::RunWithObserver( + absl::AnyInvocable<void(webrtc::PeerConnectionObserver*) &&> task) { + RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK(observer_); - return observer_; + std::move(task)(observer_); } VoiceMediaSendChannelInterface* @@ -524,7 +525,8 @@ void RtpTransmissionManager::CreateAudioReceiver( auto receiver = RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create( signaling_thread(), worker_thread(), std::move(audio_receiver)); GetAudioTransceiver()->internal()->AddReceiver(receiver); - Observer()->OnAddTrack(receiver, streams); + RunWithObserver( + [&](auto observer) { observer->OnAddTrack(receiver, streams); }); NoteUsageEvent(UsageEvent::AUDIO_ADDED); } @@ -548,7 +550,8 @@ void RtpTransmissionManager::CreateVideoReceiver( auto receiver = RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create( signaling_thread(), worker_thread(), std::move(video_receiver)); GetVideoTransceiver()->internal()->AddReceiver(receiver); - Observer()->OnAddTrack(receiver, streams); + RunWithObserver( + [&](auto observer) { observer->OnAddTrack(receiver, streams); }); NoteUsageEvent(UsageEvent::VIDEO_ADDED); } @@ -624,7 +627,7 @@ void RtpTransmissionManager::OnRemoteSenderRemoved( } if (receiver) { RTC_DCHECK(!closed_); - Observer()->OnRemoveTrack(receiver); + RunWithObserver([&](auto observer) { observer->OnRemoveTrack(receiver); }); } } diff --git a/third_party/libwebrtc/pc/rtp_transmission_manager.h b/third_party/libwebrtc/pc/rtp_transmission_manager.h @@ -17,6 +17,7 @@ #include <string> #include <vector> +#include "absl/functional/any_invocable.h" #include "api/environment/environment.h" #include "api/media_stream_interface.h" #include "api/media_types.h" @@ -28,6 +29,7 @@ #include "api/scoped_refptr.h" #include "api/sequence_checker.h" #include "media/base/media_channel.h" +#include "media/base/media_engine.h" #include "pc/codec_vendor.h" #include "pc/connection_context.h" #include "pc/legacy_stats_collector_interface.h" @@ -239,7 +241,8 @@ class RtpTransmissionManager : public RtpSenderBase::SetStreamsObserver { scoped_refptr<RtpReceiverInterface> RemoveAndStopReceiver( const RtpSenderInfo& remote_sender_info) RTC_RUN_ON(signaling_thread()); - PeerConnectionObserver* Observer() const; + void RunWithObserver( + absl::AnyInvocable<void(webrtc::PeerConnectionObserver*) &&>); void OnNegotiationNeeded(); MediaEngineInterface* media_engine() const; diff --git a/third_party/libwebrtc/pc/sdp_offer_answer.cc b/third_party/libwebrtc/pc/sdp_offer_answer.cc @@ -25,6 +25,7 @@ #include <vector> #include "absl/algorithm/container.h" +#include "absl/functional/any_invocable.h" #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -1855,13 +1856,14 @@ RTCError SdpOfferAnswerHandler::ApplyLocalDescription( transceiver->set_fired_direction(media_desc->direction()); } } - auto observer = pc_->Observer(); - for (const auto& transceiver : remove_list) { - observer->OnRemoveTrack(transceiver->receiver()); - } - for (const auto& stream : removed_streams) { - observer->OnRemoveStream(stream); - } + pc_->RunWithObserver([&](auto observer) { + for (const auto& transceiver : remove_list) { + observer->OnRemoveTrack(transceiver->receiver()); + } + for (const auto& stream : removed_streams) { + observer->OnRemoveStream(stream); + } + }); } } else { // Media channels will be created only when offer is set. These may use new @@ -2307,22 +2309,23 @@ void SdpOfferAnswerHandler::ApplyRemoteDescriptionUpdateTransceiverState( } } // Once all processing has finished, fire off callbacks. - auto observer = pc_->Observer(); - for (const auto& transceiver : now_receiving_transceivers) { - pc_->legacy_stats()->AddTrack(transceiver->receiver()->track().get()); - observer->OnTrack(transceiver); - observer->OnAddTrack(transceiver->receiver(), - transceiver->receiver()->streams()); - } - for (const auto& stream : added_streams) { - observer->OnAddStream(stream); - } - for (const auto& transceiver : remove_list) { - observer->OnRemoveTrack(transceiver->receiver()); - } - for (const auto& stream : removed_streams) { - observer->OnRemoveStream(stream); - } + pc_->RunWithObserver([&](auto observer) { + for (const auto& transceiver : now_receiving_transceivers) { + pc_->legacy_stats()->AddTrack(transceiver->receiver()->track().get()); + observer->OnTrack(transceiver); + observer->OnAddTrack(transceiver->receiver(), + transceiver->receiver()->streams()); + } + for (const auto& stream : added_streams) { + observer->OnAddStream(stream); + } + for (const auto& transceiver : remove_list) { + observer->OnRemoveTrack(transceiver->receiver()); + } + for (const auto& stream : removed_streams) { + observer->OnRemoveStream(stream); + } + }); } void SdpOfferAnswerHandler::PlanBUpdateSendersAndReceivers( @@ -2376,12 +2379,13 @@ void SdpOfferAnswerHandler::PlanBUpdateSendersAndReceivers( } // Iterate new_streams and notify the observer about new MediaStreams. - auto observer = pc_->Observer(); - for (size_t i = 0; i < new_streams->count(); ++i) { - MediaStreamInterface* new_stream = new_streams->at(i); - pc_->legacy_stats()->AddStream(new_stream); - observer->OnAddStream(scoped_refptr<MediaStreamInterface>(new_stream)); - } + pc_->RunWithObserver([&](auto observer) { + for (size_t i = 0; i < new_streams->count(); ++i) { + MediaStreamInterface* new_stream = new_streams->at(i); + pc_->legacy_stats()->AddStream(new_stream); + observer->OnAddStream(scoped_refptr<MediaStreamInterface>(new_stream)); + } + }); UpdateEndedRemoteMediaStreams(); } @@ -2600,7 +2604,8 @@ void SdpOfferAnswerHandler::DoSetLocalDescription( if (signaling_state() == PeerConnectionInterface::kStable && was_negotiation_needed && is_negotiation_needed_) { // Legacy version. - pc_->Observer()->OnRenegotiationNeeded(); + pc_->RunWithObserver( + [&](auto observer) { observer->OnRenegotiationNeeded(); }); // Spec-compliant version; the event may get invalidated before firing. GenerateNegotiationNeededEvent(); } @@ -2825,7 +2830,8 @@ void SdpOfferAnswerHandler::SetRemoteDescriptionPostProcess(bool was_answer) { if (signaling_state() == PeerConnectionInterface::kStable && was_negotiation_needed && is_negotiation_needed_) { // Legacy version. - pc_->Observer()->OnRenegotiationNeeded(); + pc_->RunWithObserver( + [&](auto observer) { observer->OnRenegotiationNeeded(); }); // Spec-compliant version; the event may get invalidated before firing. GenerateNegotiationNeededEvent(); } @@ -3097,7 +3103,10 @@ void SdpOfferAnswerHandler::ChangeSignalingState( << " New state: " << PeerConnectionInterface::AsString(signaling_state); signaling_state_ = signaling_state; - pc_->Observer()->OnSignalingChange(signaling_state_); + pc_->RunWithObserver([&](auto observer) { + RTC_DCHECK_RUN_ON(signaling_thread()); + observer->OnSignalingChange(signaling_state_); + }); } RTCError SdpOfferAnswerHandler::UpdateSessionState( @@ -3402,20 +3411,22 @@ RTCError SdpOfferAnswerHandler::Rollback(SdpType desc_type) { ChangeSignalingState(PeerConnectionInterface::kStable); // Once all processing has finished, fire off callbacks. - for (const auto& transceiver : now_receiving_transceivers) { - pc_->Observer()->OnTrack(transceiver); - pc_->Observer()->OnAddTrack(transceiver->receiver(), - transceiver->receiver()->streams()); - } - for (const auto& receiver : removed_receivers) { - pc_->Observer()->OnRemoveTrack(receiver); - } - for (const auto& stream : all_added_streams) { - pc_->Observer()->OnAddStream(stream); - } - for (const auto& stream : all_removed_streams) { - pc_->Observer()->OnRemoveStream(stream); - } + pc_->RunWithObserver([&](auto observer) { + for (const auto& transceiver : now_receiving_transceivers) { + observer->OnTrack(transceiver); + observer->OnAddTrack(transceiver->receiver(), + transceiver->receiver()->streams()); + } + for (const auto& receiver : removed_receivers) { + observer->OnRemoveTrack(receiver); + } + for (const auto& stream : all_added_streams) { + observer->OnAddStream(stream); + } + for (const auto& stream : all_removed_streams) { + observer->OnRemoveStream(stream); + } + }); // The assumption is that in case of implicit rollback // UpdateNegotiationNeeded gets called in SetRemoteDescription. @@ -3423,7 +3434,8 @@ RTCError SdpOfferAnswerHandler::Rollback(SdpType desc_type) { UpdateNegotiationNeeded(); if (is_negotiation_needed_) { // Legacy version. - pc_->Observer()->OnRenegotiationNeeded(); + pc_->RunWithObserver( + [&](auto observer) { observer->OnRenegotiationNeeded(); }); // Spec-compliant version; the event may get invalidated before firing. GenerateNegotiationNeededEvent(); } @@ -3479,7 +3491,8 @@ std::optional<SSLRole> SdpOfferAnswerHandler::GetDtlsRole( void SdpOfferAnswerHandler::UpdateNegotiationNeeded() { RTC_DCHECK_RUN_ON(signaling_thread()); if (!IsUnifiedPlan()) { - pc_->Observer()->OnRenegotiationNeeded(); + pc_->RunWithObserver( + [&](auto observer) { observer->OnRenegotiationNeeded(); }); GenerateNegotiationNeededEvent(); return; } @@ -3532,7 +3545,8 @@ void SdpOfferAnswerHandler::UpdateNegotiationNeeded() { // If connection's [[IsClosed]] slot is true, abort these steps. // If connection's [[NegotiationNeeded]] slot is false, abort these steps. // Fire an event named negotiationneeded at connection. - pc_->Observer()->OnRenegotiationNeeded(); + pc_->RunWithObserver( + [&](auto observer) { observer->OnRenegotiationNeeded(); }); // Fire the spec-compliant version; when ShouldFireNegotiationNeededEvent() // is used in the task queued by the observer, this event will only fire // when the chain is empty. @@ -3759,7 +3773,10 @@ bool SdpOfferAnswerHandler::CheckIfNegotiationIsNeeded() { void SdpOfferAnswerHandler::GenerateNegotiationNeededEvent() { RTC_DCHECK_RUN_ON(signaling_thread()); ++negotiation_needed_event_id_; - pc_->Observer()->OnNegotiationNeededEvent(negotiation_needed_event_id_); + pc_->RunWithObserver([&](auto observer) { + RTC_DCHECK_RUN_ON(signaling_thread()); + observer->OnNegotiationNeededEvent(negotiation_needed_event_id_); + }); } RTCError SdpOfferAnswerHandler::ValidateSessionDescription( @@ -5244,10 +5261,13 @@ void SdpOfferAnswerHandler::UpdateEndedRemoteMediaStreams() { } } - for (auto& stream : streams_to_remove) { - remote_streams_->RemoveStream(stream.get()); - pc_->Observer()->OnRemoveStream(std::move(stream)); - } + pc_->RunWithObserver([&](auto observer) { + RTC_DCHECK_RUN_ON(signaling_thread()); + for (auto& stream : streams_to_remove) { + remote_streams_->RemoveStream(stream.get()); + observer->OnRemoveStream(std::move(stream)); + } + }); } bool SdpOfferAnswerHandler::UseCandidatesInRemoteDescription() { diff --git a/third_party/libwebrtc/pc/test/fake_peer_connection_base.h b/third_party/libwebrtc/pc/test/fake_peer_connection_base.h @@ -20,6 +20,7 @@ #include <type_traits> #include <vector> +#include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" #include "api/adaptation/resource.h" #include "api/audio/audio_device.h" @@ -59,6 +60,7 @@ #include "pc/session_description.h" #include "pc/transport_stats.h" #include "pc/usage_pattern.h" +#include "rtc_base/checks.h" #include "rtc_base/ref_counted_object.h" #include "rtc_base/rtc_certificate.h" #include "rtc_base/ssl_certificate.h" @@ -361,7 +363,10 @@ class FakePeerConnectionBase : public PeerConnectionInternal { DataChannelController* data_channel_controller() override { return nullptr; } PortAllocator* port_allocator() override { return nullptr; } LegacyStatsCollector* legacy_stats() override { return nullptr; } - PeerConnectionObserver* Observer() const override { return nullptr; } + void RunWithObserver( + absl::AnyInvocable<void(webrtc::PeerConnectionObserver*) &&>) override { + RTC_DCHECK_NOTREACHED(); + } std::optional<SSLRole> GetSctpSslRole_n() override { return std::nullopt; } PeerConnectionInterface::IceConnectionState ice_connection_state_internal() override { diff --git a/third_party/libwebrtc/pc/test/mock_peer_connection_internal.h b/third_party/libwebrtc/pc/test/mock_peer_connection_internal.h @@ -19,6 +19,7 @@ #include <string> #include <vector> +#include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" #include "api/adaptation/resource.h" #include "api/audio/audio_device.h" @@ -286,7 +287,10 @@ class MockPeerConnectionInternal : public PeerConnectionInternal { MOCK_METHOD(DataChannelController*, data_channel_controller, (), (override)); MOCK_METHOD(PortAllocator*, port_allocator, (), (override)); MOCK_METHOD(LegacyStatsCollector*, legacy_stats, (), (override)); - MOCK_METHOD(PeerConnectionObserver*, Observer, (), (const, override)); + MOCK_METHOD(void, + RunWithObserver, + (absl::AnyInvocable<void(webrtc::PeerConnectionObserver*) &&>), + (override)); MOCK_METHOD(std::optional<SSLRole>, GetSctpSslRole_n, (), (override)); MOCK_METHOD(PeerConnectionInterface::IceConnectionState, ice_connection_state_internal,