From e125a3371f66284d3e271b7ed5e650f52b375ef1 Mon Sep 17 00:00:00 2001 From: Daniel Cheng Date: Sat, 2 Dec 2023 14:16:59 -0800 Subject: [PATCH] Add IceControllerInterface::GetConnections() and fix return type. This is a replacement for `connections()`, which is const-qualified but returns a `rtc::ArrayView`. Unfortunately, this is a view of mutable pointers to `const cricket::Connection` objects: this means that the pointers in `IceControllerInterface`'s backing store can be reassigned. Returning `rtc::ArrayView` is more consistent with how a view returned from a const-qualified method should behave. Unfortunately, there are downstream overrides of this method, so instead of just fixing this outright, add a new method with the correct return type. Once downstream is updated, the old method can then be removed. Bug: chromium:1409870, webrtc:15702 Change-Id: I3d8f0c2f0bcf4c393ee63959cb61761ac00a28ab Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/329962 Reviewed-by: Jonas Oreland Reviewed-by: Harald Alvestrand Commit-Queue: Daniel Cheng Cr-Commit-Position: refs/heads/main@{#41318} --- p2p/base/basic_ice_controller.h | 3 +++ p2p/base/ice_controller_interface.h | 15 +++++++++++++-- p2p/base/mock_ice_controller.h | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/p2p/base/basic_ice_controller.h b/p2p/base/basic_ice_controller.h index b941a0dd7e..724609d2d7 100644 --- a/p2p/base/basic_ice_controller.h +++ b/p2p/base/basic_ice_controller.h @@ -32,6 +32,9 @@ class BasicIceController : public IceControllerInterface { void SetSelectedConnection(const Connection* selected_connection) override; void AddConnection(const Connection* connection) override; void OnConnectionDestroyed(const Connection* connection) override; + rtc::ArrayView GetConnections() const override { + return connections_; + } rtc::ArrayView connections() const override { return rtc::ArrayView( const_cast(connections_.data()), diff --git a/p2p/base/ice_controller_interface.h b/p2p/base/ice_controller_interface.h index 8b63ed3fc3..fb421cf0f9 100644 --- a/p2p/base/ice_controller_interface.h +++ b/p2p/base/ice_controller_interface.h @@ -19,6 +19,7 @@ #include "p2p/base/connection.h" #include "p2p/base/ice_switch_reason.h" #include "p2p/base/ice_transport_internal.h" +#include "rtc_base/checks.h" #include "rtc_base/system/rtc_export.h" namespace cricket { @@ -53,7 +54,7 @@ struct RTC_EXPORT IceRecheckEvent { // Connection::ForgetLearnedState - return in SwitchResult // // The IceController shall keep track of all connections added -// (and not destroyed) and give them back using the connections()-function- +// (and not destroyed) and give them back using the GetConnections() function. // // When a Connection gets destroyed // - signals on Connection::SignalDestroyed @@ -101,7 +102,17 @@ class IceControllerInterface { virtual void OnConnectionDestroyed(const Connection* connection) = 0; // These are all connections that has been added and not destroyed. - virtual rtc::ArrayView connections() const = 0; + virtual rtc::ArrayView GetConnections() const { + // Stub implementation to simplify downstream roll. + RTC_CHECK_NOTREACHED(); + return {}; + } + // TODO(bugs.webrtc.org/15702): Remove this after downstream is cleaned up. + virtual rtc::ArrayView connections() const { + // Stub implementation to simplify downstream removal. + RTC_CHECK_NOTREACHED(); + return {}; + } // Is there a pingable connection ? // This function is used to boot-strap pinging, after this returns true diff --git a/p2p/base/mock_ice_controller.h b/p2p/base/mock_ice_controller.h index bde9254e7d..f552519be0 100644 --- a/p2p/base/mock_ice_controller.h +++ b/p2p/base/mock_ice_controller.h @@ -35,6 +35,10 @@ class MockIceController : public cricket::IceControllerInterface { OnConnectionDestroyed, (const cricket::Connection*), (override)); + MOCK_METHOD(rtc::ArrayView, + GetConnections, + (), + (const, override)); MOCK_METHOD(rtc::ArrayView, connections, (),