[epiphany] adblock: Use a single cache directory



commit 47e32925c75cbfffbe4add1442546947f6d3bda7
Author: Adrian Perez de Castro <aperez igalia com>
Date:   Fri Sep 6 14:46:14 2019 +0300

    adblock: Use a single cache directory
    
    Moves the adblock/ subdirectory from the profile directory to the
    default cache directory. This makes all different kind of Epiphany
    instances (normal, incognito, webapps) share the same directory for
    storing compiled filters and their metadata.
    
    Sharing the adblock/ subdirectory is desirable to avoid unneeded
    re-downloads of rule sets (e.g. currently opening a new incognito
    window creates a new profile directory, which does not have previosly
    downloaded filters), to make multiple WebKitNetworkProcess instances
    share files (they map the compiled files, so using the same ones reduces
    virtual memory pressure and enables more memory page sharing), and also
    the user experience is improved (no need to wait for rule sets to
    download whenever e.g. an incognito window is opened: the existing
    ones will be reused).
    
    Using the same directory from multiple processes is possible: all the
    Epiphany instances use the same GSettings value for the list of rule
    sets (hence, all expect the same contents to be present, or will create
    the same files in the directory), and the part managed by WebKit (the
    adblock/compiled/ subdirectory) is safe to use from multiple processes
    (temporary files are used while compiling rule sets, then moved to their
    final location; reading is only done through memory mappings and the
    kernel will keep the backing data in the filesystem for removed files
    if needed).

 embed/ephy-embed-shell.c     | 4 +---
 embed/ephy-filters-manager.c | 8 +++++++-
 2 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index c2778d6e1..7a0335126 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -1126,7 +1126,6 @@ ephy_embed_shell_startup (GApplication *application)
   WebKitCookieManager *cookie_manager;
   g_autofree char *filename = NULL;
   g_autofree char *cookie_policy = NULL;
-  g_autofree char *filters_dir = NULL;
 
   G_APPLICATION_CLASS (ephy_embed_shell_parent_class)->startup (application);
 
@@ -1272,8 +1271,7 @@ ephy_embed_shell_startup (GApplication *application)
                                          EPHY_PREFS_WEB_COOKIES_POLICY);
   ephy_embed_prefs_set_cookie_accept_policy (cookie_manager, cookie_policy);
 
-  filters_dir = g_build_filename (ephy_cache_dir (), "adblock", NULL);
-  priv->filters_manager = ephy_filters_manager_new (filters_dir);
+  priv->filters_manager = ephy_filters_manager_new (NULL);
 
   g_signal_connect_object (priv->filters_manager, "filters-disabled",
                            G_CALLBACK (webkit_user_content_manager_remove_all_filters),
diff --git a/embed/ephy-filters-manager.c b/embed/ephy-filters-manager.c
index 95136cbdc..3e9213eaf 100644
--- a/embed/ephy-filters-manager.c
+++ b/embed/ephy-filters-manager.c
@@ -23,6 +23,7 @@
 
 #include "ephy-debug.h"
 #include "ephy-download.h"
+#include "ephy-file-helpers.h"
 #include "ephy-prefs.h"
 #include "ephy-settings.h"
 
@@ -929,6 +930,11 @@ ephy_filters_manager_constructed (GObject *object)
 
   G_OBJECT_CLASS (ephy_filters_manager_parent_class)->constructed (object);
 
+  if (!manager->filters_dir) {
+    g_autofree char *cache_dir = ephy_default_cache_dir ();
+    manager->filters_dir = g_build_filename (cache_dir, "adblock", NULL);
+  }
+
   saved_filters_dir = g_build_filename (manager->filters_dir, "compiled", NULL);
   g_mkdir_with_parents (saved_filters_dir, 0700);
   manager->store = webkit_user_content_filter_store_new (saved_filters_dir);
@@ -1016,7 +1022,7 @@ ephy_filters_manager_class_init (EphyFiltersManagerClass *klass)
     g_param_spec_string ("filters-dir",
                          "Filters directory",
                          "The directory in which adblock filters are saved",
-                         "",
+                         NULL,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
 
   object_properties[PROP_IS_INITIALIZED] =


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