[empathy: 64/65] Properly handle corner cases of _prepare_async() called twice



commit dc73f3d3e51958edaf3b0508c4205c387e735547
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Aug 24 15:20:06 2010 +0200

    Properly handle corner cases of _prepare_async() called twice
    
    - If it's called twice before the first call returned, emit an error.
    - If it's called twice on an already-prepared object, just successfully
      return.

 libempathy/empathy-tls-certificate.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/libempathy/empathy-tls-certificate.c b/libempathy/empathy-tls-certificate.c
index 00ff4d5..acb94c7 100644
--- a/libempathy/empathy-tls-certificate.c
+++ b/libempathy/empathy-tls-certificate.c
@@ -52,6 +52,8 @@ typedef struct {
   gchar *cert_type;
   GPtrArray *cert_data;
   EmpTLSCertificateState state;
+
+  gboolean is_prepared;
 } EmpathyTLSCertificatePriv;
 
 G_DEFINE_TYPE (EmpathyTLSCertificate, empathy_tls_certificate,
@@ -106,6 +108,8 @@ tls_certificate_got_all_cb (TpProxy *proxy,
   DEBUG ("Got a certificate chain long %u, of type %s",
       priv->cert_data->len, priv->cert_type);
 
+  priv->is_prepared = TRUE;
+
   g_simple_async_result_complete (priv->async_prepare_res);
   tp_clear_object (&priv->async_prepare_res);
 }
@@ -117,6 +121,28 @@ empathy_tls_certificate_prepare_async (EmpathyTLSCertificate *self,
 {
   EmpathyTLSCertificatePriv *priv = GET_PRIV (self);
 
+  /* emit an error if we're already preparing the object */
+  if (priv->async_prepare_res != NULL)
+    {
+      g_simple_async_report_error_in_idle (G_OBJECT (self),
+          callback, user_data,
+          G_IO_ERROR, G_IO_ERROR_PENDING,
+          "%s",
+          "Prepare operation already in progress on the TLS certificate.");
+
+      return;
+    }
+                     
+
+  /* if the object is already prepared, just complete in idle */
+  if (priv->is_prepared)
+    {    
+      tp_simple_async_report_success_in_idle (G_OBJECT (self),
+          callback, user_data, empathy_tls_certificate_prepare_async);
+
+      return;
+    }
+
   priv->async_prepare_res = g_simple_async_result_new (G_OBJECT (self),
       callback, user_data, empathy_tls_certificate_prepare_async);
 



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