From 2f3bd5fc3dffd760edd0513c94e8801b36a2bcce Mon Sep 17 00:00:00 2001
From: Iain Lane <iainl@gnome.org>
Date: Mon, 14 May 2018 16:32:25 -0400
Subject: [PATCH 04/15] 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.
https://bugzilla.gnome.org/show_bug.cgi?id=795940
---
libgdm/gdm-client.c | 47 ---------------------------------------------
1 file changed, 47 deletions(-)
diff --git a/libgdm/gdm-client.c b/libgdm/gdm-client.c
index e7b93e382..f327344ec 100644
--- a/libgdm/gdm-client.c
+++ b/libgdm/gdm-client.c
@@ -625,67 +625,60 @@ gdm_client_open_reauthentication_channel_sync (GdmClient *client,
username,
&address,
cancellable,
error);
if (!ret) {
goto out;
}
g_debug ("GdmClient: connecting to address: %s", client->priv->address);
connection = g_dbus_connection_new_for_address_sync (address,
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
NULL,
cancellable,
error);
if (connection == NULL) {
g_free (address);
goto out;
}
g_free (address);
user_verifier = gdm_user_verifier_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
cancellable,
error);
- if (user_verifier != NULL) {
- g_object_weak_ref (G_OBJECT (user_verifier),
- (GWeakNotify)
- g_object_unref,
- connection);
- }
-
out:
return user_verifier;
}
/**
* gdm_client_open_reauthentication_channel:
* @client: a #GdmClient
* @username: user to reauthenticate
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
* @user_data: The data to pass to @callback
* @cancellable: a #GCancellable
*
* Gets a #GdmUserVerifier object that can be used to
* reauthenticate an already logged in user.
*/
void
gdm_client_open_reauthentication_channel (GdmClient *client,
const char *username,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task;
g_return_if_fail (GDM_IS_CLIENT (client));
task = g_task_new (G_OBJECT (client),
cancellable,
callback,
user_data);
@@ -736,66 +729,60 @@ gdm_client_open_reauthentication_channel_finish (GdmClient *client,
* Returns: (transfer full): #GdmUserVerifier or %NULL if not connected
*/
GdmUserVerifier *
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);
}
connection = gdm_client_get_connection_sync (client, cancellable, error);
if (connection == NULL) {
return NULL;
}
client->priv->user_verifier = gdm_user_verifier_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
cancellable,
error);
if (client->priv->user_verifier != NULL) {
g_object_add_weak_pointer (G_OBJECT (client->priv->user_verifier),
(gpointer *)
&client->priv->user_verifier);
- g_object_ref (connection);
- g_object_weak_ref (G_OBJECT (client->priv->user_verifier),
- (GWeakNotify)
- g_object_unref,
- client->priv->connection);
-
if (client->priv->enabled_extensions != NULL) {
gboolean res;
client->priv->user_verifier_extensions = g_hash_table_new_full (g_str_hash,
g_str_equal,
NULL,
(GDestroyNotify)
free_interface_skeleton);
res = gdm_user_verifier_call_enable_extensions_sync (client->priv->user_verifier,
(const char * const *)
client->priv->enabled_extensions,
cancellable,
NULL);
if (res) {
size_t i;
for (i = 0; client->priv->enabled_extensions[i] != NULL; i++) {
if (strcmp (client->priv->enabled_extensions[i],
gdm_user_verifier_choice_list_interface_info ()->name) == 0) {
GdmUserVerifierChoiceList *choice_list_interface;
choice_list_interface = gdm_user_verifier_choice_list_proxy_new_sync (client->priv->connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
cancellable,
NULL);
if (choice_list_interface != NULL)
g_hash_table_insert (client->priv->user_verifier_extensions, client->priv->enabled_extensions[i], choice_list_interface);
}
}
@@ -881,65 +868,60 @@ gdm_client_get_user_verifier (GdmClient *client,
* @result: The #GAsyncResult from the callback
* @error: a #GError
*
* Finishes an operation started with
* gdm_client_get_user_verifier().
*
* Returns: (transfer full): a #GdmUserVerifier
*/
GdmUserVerifier *
gdm_client_get_user_verifier_finish (GdmClient *client,
GAsyncResult *result,
GError **error)
{
GdmUserVerifier *user_verifier;
g_return_val_if_fail (GDM_IS_CLIENT (client), FALSE);
if (client->priv->user_verifier != NULL)
return g_object_ref (client->priv->user_verifier);
user_verifier = g_task_propagate_pointer (G_TASK (result), error);
if (user_verifier == NULL)
return NULL;
client->priv->user_verifier = user_verifier;
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_object_unref,
- client->priv->connection);
-
return user_verifier;
}
/**
* gdm_client_get_user_verifier_choice_list:
* @client: a #GdmClient
*
* Gets a #GdmUserVerifierChoiceList object that can be used to
* verify a user's local account.
*
* Returns: (transfer none): #GdmUserVerifierChoiceList or %NULL if user
* verifier isn't yet fetched, or daemon doesn't support choice lists
*/
GdmUserVerifierChoiceList *
gdm_client_get_user_verifier_choice_list (GdmClient *client)
{
if (client->priv->user_verifier_extensions == NULL)
return NULL;
return g_hash_table_lookup (client->priv->user_verifier_extensions,
gdm_user_verifier_choice_list_interface_info ()->name);
}
static void
on_timed_login_details_got (GdmGreeter *greeter,
GAsyncResult *result)
{
gdm_greeter_call_get_timed_login_details_finish (greeter, NULL, NULL, NULL, result, NULL);
}
@@ -1054,112 +1036,104 @@ gdm_client_get_greeter (GdmClient *client,
* @result: The #GAsyncResult from the callback
* @error: a #GError
*
* Finishes an operation started with
* gdm_client_get_greeter().
*
* Returns: (transfer full): a #GdmGreeter
*/
GdmGreeter *
gdm_client_get_greeter_finish (GdmClient *client,
GAsyncResult *result,
GError **error)
{
GdmGreeter *greeter;
g_return_val_if_fail (GDM_IS_CLIENT (client), FALSE);
if (client->priv->greeter != NULL)
return g_object_ref (client->priv->greeter);
greeter = g_task_propagate_pointer (G_TASK (result), error);
if (greeter == NULL)
return NULL;
client->priv->greeter = greeter;
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_object_unref,
- client->priv->connection);
return greeter;
}
/**
* gdm_client_get_greeter_sync:
* @client: a #GdmClient
* @cancellable: a #GCancellable
* @error: a #GError
*
* Gets a #GdmGreeter object that can be used
* to do do various login screen related tasks, such
* as selecting a users session, and starting that
* session.
*
* Returns: (transfer full): #GdmGreeter or %NULL if caller is not a greeter
*/
GdmGreeter *
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);
}
connection = gdm_client_get_connection_sync (client, cancellable, error);
if (connection == NULL) {
return NULL;
}
client->priv->greeter = gdm_greeter_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
cancellable,
error);
if (client->priv->greeter != NULL) {
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_object_unref,
- client->priv->connection);
query_for_timed_login_requested_signal (client->priv->greeter);
}
return client->priv->greeter;
}
static void
on_remote_greeter_proxy_created (GObject *object,
GAsyncResult *result,
GTask *task)
{
GdmRemoteGreeter *remote_greeter;
GError *error = NULL;
remote_greeter = gdm_remote_greeter_proxy_new_finish (result, &error);
if (remote_greeter == NULL) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
g_task_return_pointer (task,
remote_greeter,
(GDestroyNotify) g_object_unref);
g_object_unref (task);
}
static void
on_connection_for_remote_greeter (GdmClient *client,
@@ -1236,113 +1210,103 @@ gdm_client_get_remote_greeter (GdmClient *client,
* @result: The #GAsyncResult from the callback
* @error: a #GError
*
* Finishes an operation started with
* gdm_client_get_remote_greeter().
*
* Returns: (transfer full): a #GdmRemoteGreeter
*/
GdmRemoteGreeter *
gdm_client_get_remote_greeter_finish (GdmClient *client,
GAsyncResult *result,
GError **error)
{
GdmRemoteGreeter *remote_greeter;
g_return_val_if_fail (GDM_IS_CLIENT (client), FALSE);
if (client->priv->remote_greeter != NULL)
return g_object_ref (client->priv->remote_greeter);
remote_greeter = g_task_propagate_pointer (G_TASK (result), error);
if (remote_greeter == NULL)
return NULL;
client->priv->remote_greeter = remote_greeter;
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_object_unref,
- client->priv->connection);
-
return remote_greeter;
}
/**
* gdm_client_get_remote_greeter_sync:
* @client: a #GdmClient
* @cancellable: a #GCancellable
* @error: a #GError
*
* Gets a #GdmRemoteGreeter object that can be used
* to do do various remote login screen related tasks,
* such as disconnecting.
*
* Returns: (transfer full): #GdmRemoteGreeter or %NULL if caller is not remote
*/
GdmRemoteGreeter *
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);
}
connection = gdm_client_get_connection_sync (client, cancellable, error);
if (connection == NULL) {
return NULL;
}
client->priv->remote_greeter = gdm_remote_greeter_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
cancellable,
error);
if (client->priv->remote_greeter != NULL) {
g_object_add_weak_pointer (G_OBJECT (client->priv->remote_greeter),
(gpointer *)
&client->priv->remote_greeter);
- g_object_ref (connection);
- g_object_weak_ref (G_OBJECT (client->priv->remote_greeter),
- (GWeakNotify)
- g_object_unref,
- client->priv->connection);
}
return client->priv->remote_greeter;
}
static void
on_chooser_proxy_created (GObject *source,
GAsyncResult *result,
GTask *task)
{
GdmChooser *chooser;
GError *error = NULL;
chooser = gdm_chooser_proxy_new_finish (result, &error);
if (chooser == NULL) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
g_task_return_pointer (task,
chooser,
(GDestroyNotify) g_object_unref);
g_object_unref (task);
}
static void
on_connection_for_chooser (GdmClient *client,
GAsyncResult *result,
GTask *task)
@@ -1417,114 +1381,103 @@ gdm_client_get_chooser (GdmClient *client,
* @result: The #GAsyncResult from the callback
* @error: a #GError
*
* Finishes an operation started with
* gdm_client_get_chooser().
*
* Returns: (transfer full): a #GdmChooser
*/
GdmChooser *
gdm_client_get_chooser_finish (GdmClient *client,
GAsyncResult *result,
GError **error)
{
GdmChooser *chooser;
g_return_val_if_fail (GDM_IS_CLIENT (client), FALSE);
if (client->priv->chooser != NULL)
return g_object_ref (client->priv->chooser);
chooser = g_task_propagate_pointer (G_TASK (result), error);
if (chooser == NULL)
return NULL;
client->priv->chooser = chooser;
g_object_add_weak_pointer (G_OBJECT (client->priv->chooser),
(gpointer *)
&client->priv->chooser);
- g_object_ref (connection);
- g_object_weak_ref (G_OBJECT (client->priv->chooser),
- (GWeakNotify)
- g_object_unref,
- client->priv->connection);
-
return chooser;
}
/**
* gdm_client_get_chooser_sync:
* @client: a #GdmClient
* @cancellable: a #GCancellable
* @error: a #GError
*
* Gets a #GdmChooser object that can be used
* to do do various XDMCP chooser related tasks, such
* as selecting a host or disconnecting.
*
* Returns: (transfer full): #GdmChooser or %NULL if caller is not a chooser
*/
GdmChooser *
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);
}
connection = gdm_client_get_connection_sync (client, cancellable, error);
if (connection == NULL) {
return NULL;
}
client->priv->chooser = gdm_chooser_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
cancellable,
error);
if (client->priv->chooser != NULL) {
g_object_add_weak_pointer (G_OBJECT (client->priv->chooser),
(gpointer *)
&client->priv->chooser);
- g_object_ref (connection);
- g_object_weak_ref (G_OBJECT (client->priv->chooser),
- (GWeakNotify)
- g_object_unref,
- client->priv->connection);
}
return client->priv->chooser;
}
static void
gdm_client_class_init (GdmClientClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gdm_client_finalize;
g_type_class_add_private (klass, sizeof (GdmClientPrivate));
}
static void
gdm_client_init (GdmClient *client)
{
client->priv = GDM_CLIENT_GET_PRIVATE (client);
}
static void
gdm_client_finalize (GObject *object)
{
GdmClient *client;
g_return_if_fail (object != NULL);
g_return_if_fail (GDM_IS_CLIENT (object));
--
2.25.1