From c2b6a64834df38b493d946fab55667cebdb991b6 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Tue, 3 Oct 2017 10:00:51 -0400
Subject: [PATCH 09/13] lib: move accounts proxy creation to helper
This commit factors out hte accounts proxy creation to a
helper function.
---
src/libaccountsservice/act-user-manager.c | 74 ++++++++++++++++++-------------
1 file changed, 43 insertions(+), 31 deletions(-)
diff --git a/src/libaccountsservice/act-user-manager.c b/src/libaccountsservice/act-user-manager.c
index 556b070..5ac157d 100644
--- a/src/libaccountsservice/act-user-manager.c
+++ b/src/libaccountsservice/act-user-manager.c
@@ -197,60 +197,61 @@ struct ActUserManagerPrivate
guint load_id;
gboolean is_loaded;
gboolean has_multiple_users;
gboolean getting_sessions;
gboolean listing_cached_users;
};
enum {
PROP_0,
PROP_INCLUDE_USERNAMES_LIST,
PROP_EXCLUDE_USERNAMES_LIST,
PROP_IS_LOADED,
PROP_HAS_MULTIPLE_USERS
};
enum {
USER_ADDED,
USER_REMOVED,
USER_IS_LOGGED_IN_CHANGED,
USER_CHANGED,
LAST_SIGNAL
};
static guint signals [LAST_SIGNAL] = { 0, };
static void act_user_manager_class_init (ActUserManagerClass *klass);
static void act_user_manager_init (ActUserManager *user_manager);
static void act_user_manager_finalize (GObject *object);
+static gboolean ensure_accounts_proxy (ActUserManager *manager);
static gboolean load_seat_incrementally (ActUserManager *manager);
static void unload_seat (ActUserManager *manager);
static void load_users (ActUserManager *manager);
static void act_user_manager_queue_load (ActUserManager *manager);
static void queue_load_seat_and_users (ActUserManager *manager);
static void load_new_session_incrementally (ActUserManagerNewSession *new_session);
static void set_is_loaded (ActUserManager *manager, gboolean is_loaded);
static void on_new_user_loaded (ActUser *user,
GParamSpec *pspec,
ActUserManager *manager);
static void give_up (ActUserManager *manager,
ActUserManagerFetchUserRequest *request);
static void fetch_user_incrementally (ActUserManagerFetchUserRequest *request);
static void maybe_set_is_loaded (ActUserManager *manager);
static void update_user (ActUserManager *manager,
ActUser *user);
static gpointer user_manager_object = NULL;
G_DEFINE_TYPE (ActUserManager, act_user_manager, G_TYPE_OBJECT)
static const GDBusErrorEntry error_entries[] = {
{ ACT_USER_MANAGER_ERROR_FAILED, "org.freedesktop.Accounts.Error.Failed" },
{ ACT_USER_MANAGER_ERROR_USER_EXISTS, "org.freedesktop.Accounts.Error.UserExists" },
{ ACT_USER_MANAGER_ERROR_USER_DOES_NOT_EXIST, "org.freedesktop.Accounts.Error.UserDoesNotExist" },
{ ACT_USER_MANAGER_ERROR_PERMISSION_DENIED, "org.freedesktop.Accounts.Error.PermissionDenied" },
{ ACT_USER_MANAGER_ERROR_NOT_SUPPORTED, "org.freedesktop.Accounts.Error.NotSupported" }
};
@@ -2805,132 +2806,143 @@ act_user_manager_class_init (ActUserManagerClass *klass)
signals [USER_CHANGED] =
g_signal_new ("user-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ActUserManagerClass, user_changed),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, ACT_TYPE_USER);
g_type_class_add_private (klass, sizeof (ActUserManagerPrivate));
}
/**
* act_user_manager_queue_load:
* @manager: a #ActUserManager
*
* Queue loading users into user manager. This must be called, and the
* #ActUserManager:is-loaded property must be %TRUE before calling
* act_user_manager_list_users()
*/
static void
act_user_manager_queue_load (ActUserManager *manager)
{
g_return_if_fail (ACT_IS_USER_MANAGER (manager));
if (! manager->priv->is_loaded) {
queue_load_seat_and_users (manager);
}
}
+static gboolean
+ensure_accounts_proxy (ActUserManager *manager)
+{
+ GError *error = NULL;
+
+ if (manager->priv->accounts_proxy != NULL) {
+ return TRUE;
+ }
+
+ manager->priv->accounts_proxy = accounts_accounts_proxy_new_sync (manager->priv->connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ ACCOUNTS_NAME,
+ ACCOUNTS_PATH,
+ NULL,
+ &error);
+ if (error != NULL) {
+ g_debug ("ActUserManager: getting account proxy failed: %s", error->message);
+ g_clear_error (&error);
+ return FALSE;
+ }
+
+ g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (manager->priv->accounts_proxy), G_MAXINT);
+
+ g_object_bind_property (G_OBJECT (manager->priv->accounts_proxy),
+ "has-multiple-users",
+ G_OBJECT (manager),
+ "has-multiple-users",
+ G_BINDING_SYNC_CREATE);
+
+ g_signal_connect (manager->priv->accounts_proxy,
+ "user-added",
+ G_CALLBACK (on_new_user_in_accounts_service),
+ manager);
+ g_signal_connect (manager->priv->accounts_proxy,
+ "user-deleted",
+ G_CALLBACK (on_user_removed_in_accounts_service),
+ manager);
+
+ return TRUE;
+}
+
static void
act_user_manager_init (ActUserManager *manager)
{
GError *error;
manager->priv = ACT_USER_MANAGER_GET_PRIVATE (manager);
act_user_manager_error_quark (); /* register dbus errors */
/* sessions */
manager->priv->sessions = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_object_unref);
/* users */
manager->priv->normal_users_by_name = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_object_unref);
manager->priv->system_users_by_name = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_object_unref);
manager->priv->users_by_object_path = g_hash_table_new_full (g_str_hash,
g_str_equal,
NULL,
g_object_unref);
error = NULL;
manager->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (manager->priv->connection == NULL) {
if (error != NULL) {
g_warning ("Failed to connect to the D-Bus daemon: %s", error->message);
g_error_free (error);
} else {
g_warning ("Failed to connect to the D-Bus daemon");
}
return;
}
- manager->priv->accounts_proxy = accounts_accounts_proxy_new_sync (manager->priv->connection,
- G_DBUS_PROXY_FLAGS_NONE,
- ACCOUNTS_NAME,
- ACCOUNTS_PATH,
- NULL,
- &error);
- if (manager->priv->accounts_proxy == NULL) {
- if (error != NULL) {
- g_warning ("Failed to create accounts proxy: %s", error->message);
- g_error_free (error);
- } else {
- g_warning ("Failed to create_accounts_proxy");
- }
- return;
- }
- g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (manager->priv->accounts_proxy), G_MAXINT);
-
- g_object_bind_property (G_OBJECT (manager->priv->accounts_proxy),
- "has-multiple-users",
- G_OBJECT (manager),
- "has-multiple-users",
- G_BINDING_SYNC_CREATE);
-
- g_signal_connect (manager->priv->accounts_proxy,
- "user-added",
- G_CALLBACK (on_new_user_in_accounts_service),
- manager);
- g_signal_connect (manager->priv->accounts_proxy,
- "user-deleted",
- G_CALLBACK (on_user_removed_in_accounts_service),
- manager);
+ ensure_accounts_proxy (manager);
manager->priv->seat.state = ACT_USER_MANAGER_SEAT_STATE_UNLOADED;
}
static void
act_user_manager_finalize (GObject *object)
{
ActUserManager *manager;
GSList *node;
g_debug ("ActUserManager: finalizing user manager");
g_return_if_fail (object != NULL);
g_return_if_fail (ACT_IS_USER_MANAGER (object));
manager = ACT_USER_MANAGER (object);
g_return_if_fail (manager->priv != NULL);
g_slist_foreach (manager->priv->new_sessions,
(GFunc) unload_new_session, NULL);
g_slist_free (manager->priv->new_sessions);
g_slist_foreach (manager->priv->fetch_user_requests,
(GFunc) free_fetch_user_request, NULL);
g_slist_free (manager->priv->fetch_user_requests);
g_slist_free (manager->priv->new_users_inhibiting_load);
node = manager->priv->new_users;
--
2.14.1