[epiphany/wip/tingping/profile-migration: 97/105] Move adblock and safe-browsing data to cache dir



commit bdde4973901e7d1367648621b55cd96ed243f52c
Author: Patrick Griffis <pgriffis igalia com>
Date:   Wed Dec 19 12:11:49 2018 -0500

    Move adblock and safe-browsing data to cache dir
    
    This does reduce file sharing but that is required anyway
    for the sandbox since web apps don't have read access to the
    same directories.
    
    Fixes #477

 embed/ephy-embed-shell.c | 18 ++----------------
 lib/ephy-file-helpers.c  | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 lib/ephy-file-helpers.h  |  2 ++
 3 files changed, 49 insertions(+), 18 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 3a97c0193..93b351ae4 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -809,16 +809,13 @@ ephy_embed_shell_get_global_gsb_service (EphyEmbedShell *shell)
 
   if (priv->global_gsb_service == NULL) {
     char *api_key;
-    char *dot_dir;
     char *db_path;
 
     api_key = g_settings_get_string (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_GSB_API_KEY);
-    dot_dir = ephy_default_dot_dir ();
-    db_path = g_build_filename (dot_dir, EPHY_GSB_FILE, NULL);
+    db_path = g_build_filename (ephy_cache_dir (), EPHY_GSB_FILE, NULL);
     priv->global_gsb_service = ephy_gsb_service_new (api_key, db_path);
 
     g_free (api_key);
-    g_free (dot_dir);
     g_free (db_path);
   }
 
@@ -1109,18 +1106,7 @@ ephy_embed_shell_create_web_context (EphyEmbedShell *shell)
 static char *
 adblock_filters_dir (EphyEmbedShell *shell)
 {
-  EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
-  char *result;
-
-  if (priv->mode == EPHY_EMBED_SHELL_MODE_APPLICATION) {
-    char *default_dot_dir = ephy_default_dot_dir ();
-
-    result = g_build_filename (default_dot_dir, "adblock", NULL);
-    g_free (default_dot_dir);
-  } else
-    result = g_build_filename (ephy_dot_dir (), "adblock", NULL);
-
-  return result;
+  return g_build_filename (ephy_cache_dir (), "adblock", NULL);
 }
 
 static void
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 5ded99948..6708a3951 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -69,6 +69,7 @@ static GHashTable *mime_table;
 
 static gboolean keep_directory;
 static char *dot_dir;
+static char *cache_dir;
 static char *tmp_dir;
 static EphyProfileDirType dot_dir_type;
 
@@ -230,6 +231,21 @@ ephy_dot_dir (void)
   return dot_dir;
 }
 
+/**
+ * ephy_cache_dir:
+ *
+ * Gets Epiphany's cache directory, usually .cache/epiphany
+ * under user's homedir.
+ *
+ * Returns: the full path to Epiphany's cache directory
+ **/
+const char *
+ephy_cache_dir (void)
+{
+  return cache_dir;
+}
+
+
 /**
  * ephy_dot_dir_is_default:
  *
@@ -272,6 +288,21 @@ ephy_default_dot_dir (void)
     g_build_filename (g_get_user_config_dir (), "epiphany", NULL);
 }
 
+/**
+ * ephy_default_cache_dir:
+ *
+ * Get the path to the default cache directory found in ~/.cache
+ *
+ * Returns: a new allocated string, free with g_free() when done.
+ */
+char *
+ephy_default_cache_dir (void)
+{
+  return dot_dir_type == EPHY_PROFILE_DIR_TEST ?
+    g_build_filename (ephy_dot_dir (), "cache", NULL) :
+    g_build_filename (g_get_user_cache_dir (), "epiphany", NULL);
+}
+
 /**
  * ephy_file_helpers_init:
  * @profile_dir: directory to use as Epiphany's profile
@@ -313,8 +344,11 @@ ephy_file_helpers_init (const char          *profile_dir,
     }
 
     g_autofree char *app_file = g_build_filename (profile_dir, ".app", NULL);
-    if (g_file_test (app_file, G_FILE_TEST_EXISTS))
+    if (g_file_test (app_file, G_FILE_TEST_EXISTS)) {
+      const char *app_name = ephy_web_application_get_program_name_from_profile_directory (dot_dir);
+      cache_dir = g_build_filename (g_get_user_cache_dir (), app_name, NULL);
       dot_dir_type = EPHY_PROFILE_DIR_WEB_APP;
+    }
   } else if (private_profile) {
     if (ephy_file_tmp_dir () == NULL) {
       g_set_error (error,
@@ -328,6 +362,7 @@ ephy_file_helpers_init (const char          *profile_dir,
     dot_dir = g_build_filename (ephy_file_tmp_dir (),
                                 "epiphany",
                                 NULL);
+    cache_dir = g_build_filename (dot_dir, "cache", NULL);
     if (flags & EPHY_FILE_HELPERS_TESTING_MODE)
       dot_dir_type = EPHY_PROFILE_DIR_TEST;
   }
@@ -337,8 +372,14 @@ ephy_file_helpers_init (const char          *profile_dir,
     dot_dir = ephy_default_dot_dir ();
   }
 
-  if (flags & EPHY_FILE_HELPERS_ENSURE_EXISTS)
+  if (cache_dir == NULL)
+    cache_dir = ephy_default_cache_dir ();
+
+  if (flags & EPHY_FILE_HELPERS_ENSURE_EXISTS) {
     ret = ephy_ensure_dir_exists (ephy_dot_dir (), error);
+    ephy_ensure_dir_exists (ephy_cache_dir (), NULL);
+  }
+
 
   if (steal_data_from_profile && profile_dir) {
     guint i;
@@ -396,6 +437,8 @@ ephy_file_helpers_shutdown (void)
   g_free (dot_dir);
   dot_dir = NULL;
 
+  g_clear_pointer (&cache_dir, g_free);
+
   if (tmp_dir != NULL) {
     if (!keep_directory) {
       /* recursively delete the contents and the
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index f45db3741..bb861c1ba 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -59,7 +59,9 @@ gboolean           ephy_file_helpers_init                   (const char
 const char *       ephy_dot_dir                             (void);
 gboolean           ephy_dot_dir_is_default                  (void);
 gboolean           ephy_dot_dir_is_web_application          (void);
+const char *       ephy_cache_dir                           (void);
 char       *       ephy_default_dot_dir                     (void);
+char       *       ephy_default_cache_dir                   (void);
 void               ephy_file_helpers_shutdown               (void);
 char       *       ephy_file_get_downloads_dir              (void);
 char       *       ephy_file_desktop_dir                    (void);


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