[evolution] EClientCache: Keep a strong reference on the ESourceRegistry.



commit d84b67875c88bc600e55f5e3060820530e46cc56
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Feb 17 14:22:39 2013 -0500

    EClientCache: Keep a strong reference on the ESourceRegistry.
    
    Changed my mind.  There's some scenarios where a function depends on an
    ESourceRegistry but could also utilize an EClientCache, and it would be
    nice to just pass the EClientCache and extract the ESourceRegistry from
    it, so we need to make sure the ESourceRegistry will be there when it's
    needed and not quietly disappear.

 e-util/e-client-cache.c |   39 +++++++++++++++++++--------------------
 1 files changed, 19 insertions(+), 20 deletions(-)
---
diff --git a/e-util/e-client-cache.c b/e-util/e-client-cache.c
index d99302a..b9bbb54 100644
--- a/e-util/e-client-cache.c
+++ b/e-util/e-client-cache.c
@@ -47,7 +47,7 @@ typedef struct _ClientData ClientData;
 typedef struct _SignalClosure SignalClosure;
 
 struct _EClientCachePrivate {
-       GWeakRef registry;
+       ESourceRegistry *registry;
 
        GHashTable *client_ht;
        GMutex client_ht_lock;
@@ -215,37 +215,35 @@ static gchar *
 client_cache_build_source_description (EClientCache *cache,
                                        ESource *source)
 {
-       GString *description;
        ESourceRegistry *registry;
+       ESource *parent;
+       GString *description;
        gchar *display_name;
+       gchar *parent_uid;
 
        description = g_string_sized_new (128);
 
        registry = e_client_cache_ref_registry (cache);
-       if (registry != NULL) {
-               ESource *parent;
-               gchar *parent_uid;
 
-               parent_uid = e_source_dup_parent (source);
-               parent = e_source_registry_ref_source (registry, parent_uid);
-               g_free (parent_uid);
+       parent_uid = e_source_dup_parent (source);
+       parent = e_source_registry_ref_source (registry, parent_uid);
+       g_free (parent_uid);
 
-               if (parent != NULL) {
-                       display_name = e_source_dup_display_name (parent);
-                       g_string_append (description, display_name);
-                       g_string_append (description, " / ");
-                       g_free (display_name);
+       if (parent != NULL) {
+               display_name = e_source_dup_display_name (parent);
+               g_string_append (description, display_name);
+               g_string_append (description, " / ");
+               g_free (display_name);
 
-                       g_object_unref (parent);
-               }
-
-               g_object_unref (registry);
+               g_object_unref (parent);
        }
 
        display_name = e_source_dup_display_name (source);
        g_string_append (description, display_name);
        g_free (display_name);
 
+       g_object_unref (registry);
+
        return g_string_free (description, FALSE);
 }
 
@@ -524,8 +522,9 @@ client_cache_set_registry (EClientCache *cache,
                            ESourceRegistry *registry)
 {
        g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+       g_return_if_fail (cache->priv->registry == NULL);
 
-       g_weak_ref_set (&cache->priv->registry, registry);
+       cache->priv->registry = g_object_ref (registry);
 }
 
 static void
@@ -570,7 +569,7 @@ client_cache_dispose (GObject *object)
 
        priv = E_CLIENT_CACHE_GET_PRIVATE (object);
 
-       g_weak_ref_set (&priv->registry, NULL);
+       g_clear_object (&priv->registry);
 
        g_hash_table_remove_all (priv->client_ht);
 
@@ -783,7 +782,7 @@ e_client_cache_ref_registry (EClientCache *cache)
 {
        g_return_val_if_fail (E_IS_CLIENT_CACHE (cache), NULL);
 
-       return g_weak_ref_get (&cache->priv->registry);
+       return g_object_ref (cache->priv->registry);
 }
 
 /**


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