From 8da35a60ab3c3b641e308fba8e2a6290371d4ab0 Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Fri, 10 May 2019 09:31:04 +0200 Subject: [PATCH] Deprecate owned naked pointers to cricket::SessionDescription Recommended usage is to create copies with Clone() and to call JsepSessionDescription::Initialize using std::move. Bug: webrtc:10612 Change-Id: I626a08a35ba8e112471cec0374c944e96f8effbc Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/135941 Reviewed-by: Karl Wiberg Commit-Queue: Harald Alvestrand Cr-Commit-Position: refs/heads/master@{#27911} --- api/jsep_session_description.h | 9 +++++---- pc/BUILD.gn | 1 + pc/session_description.h | 6 ++++-- pc/webrtc_sdp_unittest.cc | 10 +++++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/api/jsep_session_description.h b/api/jsep_session_description.h index 2797c881fe..5a38c3a0e8 100644 --- a/api/jsep_session_description.h +++ b/api/jsep_session_description.h @@ -23,6 +23,7 @@ #include "api/jsep.h" #include "api/jsep_ice_candidate.h" #include "rtc_base/constructor_magic.h" +#include "rtc_base/deprecation.h" namespace cricket { class SessionDescription; @@ -47,10 +48,10 @@ class JsepSessionDescription : public SessionDescriptionInterface { bool Initialize(std::unique_ptr description, const std::string& session_id, const std::string& session_version); - // Backwards compatible version. To be deprecated. - bool Initialize(cricket::SessionDescription* description, - const std::string& session_id, - const std::string& session_version); + // Backwards compatible version. Replace with version above. + RTC_DEPRECATED bool Initialize(cricket::SessionDescription* description, + const std::string& session_id, + const std::string& session_version); virtual cricket::SessionDescription* description() { return description_.get(); diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 48271234a0..1013f7cf4e 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -95,6 +95,7 @@ rtc_static_library("rtc_pc_base") { "../p2p:rtc_p2p", "../rtc_base", "../rtc_base:checks", + "../rtc_base:deprecation", "../rtc_base:rtc_task_queue", "../rtc_base:stringutils", "../rtc_base/third_party/base64", diff --git a/pc/session_description.h b/pc/session_description.h index 60c3d6b92c..27b781f385 100644 --- a/pc/session_description.h +++ b/pc/session_description.h @@ -29,6 +29,7 @@ #include "p2p/base/transport_info.h" #include "pc/media_protocol_names.h" #include "pc/simulcast_description.h" +#include "rtc_base/deprecation.h" #include "rtc_base/socket_address.h" namespace cricket { @@ -598,8 +599,9 @@ class SessionDescription { ~SessionDescription(); std::unique_ptr Clone() const; - // Older API - to be deprecated. Still expects caller to take ownership. - SessionDescription* Copy() const; + // Older API - deprecated. Still expects caller to take ownership. + // Replace with Clone(). + RTC_DEPRECATED SessionDescription* Copy() const; struct MediaTransportSetting; diff --git a/pc/webrtc_sdp_unittest.cc b/pc/webrtc_sdp_unittest.cc index 367fac84d7..5b2bf296ef 100644 --- a/pc/webrtc_sdp_unittest.cc +++ b/pc/webrtc_sdp_unittest.cc @@ -2239,12 +2239,12 @@ void MutateJsepSctpPort(JsepSessionDescription* jdesc, const SessionDescription& desc, int port) { // Take our pre-built session description and change the SCTP port. - cricket::SessionDescription* mutant = desc.Copy(); + std::unique_ptr mutant = desc.Clone(); SctpDataContentDescription* dcdesc = mutant->GetContentDescriptionByName(kDataContentName)->as_sctp(); dcdesc->set_port(port); - // Note: mutant's owned by jdesc now. - ASSERT_TRUE(jdesc->Initialize(mutant, kSessionId, kSessionVersion)); + ASSERT_TRUE( + jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion)); } TEST_F(WebRtcSdpTest, SerializeWithSctpDataChannelAndNewPort) { @@ -2895,11 +2895,11 @@ TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) { void MutateJsepSctpMaxMessageSize(const SessionDescription& desc, int new_value, JsepSessionDescription* jdesc) { - cricket::SessionDescription* mutant = desc.Copy(); + std::unique_ptr mutant = desc.Clone(); SctpDataContentDescription* dcdesc = mutant->GetContentDescriptionByName(kDataContentName)->as_sctp(); dcdesc->set_max_message_size(new_value); - jdesc->Initialize(mutant, kSessionId, kSessionVersion); + jdesc->Initialize(std::move(mutant), kSessionId, kSessionVersion); } TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithMaxMessageSize) {