[next] telepathy-glib: client-factory: cache TpTLSCertificate proxies

Guillaume Desmottes gdesmott at kemper.freedesktop.org
Mon Mar 17 07:25:42 PDT 2014


Module: telepathy-glib
Branch: next
Commit: 4d921d5e18404a6329fc660f4f8e501ca88b388c
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=4d921d5e18404a6329fc660f4f8e501ca88b388c

Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date:   Thu Mar 13 12:46:12 2014 +0100

client-factory: cache TpTLSCertificate proxies

---

 telepathy-glib/client-factory.c |   17 ++++++++++++++++-
 tests/dbus/tls-certificate.c    |   20 ++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/telepathy-glib/client-factory.c b/telepathy-glib/client-factory.c
index 8118f76..17f1dd8 100644
--- a/telepathy-glib/client-factory.c
+++ b/telepathy-glib/client-factory.c
@@ -1499,5 +1499,20 @@ tp_client_factory_ensure_tls_certificate (TpClientFactory *self,
     const gchar *object_path,
     GError **error)
 {
-  return tp_tls_certificate_new (conn_or_chan, object_path, error);
+  TpTLSCertificate *cert;
+
+  g_return_val_if_fail (tp_proxy_get_factory (conn_or_chan) == self, NULL);
+
+  cert = lookup_proxy (self, object_path);
+  if (cert != NULL)
+    {
+      g_object_ref (cert);
+    }
+  else
+    {
+      cert = tp_tls_certificate_new (conn_or_chan, object_path, error);
+      insert_proxy (self, cert);
+    }
+
+  return cert;
 }
diff --git a/tests/dbus/tls-certificate.c b/tests/dbus/tls-certificate.c
index 3b0f7d8..6e1b542 100644
--- a/tests/dbus/tls-certificate.c
+++ b/tests/dbus/tls-certificate.c
@@ -289,6 +289,8 @@ test_reject (Test *test,
   /* Test if we cope with an empty rejections list */
   tp_tests_tls_certificate_clear_rejection (test->service_cert);
 
+  tp_clear_object (&test->cert);
+
   cert = tp_client_factory_ensure_tls_certificate (test->factory,
       TP_PROXY (test->connection), test->cert_path, &test->error);
   g_assert_no_error (test->error);
@@ -336,6 +338,22 @@ test_invalidated (Test *test,
   g_assert_error (test->error, TP_ERROR, TP_ERROR_CANCELLED);
 }
 
+static void
+test_factory (Test *test,
+    gconstpointer data G_GNUC_UNUSED)
+{
+  /* TpTLSCertificate is cached by the factory */
+  TpTLSCertificate *cert;
+
+  cert = tp_client_factory_ensure_tls_certificate (test->factory,
+      TP_PROXY (test->connection), test->cert_path, &test->error);
+  g_assert_no_error (test->error);
+
+  g_assert (cert == test->cert);
+
+  g_object_unref (cert);
+}
+
 int
 main (int argc,
       char **argv)
@@ -353,6 +371,8 @@ main (int argc,
       test_reject, teardown);
   g_test_add ("/tls-certificate/invalidated", Test, NULL, setup,
       test_invalidated, teardown);
+  g_test_add ("/tls-certificate/factory", Test, NULL, setup,
+      test_factory, teardown);
 
   return tp_tests_run_with_bus ();
 }



More information about the telepathy-commits mailing list