Change TurnPort::Create to return a unique_ptr
Bug: webrtc:9198
Change-Id: I13c9eab549b4973ce4f8fd2f562f1ff7f7e0a2cb
Reviewed-on: https://webrtc-review.googlesource.com/c/105182
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25100}
diff --git a/p2p/base/port_unittest.cc b/p2p/base/port_unittest.cc
index dc78c58..3aa1d52 100644
--- a/p2p/base/port_unittest.cc
+++ b/p2p/base/port_unittest.cc
@@ -530,10 +530,10 @@
ProtocolType int_proto,
ProtocolType ext_proto,
const rtc::SocketAddress& server_addr) {
- return TurnPort::CreateUnique(
- &main_, socket_factory, MakeNetwork(addr), 0, 0, username_, password_,
- ProtocolAddress(server_addr, int_proto), kRelayCredentials, 0, "", {},
- {}, nullptr, nullptr);
+ return TurnPort::Create(&main_, socket_factory, MakeNetwork(addr), 0, 0,
+ username_, password_,
+ ProtocolAddress(server_addr, int_proto),
+ kRelayCredentials, 0, "", {}, {}, nullptr, nullptr);
}
std::unique_ptr<RelayPort> CreateGturnPort(const SocketAddress& addr,
ProtocolType int_proto,
diff --git a/p2p/base/turnport.h b/p2p/base/turnport.h
index fe59298..b4eb13d 100644
--- a/p2p/base/turnport.h
+++ b/p2p/base/turnport.h
@@ -51,25 +51,7 @@
// packets.
};
// Create a TURN port using the shared UDP socket, |socket|.
- // TODO(steveanton): Change to unique_ptr once downstream clients have
- // converted.
- static TurnPort* Create(rtc::Thread* thread,
- rtc::PacketSocketFactory* factory,
- rtc::Network* network,
- rtc::AsyncPacketSocket* socket,
- const std::string& username, // ice username.
- const std::string& password, // ice password.
- const ProtocolAddress& server_address,
- const RelayCredentials& credentials,
- int server_priority,
- const std::string& origin,
- webrtc::TurnCustomizer* customizer) {
- return CreateUnique(thread, factory, network, socket, username, password,
- server_address, credentials, server_priority, origin,
- customizer)
- .release();
- }
- static std::unique_ptr<TurnPort> CreateUnique(
+ static std::unique_ptr<TurnPort> Create(
rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
@@ -86,35 +68,27 @@
thread, factory, network, socket, username, password, server_address,
credentials, server_priority, origin, customizer));
}
-
- // Create a TURN port that will use a new socket, bound to |network| and
- // using a port in the range between |min_port| and |max_port|.
- // TODO(steveanton): Change to unique_ptr once downstream clients have
- // converted.
- static TurnPort* Create(
+ // TODO(steveanton): Remove once downstream clients have moved to |Create|.
+ static std::unique_ptr<TurnPort> CreateUnique(
rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
- uint16_t min_port,
- uint16_t max_port,
+ rtc::AsyncPacketSocket* socket,
const std::string& username, // ice username.
const std::string& password, // ice password.
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority,
const std::string& origin,
- const std::vector<std::string>& tls_alpn_protocols,
- const std::vector<std::string>& tls_elliptic_curves,
- webrtc::TurnCustomizer* customizer,
- rtc::SSLCertificateVerifier* tls_cert_verifier = nullptr) {
- // Using `new` to access a non-public constructor.
- return CreateUnique(thread, factory, network, min_port, max_port, username,
- password, server_address, credentials, server_priority,
- origin, tls_alpn_protocols, tls_elliptic_curves,
- customizer, tls_cert_verifier)
- .release();
+ webrtc::TurnCustomizer* customizer) {
+ return Create(thread, factory, network, socket, username, password,
+ server_address, credentials, server_priority, origin,
+ customizer);
}
- static std::unique_ptr<TurnPort> CreateUnique(
+
+ // Create a TURN port that will use a new socket, bound to |network| and
+ // using a port in the range between |min_port| and |max_port|.
+ static std::unique_ptr<TurnPort> Create(
rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
@@ -137,6 +111,28 @@
origin, tls_alpn_protocols, tls_elliptic_curves,
customizer, tls_cert_verifier));
}
+ // TODO(steveanton): Remove once downstream clients have moved to |Create|.
+ static std::unique_ptr<TurnPort> CreateUnique(
+ rtc::Thread* thread,
+ rtc::PacketSocketFactory* factory,
+ rtc::Network* network,
+ uint16_t min_port,
+ uint16_t max_port,
+ const std::string& username, // ice username.
+ const std::string& password, // ice password.
+ const ProtocolAddress& server_address,
+ const RelayCredentials& credentials,
+ int server_priority,
+ const std::string& origin,
+ const std::vector<std::string>& tls_alpn_protocols,
+ const std::vector<std::string>& tls_elliptic_curves,
+ webrtc::TurnCustomizer* customizer,
+ rtc::SSLCertificateVerifier* tls_cert_verifier = nullptr) {
+ return Create(thread, factory, network, min_port, max_port, username,
+ password, server_address, credentials, server_priority,
+ origin, tls_alpn_protocols, tls_elliptic_curves, customizer,
+ tls_cert_verifier);
+ }
~TurnPort() override;
diff --git a/p2p/base/turnport_unittest.cc b/p2p/base/turnport_unittest.cc
index 27657a3..16f89e9 100644
--- a/p2p/base/turnport_unittest.cc
+++ b/p2p/base/turnport_unittest.cc
@@ -270,7 +270,7 @@
const ProtocolAddress& server_address,
const std::string& origin) {
RelayCredentials credentials(username, password);
- turn_port_ = TurnPort::CreateUnique(
+ turn_port_ = TurnPort::Create(
&main_, &socket_factory_, network, 0, 0, kIceUfrag1, kIcePwd1,
server_address, credentials, 0, origin, {}, {}, turn_customizer_.get());
// This TURN port will be the controlling.
@@ -300,10 +300,10 @@
}
RelayCredentials credentials(username, password);
- turn_port_ = TurnPort::CreateUnique(&main_, &socket_factory_,
- MakeNetwork(kLocalAddr1), socket_.get(),
- kIceUfrag1, kIcePwd1, server_address,
- credentials, 0, std::string(), nullptr);
+ turn_port_ =
+ TurnPort::Create(&main_, &socket_factory_, MakeNetwork(kLocalAddr1),
+ socket_.get(), kIceUfrag1, kIcePwd1, server_address,
+ credentials, 0, std::string(), nullptr);
// This TURN port will be the controlling.
turn_port_->SetIceRole(ICEROLE_CONTROLLING);
ConnectSignals();