Update rtc_base to not use implicit T* --> scoped_refptr<T> conversion
Also updated the OperationsChain and CallbackHandle classes to not use any virtual methods. Bug: webrtc:13464 Change-Id: I3437d1b7b043339e66411f5a46c226624b7ff9a5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/246102 Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35682}
This commit is contained in:
parent
70fe704588
commit
9512910e6e
@ -499,6 +499,7 @@ rtc_source_set("rtc_operations_chain") {
|
|||||||
":checks",
|
":checks",
|
||||||
":macromagic",
|
":macromagic",
|
||||||
":refcount",
|
":refcount",
|
||||||
|
"../api:refcountedbase",
|
||||||
"../api:scoped_refptr",
|
"../api:scoped_refptr",
|
||||||
"../api:sequence_checker",
|
"../api:sequence_checker",
|
||||||
"system:no_unique_address",
|
"system:no_unique_address",
|
||||||
|
|||||||
@ -37,10 +37,11 @@ void OperationsChain::CallbackHandle::OnOperationComplete() {
|
|||||||
|
|
||||||
// static
|
// static
|
||||||
scoped_refptr<OperationsChain> OperationsChain::Create() {
|
scoped_refptr<OperationsChain> OperationsChain::Create() {
|
||||||
return new OperationsChain();
|
// Explicit new, to access private constructor.
|
||||||
|
return rtc::scoped_refptr<OperationsChain>(new OperationsChain());
|
||||||
}
|
}
|
||||||
|
|
||||||
OperationsChain::OperationsChain() : RefCountedObject() {
|
OperationsChain::OperationsChain() {
|
||||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +64,10 @@ bool OperationsChain::IsEmpty() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::function<void()> OperationsChain::CreateOperationsChainCallback() {
|
std::function<void()> OperationsChain::CreateOperationsChainCallback() {
|
||||||
return [handle = rtc::scoped_refptr<CallbackHandle>(
|
return [handle = rtc::make_ref_counted<CallbackHandle>(
|
||||||
new CallbackHandle(this))]() { handle->OnOperationComplete(); };
|
rtc::scoped_refptr<OperationsChain>(this))]() {
|
||||||
|
handle->OnOperationComplete();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void OperationsChain::OnOperationComplete() {
|
void OperationsChain::OnOperationComplete() {
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
|
#include "api/ref_counted_base.h"
|
||||||
#include "api/scoped_refptr.h"
|
#include "api/scoped_refptr.h"
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
@ -113,7 +114,7 @@ class OperationWithFunctor final : public Operation {
|
|||||||
// The OperationsChain is kept-alive through reference counting if there are
|
// The OperationsChain is kept-alive through reference counting if there are
|
||||||
// operations pending. This, together with the contract, guarantees that all
|
// operations pending. This, together with the contract, guarantees that all
|
||||||
// operations that are chained get executed.
|
// operations that are chained get executed.
|
||||||
class OperationsChain final : public RefCountedObject<RefCountInterface> {
|
class OperationsChain final : public RefCountedNonVirtual<OperationsChain> {
|
||||||
public:
|
public:
|
||||||
static scoped_refptr<OperationsChain> Create();
|
static scoped_refptr<OperationsChain> Create();
|
||||||
~OperationsChain();
|
~OperationsChain();
|
||||||
@ -163,7 +164,7 @@ class OperationsChain final : public RefCountedObject<RefCountInterface> {
|
|||||||
// std::function<void()>, which is a copyable type. To allow the callback to
|
// std::function<void()>, which is a copyable type. To allow the callback to
|
||||||
// be copyable, it is backed up by this reference counted handle. See
|
// be copyable, it is backed up by this reference counted handle. See
|
||||||
// CreateOperationsChainCallback().
|
// CreateOperationsChainCallback().
|
||||||
class CallbackHandle final : public RefCountedObject<RefCountInterface> {
|
class CallbackHandle final : public RefCountedNonVirtual<CallbackHandle> {
|
||||||
public:
|
public:
|
||||||
explicit CallbackHandle(scoped_refptr<OperationsChain> operations_chain);
|
explicit CallbackHandle(scoped_refptr<OperationsChain> operations_chain);
|
||||||
~CallbackHandle();
|
~CallbackHandle();
|
||||||
|
|||||||
@ -148,7 +148,7 @@ template <typename T,
|
|||||||
typename std::enable_if<std::is_convertible_v<T*, RefCountInterface*>,
|
typename std::enable_if<std::is_convertible_v<T*, RefCountInterface*>,
|
||||||
T>::type* = nullptr>
|
T>::type* = nullptr>
|
||||||
scoped_refptr<T> make_ref_counted(Args&&... args) {
|
scoped_refptr<T> make_ref_counted(Args&&... args) {
|
||||||
return new RefCountedObject<T>(std::forward<Args>(args)...);
|
return scoped_refptr<T>(new RefCountedObject<T>(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
// `make_ref_counted` for complete classes that are not convertible to
|
// `make_ref_counted` for complete classes that are not convertible to
|
||||||
@ -175,7 +175,8 @@ template <
|
|||||||
|
|
||||||
T>::type* = nullptr>
|
T>::type* = nullptr>
|
||||||
scoped_refptr<FinalRefCountedObject<T>> make_ref_counted(Args&&... args) {
|
scoped_refptr<FinalRefCountedObject<T>> make_ref_counted(Args&&... args) {
|
||||||
return new FinalRefCountedObject<T>(std::forward<Args>(args)...);
|
return scoped_refptr<FinalRefCountedObject<T>>(
|
||||||
|
new FinalRefCountedObject<T>(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
// `Ref<>`, `Ref<>::Type` and `Ref<>::Ptr`:
|
// `Ref<>`, `Ref<>::Type` and `Ref<>::Ptr`:
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
#include "rtc_base/ref_counted_object.h"
|
||||||
#include "rtc_base/ssl_certificate.h"
|
#include "rtc_base/ssl_certificate.h"
|
||||||
#include "rtc_base/ssl_identity.h"
|
#include "rtc_base/ssl_identity.h"
|
||||||
#include "rtc_base/time_utils.h"
|
#include "rtc_base/time_utils.h"
|
||||||
@ -21,7 +22,9 @@ namespace rtc {
|
|||||||
|
|
||||||
scoped_refptr<RTCCertificate> RTCCertificate::Create(
|
scoped_refptr<RTCCertificate> RTCCertificate::Create(
|
||||||
std::unique_ptr<SSLIdentity> identity) {
|
std::unique_ptr<SSLIdentity> identity) {
|
||||||
return new RTCCertificate(identity.release());
|
// Explicit new to access proteced constructor.
|
||||||
|
return rtc::scoped_refptr<RTCCertificate>(
|
||||||
|
new RTCCertificate(identity.release()));
|
||||||
}
|
}
|
||||||
|
|
||||||
RTCCertificate::RTCCertificate(SSLIdentity* identity) : identity_(identity) {
|
RTCCertificate::RTCCertificate(SSLIdentity* identity) : identity_(identity) {
|
||||||
@ -61,7 +64,7 @@ scoped_refptr<RTCCertificate> RTCCertificate::FromPEM(
|
|||||||
SSLIdentity::CreateFromPEMStrings(pem.private_key(), pem.certificate()));
|
SSLIdentity::CreateFromPEMStrings(pem.private_key(), pem.certificate()));
|
||||||
if (!identity)
|
if (!identity)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return new RTCCertificate(identity.release());
|
return RTCCertificate::Create(std::move(identity));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RTCCertificate::operator==(const RTCCertificate& certificate) const {
|
bool RTCCertificate::operator==(const RTCCertificate& certificate) const {
|
||||||
|
|||||||
@ -12,23 +12,29 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
// static
|
||||||
|
rtc::scoped_refptr<PendingTaskSafetyFlag> PendingTaskSafetyFlag::CreateInternal(
|
||||||
|
bool alive) {
|
||||||
|
// Explicit new, to access private constructor.
|
||||||
|
return rtc::scoped_refptr<PendingTaskSafetyFlag>(
|
||||||
|
new PendingTaskSafetyFlag(alive));
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
rtc::scoped_refptr<PendingTaskSafetyFlag> PendingTaskSafetyFlag::Create() {
|
rtc::scoped_refptr<PendingTaskSafetyFlag> PendingTaskSafetyFlag::Create() {
|
||||||
return new PendingTaskSafetyFlag(true);
|
return CreateInternal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<PendingTaskSafetyFlag>
|
rtc::scoped_refptr<PendingTaskSafetyFlag>
|
||||||
PendingTaskSafetyFlag::CreateDetached() {
|
PendingTaskSafetyFlag::CreateDetached() {
|
||||||
rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag(
|
rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(true);
|
||||||
new PendingTaskSafetyFlag(true));
|
|
||||||
safety_flag->main_sequence_.Detach();
|
safety_flag->main_sequence_.Detach();
|
||||||
return safety_flag;
|
return safety_flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<PendingTaskSafetyFlag>
|
rtc::scoped_refptr<PendingTaskSafetyFlag>
|
||||||
PendingTaskSafetyFlag::CreateDetachedInactive() {
|
PendingTaskSafetyFlag::CreateDetachedInactive() {
|
||||||
rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag(
|
rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(false);
|
||||||
new PendingTaskSafetyFlag(false));
|
|
||||||
safety_flag->main_sequence_.Detach();
|
safety_flag->main_sequence_.Detach();
|
||||||
return safety_flag;
|
return safety_flag;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,6 +93,8 @@ class PendingTaskSafetyFlag final
|
|||||||
explicit PendingTaskSafetyFlag(bool alive) : alive_(alive) {}
|
explicit PendingTaskSafetyFlag(bool alive) : alive_(alive) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static rtc::scoped_refptr<PendingTaskSafetyFlag> CreateInternal(bool alive);
|
||||||
|
|
||||||
bool alive_ = true;
|
bool alive_ = true;
|
||||||
RTC_NO_UNIQUE_ADDRESS SequenceChecker main_sequence_;
|
RTC_NO_UNIQUE_ADDRESS SequenceChecker main_sequence_;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user