Blame SOURCES/0005-lib-consolidate-change-notification.patch

34a24a
From 42bd3bd41d69100308a22df43482569f6ab53dbe Mon Sep 17 00:00:00 2001
34a24a
From: Ray Strode <rstrode@redhat.com>
34a24a
Date: Wed, 27 Sep 2017 14:44:48 -0400
34a24a
Subject: [PATCH 05/13] lib: consolidate change notification
34a24a
34a24a
if the daemon sends out multiple change notifications for a user
34a24a
because several properties changed in quick succession, try to
34a24a
batch them up, and only update info at the end.
34a24a
---
34a24a
 src/libaccountsservice/act-user.c | 20 +++++++++++++++++++-
34a24a
 1 file changed, 19 insertions(+), 1 deletion(-)
34a24a
34a24a
diff --git a/src/libaccountsservice/act-user.c b/src/libaccountsservice/act-user.c
34a24a
index dbb9b53..17acacb 100644
34a24a
--- a/src/libaccountsservice/act-user.c
34a24a
+++ b/src/libaccountsservice/act-user.c
34a24a
@@ -113,60 +113,62 @@ struct _ActUser {
34a24a
         char            *object_path;
34a24a
 
34a24a
         uid_t           uid;
34a24a
         char           *user_name;
34a24a
         char           *real_name;
34a24a
         char           *password_hint;
34a24a
         char           *home_dir;
34a24a
         char           *shell;
34a24a
         char           *email;
34a24a
         char           *location;
34a24a
         char           *icon_file;
34a24a
         char           *language;
34a24a
         char           *x_session;
34a24a
         GList          *our_sessions;
34a24a
         GList          *other_sessions;
34a24a
         int             login_frequency;
34a24a
         gint64          login_time;
34a24a
         GVariant       *login_history;
34a24a
 
34a24a
         ActUserAccountType  account_type;
34a24a
         ActUserPasswordMode password_mode;
34a24a
 
34a24a
         guint           uid_set : 1;
34a24a
 
34a24a
         guint           is_loaded : 1;
34a24a
         guint           locked : 1;
34a24a
         guint           automatic_login : 1;
34a24a
         guint           system_account : 1;
34a24a
         guint           local_account : 1;
34a24a
         guint           nonexistent : 1;
34a24a
+
34a24a
+        guint           update_info_timeout_id;
34a24a
 };
34a24a
 
34a24a
 struct _ActUserClass
34a24a
 {
34a24a
         GObjectClass parent_class;
34a24a
 };
34a24a
 
34a24a
 static void act_user_finalize     (GObject      *object);
34a24a
 
34a24a
 static guint signals[LAST_SIGNAL] = { 0 };
34a24a
 
34a24a
 G_DEFINE_TYPE (ActUser, act_user, G_TYPE_OBJECT)
34a24a
 
34a24a
 static int
34a24a
 session_compare (const char *a,
34a24a
                  const char *b)
34a24a
 {
34a24a
         if (a == NULL) {
34a24a
                 return 1;
34a24a
         } else if (b == NULL) {
34a24a
                 return -1;
34a24a
         }
34a24a
 
34a24a
         return strcmp (a, b);
34a24a
 }
34a24a
 
34a24a
 void
34a24a
 _act_user_add_session (ActUser    *user,
34a24a
                        const char *ssid,
34a24a
                        gboolean    is_ours)
34a24a
@@ -573,60 +575,64 @@ act_user_finalize (GObject *object)
34a24a
 
34a24a
         g_free (user->user_name);
34a24a
         g_free (user->real_name);
34a24a
         g_free (user->icon_file);
34a24a
         g_free (user->language);
34a24a
         g_free (user->object_path);
34a24a
         g_free (user->password_hint);
34a24a
         g_free (user->home_dir);
34a24a
         g_free (user->shell);
34a24a
         g_free (user->email);
34a24a
         g_free (user->location);
34a24a
         if (user->login_history)
34a24a
           g_variant_unref (user->login_history);
34a24a
 
34a24a
         if (user->accounts_proxy != NULL) {
34a24a
                 g_object_unref (user->accounts_proxy);
34a24a
         }
34a24a
 
34a24a
         if (user->object_proxy != NULL) {
34a24a
                 g_object_unref (user->object_proxy);
34a24a
         }
34a24a
 
34a24a
         if (user->get_all_cancellable != NULL) {
34a24a
                 g_object_unref (user->get_all_cancellable);
34a24a
         }
34a24a
 
34a24a
         if (user->connection != NULL) {
34a24a
                 g_object_unref (user->connection);
34a24a
         }
34a24a
 
34a24a
+        if (user->update_info_timeout_id != 0) {
34a24a
+                g_source_remove (user->update_info_timeout_id);
34a24a
+        }
34a24a
+
34a24a
         if (G_OBJECT_CLASS (act_user_parent_class)->finalize)
34a24a
                 (*G_OBJECT_CLASS (act_user_parent_class)->finalize) (object);
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
 set_is_loaded (ActUser  *user,
34a24a
                gboolean  is_loaded)
34a24a
 {
34a24a
         if (user->is_loaded != is_loaded) {
34a24a
                 user->is_loaded = is_loaded;
34a24a
                 g_object_notify (G_OBJECT (user), "is-loaded");
34a24a
         }
34a24a
 }
34a24a
 
34a24a
 /**
34a24a
  * act_user_get_uid:
34a24a
  * @user: the user object to examine.
34a24a
  *
34a24a
  * Retrieves the ID of @user.
34a24a
  *
34a24a
  * Returns: (transfer none): a pointer to an array of characters which must not be modified or
34a24a
  *  freed, or %NULL.
34a24a
  **/
34a24a
 
34a24a
 uid_t
34a24a
 act_user_get_uid (ActUser *user)
34a24a
 {
34a24a
         g_return_val_if_fail (ACT_IS_USER (user), -1);
34a24a
 
34a24a
         return user->uid;
34a24a
@@ -1339,67 +1345,79 @@ on_get_all_finished (GObject        *object,
34a24a
         g_variant_unref (res);
34a24a
 
34a24a
         if (!user->is_loaded) {
34a24a
                 set_is_loaded (user, TRUE);
34a24a
         }
34a24a
 
34a24a
         g_signal_emit (user, signals[CHANGED], 0);
34a24a
 }
34a24a
 
34a24a
 static void
34a24a
 update_info (ActUser *user)
34a24a
 {
34a24a
         g_assert (G_IS_DBUS_PROXY (user->object_proxy));
34a24a
 
34a24a
         if (user->get_all_cancellable != NULL) {
34a24a
                 g_cancellable_cancel (user->get_all_cancellable);
34a24a
                 g_clear_object (&user->get_all_cancellable);
34a24a
         }
34a24a
 
34a24a
         user->get_all_cancellable = g_cancellable_new ();
34a24a
         g_dbus_proxy_call (user->object_proxy,
34a24a
                            "GetAll",
34a24a
                            g_variant_new ("(s)", ACCOUNTS_USER_INTERFACE),
34a24a
                            G_DBUS_CALL_FLAGS_NONE,
34a24a
                            -1,
34a24a
                            user->get_all_cancellable,
34a24a
                            on_get_all_finished,
34a24a
                            user);
34a24a
 }
34a24a
 
34a24a
+static gboolean
34a24a
+on_timeout_update_info (ActUser *user)
34a24a
+{
34a24a
+        update_info (user);
34a24a
+        user->update_info_timeout_id = 0;
34a24a
+
34a24a
+        return G_SOURCE_REMOVE;
34a24a
+}
34a24a
+
34a24a
 static void
34a24a
 changed_handler (AccountsUser *object,
34a24a
                  gpointer   *data)
34a24a
 {
34a24a
         ActUser *user = ACT_USER (data);
34a24a
 
34a24a
-        update_info (user);
34a24a
+        if (user->update_info_timeout_id != 0)
34a24a
+                return;
34a24a
+
34a24a
+        user->update_info_timeout_id = g_timeout_add (250, (GSourceFunc) on_timeout_update_info, user);
34a24a
 }
34a24a
 
34a24a
 /**
34a24a
  * _act_user_update_as_nonexistent:
34a24a
  * @user: the user object to update.
34a24a
  *
34a24a
  * Set's the 'non-existent' property of @user to #TRUE
34a24a
  * Can only be called before the user is loaded.
34a24a
  **/
34a24a
 void
34a24a
 _act_user_update_as_nonexistent (ActUser *user)
34a24a
 {
34a24a
         g_return_if_fail (ACT_IS_USER (user));
34a24a
         g_return_if_fail (!act_user_is_loaded (user));
34a24a
         g_return_if_fail (user->object_path == NULL);
34a24a
 
34a24a
         user->nonexistent = TRUE;
34a24a
         g_object_notify (G_OBJECT (user), "nonexistent");
34a24a
 
34a24a
         set_is_loaded (user, TRUE);
34a24a
 }
34a24a
 
34a24a
 /**
34a24a
  * _act_user_update_from_object_path:
34a24a
  * @user: the user object to update.
34a24a
  * @object_path: the object path of the user to use.
34a24a
  *
34a24a
  * Updates the properties of @user from the accounts service via
34a24a
  * the object path in @object_path.
34a24a
  **/
34a24a
-- 
34a24a
2.14.1
34a24a