diff options
author | Michael Catanzaro <mcatanzaro@gnome.org> | 2021-02-24 11:23:56 -0600 |
---|---|---|
committer | Jan-Michael Brummer <jan.brummer@tabos.org> | 2021-04-05 09:36:48 +0000 |
commit | 75574dff83e0e43bdf50f44cb20cd1ba3fa793b6 (patch) | |
tree | 92e933429a543f617acbc8322af4a2b555d47a21 /src/ephy-session.c | |
parent | 8afa0f40d08d2b867dc89037f0df8fcdca0d12bd (diff) | |
download | epiphany-75574dff83e0e43bdf50f44cb20cd1ba3fa793b6.tar.gz |
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.
Diffstat (limited to 'src/ephy-session.c')
-rw-r--r-- | src/ephy-session.c | 25 |
1 files 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 |