[glib] gproxyresolverportal: do not connect to session bus when not under flatpak
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gproxyresolverportal: do not connect to session bus when not under flatpak
- Date: Mon, 27 Nov 2017 11:36:51 +0000 (UTC)
commit 7dcc09e58688ea4c538f77824268a35c9654f5e6
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Nov 27 11:32:49 2017 +0100
gproxyresolverportal: do not connect to session bus when not under flatpak
While gio module extension is loaded a new GProxyResolverPortal is
created to query whether it's supported. We always return FALSE when not
aunder flatpak, so we don't need to connect to the session bus in that
case. Add a helper ensure_resolver_proxy() that returns TRUE when the
proxy is created and use it in is_supported() instead of creating the
proxy unconditionally in the instance initialization.
https://bugzilla.gnome.org/show_bug.cgi?id=790894
gio/gproxyresolverportal.c | 25 ++++++++++++++++++++++---
1 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/gio/gproxyresolverportal.c b/gio/gproxyresolverportal.c
index c300ec3..d525800 100644
--- a/gio/gproxyresolverportal.c
+++ b/gio/gproxyresolverportal.c
@@ -42,9 +42,15 @@ G_DEFINE_TYPE_WITH_CODE (GProxyResolverPortal, g_proxy_resolver_portal, G_TYPE_O
"portal",
90))
-static void
-g_proxy_resolver_portal_init (GProxyResolverPortal *resolver)
+static gboolean
+ensure_resolver_proxy (GProxyResolverPortal *resolver)
{
+ if (resolver->resolver)
+ return TRUE;
+
+ if (!glib_should_use_portal ())
+ return FALSE;
+
resolver->resolver = gxdp_proxy_resolver_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
"org.freedesktop.portal.Desktop",
@@ -53,6 +59,13 @@ g_proxy_resolver_portal_init (GProxyResolverPortal *resolver)
NULL);
resolver->network_available = glib_network_available_in_sandbox ();
+
+ return resolver->resolver != NULL;
+}
+
+static void
+g_proxy_resolver_portal_init (GProxyResolverPortal *resolver)
+{
}
static gboolean
@@ -62,7 +75,7 @@ g_proxy_resolver_portal_is_supported (GProxyResolver *object)
char *name_owner;
gboolean has_portal;
- if (!glib_should_use_portal () || !resolver->resolver)
+ if (!ensure_resolver_proxy (resolver))
return FALSE;
name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (resolver->resolver));
@@ -83,6 +96,9 @@ g_proxy_resolver_portal_lookup (GProxyResolver *proxy_resolver,
GProxyResolverPortal *resolver = G_PROXY_RESOLVER_PORTAL (proxy_resolver);
char **proxy = NULL;
+ ensure_resolver_proxy (resolver);
+ g_assert (resolver->resolver);
+
if (!gxdp_proxy_resolver_call_lookup_sync (resolver->resolver,
uri,
&proxy,
@@ -129,6 +145,9 @@ g_proxy_resolver_portal_lookup_async (GProxyResolver *proxy_resolver,
GProxyResolverPortal *resolver = G_PROXY_RESOLVER_PORTAL (proxy_resolver);
GTask *task;
+ ensure_resolver_proxy (resolver);
+ g_assert (resolver->resolver);
+
task = g_task_new (proxy_resolver, cancellable, callback, user_data);
gxdp_proxy_resolver_call_lookup (resolver->resolver,
uri,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]