[gdm/wip/weak-ref-removal: 6/6] libgdm: Drop weak refs on the GDBusConnection



commit 83ea8ca7e9f3882aef39c161c024096aa2f41ef7
Author: Iain Lane <iainl gnome org>
Date:   Mon May 14 16:32:25 2018 -0400

    libgdm: Drop weak refs on the GDBusConnection
    
    The GDBusProxies hold a strong reference to the connection themselves,
    so maintaining separate weak references is unnecessary.
    
    This commit drops those extraneous weak references.
    
    Some changes to original patch made by Ray Strode.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=795940

 libgdm/gdm-client.c |   81 ++++++++++++++++----------------------------------
 1 files changed, 26 insertions(+), 55 deletions(-)
---
diff --git a/libgdm/gdm-client.c b/libgdm/gdm-client.c
index c34121e..d3393fc 100644
--- a/libgdm/gdm-client.c
+++ b/libgdm/gdm-client.c
@@ -393,7 +393,7 @@ on_got_manager_for_reauthentication (GdmClient           *client,
 
 }
 
-static gboolean
+static GDBusConnection *
 gdm_client_open_connection_sync (GdmClient      *client,
                                  GCancellable   *cancellable,
                                  GError        **error)
@@ -404,8 +404,7 @@ gdm_client_open_connection_sync (GdmClient      *client,
         g_return_val_if_fail (GDM_IS_CLIENT (client), FALSE);
 
         if (client->priv->connection != NULL) {
-                g_object_ref (client->priv->connection);
-                return TRUE;
+                return g_object_ref (client->priv->connection);
         }
 
         manager = gdm_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
@@ -446,7 +445,7 @@ gdm_client_open_connection_sync (GdmClient      *client,
                                    &client->priv->connection);
 
  out:
-        return client->priv->connection != NULL;
+        return client->priv->connection;
 }
 
 static void
@@ -655,13 +654,6 @@ gdm_client_open_reauthentication_channel_sync (GdmClient     *client,
                                                           cancellable,
                                                           error);
 
-        if (user_verifier != NULL) {
-                g_object_weak_ref (G_OBJECT (user_verifier),
-                                   (GWeakNotify)
-                                   g_object_unref,
-                                   connection);
-        }
-
  out:
         return user_verifier;
 }
@@ -743,15 +735,19 @@ gdm_client_get_user_verifier_sync (GdmClient     *client,
                                    GCancellable  *cancellable,
                                    GError       **error)
 {
+        g_autoptr(GDBusConnection) connection = NULL;
+
         if (client->priv->user_verifier != NULL) {
                 return g_object_ref (client->priv->user_verifier);
         }
 
-        if (!gdm_client_open_connection_sync (client, cancellable, error)) {
+        connection = gdm_client_open_connection_sync (client, cancellable, error);
+
+        if (connection == NULL) {
                 return NULL;
         }
 
-        client->priv->user_verifier = gdm_user_verifier_proxy_new_sync (client->priv->connection,
+        client->priv->user_verifier = gdm_user_verifier_proxy_new_sync (connection,
                                                                         G_DBUS_PROXY_FLAGS_NONE,
                                                                         NULL,
                                                                         SESSION_DBUS_PATH,
@@ -762,11 +758,6 @@ gdm_client_get_user_verifier_sync (GdmClient     *client,
                 g_object_add_weak_pointer (G_OBJECT (client->priv->user_verifier),
                                            (gpointer *)
                                            &client->priv->user_verifier);
-                g_object_weak_ref (G_OBJECT (client->priv->user_verifier),
-                                   (GWeakNotify)
-                                   g_clear_object,
-                                   &client->priv->connection);
-
                 if (client->priv->enabled_extensions != NULL) {
                         gboolean res;
 
@@ -903,11 +894,6 @@ gdm_client_get_user_verifier_finish (GdmClient       *client,
                                    (gpointer *)
                                    &client->priv->user_verifier);
 
-        g_object_weak_ref (G_OBJECT (client->priv->user_verifier),
-                           (GWeakNotify)
-                           g_object_unref,
-                           client->priv->connection);
-
         return user_verifier;
 }
 
@@ -1073,10 +1059,6 @@ gdm_client_get_greeter_finish (GdmClient       *client,
                                    (gpointer *)
                                    &client->priv->greeter);
 
-        g_object_weak_ref (G_OBJECT (client->priv->greeter),
-                           (GWeakNotify)
-                           g_object_unref,
-                           client->priv->connection);
         return greeter;
 }
 
@@ -1098,15 +1080,19 @@ gdm_client_get_greeter_sync (GdmClient     *client,
                              GCancellable  *cancellable,
                              GError       **error)
 {
+        g_autoptr(GDBusConnection) connection = NULL;
+
         if (client->priv->greeter != NULL) {
                 return g_object_ref (client->priv->greeter);
         }
 
-        if (!gdm_client_open_connection_sync (client, cancellable, error)) {
+        connection = gdm_client_open_connection_sync (client, cancellable, error);
+
+        if (connection == NULL) {
                 return NULL;
         }
 
-        client->priv->greeter = gdm_greeter_proxy_new_sync (client->priv->connection,
+        client->priv->greeter = gdm_greeter_proxy_new_sync (connection,
                                                             G_DBUS_PROXY_FLAGS_NONE,
                                                             NULL,
                                                             SESSION_DBUS_PATH,
@@ -1117,10 +1103,6 @@ gdm_client_get_greeter_sync (GdmClient     *client,
                 g_object_add_weak_pointer (G_OBJECT (client->priv->greeter),
                                            (gpointer *)
                                            &client->priv->greeter);
-                g_object_weak_ref (G_OBJECT (client->priv->greeter),
-                                   (GWeakNotify)
-                                   g_clear_object,
-                                   &client->priv->connection);
 
                 query_for_timed_login_requested_signal (client->priv->greeter);
         }
@@ -1248,11 +1230,6 @@ gdm_client_get_remote_greeter_finish (GdmClient     *client,
                                    (gpointer *)
                                    &client->priv->remote_greeter);
 
-        g_object_weak_ref (G_OBJECT (client->priv->remote_greeter),
-                           (GWeakNotify)
-                           g_object_unref,
-                           client->priv->connection);
-
         return remote_greeter;
 }
 
@@ -1273,15 +1250,19 @@ gdm_client_get_remote_greeter_sync (GdmClient     *client,
                                     GCancellable  *cancellable,
                                     GError       **error)
 {
+        g_autoptr(GDBusConnection) connection = NULL;
+
         if (client->priv->remote_greeter != NULL) {
                 return g_object_ref (client->priv->remote_greeter);
         }
 
-        if (!gdm_client_open_connection_sync (client, cancellable, error)) {
+        connection = gdm_client_open_connection_sync (client, cancellable, error);
+
+        if (connection == NULL) {
                 return NULL;
         }
 
-        client->priv->remote_greeter = gdm_remote_greeter_proxy_new_sync (client->priv->connection,
+        client->priv->remote_greeter = gdm_remote_greeter_proxy_new_sync (connection,
                                                                           G_DBUS_PROXY_FLAGS_NONE,
                                                                           NULL,
                                                                           SESSION_DBUS_PATH,
@@ -1292,10 +1273,6 @@ gdm_client_get_remote_greeter_sync (GdmClient     *client,
                 g_object_add_weak_pointer (G_OBJECT (client->priv->remote_greeter),
                                            (gpointer *)
                                            &client->priv->remote_greeter);
-                g_object_weak_ref (G_OBJECT (client->priv->remote_greeter),
-                                   (GWeakNotify)
-                                   g_clear_object,
-                                   &client->priv->connection);
         }
 
         return client->priv->remote_greeter;
@@ -1421,11 +1398,6 @@ gdm_client_get_chooser_finish (GdmClient       *client,
                                    (gpointer *)
                                    &client->priv->chooser);
 
-        g_object_weak_ref (G_OBJECT (client->priv->chooser),
-                           (GWeakNotify)
-                           g_object_unref,
-                           client->priv->connection);
-
         return chooser;
 }
 
@@ -1446,16 +1418,19 @@ gdm_client_get_chooser_sync (GdmClient     *client,
                              GCancellable  *cancellable,
                              GError       **error)
 {
+        g_autoptr(GDBusConnection) connection = NULL;
 
         if (client->priv->chooser != NULL) {
                 return g_object_ref (client->priv->chooser);
         }
 
-        if (!gdm_client_open_connection_sync (client, cancellable, error)) {
+        connection = gdm_client_open_connection_sync (client, cancellable, error);
+
+        if (connection == NULL) {
                 return NULL;
         }
 
-        client->priv->chooser = gdm_chooser_proxy_new_sync (client->priv->connection,
+        client->priv->chooser = gdm_chooser_proxy_new_sync (connection,
                                                             G_DBUS_PROXY_FLAGS_NONE,
                                                             NULL,
                                                             SESSION_DBUS_PATH,
@@ -1466,10 +1441,6 @@ gdm_client_get_chooser_sync (GdmClient     *client,
                 g_object_add_weak_pointer (G_OBJECT (client->priv->chooser),
                                            (gpointer *)
                                            &client->priv->chooser);
-                g_object_weak_ref (G_OBJECT (client->priv->chooser),
-                                   (GWeakNotify)
-                                   g_clear_object,
-                                   &client->priv->connection);
         }
 
         return client->priv->chooser;


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