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



commit 52e95a040e79234b243482de969a68c74acd3993
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.
    
    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 d2e9d2d8a..41cd1c2dd 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -801,16 +801,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);
   }
 
@@ -1128,18 +1125,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 5d5850485..209f16f46 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 GList *del_on_exit;
 static EphyProfileDirType dot_dir_type;
@@ -233,6 +234,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:
  *
@@ -275,6 +291,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
@@ -316,8 +347,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,
@@ -331,6 +365,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;
   }
@@ -340,8 +375,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;
@@ -413,6 +454,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 eff671d89..9b5d08a57 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -54,7 +54,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]