[gvfs] proxy volume monitor: Get session bus on demand



commit 10ca359c57eb6f5481a61bf1bf52996bd992aa09
Author: Tomas Bzatek <tbzatek redhat com>
Date:   Thu Nov 1 14:37:50 2012 +0100

    proxy volume monitor: Get session bus on demand
    
    Do not connect to session bus at module load, let proxies to get
    a bus when needed. No need to keep it active all the time. Proxies
    will return an error when a bus is unavailable.
    
    Also don't close the shared d-bus connection on module unload, let
    it be managed by proxies.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687074

 monitor/proxy/gproxyvolumemonitor.c          |   49 +++++++------------------
 monitor/proxy/gproxyvolumemonitor.h          |    2 +-
 monitor/proxy/remote-volume-monitor-module.c |    2 +-
 3 files changed, 16 insertions(+), 37 deletions(-)
---
diff --git a/monitor/proxy/gproxyvolumemonitor.c b/monitor/proxy/gproxyvolumemonitor.c
index c46e27f..d21da7f 100644
--- a/monitor/proxy/gproxyvolumemonitor.c
+++ b/monitor/proxy/gproxyvolumemonitor.c
@@ -45,7 +45,6 @@
 
 G_LOCK_DEFINE_STATIC(proxy_vm);
 
-static GDBusConnection *the_session_bus = NULL;
 static GHashTable *the_volume_monitors = NULL;
 
 struct _GProxyVolumeMonitor {
@@ -979,12 +978,12 @@ g_proxy_volume_monitor_constructor (GType                  type,
   monitor = G_PROXY_VOLUME_MONITOR (object);
 
   error = NULL;
-  monitor->proxy = gvfs_remote_volume_monitor_proxy_new_sync (the_session_bus,
-                                                              G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
-                                                              dbus_name,
-                                                              "/org/gtk/Private/RemoteVolumeMonitor",
-                                                              NULL,
-                                                              &error);
+  monitor->proxy = gvfs_remote_volume_monitor_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+                                                                      G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+                                                                      dbus_name,
+                                                                      "/org/gtk/Private/RemoteVolumeMonitor",
+                                                                      NULL,
+                                                                      &error);
   if (monitor->proxy == NULL)
     {
       g_printerr ("Error creating proxy: %s (%s, %d)\n",
@@ -1144,12 +1143,12 @@ is_remote_monitor_supported (const char *dbus_name)
   is_supported = FALSE;
   error = NULL;
 
-  proxy = gvfs_remote_volume_monitor_proxy_new_sync (the_session_bus,
-                                                     G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
-                                                     dbus_name,
-                                                     "/org/gtk/Private/RemoteVolumeMonitor",
-                                                     NULL,
-                                                     &error);
+  proxy = gvfs_remote_volume_monitor_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+                                                             G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+                                                             dbus_name,
+                                                             "/org/gtk/Private/RemoteVolumeMonitor",
+                                                             NULL,
+                                                             &error);
   if (proxy == NULL)
     {
       g_printerr ("Error creating proxy: %s (%s, %d)\n",
@@ -1401,13 +1400,9 @@ static gboolean
 g_proxy_volume_monitor_setup_session_bus_connection (void)
 {
   gboolean ret;
-  GError *error;
 
   ret = FALSE;
 
-  if (the_session_bus != NULL)
-    goto has_bus_already;
-
   /* This is so that system daemons can use gio
    * without spawning private dbus instances.
    * See bug 526454.
@@ -1415,20 +1410,8 @@ g_proxy_volume_monitor_setup_session_bus_connection (void)
   if (g_getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL)
     goto out;
 
-  error = NULL;
-  the_session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
-  if (error != NULL)
-    {
-      g_printerr ("cannot connect to the session bus: %s (%s, %d)\n",
-                  error->message, g_quark_to_string (error->domain), error->code);
-      g_error_free (error);
-      goto out;
-    }
-
   the_volume_monitors = g_hash_table_new (g_direct_hash, g_direct_equal);
 
- has_bus_already:
-
   ret = TRUE;
 
  out:
@@ -1436,15 +1419,11 @@ g_proxy_volume_monitor_setup_session_bus_connection (void)
 }
 
 void
-g_proxy_volume_monitor_teardown_session_bus_connection (void)
+g_proxy_volume_monitor_unload_cleanup (void)
 {
   G_LOCK (proxy_vm);
-  if (the_session_bus != NULL)
+  if (the_volume_monitors != NULL)
     {
-      g_dbus_connection_close_sync (the_session_bus, NULL, NULL);
-      g_object_unref (the_session_bus);
-      the_session_bus = NULL;
-
       g_hash_table_unref (the_volume_monitors);
       the_volume_monitors = NULL;
     }
diff --git a/monitor/proxy/gproxyvolumemonitor.h b/monitor/proxy/gproxyvolumemonitor.h
index d99ce4b..1087d5d 100644
--- a/monitor/proxy/gproxyvolumemonitor.h
+++ b/monitor/proxy/gproxyvolumemonitor.h
@@ -74,7 +74,7 @@ GProxyMount     *g_proxy_volume_monitor_get_mount_for_id  (GProxyVolumeMonitor *
                                                           const char          *id);
 GVfsRemoteVolumeMonitor *g_proxy_volume_monitor_get_dbus_proxy (GProxyVolumeMonitor *volume_monitor);
 
-void g_proxy_volume_monitor_teardown_session_bus_connection (void);
+void             g_proxy_volume_monitor_unload_cleanup    (void);
 
 
 GHashTable *_get_identifiers (GVariantIter *identifiers);
diff --git a/monitor/proxy/remote-volume-monitor-module.c b/monitor/proxy/remote-volume-monitor-module.c
index 844d76e..1df946b 100644
--- a/monitor/proxy/remote-volume-monitor-module.c
+++ b/monitor/proxy/remote-volume-monitor-module.c
@@ -68,7 +68,7 @@ g_io_module_unload (GIOModule *module)
   if (g_getenv ("GVFS_REMOTE_VOLUME_MONITOR_IGNORE") != NULL)
     goto out;
 
-  g_proxy_volume_monitor_teardown_session_bus_connection ();
+  g_proxy_volume_monitor_unload_cleanup ();
 
 out:
   ;



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