Blame SOURCES/0008-lib-factor-user-loading-functions-into-helpers.patch

34a24a
From 86048b515f2f2edcea0f2aab2abf5e15f7b777d6 Mon Sep 17 00:00:00 2001
34a24a
From: Ray Strode <rstrode@redhat.com>
34a24a
Date: Tue, 3 Oct 2017 09:58:42 -0400
34a24a
Subject: [PATCH 08/13] lib: factor user loading functions into helpers
34a24a
34a24a
Right now, we process ListCachedUser results open coded.
34a24a
34a24a
This commit moves the processing to helper functions.
34a24a
---
34a24a
 src/libaccountsservice/act-user-manager.c | 85 +++++++++++++++++--------------
34a24a
 1 file changed, 48 insertions(+), 37 deletions(-)
34a24a
34a24a
diff --git a/src/libaccountsservice/act-user-manager.c b/src/libaccountsservice/act-user-manager.c
34a24a
index 30bbd78..556b070 100644
34a24a
--- a/src/libaccountsservice/act-user-manager.c
34a24a
+++ b/src/libaccountsservice/act-user-manager.c
34a24a
@@ -1473,124 +1473,135 @@ find_user_in_accounts_service (ActUserManager                 *manager,
34a24a
         switch (request->type) {
34a24a
                 case ACT_USER_MANAGER_FETCH_USER_FROM_USERNAME_REQUEST:
34a24a
                     accounts_accounts_call_find_user_by_name (manager->priv->accounts_proxy,
34a24a
                                                               request->username,
34a24a
                                                               NULL,
34a24a
                                                               on_find_user_by_name_finished,
34a24a
                                                               request);
34a24a
                     break;
34a24a
                 case ACT_USER_MANAGER_FETCH_USER_FROM_ID_REQUEST:
34a24a
                     accounts_accounts_call_find_user_by_id (manager->priv->accounts_proxy,
34a24a
                                                             request->uid,
34a24a
                                                             NULL,
34a24a
                                                             on_find_user_by_id_finished,
34a24a
                                                             request);
34a24a
                     break;
34a24a
 
34a24a
         }
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
 set_is_loaded (ActUserManager *manager,
34a24a
                gboolean        is_loaded)
34a24a
 {
34a24a
         if (manager->priv->is_loaded != is_loaded) {
34a24a
                 manager->priv->is_loaded = is_loaded;
34a24a
                 g_object_notify (G_OBJECT (manager), "is-loaded");
34a24a
         }
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
-on_list_cached_users_finished (GObject      *object,
34a24a
-                               GAsyncResult *result,
34a24a
-                               gpointer      data)
34a24a
+load_user_paths (ActUserManager       *manager,
34a24a
+                 const char * const * user_paths)
34a24a
 {
34a24a
-        AccountsAccounts *proxy = ACCOUNTS_ACCOUNTS (object);
34a24a
-        ActUserManager   *manager = data;
34a24a
-        gchar           **user_paths;
34a24a
-        GError           *error = NULL;
34a24a
-
34a24a
-        manager->priv->listing_cached_users = FALSE;
34a24a
-        if (!accounts_accounts_call_list_cached_users_finish (proxy, &user_paths, result, &error)) {
34a24a
-                g_debug ("ActUserManager: ListCachedUsers failed: %s", error->message);
34a24a
-                g_error_free (error);
34a24a
-
34a24a
-                g_object_unref (manager->priv->accounts_proxy);
34a24a
-                manager->priv->accounts_proxy = NULL;
34a24a
-
34a24a
-                g_debug ("ActUserManager: unrefing manager owned by failed ListCachedUsers call");
34a24a
-                g_object_unref (manager);
34a24a
-                return;
34a24a
-        }
34a24a
-
34a24a
         /* We now have a batch of unloaded users that we know about. Once that initial
34a24a
          * batch is loaded up, we can mark the manager as loaded.
34a24a
          *
34a24a
          * (see on_new_user_loaded)
34a24a
          */
34a24a
-        if (g_strv_length (user_paths) > 0) {
34a24a
+        if (g_strv_length ((char **) user_paths) > 0) {
34a24a
                 int i;
34a24a
 
34a24a
                 g_debug ("ActUserManager: ListCachedUsers finished, will set loaded property after list is fully loaded");
34a24a
                 for (i = 0; user_paths[i] != NULL; i++) {
34a24a
                         ActUser *user;
34a24a
 
34a24a
                         user = add_new_user_for_object_path (user_paths[i], manager);
34a24a
                         if (!manager->priv->is_loaded) {
34a24a
                                 manager->priv->new_users_inhibiting_load = g_slist_prepend (manager->priv->new_users_inhibiting_load, user);
34a24a
                         }
34a24a
                 }
34a24a
         } else {
34a24a
                 g_debug ("ActUserManager: ListCachedUsers finished with empty list, maybe setting loaded property now");
34a24a
                 maybe_set_is_loaded (manager);
34a24a
         }
34a24a
+}
34a24a
 
34a24a
-        g_strfreev (user_paths);
34a24a
+static void
34a24a
+load_included_usernames (ActUserManager *manager)
34a24a
+{
34a24a
+        GSList *l;
34a24a
 
34a24a
         /* Add users who are specifically included */
34a24a
-        if (manager->priv->include_usernames != NULL) {
34a24a
-                GSList *l;
34a24a
-
34a24a
-                for (l = manager->priv->include_usernames; l != NULL; l = l->next) {
34a24a
-                        ActUser *user;
34a24a
+        for (l = manager->priv->include_usernames; l != NULL; l = l->next) {
34a24a
+                ActUser *user;
34a24a
 
34a24a
-                        g_debug ("ActUserManager: Adding included user %s", (char *)l->data);
34a24a
-                        /*
34a24a
-                         * The call to act_user_manager_get_user will add the user if it is
34a24a
-                         * valid and not already in the hash.
34a24a
-                         */
34a24a
-                        user = act_user_manager_get_user (manager, l->data);
34a24a
-                        if (user == NULL) {
34a24a
-                                g_debug ("ActUserManager: unable to lookup user '%s'", (char *)l->data);
34a24a
-                        }
34a24a
+                g_debug ("ActUserManager: Adding included user %s", (char *)l->data);
34a24a
+                /*
34a24a
+                 * The call to act_user_manager_get_user will add the user if it is
34a24a
+                 * valid and not already in the hash.
34a24a
+                 */
34a24a
+                user = act_user_manager_get_user (manager, l->data);
34a24a
+                if (user == NULL) {
34a24a
+                        g_debug ("ActUserManager: unable to lookup user '%s'", (char *)l->data);
34a24a
                 }
34a24a
         }
34a24a
+}
34a24a
+
34a24a
+static void
34a24a
+on_list_cached_users_finished (GObject      *object,
34a24a
+                               GAsyncResult *result,
34a24a
+                               gpointer      data)
34a24a
+{
34a24a
+        AccountsAccounts *proxy = ACCOUNTS_ACCOUNTS (object);
34a24a
+        ActUserManager   *manager = data;
34a24a
+        gchar           **user_paths;
34a24a
+        GError           *error = NULL;
34a24a
+
34a24a
+        manager->priv->listing_cached_users = FALSE;
34a24a
+
34a24a
+        if (!accounts_accounts_call_list_cached_users_finish (proxy, &user_paths, result, &error)) {
34a24a
+                g_debug ("ActUserManager: ListCachedUsers failed: %s", error->message);
34a24a
+                g_error_free (error);
34a24a
+
34a24a
+                g_object_unref (manager->priv->accounts_proxy);
34a24a
+                manager->priv->accounts_proxy = NULL;
34a24a
+
34a24a
+                g_debug ("ActUserManager: unrefing manager owned by failed ListCachedUsers call");
34a24a
+                g_object_unref (manager);
34a24a
+                return;
34a24a
+        }
34a24a
+
34a24a
+        load_user_paths (manager, (const char * const *) user_paths);
34a24a
+        g_strfreev (user_paths);
34a24a
+
34a24a
+        load_included_usernames (manager);
34a24a
 
34a24a
         g_debug ("ActUserManager: unrefing manager owned by finished ListCachedUsers call");
34a24a
         g_object_unref (manager);
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
 on_get_x11_display_finished (GObject      *object,
34a24a
                              GAsyncResult *result,
34a24a
                              gpointer      data)
34a24a
 {
34a24a
         ConsoleKitSession *proxy = CONSOLE_KIT_SESSION (object);
34a24a
         ActUserManagerNewSession *new_session = data;
34a24a
         GError            *error = NULL;
34a24a
         char              *x11_display;
34a24a
 
34a24a
         new_session->pending_calls--;
34a24a
 
34a24a
         if (new_session->cancellable == NULL || g_cancellable_is_cancelled (new_session->cancellable)) {
34a24a
                 unload_new_session (new_session);
34a24a
                 return;
34a24a
         }
34a24a
 
34a24a
         if (!console_kit_session_call_get_x11_display_finish (proxy, &x11_display, result, &error)) {
34a24a
                 if (error != NULL) {
34a24a
                         g_debug ("Failed to get the x11 display of session '%s': %s",
34a24a
                                  new_session->id, error->message);
34a24a
                         g_error_free (error);
34a24a
                 } else {
34a24a
                         g_debug ("Failed to get the x11 display of session '%s'",
34a24a
                                  new_session->id);
34a24a
-- 
34a24a
2.14.1
34a24a