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}
This commit is contained in:
Steve Anton 2018-10-10 15:06:28 -07:00 committed by Commit Bot
parent 9cfce17a2d
commit f7dd9df7e1
3 changed files with 43 additions and 47 deletions

View File

@ -530,10 +530,10 @@ class PortTest : public testing::Test, public sigslot::has_slots<> {
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,

View File

@ -51,25 +51,7 @@ class TurnPort : public Port {
// 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 @@ class TurnPort : public Port {
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 @@ class TurnPort : public Port {
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;

View File

@ -270,7 +270,7 @@ class TurnPortTest : public testing::Test,
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 @@ class TurnPortTest : public testing::Test,
}
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();