Replace most explicit new RefCountedObject... with make_ref_counted

Bug: webrtc:12701
Change-Id: Iab91f1e96715eed7f9ddcfe1ca55510a18c817eb
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/224544
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35786}
This commit is contained in:
Niels Möller
2022-01-25 13:56:07 +01:00
committed by WebRTC LUCI CQ
parent b428d6bad4
commit 027c793c57
16 changed files with 37 additions and 55 deletions

View File

@ -221,8 +221,7 @@ class FakeAudioTrackForStats : public MediaStreamTrack<AudioTrackInterface> {
const std::string& id,
MediaStreamTrackInterface::TrackState state,
bool create_fake_audio_processor) {
rtc::scoped_refptr<FakeAudioTrackForStats> audio_track_stats(
new rtc::RefCountedObject<FakeAudioTrackForStats>(id));
auto audio_track_stats = rtc::make_ref_counted<FakeAudioTrackForStats>(id);
audio_track_stats->set_state(state);
if (create_fake_audio_processor) {
audio_track_stats->processor_ =
@ -254,9 +253,8 @@ class FakeVideoTrackSourceForStats : public VideoTrackSourceInterface {
static rtc::scoped_refptr<FakeVideoTrackSourceForStats> Create(
int input_width,
int input_height) {
return rtc::scoped_refptr<FakeVideoTrackSourceForStats>(
new rtc::RefCountedObject<FakeVideoTrackSourceForStats>(input_width,
input_height));
return rtc::make_ref_counted<FakeVideoTrackSourceForStats>(input_width,
input_height);
}
FakeVideoTrackSourceForStats(int input_width, int input_height)
@ -301,9 +299,8 @@ class FakeVideoTrackForStats : public MediaStreamTrack<VideoTrackInterface> {
const std::string& id,
MediaStreamTrackInterface::TrackState state,
rtc::scoped_refptr<VideoTrackSourceInterface> source) {
rtc::scoped_refptr<FakeVideoTrackForStats> video_track(
new rtc::RefCountedObject<FakeVideoTrackForStats>(id,
std::move(source)));
auto video_track =
rtc::make_ref_counted<FakeVideoTrackForStats>(id, std::move(source));
video_track->set_state(state);
return video_track;
}
@ -353,8 +350,7 @@ rtc::scoped_refptr<MockRtpSenderInternal> CreateMockSender(
media_type == cricket::MEDIA_TYPE_AUDIO) ||
(track->kind() == MediaStreamTrackInterface::kVideoKind &&
media_type == cricket::MEDIA_TYPE_VIDEO));
rtc::scoped_refptr<MockRtpSenderInternal> sender(
new rtc::RefCountedObject<MockRtpSenderInternal>());
auto sender = rtc::make_ref_counted<MockRtpSenderInternal>();
EXPECT_CALL(*sender, track()).WillRepeatedly(Return(track));
EXPECT_CALL(*sender, ssrc()).WillRepeatedly(Return(ssrc));
EXPECT_CALL(*sender, media_type()).WillRepeatedly(Return(media_type));
@ -375,8 +371,7 @@ rtc::scoped_refptr<MockRtpReceiverInternal> CreateMockReceiver(
const rtc::scoped_refptr<MediaStreamTrackInterface>& track,
uint32_t ssrc,
int attachment_id) {
rtc::scoped_refptr<MockRtpReceiverInternal> receiver(
new rtc::RefCountedObject<MockRtpReceiverInternal>());
auto receiver = rtc::make_ref_counted<MockRtpReceiverInternal>();
EXPECT_CALL(*receiver, track()).WillRepeatedly(Return(track));
EXPECT_CALL(*receiver, streams())
.WillRepeatedly(
@ -626,7 +621,7 @@ class RTCStatsCollectorWrapper {
class RTCStatsCollectorTest : public ::testing::Test {
public:
RTCStatsCollectorTest()
: pc_(new rtc::RefCountedObject<FakePeerConnectionForStats>()),
: pc_(rtc::make_ref_counted<FakePeerConnectionForStats>()),
stats_(new RTCStatsCollectorWrapper(pc_)) {}
void ExpectReportContainsCertificateInfo(
@ -3328,10 +3323,8 @@ class RecursiveCallback : public RTCStatsCollectorCallback {
// Test that nothing bad happens if a callback causes GetStatsReport to be
// called again recursively. Regression test for crbug.com/webrtc/8973.
TEST_F(RTCStatsCollectorTest, DoNotCrashWhenGetStatsCalledDuringCallback) {
rtc::scoped_refptr<RecursiveCallback> callback1(
new rtc::RefCountedObject<RecursiveCallback>(stats_.get()));
rtc::scoped_refptr<RecursiveCallback> callback2(
new rtc::RefCountedObject<RecursiveCallback>(stats_.get()));
auto callback1 = rtc::make_ref_counted<RecursiveCallback>(stats_.get());
auto callback2 = rtc::make_ref_counted<RecursiveCallback>(stats_.get());
stats_->stats_collector()->GetStatsReport(callback1);
stats_->stats_collector()->GetStatsReport(callback2);
EXPECT_TRUE_WAIT(callback1->called(), kGetStatsReportTimeoutMs);
@ -3452,8 +3445,7 @@ class FakeRTCStatsCollector : public RTCStatsCollector,
};
TEST(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) {
rtc::scoped_refptr<FakePeerConnectionForStats> pc(
new rtc::RefCountedObject<FakePeerConnectionForStats>());
auto pc = rtc::make_ref_counted<FakePeerConnectionForStats>();
rtc::scoped_refptr<FakeRTCStatsCollector> stats_collector(
FakeRTCStatsCollector::Create(pc, 50 * rtc::kNumMicrosecsPerMillisec));
stats_collector->VerifyThreadUsageAndResultsMerging();