Adopt absl::string_view in modules/desktop_capture/
Bug: webrtc:13579
Change-Id: I9fbc3d6df2dedb7eac908e1af38300d2b42142c8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/272000
Commit-Queue: Ali Tofigh <alito@webrtc.org>
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/main@{#37817}
diff --git a/modules/desktop_capture/BUILD.gn b/modules/desktop_capture/BUILD.gn
index fba4538..689d659 100644
--- a/modules/desktop_capture/BUILD.gn
+++ b/modules/desktop_capture/BUILD.gn
@@ -209,6 +209,7 @@
"../../rtc_base:logging",
"../../system_wrappers",
]
+ absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
if (is_posix || is_fuchsia) {
sources += [
diff --git a/modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.cc b/modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.cc
index 4fdf54a..4a74b9f 100644
--- a/modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.cc
+++ b/modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.cc
@@ -9,6 +9,9 @@
*/
#include "modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.h"
+#include <string>
+
+#include "absl/strings/string_view.h"
#include "modules/desktop_capture/linux/wayland/scoped_glib.h"
#include "rtc_base/logging.h"
@@ -30,7 +33,7 @@
}
}
-std::string PrepareSignalHandle(const char* token,
+std::string PrepareSignalHandle(absl::string_view token,
GDBusConnection* connection) {
Scoped<char> sender(
g_strdup(g_dbus_connection_get_unique_name(connection) + 1));
@@ -39,33 +42,36 @@
sender.get()[i] = '_';
}
}
- const char* handle = g_strconcat(kDesktopRequestObjectPath, "/", sender.get(),
- "/", token, /*end of varargs*/ nullptr);
+ const char* handle =
+ g_strconcat(kDesktopRequestObjectPath, "/", sender.get(), "/",
+ std::string(token).c_str(), /*end of varargs*/ nullptr);
return handle;
}
-uint32_t SetupRequestResponseSignal(const char* object_path,
+uint32_t SetupRequestResponseSignal(absl::string_view object_path,
const GDBusSignalCallback callback,
gpointer user_data,
GDBusConnection* connection) {
return g_dbus_connection_signal_subscribe(
connection, kDesktopBusName, kRequestInterfaceName, "Response",
- object_path, /*arg0=*/nullptr, G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
- callback, user_data, /*user_data_free_func=*/nullptr);
+ std::string(object_path).c_str(), /*arg0=*/nullptr,
+ G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE, callback, user_data,
+ /*user_data_free_func=*/nullptr);
}
-void RequestSessionProxy(const char* interface_name,
+void RequestSessionProxy(absl::string_view interface_name,
const ProxyRequestCallback proxy_request_callback,
GCancellable* cancellable,
gpointer user_data) {
g_dbus_proxy_new_for_bus(
G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, /*info=*/nullptr,
- kDesktopBusName, kDesktopObjectPath, interface_name, cancellable,
+ kDesktopBusName, kDesktopObjectPath, std::string(interface_name).c_str(),
+ cancellable,
reinterpret_cast<GAsyncReadyCallback>(proxy_request_callback), user_data);
}
void SetupSessionRequestHandlers(
- const std::string& portal_prefix,
+ absl::string_view portal_prefix,
const SessionRequestCallback session_request_callback,
const SessionRequestResponseSignalHandler request_response_signale_handler,
GDBusConnection* connection,
@@ -78,13 +84,15 @@
Scoped<char> variant_string;
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
- variant_string = g_strdup_printf("%s_session%d", portal_prefix.c_str(),
- g_random_int_range(0, G_MAXINT));
+ variant_string =
+ g_strdup_printf("%.*s_session%d", static_cast<int>(portal_prefix.size()),
+ portal_prefix.data(), g_random_int_range(0, G_MAXINT));
g_variant_builder_add(&builder, "{sv}", "session_handle_token",
g_variant_new_string(variant_string.get()));
- variant_string = g_strdup_printf("%s_%d", portal_prefix.c_str(),
- g_random_int_range(0, G_MAXINT));
+ variant_string =
+ g_strdup_printf("%.*s_%d", static_cast<int>(portal_prefix.size()),
+ portal_prefix.data(), g_random_int_range(0, G_MAXINT));
g_variant_builder_add(&builder, "{sv}", "handle_token",
g_variant_new_string(variant_string.get()));
@@ -102,8 +110,8 @@
}
void StartSessionRequest(
- const std::string& prefix,
- const std::string session_handle,
+ absl::string_view prefix,
+ absl::string_view session_handle,
const StartRequestResponseSignalHandler signal_handler,
const SessionStartRequestedHandler session_started_handler,
GDBusProxy* proxy,
@@ -117,7 +125,8 @@
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
variant_string =
- g_strdup_printf("%s%d", prefix.c_str(), g_random_int_range(0, G_MAXINT));
+ g_strdup_printf("%.*s%d", static_cast<int>(prefix.size()), prefix.data(),
+ g_random_int_range(0, G_MAXINT));
g_variant_builder_add(&builder, "{sv}", "handle_token",
g_variant_new_string(variant_string.get()));
@@ -131,21 +140,21 @@
RTC_LOG(LS_INFO) << "Starting the portal session.";
g_dbus_proxy_call(
proxy, "Start",
- g_variant_new("(osa{sv})", session_handle.c_str(), parent_window,
- &builder),
+ g_variant_new("(osa{sv})", std::string(session_handle).c_str(),
+ parent_window, &builder),
G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, cancellable,
reinterpret_cast<GAsyncReadyCallback>(session_started_handler),
user_data);
}
-void TearDownSession(std::string session_handle,
+void TearDownSession(absl::string_view session_handle,
GDBusProxy* proxy,
GCancellable* cancellable,
GDBusConnection* connection) {
if (!session_handle.empty()) {
- Scoped<GDBusMessage> message(
- g_dbus_message_new_method_call(kDesktopBusName, session_handle.c_str(),
- kSessionInterfaceName, "Close"));
+ Scoped<GDBusMessage> message(g_dbus_message_new_method_call(
+ kDesktopBusName, std::string(session_handle).c_str(),
+ kSessionInterfaceName, "Close"));
if (message.get()) {
Scoped<GError> error;
g_dbus_connection_send_message(connection, message.get(),
diff --git a/modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.h b/modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.h
index 7f1ef0b..edd0466 100644
--- a/modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.h
+++ b/modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.h
@@ -17,6 +17,7 @@
#include <string>
#include <vector>
+#include "absl/strings/string_view.h"
#include "modules/desktop_capture/linux/wayland/portal_request_response.h"
#include "modules/desktop_capture/linux/wayland/scoped_glib.h"
#include "modules/desktop_capture/linux/wayland/xdg_session_details.h"
@@ -43,7 +44,6 @@
const char*,
GVariant*,
gpointer);
-using SessionRequestResponseSignalCallback = void (*)(std::string);
using StartRequestResponseSignalHandler = void (*)(GDBusConnection*,
const char*,
const char*,
@@ -59,22 +59,23 @@
// Returns a string path for signal handle based on the provided connection and
// token.
-std::string PrepareSignalHandle(const char* token, GDBusConnection* connection);
+std::string PrepareSignalHandle(absl::string_view token,
+ GDBusConnection* connection);
// Sets up the callback to execute when a response signal is received for the
// given object.
-uint32_t SetupRequestResponseSignal(const char* object_path,
+uint32_t SetupRequestResponseSignal(absl::string_view object_path,
const GDBusSignalCallback callback,
gpointer user_data,
GDBusConnection* connection);
-void RequestSessionProxy(const char* interface_name,
+void RequestSessionProxy(absl::string_view interface_name,
const ProxyRequestCallback proxy_request_callback,
GCancellable* cancellable,
gpointer user_data);
void SetupSessionRequestHandlers(
- const std::string& portal_prefix,
+ absl::string_view portal_prefix,
const SessionRequestCallback session_request_callback,
const SessionRequestResponseSignalHandler request_response_signale_handler,
GDBusConnection* connection,
@@ -85,8 +86,8 @@
gpointer user_data);
void StartSessionRequest(
- const std::string& prefix,
- const std::string session_handle,
+ absl::string_view prefix,
+ absl::string_view session_handle,
const StartRequestResponseSignalHandler signal_handler,
const SessionStartRequestedHandler session_started_handler,
GDBusProxy* proxy,
@@ -97,7 +98,7 @@
gpointer user_data);
// Tears down the portal session and cleans up related objects.
-void TearDownSession(std::string session_handle,
+void TearDownSession(absl::string_view session_handle,
GDBusProxy* proxy,
GCancellable* cancellable,
GDBusConnection* connection);
diff --git a/modules/desktop_capture/linux/x11/shared_x_display.cc b/modules/desktop_capture/linux/x11/shared_x_display.cc
index ad2e043..b784950 100644
--- a/modules/desktop_capture/linux/x11/shared_x_display.cc
+++ b/modules/desktop_capture/linux/x11/shared_x_display.cc
@@ -15,6 +15,7 @@
#include <algorithm>
+#include "absl/strings/string_view.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
@@ -31,9 +32,9 @@
// static
rtc::scoped_refptr<SharedXDisplay> SharedXDisplay::Create(
- const std::string& display_name) {
- Display* display =
- XOpenDisplay(display_name.empty() ? NULL : display_name.c_str());
+ absl::string_view display_name) {
+ Display* display = XOpenDisplay(
+ display_name.empty() ? NULL : std::string(display_name).c_str());
if (!display) {
RTC_LOG(LS_ERROR) << "Unable to open display";
return nullptr;
diff --git a/modules/desktop_capture/linux/x11/shared_x_display.h b/modules/desktop_capture/linux/x11/shared_x_display.h
index 6405c36..084da80 100644
--- a/modules/desktop_capture/linux/x11/shared_x_display.h
+++ b/modules/desktop_capture/linux/x11/shared_x_display.h
@@ -12,9 +12,9 @@
#define MODULES_DESKTOP_CAPTURE_LINUX_X11_SHARED_X_DISPLAY_H_
#include <map>
-#include <string>
#include <vector>
+#include "absl/strings/string_view.h"
#include "api/ref_counted_base.h"
#include "api/scoped_refptr.h"
#include "rtc_base/system/rtc_export.h"
@@ -42,7 +42,7 @@
// connection failed. Equivalent to CreateDefault() when `display_name` is
// empty.
static rtc::scoped_refptr<SharedXDisplay> Create(
- const std::string& display_name);
+ absl::string_view display_name);
// Creates X11 Display connection for the default display (e.g. specified in
// DISPLAY). NULL is returned if X11 connection failed.
diff --git a/modules/desktop_capture/mac/full_screen_mac_application_handler.cc b/modules/desktop_capture/mac/full_screen_mac_application_handler.cc
index 6eab0c7..45cd322 100644
--- a/modules/desktop_capture/mac/full_screen_mac_application_handler.cc
+++ b/modules/desktop_capture/mac/full_screen_mac_application_handler.cc
@@ -9,11 +9,15 @@
*/
#include "modules/desktop_capture/mac/full_screen_mac_application_handler.h"
+
#include <libproc.h>
+
#include <algorithm>
#include <functional>
#include <string>
+
#include "absl/strings/match.h"
+#include "absl/strings/string_view.h"
#include "api/function_view.h"
#include "modules/desktop_capture/mac/window_list_utils.h"
@@ -52,7 +56,7 @@
class FullScreenMacApplicationHandler : public FullScreenApplicationHandler {
public:
using TitlePredicate =
- std::function<bool(const std::string&, const std::string&)>;
+ std::function<bool(absl::string_view, absl::string_view)>;
FullScreenMacApplicationHandler(DesktopCapturer::SourceId sourceId,
TitlePredicate title_predicate,
@@ -134,14 +138,14 @@
mutable DesktopCapturer::SourceList cache_sources_;
};
-bool equal_title_predicate(const std::string& original_title,
- const std::string& title) {
+bool equal_title_predicate(absl::string_view original_title,
+ absl::string_view title) {
return original_title == title;
}
-bool slide_show_title_predicate(const std::string& original_title,
- const std::string& title) {
- if (title.find(original_title) == std::string::npos)
+bool slide_show_title_predicate(absl::string_view original_title,
+ absl::string_view title) {
+ if (title.find(original_title) == absl::string_view::npos)
return false;
for (const char* pp_slide_title : kPowerPointSlideShowTitles) {
diff --git a/modules/desktop_capture/screen_drawer_lock_posix.cc b/modules/desktop_capture/screen_drawer_lock_posix.cc
index bfee619..28cb501 100644
--- a/modules/desktop_capture/screen_drawer_lock_posix.cc
+++ b/modules/desktop_capture/screen_drawer_lock_posix.cc
@@ -13,6 +13,7 @@
#include <fcntl.h>
#include <sys/stat.h>
+#include "absl/strings/string_view.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
@@ -51,8 +52,8 @@
}
// static
-void ScreenDrawerLockPosix::Unlink(const char* name) {
- sem_unlink(name);
+void ScreenDrawerLockPosix::Unlink(absl::string_view name) {
+ sem_unlink(std::string(name).c_str());
}
} // namespace webrtc
diff --git a/modules/desktop_capture/screen_drawer_lock_posix.h b/modules/desktop_capture/screen_drawer_lock_posix.h
index 1d5adf2..13899b2 100644
--- a/modules/desktop_capture/screen_drawer_lock_posix.h
+++ b/modules/desktop_capture/screen_drawer_lock_posix.h
@@ -13,6 +13,7 @@
#include <semaphore.h>
+#include "absl/strings/string_view.h"
#include "modules/desktop_capture/screen_drawer.h"
namespace webrtc {
@@ -27,7 +28,7 @@
// Unlinks the named semaphore actively. This will remove the sem_t object in
// the system and allow others to create a different sem_t object with the
// same/ name.
- static void Unlink(const char* name);
+ static void Unlink(absl::string_view name);
private:
sem_t* semaphore_;