[glib/portal] proxy: Redo the network availability check



commit 90b847534086fcb3074da4ed9c2b3cf4305c4b5c
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jun 23 10:27:50 2016 -0400

    proxy: Redo the network availability check
    
    Do this more like for the network monitor: We keep using the
    portal proxy, but we neuter all results. Eventually, we can
    do this on the portal side, but we need some systemd infrastructure
    for it.

 gio/gproxyresolverportal.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/gio/gproxyresolverportal.c b/gio/gproxyresolverportal.c
index e2c3caa..bfa74ea 100644
--- a/gio/gproxyresolverportal.c
+++ b/gio/gproxyresolverportal.c
@@ -28,6 +28,7 @@ struct _GProxyResolverPortal {
   GObject parent_instance;
 
   XdpProxyResolver *resolver;
+  gboolean network_available;
 };
 
 static void g_proxy_resolver_portal_iface_init (GProxyResolverInterface *iface);
@@ -50,6 +51,8 @@ g_proxy_resolver_portal_init (GProxyResolverPortal *resolver)
                                                                 "/org/freedesktop/portal/desktop",
                                                                 NULL,
                                                                 NULL);
+
+  resolver->network_available = glib_network_available_in_sandbox ();
 }
 
 static gboolean
@@ -59,9 +62,7 @@ g_proxy_resolver_portal_is_supported (GProxyResolver *object)
   char *name_owner;
   gboolean has_portal;
 
-  if (!glib_should_use_portal () ||
-      !glib_network_available_in_sandbox () ||
-      !resolver->resolver)
+  if (!glib_should_use_portal () || !resolver->resolver)
     return FALSE;
 
   name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (resolver->resolver));
@@ -71,6 +72,8 @@ g_proxy_resolver_portal_is_supported (GProxyResolver *object)
   return has_portal;
 }
 
+static const char *no_proxy[2] = { "direct://", NULL };
+
 static gchar **
 g_proxy_resolver_portal_lookup (GProxyResolver *proxy_resolver,
                                 const gchar     *uri,
@@ -87,6 +90,12 @@ g_proxy_resolver_portal_lookup (GProxyResolver *proxy_resolver,
                                             error))
     return NULL;
 
+  if (!resolver->network_available)
+    {
+      g_strfreev ((gchar **)proxy);
+      proxy = g_strdupv ((gchar **)no_proxy);
+    }
+
   return proxy;
 }
 
@@ -120,6 +129,12 @@ g_proxy_resolver_portal_lookup_finish (GProxyResolver  *proxy_resolver,
                                               error))
     return NULL;
 
+  if (!resolver->network_available)
+    {
+      g_strfreev ((gchar **)proxy);
+      proxy = g_strdupv ((gchar **)no_proxy);
+    }
+
   return proxy;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]