[gnome-online-accounts/wip/rishi/simplify-cleanup: 2/3] ewsclient: Simplify the clean up



commit 0fbb492da8f9646320e3966167e5f30dcbb3c3b9
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Nov 23 18:04:33 2018 +0100

    ewsclient: Simplify the clean up
    
    Now that the deprecated SoupSessionAsync has been replaced with
    SoupSession [1], the response callbacks are invoked in the next
    iteration of the main loop after soup_session_abort has returned. This
    means that ews_client_autodiscover_response_cb is no longer called
    from a GCancellable::cancelled signal handler. Therefore, it's safe to
    directly disconnect from the GCancellable in the response callback
    without fearing for any deadlocks.
    
    This reverts commit 07f13b1d773b79e5c1049660c154b988b5ff6357.
    
    [1] Commit 6c3e3c2d2d9f6881
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764157

 src/goabackend/goaewsclient.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)
---
diff --git a/src/goabackend/goaewsclient.c b/src/goabackend/goaewsclient.c
index d762d071..f3d6278b 100644
--- a/src/goabackend/goaewsclient.c
+++ b/src/goabackend/goaewsclient.c
@@ -1,6 +1,6 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /*
- * Copyright © 2012 – 2017 Red Hat, Inc.
+ * Copyright © 2012 – 2018 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -79,13 +79,11 @@ typedef struct
   gchar *username;
 } AutodiscoverAuthData;
 
-static gboolean
+static void
 ews_client_autodiscover_data_free (gpointer user_data)
 {
   AutodiscoverData *data = user_data;
 
-  g_simple_async_result_complete_in_idle (data->res);
-
   if (data->cancellable_id > 0)
     {
       g_cancellable_disconnect (data->cancellable, data->cancellable_id);
@@ -97,8 +95,6 @@ ews_client_autodiscover_data_free (gpointer user_data)
   g_object_unref (data->res);
   g_object_unref (data->session);
   g_slice_free (AutodiscoverData, data);
-
-  return G_SOURCE_REMOVE;
 }
 
 static void
@@ -148,6 +144,10 @@ ews_client_request_started (SoupSession *session, SoupMessage *msg, SoupSocket *
     {
       goa_utils_set_error_ssl (&error, cert_flags);
       g_simple_async_result_take_error (data->res, error);
+
+      /* The callback will be invoked after we have returned to the
+       * main loop.
+       */
       soup_session_abort (data->session);
     }
 }
@@ -156,6 +156,10 @@ static void
 ews_client_autodiscover_cancelled_cb (GCancellable *cancellable, gpointer user_data)
 {
   AutodiscoverData *data = user_data;
+
+  /* The callback will be invoked after we have returned to the main
+   * loop.
+   */
   soup_session_abort (data->session);
 }
 
@@ -337,9 +341,6 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
   data->pending--;
   if (data->pending == 0)
     {
-      GMainContext *context;
-      GSource *source;
-
       /* The result of the GAsyncResult should already be set when we
        * get here. If it wasn't explicitly set to TRUE then
        * autodiscovery has failed and the default value of the
@@ -347,14 +348,8 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
        * original caller.
        */
 
-      source = g_idle_source_new ();
-      g_source_set_priority (source, G_PRIORITY_DEFAULT_IDLE);
-      g_source_set_callback (source, ews_client_autodiscover_data_free, data, NULL);
-      g_source_set_name (source, "[goa] ews_client_autodiscover_data_free");
-
-      context = g_main_context_get_thread_default ();
-      g_source_attach (source, context);
-      g_source_unref (source);
+      g_simple_async_result_complete_in_idle (data->res);
+      ews_client_autodiscover_data_free (data);
     }
 }
 


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