[evolution/wip/webkit2] Bug 758152 - Network connection not detected on resume from suspend



commit bef3d34ee539d50610b1fd28cef644a8b4731c34
Author: Milan Crha <mcrha redhat com>
Date:   Wed Nov 25 14:41:17 2015 +0100

    Bug 758152 - Network connection not detected on resume from suspend

 shell/e-shell.c |   81 ++++++++++++++++++++++++++++++-------------------------
 1 files changed, 44 insertions(+), 37 deletions(-)
---
diff --git a/shell/e-shell.c b/shell/e-shell.c
index df0011d..c6eeead 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -61,6 +61,7 @@ struct _EShellPrivate {
        GHashTable *backends_by_name;
        GHashTable *backends_by_scheme;
 
+       gboolean preparing_for_online;
        gpointer preparing_for_line_change;  /* weak pointer */
        gpointer preparing_for_quit;         /* weak pointer */
 
@@ -299,10 +300,12 @@ e_shell_set_online_cb (gpointer user_data)
 }
 
 static void
-shell_ready_for_offline (EShell *shell,
-                         EActivity *activity,
-                         gboolean is_last_ref)
+shell_ready_for_online_change (EShell *shell,
+                              EActivity *activity,
+                              gboolean is_last_ref)
 {
+       gboolean is_cancelled;
+
        if (!is_last_ref)
                return;
 
@@ -310,27 +313,49 @@ shell_ready_for_offline (EShell *shell,
         * a signal without triggering the toggle reference. */
        g_object_ref (activity);
 
-       e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
+       is_cancelled = e_activity_get_state (activity) == E_ACTIVITY_CANCELLED ||
+               g_cancellable_is_cancelled (e_activity_get_cancellable (activity));
+       e_activity_set_state (activity, is_cancelled ? E_ACTIVITY_CANCELLED : E_ACTIVITY_COMPLETED);
 
        g_object_remove_toggle_ref (
                G_OBJECT (activity), (GToggleNotify)
-               shell_ready_for_offline, shell);
+               shell_ready_for_online_change, shell);
 
        /* Finalize the activity. */
        g_object_unref (activity);
 
-       shell->priv->online = FALSE;
+       if (!is_cancelled)
+               shell->priv->online = shell->priv->preparing_for_online;
+
        g_object_notify (G_OBJECT (shell), "online");
 }
 
 static void
+shell_cancel_ongoing_preparing_line_change (EShell *shell)
+{
+       EActivity *activity;
+
+       activity = g_object_ref (shell->priv->preparing_for_line_change);
+       shell->priv->preparing_for_line_change = NULL;
+
+       g_object_remove_toggle_ref (G_OBJECT (activity), (GToggleNotify) shell_ready_for_online_change, 
shell);
+
+       g_object_remove_weak_pointer (G_OBJECT (activity), &shell->priv->preparing_for_line_change);
+
+       e_activity_cancel (activity);
+
+       g_clear_object (&activity);
+}
+
+static void
 shell_prepare_for_offline (EShell *shell)
 {
        /* Are preparations already in progress? */
        if (shell->priv->preparing_for_line_change != NULL)
-               return;
+               shell_cancel_ongoing_preparing_line_change (shell);
 
        shell->priv->preparing_for_line_change = e_activity_new ();
+       shell->priv->preparing_for_online = FALSE;
 
        e_activity_set_text (
                shell->priv->preparing_for_line_change,
@@ -338,7 +363,7 @@ shell_prepare_for_offline (EShell *shell)
 
        g_object_add_toggle_ref (
                G_OBJECT (shell->priv->preparing_for_line_change),
-               (GToggleNotify) shell_ready_for_offline, shell);
+               (GToggleNotify) shell_ready_for_online_change, shell);
 
        g_object_add_weak_pointer (
                G_OBJECT (shell->priv->preparing_for_line_change),
@@ -352,38 +377,14 @@ shell_prepare_for_offline (EShell *shell)
 }
 
 static void
-shell_ready_for_online (EShell *shell,
-                        EActivity *activity,
-                        gboolean is_last_ref)
-{
-       if (!is_last_ref)
-               return;
-
-       /* Increment the reference count so we can safely emit
-        * a signal without triggering the toggle reference. */
-       g_object_ref (activity);
-
-       e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
-
-       g_object_remove_toggle_ref (
-               G_OBJECT (activity), (GToggleNotify)
-               shell_ready_for_online, shell);
-
-       /* Finalize the activity. */
-       g_object_unref (activity);
-
-       shell->priv->online = TRUE;
-       g_object_notify (G_OBJECT (shell), "online");
-}
-
-static void
 shell_prepare_for_online (EShell *shell)
 {
        /* Are preparations already in progress? */
        if (shell->priv->preparing_for_line_change != NULL)
-               return;
+               shell_cancel_ongoing_preparing_line_change (shell);
 
        shell->priv->preparing_for_line_change = e_activity_new ();
+       shell->priv->preparing_for_online = TRUE;
 
        e_activity_set_text (
                shell->priv->preparing_for_line_change,
@@ -391,7 +392,7 @@ shell_prepare_for_online (EShell *shell)
 
        g_object_add_toggle_ref (
                G_OBJECT (shell->priv->preparing_for_line_change),
-               (GToggleNotify) shell_ready_for_online, shell);
+               (GToggleNotify) shell_ready_for_online_change, shell);
 
        g_object_add_weak_pointer (
                G_OBJECT (shell->priv->preparing_for_line_change),
@@ -2492,8 +2493,14 @@ e_shell_set_network_available (EShell *shell,
 
        /* If we're being forced offline, perhaps due to a network outage,
         * reconnect automatically when the network becomes available. */
-       if (!network_available && shell->priv->online) {
+       if (!network_available && (shell->priv->online || shell->priv->preparing_for_line_change)) {
                g_message ("Network disconnected.  Forced offline.");
+
+               if (shell->priv->set_online_timeout_id > 0) {
+                       g_source_remove (shell->priv->set_online_timeout_id);
+                       shell->priv->set_online_timeout_id = 0;
+               }
+
                e_shell_set_online (shell, FALSE);
                shell->priv->auto_reconnect = TRUE;
        } else if (network_available && shell->priv->auto_reconnect) {
@@ -2565,7 +2572,7 @@ e_shell_set_online (EShell *shell,
 {
        g_return_if_fail (E_IS_SHELL (shell));
 
-       if (online == shell->priv->online)
+       if (online == shell->priv->online && !shell->priv->preparing_for_line_change)
                return;
 
        if (online)


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