[epiphany/mcatanzaro/ephy-session] session: ephy_session_close() should do sync I/O on the main thread




commit ac3d62bcc83b1e5b75ba46205fa7942837f6fe5c
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Mar 11 19:39:20 2021 -0600

    session: ephy_session_close() should do sync I/O on the main thread
    
    Do not return from ephy_session_close() until the session is saved to
    disk. We should just hang the UI process until the data is written. I
    want zero race windows here. Losing the session state is terrible and
    should not be possible.
    
    The usual rule about avoiding sync I/O on the UI thread does not apply
    because Epiphany is quitting and is not expected to respond to further
    user input.

 src/ephy-session.c | 45 +++++++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 16 deletions(-)
---
diff --git a/src/ephy-session.c b/src/ephy-session.c
index fb3887bbb..1b3eac063 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -512,7 +512,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_now (session);
+    ephy_session_save_now_sync (session);
   } else {
     session_delete (session);
   }
@@ -962,17 +962,16 @@ ephy_session_save_timeout_finished (EphySession *session)
   g_object_unref (session);
 }
 
-static gboolean
-ephy_session_save_timeout_cb (EphySession *session)
+static void
+ephy_session_do_save (EphySession *session,
+                      gboolean     blocking)
 {
   EphyShell *shell = ephy_shell_get_default ();
   SaveData *data;
   GTask *task;
 
-  session->save_source_id = 0;
-
   if (!session->loaded_page)
-    return G_SOURCE_REMOVE;
+    return;
 
   /* If we have never successfully loaded any page, or any web view has an
    * insane URL, then something has probably gone wrong inside WebKit. For
@@ -984,15 +983,15 @@ ephy_session_save_timeout_cb (EphySession *session)
   data = save_data_new (session);
   if (!session_seems_reasonable (data->windows)) {
     save_data_free (data);
-    return G_SOURCE_REMOVE;
+    return;
   }
 
-  LOG ("ephy_sesion_save");
+  LOG ("ephy_session_do_save");
 
   if (ephy_shell_get_n_windows (shell) == 0) {
     session_delete (session);
     save_data_free (data);
-    return G_SOURCE_REMOVE;
+    return;
   }
 
   g_application_hold (G_APPLICATION (ephy_shell_get_default ()));
@@ -1000,12 +999,32 @@ ephy_session_save_timeout_cb (EphySession *session)
 
   task = g_task_new (session, NULL, save_session_in_thread_finished_cb, NULL);
   g_task_set_task_data (task, data, (GDestroyNotify)save_data_free);
-  g_task_run_in_thread (task, save_session_sync);
+  if (blocking)
+    g_task_run_in_thread_sync (task, save_session_sync);
+  else
+    g_task_run_in_thread (task, save_session_sync);
   g_object_unref (task);
 
   return G_SOURCE_REMOVE;
 }
 
+static gboolean
+ephy_session_save_timeout_cb (EphySession *session)
+{
+
+  session->save_source_id = 0;
+
+  ephy_session_do_save (session, FALSE);
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+ephy_session_save_now_sync (EphySession *session)
+{
+  ephy_session_do_save (session, TRUE);
+}
+
 void
 ephy_session_save (EphySession *session)
 {
@@ -1032,12 +1051,6 @@ ephy_session_save (EphySession *session)
                                                         (GDestroyNotify)ephy_session_save_timeout_finished);
 }
 
-static void
-ephy_session_save_now (EphySession *session)
-{
-  ephy_session_save_timeout_cb (session);
-}
-
 static void
 confirm_before_recover (EphyWindow *window,
                         const char *url,


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