From ea1adea24db659b2a37678e3276044d7dfa53d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sat, 14 Mar 2020 21:51:33 +0100 Subject: [PATCH] shell/network-agent: Wrap nm_plugin_info_new_search_file() While we can use the libnm API directly from JS, the call will synchronously load the VPN service descriptions from disk. Previously we were lowering the impact by caching the result, but as we stopped doing that, it becomes more important to address the issue properly and move it off to a thread. https://gitlab.gnome.org/GNOME/gnome-shell/issues/2386 --- src/shell-network-agent.c | 57 +++++++++++++++++++++++++++++++++++++++ src/shell-network-agent.h | 8 ++++++ 2 files changed, 65 insertions(+) diff --git a/src/shell-network-agent.c b/src/shell-network-agent.c index 8e1f82017..4fab298e5 100644 --- a/src/shell-network-agent.c +++ b/src/shell-network-agent.c @@ -478,6 +478,63 @@ shell_network_agent_respond (ShellNetworkAgent *self, g_hash_table_remove (priv->requests, request_id); } +static void +search_vpn_plugin (GTask *task, + gpointer object, + gpointer task_data, + GCancellable *cancellable) +{ + NMVpnPluginInfo *info = NULL; + char *service = task_data; + + info = nm_vpn_plugin_info_new_search_file (NULL, service); + + if (info) + { + g_task_return_pointer (task, info, g_object_unref); + } + else + { + g_task_return_new_error (task, + G_IO_ERROR, G_IO_ERROR_NOT_FOUND, + "No plugin for %s", service); + } +} + +void +shell_network_agent_search_vpn_plugin (ShellNetworkAgent *self, + const char *service, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_autoptr(GTask) task = NULL; + + g_return_if_fail (SHELL_IS_NETWORK_AGENT (self)); + g_return_if_fail (service != NULL); + + task = g_task_new (self, NULL, callback, user_data); + g_task_set_source_tag (task, shell_network_agent_search_vpn_plugin); + g_task_set_task_data (task, g_strdup (service), g_free); + + g_task_run_in_thread (task, search_vpn_plugin); +} + +/** + * shell_network_agent_search_vpn_plugin_finish: + * + * Returns: (nullable) (transfer full): The found plugin or %NULL + */ +NMVpnPluginInfo * +shell_network_agent_search_vpn_plugin_finish (ShellNetworkAgent *self, + GAsyncResult *result, + GError **error) +{ + g_return_val_if_fail (SHELL_IS_NETWORK_AGENT (self), NULL); + g_return_val_if_fail (G_IS_TASK (result), NULL); + + return g_task_propagate_pointer (G_TASK (result), error); +} + static void shell_network_agent_cancel_get_secrets (NMSecretAgentOld *agent, const gchar *connection_path, diff --git a/src/shell-network-agent.h b/src/shell-network-agent.h index 73dfe5b1d..e01b368f0 100644 --- a/src/shell-network-agent.h +++ b/src/shell-network-agent.h @@ -51,6 +51,14 @@ void shell_network_agent_respond (ShellNetworkAgent *self, gchar *request_id, ShellNetworkAgentResponse response); +void shell_network_agent_search_vpn_plugin (ShellNetworkAgent *self, + const char *service, + GAsyncReadyCallback callback, + gpointer user_data); +NMVpnPluginInfo *shell_network_agent_search_vpn_plugin_finish (ShellNetworkAgent *self, + GAsyncResult *result, + GError **error); + /* If these are kept in sync with nm-applet, secrets will be shared */ #define SHELL_KEYRING_UUID_TAG "connection-uuid" #define SHELL_KEYRING_SN_TAG "setting-name"