Update call/ to not use implicit T* --> scoped_refptr<T> conversion

Also change the class SharedModuleThread to final and
without any virtual methods.

Bug: webrtc:13464
Change-Id: If440e4c794955781f7d6bfce67f4554bcc3dc77e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/246205
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35695}
diff --git a/call/adaptation/broadcast_resource_listener.cc b/call/adaptation/broadcast_resource_listener.cc
index 876d4c0..5a1250ae 100644
--- a/call/adaptation/broadcast_resource_listener.cc
+++ b/call/adaptation/broadcast_resource_listener.cc
@@ -32,7 +32,8 @@
     MutexLock lock(&lock_);
     if (!listener_)
       return;
-    listener_->OnResourceUsageStateMeasured(this, usage_state);
+    listener_->OnResourceUsageStateMeasured(rtc::scoped_refptr<Resource>(this),
+                                            usage_state);
   }
 
   // Resource implementation.
diff --git a/call/adaptation/test/fake_resource.cc b/call/adaptation/test/fake_resource.cc
index d125468..70df058 100644
--- a/call/adaptation/test/fake_resource.cc
+++ b/call/adaptation/test/fake_resource.cc
@@ -29,7 +29,8 @@
 
 void FakeResource::SetUsageState(ResourceUsageState usage_state) {
   if (listener_) {
-    listener_->OnResourceUsageStateMeasured(this, usage_state);
+    listener_->OnResourceUsageStateMeasured(rtc::scoped_refptr<Resource>(this),
+                                            usage_state);
   }
 }
 
diff --git a/call/call.cc b/call/call.cc
index b30b92f..d83d5fb 100644
--- a/call/call.cc
+++ b/call/call.cc
@@ -591,8 +591,9 @@
 rtc::scoped_refptr<SharedModuleThread> SharedModuleThread::Create(
     std::unique_ptr<ProcessThread> process_thread,
     std::function<void()> on_one_ref_remaining) {
-  return new SharedModuleThread(std::move(process_thread),
-                                std::move(on_one_ref_remaining));
+  // Using `new` to access a non-public constructor.
+  return rtc::scoped_refptr<SharedModuleThread>(new SharedModuleThread(
+      std::move(process_thread), std::move(on_one_ref_remaining)));
 }
 
 void SharedModuleThread::EnsureStarted() {
diff --git a/call/call.h b/call/call.h
index f6388c3..1442c05 100644
--- a/call/call.h
+++ b/call/call.h
@@ -40,13 +40,7 @@
 // SharedModuleThread supports a callback that is issued when only one reference
 // remains, which is used to indicate to the original owner that the thread may
 // be discarded.
-class SharedModuleThread : public rtc::RefCountInterface {
- protected:
-  SharedModuleThread(std::unique_ptr<ProcessThread> process_thread,
-                     std::function<void()> on_one_ref_remaining);
-  friend class rtc::scoped_refptr<SharedModuleThread>;
-  ~SharedModuleThread() override;
-
+class SharedModuleThread final {
  public:
   // Allows injection of an externally created process thread.
   static rtc::scoped_refptr<SharedModuleThread> Create(
@@ -58,8 +52,13 @@
   ProcessThread* process_thread();
 
  private:
-  void AddRef() const override;
-  rtc::RefCountReleaseStatus Release() const override;
+  friend class rtc::scoped_refptr<SharedModuleThread>;
+  SharedModuleThread(std::unique_ptr<ProcessThread> process_thread,
+                     std::function<void()> on_one_ref_remaining);
+  ~SharedModuleThread();
+
+  void AddRef() const;
+  rtc::RefCountReleaseStatus Release() const;
 
   class Impl;
   mutable std::unique_ptr<Impl> impl_;