[epiphany/mcatanzaro/ephy-session: 10/13] session: rename save_idle to save_timeout




commit 75574dff83e0e43bdf50f44cb20cd1ba3fa793b6
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Wed Feb 24 11:23:56 2021 -0600

    session: rename save_idle to save_timeout
    
    It's a timeout, not an idle callback.
    
    Also, add a comment to explain why the timeout should not be removed.
    
    Also, let's avoid calling the timeout's callback directly.

 src/ephy-session.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/src/ephy-session.c b/src/ephy-session.c
index 44cc49e43..fe86bc82a 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -77,7 +77,7 @@ enum {
 
 static GParamSpec *obj_properties[LAST_PROP];
 
-static gboolean ephy_session_save_idle_cb (EphySession *session);
+static void ephy_session_save_now (EphySession *session);
 
 G_DEFINE_TYPE (EphySession, ephy_session, G_TYPE_OBJECT)
 
@@ -527,7 +527,7 @@ ephy_session_close (EphySession *session)
 
   policy = g_settings_get_enum (EPHY_SETTINGS_MAIN, EPHY_PREFS_RESTORE_SESSION_POLICY);
   if (policy == EPHY_PREFS_RESTORE_SESSION_POLICY_ALWAYS) {
-    ephy_session_save_idle_cb (session);
+    ephy_session_save_now (session);
   } else {
     session_delete (session);
   }
@@ -974,21 +974,21 @@ out:
 }
 
 static EphySession *
-ephy_session_save_idle_started (EphySession *session)
+ephy_session_save_timeout_started (EphySession *session)
 {
   g_application_hold (G_APPLICATION (ephy_shell_get_default ()));
   return g_object_ref (session);
 }
 
 static void
-ephy_session_save_idle_finished (EphySession *session)
+ephy_session_save_timeout_finished (EphySession *session)
 {
   g_application_release (G_APPLICATION (ephy_shell_get_default ()));
   g_object_unref (session);
 }
 
 static gboolean
-ephy_session_save_idle_cb (EphySession *session)
+ephy_session_save_timeout_cb (EphySession *session)
 {
   EphyShell *shell = ephy_shell_get_default ();
   SaveData *data;
@@ -1043,10 +1043,19 @@ ephy_session_save (EphySession *session)
   if (policy == EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER)
     return;
 
+  /* Schedule the save to occur one second in the future to ensure we don't
+   * repeatedly write to disk when opening or closing many tabs at once.
+   */
   session->save_source_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT_IDLE, 1,
-                                                        (GSourceFunc)ephy_session_save_idle_cb,
-                                                        ephy_session_save_idle_started (session),
-                                                        (GDestroyNotify)ephy_session_save_idle_finished);
+                                                        (GSourceFunc)ephy_session_save_timeout_cb,
+                                                        ephy_session_save_timeout_started (session),
+                                                        (GDestroyNotify)ephy_session_save_timeout_finished);
+}
+
+static void
+ephy_session_save_now (EphySession *session)
+{
+  ephy_session_save_timeout_cb (session);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]