Blame SOURCES/0009-lib-move-accounts-proxy-creation-to-helper.patch

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