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



commit bf6725d97d34979730ad9bc45ba6c1ea9ab4df23
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.

 embed/ephy-embed-shell.c | 18 ++----------------
 lib/ephy-file-helpers.c  | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 lib/ephy-file-helpers.h  |  2 ++
 3 files changed, 48 insertions(+), 18 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 2b1ce4fdd..12e3c92d8 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -799,16 +799,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);
   }
 
@@ -1120,18 +1117,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 65758b01d..0c13bea66 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -71,6 +71,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;
@@ -235,6 +236,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:
  *
@@ -277,6 +293,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
@@ -318,8 +349,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,
@@ -333,6 +367,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;
   }
@@ -342,8 +377,15 @@ 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;
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index 923d25460..f2c3b94ce 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]