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
This commit is contained in:
Florian Müllner 2020-03-14 21:51:33 +01:00
parent 2756806f84
commit c5dd9a9341
2 changed files with 65 additions and 0 deletions

View File

@ -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,

View File

@ -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"