[epiphany] web-extensions: Release EphyWebExtensionProxy when the web extension is destroyed



commit 9e8e34a398788754ce76119b502eb8e458f1aec8
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Thu Jul 31 10:56:15 2014 +0200

    web-extensions: Release EphyWebExtensionProxy when the web extension is destroyed
    
    We were leaking all EphyWebExtensionProxy objects because they were
    released when the bus named was unwatched, and we were unwatching the
    name in the object dispose method. So, now unref the object when the
    name is vanished instead. Also added a GCancellable to use in all async
    operations.

 embed/ephy-web-extension-proxy.c |   53 ++++++++++++++++++++++++++++---------
 1 files changed, 40 insertions(+), 13 deletions(-)
---
diff --git a/embed/ephy-web-extension-proxy.c b/embed/ephy-web-extension-proxy.c
index 4a564c6..5787fd7 100644
--- a/embed/ephy-web-extension-proxy.c
+++ b/embed/ephy-web-extension-proxy.c
@@ -28,6 +28,7 @@ struct _EphyWebExtensionProxyPrivate
 {
   GDBusProxy *proxy;
   gchar *name_owner;
+  GCancellable *cancellable;
   guint watch_name_id;
   guint form_auth_save_signal_id;
 };
@@ -58,6 +59,8 @@ ephy_web_extension_proxy_dispose (GObject *object)
 {
   EphyWebExtensionProxyPrivate *priv = EPHY_WEB_EXTENSION_PROXY (object)->priv;
 
+  g_clear_object (&priv->cancellable);
+
   if (priv->watch_name_id > 0) {
     g_bus_unwatch_name (priv->watch_name_id);
     priv->watch_name_id = 0;
@@ -130,6 +133,7 @@ web_extension_appeared_cb (GDBusConnection *connection,
                            EphyWebExtensionProxy *web_extension)
 {
   web_extension->priv->name_owner = g_strdup (name_owner);
+  web_extension->priv->cancellable = g_cancellable_new ();
   g_dbus_proxy_new (connection,
                     G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START |
                     G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
@@ -138,12 +142,21 @@ web_extension_appeared_cb (GDBusConnection *connection,
                     name,
                     EPHY_WEB_EXTENSION_OBJECT_PATH,
                     EPHY_WEB_EXTENSION_INTERFACE,
-                    NULL,
+                    web_extension->priv->cancellable,
                     (GAsyncReadyCallback)web_extension_proxy_created_cb,
                     web_extension);
 }
 
 static void
+web_extension_vanished_cb (GDBusConnection *connection,
+                           const gchar *name,
+                           EphyWebExtensionProxy *web_extension)
+{
+  if (web_extension->priv->name_owner)
+    g_object_unref (web_extension);
+}
+
+static void
 ephy_web_extension_proxy_watch_name (EphyWebExtensionProxy *web_extension,
                                      GDBusConnection* bus,
                                      const char *service_name)
@@ -155,9 +168,9 @@ ephy_web_extension_proxy_watch_name (EphyWebExtensionProxy *web_extension,
                                     service_name,
                                     G_BUS_NAME_WATCHER_FLAGS_NONE,
                                     (GBusNameAppearedCallback)web_extension_appeared_cb,
-                                    NULL,
+                                    (GBusNameVanishedCallback)web_extension_vanished_cb,
                                     web_extension,
-                                    (GDestroyNotify)g_object_unref);
+                                    NULL);
 }
 
 EphyWebExtensionProxy *
@@ -210,7 +223,9 @@ ephy_web_extension_proxy_form_auth_data_save_confirmation_response (EphyWebExten
                      "FormAuthDataSaveConfirmationResponse",
                      g_variant_new ("(ub)", request_id, response),
                      G_DBUS_CALL_FLAGS_NONE,
-                     -1, NULL, NULL, NULL);
+                     -1,
+                     web_extension->priv->cancellable,
+                     NULL, NULL);
 }
 
 static void
@@ -250,7 +265,7 @@ ephy_web_extension_proxy_web_page_has_modified_forms (EphyWebExtensionProxy *web
                        g_variant_new ("(t)", page_id),
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
-                       cancellable,
+                       web_extension->priv->cancellable,
                        (GAsyncReadyCallback)has_modified_forms_cb,
                        g_object_ref (task));
   } else {
@@ -307,7 +322,7 @@ ephy_web_extension_proxy_get_best_web_app_icon (EphyWebExtensionProxy *web_exten
                        g_variant_new("(ts)", page_id, base_uri),
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
-                       cancellable,
+                       web_extension->priv->cancellable,
                        (GAsyncReadyCallback)get_best_web_app_icon_cb,
                        g_object_ref (task));
   } else {
@@ -380,7 +395,7 @@ ephy_web_extension_proxy_get_web_app_title (EphyWebExtensionProxy *web_extension
                        g_variant_new("(t)", page_id),
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
-                       NULL,
+                       web_extension->priv->cancellable,
                        (GAsyncReadyCallback)get_web_app_title_cb,
                        g_object_ref (task));
   } else {
@@ -421,7 +436,9 @@ ephy_web_extension_proxy_history_set_urls (EphyWebExtensionProxy *web_extension,
                      "HistorySetURLs",
                      g_variant_new ("(@a(ss))", g_variant_builder_end (&builder)),
                      G_DBUS_CALL_FLAGS_NONE,
-                     -1, NULL, NULL, NULL);
+                     -1,
+                     web_extension->priv->cancellable,
+                     NULL, NULL);
 }
 
 void
@@ -436,7 +453,9 @@ ephy_web_extension_proxy_history_set_url_thumbnail (EphyWebExtensionProxy *web_e
                      "HistorySetURLThumbnail",
                      g_variant_new ("(ss)", url, path),
                      G_DBUS_CALL_FLAGS_NONE,
-                     -1, NULL, NULL, NULL);
+                     -1,
+                     web_extension->priv->cancellable,
+                     NULL, NULL);
 }
 
 void
@@ -451,7 +470,9 @@ ephy_web_extension_proxy_history_set_url_title (EphyWebExtensionProxy *web_exten
                      "HistorySetURLTitle",
                      g_variant_new ("(ss)", url, title),
                      G_DBUS_CALL_FLAGS_NONE,
-                     -1, NULL, NULL, NULL);
+                     -1,
+                     web_extension->priv->cancellable,
+                     NULL, NULL);
 }
 
 void
@@ -465,7 +486,9 @@ ephy_web_extension_proxy_history_delete_url (EphyWebExtensionProxy *web_extensio
                      "HistoryDeleteURL",
                      g_variant_new ("(s)", url),
                      G_DBUS_CALL_FLAGS_NONE,
-                     -1, NULL, NULL, NULL);
+                     -1,
+                     web_extension->priv->cancellable,
+                     NULL, NULL);
 }
 
 void
@@ -479,7 +502,9 @@ ephy_web_extension_proxy_history_delete_host (EphyWebExtensionProxy *web_extensi
                      "HistoryDeleteHost",
                      g_variant_new ("(s)", host),
                      G_DBUS_CALL_FLAGS_NONE,
-                     -1, NULL, NULL, NULL);
+                     -1,
+                     web_extension->priv->cancellable,
+                     NULL, NULL);
 }
 
 void
@@ -492,5 +517,7 @@ ephy_web_extension_proxy_history_clear (EphyWebExtensionProxy *web_extension)
                      "HistoryClear",
                      NULL,
                      G_DBUS_CALL_FLAGS_NONE,
-                     -1, NULL, NULL, NULL);
+                     -1,
+                     web_extension->priv->cancellable,
+                     NULL, NULL);
 }


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