[Xfce4-commits] <midori:master> Adblock: use queue to prevent endless update loop

Christian Dywan noreply at xfce.org
Tue Sep 11 00:46:04 CEST 2012


Updating branch refs/heads/master
         to 9af985e7e8507709efef941b84225b90b6407880 (commit)
       from 419d4c1ae588252357ab75c09956f8878579771c (commit)

commit 9af985e7e8507709efef941b84225b90b6407880
Author: Paweł Forysiuk <tuxator at o2.pl>
Date:   Fri Sep 7 19:51:32 2012 +0200

    Adblock: use queue to prevent endless update loop

 extensions/adblock.c |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/extensions/adblock.c b/extensions/adblock.c
index e6608e7..78bf6cf 100644
--- a/extensions/adblock.c
+++ b/extensions/adblock.c
@@ -42,6 +42,8 @@ static GHashTable* urlcache = NULL;
 static GHashTable* blockcssprivate = NULL;
 static GHashTable* navigationwhitelist = NULL;
 static GString* blockcss = NULL;
+static GList* update_list = NULL;
+static gboolean update_done = FALSE;
 
 static void
 adblock_parse_file (gchar* path);
@@ -165,9 +167,26 @@ adblock_download_notify_status_cb (WebKitDownload*  download,
                                    GParamSpec*      pspec,
                                    MidoriExtension* extension)
 {
-    if (webkit_download_get_status (download) != WEBKIT_DOWNLOAD_STATUS_FINISHED)
+    if (update_done)
         return;
-    adblock_reload_rules (extension, FALSE);
+
+    if (webkit_download_get_status (download) == WEBKIT_DOWNLOAD_STATUS_FINISHED)
+    {
+        GList* li = NULL;
+        for (li = update_list; li != NULL; li = g_list_next (li))
+        {
+            gchar* uri = g_strdup (webkit_download_get_destination_uri (download) + 7);
+            if (g_strcmp0 (li->data, uri))
+                update_list = g_list_remove (update_list, li->data);
+            g_free (uri);
+        }
+    }
+
+    if (g_list_length (update_list) == 0)
+    {
+        adblock_reload_rules (extension, FALSE);
+        update_done = TRUE;
+    }
 }
 
 static gchar*
@@ -236,6 +255,7 @@ adblock_reload_rules (MidoriExtension* extension,
                 download = webkit_download_new (request);
                 g_object_unref (request);
                 webkit_download_set_destination_uri (download, destination);
+                update_list = g_list_prepend (update_list, path);
                 g_free (destination);
                 g_signal_connect (download, "notify::status",
                     G_CALLBACK (adblock_download_notify_status_cb), extension);


More information about the Xfce4-commits mailing list