diff --git a/api/test/mock_peerconnectioninterface.h b/api/test/mock_peerconnectioninterface.h index effd24e294..97b2b7d7b1 100644 --- a/api/test/mock_peerconnectioninterface.h +++ b/api/test/mock_peerconnectioninterface.h @@ -25,8 +25,7 @@ namespace webrtc { -class MockPeerConnectionInterface - : public rtc::RefCountedObject { +class MockPeerConnectionInterface : public webrtc::PeerConnectionInterface { public: static rtc::scoped_refptr Create() { return rtc::make_ref_counted(); @@ -199,7 +198,9 @@ class MockPeerConnectionInterface MOCK_METHOD(void, Close, (), (override)); }; -static_assert(!std::is_abstract::value, ""); +static_assert( + !std::is_abstract_v>, + ""); } // namespace webrtc diff --git a/pc/peer_connection_rtp_unittest.cc b/pc/peer_connection_rtp_unittest.cc index 6c08ba47bc..98b14d268a 100644 --- a/pc/peer_connection_rtp_unittest.cc +++ b/pc/peer_connection_rtp_unittest.cc @@ -69,8 +69,7 @@ using ::testing::Values; const uint32_t kDefaultTimeout = 10000u; template -class OnSuccessObserver : public rtc::RefCountedObject< - webrtc::SetRemoteDescriptionObserverInterface> { +class OnSuccessObserver : public webrtc::SetRemoteDescriptionObserverInterface { public: explicit OnSuccessObserver(MethodFunctor on_success) : on_success_(std::move(on_success)) {} diff --git a/pc/peer_connection_signaling_unittest.cc b/pc/peer_connection_signaling_unittest.cc index 5923d2c47f..bf8b8099fb 100644 --- a/pc/peer_connection_signaling_unittest.cc +++ b/pc/peer_connection_signaling_unittest.cc @@ -610,8 +610,7 @@ TEST_P(PeerConnectionSignalingTest, TEST_P(PeerConnectionSignalingTest, ImplicitCreateOfferAndShutdown) { auto caller = CreatePeerConnection(); - rtc::scoped_refptr observer( - new FakeSetLocalDescriptionObserver()); + auto observer = rtc::make_ref_counted(); caller->pc()->SetLocalDescription(observer); caller.reset(nullptr); // The new observer gets invoked because it is called immediately. @@ -632,8 +631,7 @@ TEST_P(PeerConnectionSignalingTest, TEST_P(PeerConnectionSignalingTest, CloseBeforeImplicitCreateOfferAndShutdown) { auto caller = CreatePeerConnection(); - rtc::scoped_refptr observer( - new FakeSetLocalDescriptionObserver()); + auto observer = rtc::make_ref_counted(); caller->pc()->Close(); caller->pc()->SetLocalDescription(observer); caller.reset(nullptr); @@ -655,8 +653,7 @@ TEST_P(PeerConnectionSignalingTest, TEST_P(PeerConnectionSignalingTest, CloseAfterImplicitCreateOfferAndShutdown) { auto caller = CreatePeerConnection(); - rtc::scoped_refptr observer( - new FakeSetLocalDescriptionObserver()); + auto observer = rtc::make_ref_counted(); caller->pc()->SetLocalDescription(observer); caller->pc()->Close(); caller.reset(nullptr); @@ -670,8 +667,7 @@ TEST_P(PeerConnectionSignalingTest, auto caller = CreatePeerConnection(); auto offer = caller->CreateOffer(RTCOfferAnswerOptions()); - rtc::scoped_refptr observer( - new FakeSetLocalDescriptionObserver()); + auto observer = rtc::make_ref_counted(); caller->pc()->SetLocalDescription(std::move(offer), observer); // The new observer is invoked immediately. EXPECT_TRUE(observer->called()); diff --git a/pc/test/mock_data_channel.h b/pc/test/mock_data_channel.h index ab4b0073da..f1c5374d28 100644 --- a/pc/test/mock_data_channel.h +++ b/pc/test/mock_data_channel.h @@ -18,7 +18,7 @@ namespace webrtc { -class MockSctpDataChannel : public rtc::RefCountedObject { +class MockSctpDataChannel : public SctpDataChannel { public: MockSctpDataChannel(int id, DataState state) : MockSctpDataChannel(id, @@ -41,11 +41,11 @@ class MockSctpDataChannel : public rtc::RefCountedObject { const InternalDataChannelInit& config = InternalDataChannelInit(), rtc::Thread* signaling_thread = rtc::Thread::Current(), rtc::Thread* network_thread = rtc::Thread::Current()) - : rtc::RefCountedObject(config, - nullptr, - label, - signaling_thread, - network_thread) { + : SctpDataChannel(config, + nullptr, + label, + signaling_thread, + network_thread) { EXPECT_CALL(*this, id()).WillRepeatedly(::testing::Return(id)); EXPECT_CALL(*this, state()).WillRepeatedly(::testing::Return(state)); EXPECT_CALL(*this, protocol()).WillRepeatedly(::testing::Return(protocol)); diff --git a/pc/test/mock_peer_connection_observers.h b/pc/test/mock_peer_connection_observers.h index 2698d956af..51e24b7b30 100644 --- a/pc/test/mock_peer_connection_observers.h +++ b/pc/test/mock_peer_connection_observers.h @@ -336,7 +336,7 @@ class MockSetSessionDescriptionObserver }; class FakeSetLocalDescriptionObserver - : public rtc::RefCountedObject { + : public SetLocalDescriptionObserverInterface { public: bool called() const { return error_.has_value(); } RTCError& error() { @@ -355,7 +355,7 @@ class FakeSetLocalDescriptionObserver }; class FakeSetRemoteDescriptionObserver - : public rtc::RefCountedObject { + : public SetRemoteDescriptionObserverInterface { public: bool called() const { return error_.has_value(); } RTCError& error() { diff --git a/rtc_base/ref_counted_object.h b/rtc_base/ref_counted_object.h index 54aac952ce..8309ba40d5 100644 --- a/rtc_base/ref_counted_object.h +++ b/rtc_base/ref_counted_object.h @@ -142,11 +142,17 @@ class FinalRefCountedObject final : public T { // Note that in some cases, using RefCountedObject directly may still be what's // needed. -// `make_ref_counted` for classes that are convertible to RefCountInterface. -template , - T>::type* = nullptr> +// `make_ref_counted` for abstract classes that are convertible to +// RefCountInterface. The is_abstract requirement rejects classes that inherit +// both RefCountInterface and RefCounted object, which is a a discouraged +// pattern, and would result in double inheritance of RefCountedObject if this +// template was applied. +template < + typename T, + typename... Args, + typename std::enable_if && + std::is_abstract_v, + T>::type* = nullptr> scoped_refptr make_ref_counted(Args&&... args) { return scoped_refptr(new RefCountedObject(std::forward(args)...)); }