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}
diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn
index 8cd16eb..46ce807 100644
--- a/p2p/BUILD.gn
+++ b/p2p/BUILD.gn
@@ -184,6 +184,7 @@
"../rtc_base:threading",
"../test:scoped_key_value_config",
]
+ absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
rtc_library("p2p_test_utils") {
diff --git a/p2p/base/fake_port_allocator.h b/p2p/base/fake_port_allocator.h
index 59533fa..66dc6a4 100644
--- a/p2p/base/fake_port_allocator.h
+++ b/p2p/base/fake_port_allocator.h
@@ -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 @@
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_; }
diff --git a/p2p/base/port_allocator.cc b/p2p/base/port_allocator.cc
index 6c3ccc8..4963f34 100644
--- a/p2p/base/port_allocator.cc
+++ b/p2p/base/port_allocator.cc
@@ -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 @@
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
diff --git a/p2p/base/port_allocator.h b/p2p/base/port_allocator.h
index 08584d9..29f5326 100644
--- a/p2p/base/port_allocator.h
+++ b/p2p/base/port_allocator.h
@@ -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 @@
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_;
diff --git a/p2p/client/basic_port_allocator.cc b/p2p/client/basic_port_allocator.cc
index 3a1488e..a8a0b62 100644
--- a/p2p/client/basic_port_allocator.cc
+++ b/p2p/client/basic_port_allocator.cc
@@ -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 @@
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;
diff --git a/p2p/client/basic_port_allocator.h b/p2p/client/basic_port_allocator.h
index 048b527..ae3a5360 100644
--- a/p2p/client/basic_port_allocator.h
+++ b/p2p/client/basic_port_allocator.h
@@ -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 @@
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);