Add absl::string_view version of PortAllocator::CreateSessionInternal()

This is the first step of migrating CreateSessionInternal() to
absl::string_view. The std::string version will be removed once all
downstream users have migrated and have implemented the
absl::string_view version.

Bug: webrtc:13579
Change-Id: Ia8bb25c010de118b194e66fd992b910509b9857f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265808
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Ali Tofigh <alito@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37227}
This commit is contained in:
Ali Tofigh
2022-06-14 15:29:35 +02:00
committed by WebRTC LUCI CQ
parent 5abfc920b5
commit 1b984214bb
6 changed files with 52 additions and 4 deletions

View File

@ -184,6 +184,7 @@ if (rtc_include_tests) {
"../rtc_base:threading",
"../test:scoped_key_value_config",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
rtc_library("p2p_test_utils") {

View File

@ -15,6 +15,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/port_allocator.h"
#include "p2p/base/udp_port.h"
@ -237,9 +238,19 @@ class FakePortAllocator : public cricket::PortAllocator {
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd) override {
return new FakePortAllocatorSession(this, network_thread_, factory_,
content_name, component, ice_ufrag,
ice_pwd, field_trials_);
return CreateSessionInternal(absl::string_view(content_name), component,
absl::string_view(ice_ufrag),
absl::string_view(ice_pwd));
}
cricket::PortAllocatorSession* CreateSessionInternal(
absl::string_view content_name,
int component,
absl::string_view ice_ufrag,
absl::string_view ice_pwd) override {
return new FakePortAllocatorSession(
this, network_thread_, factory_, std::string(content_name), component,
std::string(ice_ufrag), std::string(ice_pwd), field_trials_);
}
bool initialized() const { return initialized_; }

View File

@ -14,6 +14,7 @@
#include <set>
#include <utility>
#include "absl/strings/string_view.h"
#include "p2p/base/ice_credentials_iterator.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
@ -312,6 +313,15 @@ std::vector<IceParameters> PortAllocator::GetPooledIceCredentials() {
return list;
}
PortAllocatorSession* PortAllocator::CreateSessionInternal(
absl::string_view content_name,
int component,
absl::string_view ice_ufrag,
absl::string_view ice_pwd) {
return CreateSessionInternal(std::string(content_name), component,
std::string(ice_ufrag), std::string(ice_pwd));
}
Candidate PortAllocator::SanitizeCandidate(const Candidate& c) const {
CheckRunOnValidThreadAndInitialized();
// For a local host candidate, we need to conceal its IP address candidate if

View File

@ -16,6 +16,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/sequence_checker.h"
#include "api/transport/enums.h"
#include "p2p/base/port.h"
@ -602,11 +603,18 @@ class RTC_EXPORT PortAllocator : public sigslot::has_slots<> {
SignalCandidateFilterChanged;
protected:
// TODO(webrtc::13579): Remove std::string version once downstream users have
// migrated to the absl::string_view version.
virtual PortAllocatorSession* CreateSessionInternal(
const std::string& content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd) = 0;
virtual PortAllocatorSession* CreateSessionInternal(
absl::string_view content_name,
int component,
absl::string_view ice_ufrag,
absl::string_view ice_pwd);
const std::vector<std::unique_ptr<PortAllocatorSession>>& pooled_sessions() {
return pooled_sessions_;

View File

@ -20,6 +20,7 @@
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "api/transport/field_trial_based_config.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/port.h"
@ -258,9 +259,20 @@ PortAllocatorSession* BasicPortAllocator::CreateSessionInternal(
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd) {
return CreateSessionInternal(absl::string_view(content_name), component,
absl::string_view(ice_ufrag),
absl::string_view(ice_pwd));
}
PortAllocatorSession* BasicPortAllocator::CreateSessionInternal(
absl::string_view content_name,
int component,
absl::string_view ice_ufrag,
absl::string_view ice_pwd) {
CheckRunOnValidThreadAndInitialized();
PortAllocatorSession* session = new BasicPortAllocatorSession(
this, content_name, component, ice_ufrag, ice_pwd);
this, std::string(content_name), component, std::string(ice_ufrag),
std::string(ice_pwd));
session->SignalIceRegathering.connect(this,
&BasicPortAllocator::OnIceRegathering);
return session;

View File

@ -15,6 +15,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/field_trials_view.h"
#include "api/turn_customizer.h"
#include "p2p/base/port_allocator.h"
@ -72,6 +73,11 @@ class RTC_EXPORT BasicPortAllocator : public PortAllocator {
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd) override;
PortAllocatorSession* CreateSessionInternal(
absl::string_view content_name,
int component,
absl::string_view ice_ufrag,
absl::string_view ice_pwd) override;
// Convenience method that adds a TURN server to the configuration.
void AddTurnServer(const RelayServerConfig& turn_server);