From f0e65bab0e6cce9cb2453f703f7561c080fbcfd0 Mon Sep 17 00:00:00 2001 From: Sameer Vijaykar Date: Tue, 11 Oct 2022 10:02:06 +0200 Subject: [PATCH] Accept ArrayView in ICE agent interface where feasible. Ownership does not need to cross the interface boundary, so ArrayView can be safely accepted in ForgetStateForConnections and PruneConnections. Bug: webrtc:14131 Change-Id: I18a739aea1dc47976d17925e9bca3461225bf803 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/278629 Commit-Queue: Sameer Vijaykar Reviewed-by: Jonas Oreland Cr-Commit-Position: refs/heads/main@{#38418} --- p2p/base/ice_agent_interface.h | 8 ++++---- p2p/base/mock_ice_agent.h | 4 ++-- p2p/base/p2p_transport_channel.cc | 4 ++-- p2p/base/p2p_transport_channel.h | 5 +++-- p2p/base/wrapping_active_ice_controller_unittest.cc | 12 +++++++----- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/p2p/base/ice_agent_interface.h b/p2p/base/ice_agent_interface.h index c00204cbc5..30b6ade6e6 100644 --- a/p2p/base/ice_agent_interface.h +++ b/p2p/base/ice_agent_interface.h @@ -11,8 +11,7 @@ #ifndef P2P_BASE_ICE_AGENT_INTERFACE_H_ #define P2P_BASE_ICE_AGENT_INTERFACE_H_ -#include - +#include "api/array_view.h" #include "p2p/base/connection.h" #include "p2p/base/ice_switch_reason.h" @@ -61,7 +60,7 @@ class IceAgentInterface { // // SignalStateChange will not be triggered. virtual void ForgetLearnedStateForConnections( - std::vector connections) = 0; + rtc::ArrayView connections) = 0; // Send a STUN ping request for the given connection. virtual void SendPingRequest(const Connection* connection) = 0; @@ -72,7 +71,8 @@ class IceAgentInterface { // Prune away the given connections. Returns true if pruning is permitted and // successfully performed. - virtual bool PruneConnections(std::vector connections) = 0; + virtual bool PruneConnections( + rtc::ArrayView connections) = 0; }; } // namespace cricket diff --git a/p2p/base/mock_ice_agent.h b/p2p/base/mock_ice_agent.h index e4100ecd7a..a1c0ebffbf 100644 --- a/p2p/base/mock_ice_agent.h +++ b/p2p/base/mock_ice_agent.h @@ -32,7 +32,7 @@ class MockIceAgent : public IceAgentInterface { MOCK_METHOD(void, UpdateState, (), (override)); MOCK_METHOD(void, ForgetLearnedStateForConnections, - (std::vector), + (rtc::ArrayView), (override)); MOCK_METHOD(void, SendPingRequest, (const Connection*), (override)); MOCK_METHOD(void, @@ -41,7 +41,7 @@ class MockIceAgent : public IceAgentInterface { (override)); MOCK_METHOD(bool, PruneConnections, - (std::vector), + (rtc::ArrayView), (override)); }; diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc index 5acd2e8cb9..02d1f321f7 100644 --- a/p2p/base/p2p_transport_channel.cc +++ b/p2p/base/p2p_transport_channel.cc @@ -339,7 +339,7 @@ bool P2PTransportChannel::MaybeSwitchSelectedConnection( } void P2PTransportChannel::ForgetLearnedStateForConnections( - std::vector connections) { + rtc::ArrayView connections) { for (const Connection* con : connections) { FromIceController(con)->ForgetLearnedState(); } @@ -1885,7 +1885,7 @@ void P2PTransportChannel::PruneConnections() { } bool P2PTransportChannel::PruneConnections( - std::vector connections) { + rtc::ArrayView connections) { RTC_DCHECK_RUN_ON(network_thread_); if (!AllowedToPruneConnections()) { RTC_LOG(LS_WARNING) << "Not allowed to prune connections"; diff --git a/p2p/base/p2p_transport_channel.h b/p2p/base/p2p_transport_channel.h index d7bcd239df..f7bfce0e17 100644 --- a/p2p/base/p2p_transport_channel.h +++ b/p2p/base/p2p_transport_channel.h @@ -180,8 +180,9 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal, void SwitchSelectedConnection(const Connection* connection, IceSwitchReason reason) override; void ForgetLearnedStateForConnections( - std::vector connections) override; - bool PruneConnections(std::vector connections) override; + rtc::ArrayView connections) override; + bool PruneConnections( + rtc::ArrayView connections) override; // TODO(honghaiz): Remove this method once the reference of it in // Chromoting is removed. diff --git a/p2p/base/wrapping_active_ice_controller_unittest.cc b/p2p/base/wrapping_active_ice_controller_unittest.cc index 7dfdfef0f5..b4811bd297 100644 --- a/p2p/base/wrapping_active_ice_controller_unittest.cc +++ b/p2p/base/wrapping_active_ice_controller_unittest.cc @@ -37,6 +37,8 @@ using ::cricket::NominationMode; using ::cricket::WrappingActiveIceController; using ::testing::_; +using ::testing::ElementsAreArray; +using ::testing::IsEmpty; using ::testing::NiceMock; using ::testing::Ref; using ::testing::Return; @@ -132,7 +134,8 @@ TEST(WrappingActiveIceControllerTest, HandlesImmediateSwitchRequest) { .WillOnce(Return(switch_result)); EXPECT_CALL(agent, SwitchSelectedConnection(kConnection, reason)) .InSequence(check_then_switch); - EXPECT_CALL(agent, ForgetLearnedStateForConnections(conns_to_forget)); + EXPECT_CALL(agent, ForgetLearnedStateForConnections( + ElementsAreArray(conns_to_forget))); EXPECT_TRUE(controller.OnImmediateSwitchRequest(reason, kConnection)); @@ -146,7 +149,7 @@ TEST(WrappingActiveIceControllerTest, HandlesImmediateSwitchRequest) { SortAndSwitchConnection(IceSwitchReason::ICE_CONTROLLER_RECHECK)) .InSequence(recheck_sort) .WillOnce(Return(IceControllerInterface::SwitchResult{})); - EXPECT_CALL(agent, ForgetLearnedStateForConnections(kEmptyConnsList)); + EXPECT_CALL(agent, ForgetLearnedStateForConnections(IsEmpty())); clock.AdvanceTime(kTick); } @@ -180,7 +183,7 @@ TEST(WrappingActiveIceControllerTest, HandlesImmediateSortAndSwitchRequest) { EXPECT_CALL(*wrapped, PruneConnections()) .InSequence(sort_and_switch) .WillOnce(Return(conns_to_prune)); - EXPECT_CALL(agent, PruneConnections(conns_to_prune)) + EXPECT_CALL(agent, PruneConnections(ElementsAreArray(conns_to_prune))) .InSequence(sort_and_switch); controller.OnImmediateSortAndSwitchRequest(reason); @@ -198,8 +201,7 @@ TEST(WrappingActiveIceControllerTest, HandlesImmediateSortAndSwitchRequest) { EXPECT_CALL(*wrapped, PruneConnections()) .InSequence(recheck_sort) .WillOnce(Return(kEmptyConnsList)); - EXPECT_CALL(agent, PruneConnections(kEmptyConnsList)) - .InSequence(recheck_sort); + EXPECT_CALL(agent, PruneConnections(IsEmpty())).InSequence(recheck_sort); clock.AdvanceTime(kTick); }