From bed8507b95710818e1a4642a269c59a1a5ea07de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Tue, 14 Jun 2022 12:30:16 +0200 Subject: [PATCH] Delete almost unused utility rtc::Ref Instead, use explicit declaration scoped_ref_ptr> in AsyncInvoker classes. Bug: webrtc:12701 Change-Id: I7ce43e2dc99a51b610852b4feda79e4bf86ee4ea Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265803 Commit-Queue: Niels Moller Reviewed-by: Harald Alvestrand Reviewed-by: Tomas Gunnarsson Reviewed-by: Mirko Bonadei Cr-Commit-Position: refs/heads/main@{#37210} --- rtc_base/async_invoker.h | 2 +- rtc_base/async_invoker_inl.h | 2 +- rtc_base/ref_counted_object.h | 53 ------------------------- rtc_base/ref_counted_object_unittest.cc | 15 ++----- 4 files changed, 5 insertions(+), 67 deletions(-) diff --git a/rtc_base/async_invoker.h b/rtc_base/async_invoker.h index c1f2060134..f1b03115f3 100644 --- a/rtc_base/async_invoker.h +++ b/rtc_base/async_invoker.h @@ -153,7 +153,7 @@ class DEPRECATED_AsyncInvoker : public MessageHandlerAutoCleanup { // Reference counted so that if the destructor finishes before an // AsyncClosure's destructor that's about to call // "invocation_complete_->Set()", it's not dereferenced after being destroyed. - rtc::Ref::Ptr invocation_complete_; + rtc::scoped_refptr> invocation_complete_; // This flag is used to ensure that if an application AsyncInvokes tasks that // recursively AsyncInvoke other tasks ad infinitum, the cycle eventually diff --git a/rtc_base/async_invoker_inl.h b/rtc_base/async_invoker_inl.h index c2b6413519..0ab0efb95e 100644 --- a/rtc_base/async_invoker_inl.h +++ b/rtc_base/async_invoker_inl.h @@ -39,7 +39,7 @@ class AsyncClosure { // an AsyncClosure's destructor that's about to call // "invocation_complete_->Set()", it's not dereferenced after being // destroyed. - rtc::Ref::Ptr invocation_complete_; + rtc::scoped_refptr> invocation_complete_; }; // Simple closure that doesn't trigger a callback for the calling thread. diff --git a/rtc_base/ref_counted_object.h b/rtc_base/ref_counted_object.h index 8309ba40d5..d94e6705c3 100644 --- a/rtc_base/ref_counted_object.h +++ b/rtc_base/ref_counted_object.h @@ -185,59 +185,6 @@ scoped_refptr> make_ref_counted(Args&&... args) { new FinalRefCountedObject(std::forward(args)...)); } -// `Ref<>`, `Ref<>::Type` and `Ref<>::Ptr`: -// -// `Ref` is a type declaring utility that is compatible with `make_ref_counted` -// and can be used in classes and methods where it's more convenient (or -// readable) to have the compiler figure out the fully fleshed out type for a -// class rather than spell it out verbatim in all places the type occurs (which -// can mean maintenance work if the class layout changes). -// -// Usage examples: -// -// If you want to declare the parameter type that's always compatible with -// this code: -// -// Bar(make_ref_counted()); -// -// You can use `Ref<>::Ptr` to declare a compatible scoped_refptr type: -// -// void Bar(Ref::Ptr p); -// -// This might be more practically useful in templates though. -// -// In rare cases you might need to be able to declare a parameter that's fully -// compatible with the reference counted T type - and just using T* is not -// enough. To give a code example, we can declare a function, `Foo` that is -// compatible with this code: -// auto p = make_ref_counted(); -// Foo(p.get()); -// -// void Foo(Ref::Type* foo_ptr); -// -// Alternatively this would be: -// void Foo(Foo* foo_ptr); -// or -// void Foo(FinalRefCountedObject* foo_ptr); - -// Declares the approprate reference counted type for T depending on whether -// T is convertible to RefCountInterface or not. -// For classes that are convertible, the type will simply be T. -// For classes that cannot be converted to RefCountInterface, the type will be -// FinalRefCountedObject. -// This is most useful for declaring a scoped_refptr instance for a class -// that may or may not implement a virtual reference counted interface: -// * scoped_refptr::Type> my_ptr; -template -struct Ref { - typedef typename std::conditional< - webrtc_make_ref_counted_internal::HasAddRefAndRelease::value, - T, - FinalRefCountedObject>::type Type; - - typedef scoped_refptr Ptr; -}; - } // namespace rtc #endif // RTC_BASE_REF_COUNTED_OBJECT_H_ diff --git a/rtc_base/ref_counted_object_unittest.cc b/rtc_base/ref_counted_object_unittest.cc index ab051d4f8a..c06a61ee60 100644 --- a/rtc_base/ref_counted_object_unittest.cc +++ b/rtc_base/ref_counted_object_unittest.cc @@ -151,12 +151,6 @@ TEST(RefCounted, SmartPointers) { static_assert(std::is_polymorphic::value, ""); static_assert(!std::is_polymorphic::value, ""); - // Check if Ref generates the expected types for Foo and FooItf. - static_assert(std::is_base_of::Type>::value && - !std::is_same::Type>::value, - ""); - static_assert(std::is_same::Type>::value, ""); - { // Test with FooItf, a class that inherits from RefCountInterface. // Check that we get a valid FooItf reference counted object. @@ -164,10 +158,8 @@ TEST(RefCounted, SmartPointers) { EXPECT_NE(p.get(), nullptr); EXPECT_EQ(p->foo_, 5); // the FooItf ctor just stores 2+3 in foo_. - // Use a couple of different ways of declaring what should result in the - // same type as `p` is of. - scoped_refptr::Type> p2 = p; - Ref::Ptr p3 = p; + // Declaring what should result in the same type as `p` is of. + scoped_refptr p2 = p; } { @@ -175,8 +167,7 @@ TEST(RefCounted, SmartPointers) { auto p = make_ref_counted(2, 3); EXPECT_NE(p.get(), nullptr); EXPECT_EQ(p->foo_, 5); - scoped_refptr::Type> p2 = p; - Ref::Ptr p3 = p; + scoped_refptr> p2 = p; } }