[epiphany] Delete snapshot thumbnails when clearing history



commit 60ca7d5ff5f9f2de308f93d3daf35baba59b2a9a
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sat Jan 6 16:30:11 2018 -0600

    Delete snapshot thumbnails when clearing history
    
    Currently, you can clear your browser history and delete your entire
    disk cache, but thumbnails of all the webpages you've visited will still
    be stored on disk. Fix this by deleting thumbnails when the associated
    page is removed from history.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=778578

 lib/ephy-snapshot-service.c |   62 ++++++++++++++++++++++++++++++++++++++----
 lib/ephy-snapshot-service.h |    5 +++
 src/ephy-history-dialog.c   |    8 +++++
 3 files changed, 69 insertions(+), 6 deletions(-)
---
diff --git a/lib/ephy-snapshot-service.c b/lib/ephy-snapshot-service.c
index 7495e7d..6e824b0 100644
--- a/lib/ephy-snapshot-service.c
+++ b/lib/ephy-snapshot-service.c
@@ -22,6 +22,7 @@
 #include "ephy-snapshot-service.h"
 
 #include "ephy-favicon-helpers.h"
+#include "ephy-file-helpers.h"
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <stdio.h>
@@ -119,16 +120,24 @@ validate_thumbnail_path (const char *path,
 }
 
 static char *
-thumbnail_path (const char *uri)
+thumbnail_directory (void)
 {
-  char *path, *file;
-
-  file = thumbnail_filename (uri);
-  path = g_build_filename (g_get_user_cache_dir (),
+  return g_build_filename (g_get_user_cache_dir (),
                            "epiphany",
                            "thumbnails",
-                           file,
                            NULL);
+}
+
+static char *
+thumbnail_path (const char *uri)
+{
+  char *path, *file, *dir;
+
+  dir = thumbnail_directory ();
+  file = thumbnail_filename (uri);
+  path = g_build_filename (dir, file, NULL);
+
+  g_free (dir);
   g_free (file);
 
   return path;
@@ -741,3 +750,44 @@ ephy_snapshot_service_get_snapshot_path_finish (EphySnapshotService *service,
 
   return g_task_propagate_pointer (G_TASK (result), error);
 }
+
+static void
+got_snapshot_path_to_delete_cb (EphySnapshotService *service,
+                                GAsyncResult        *result,
+                                gpointer             user_data)
+{
+  char *path;
+
+  path = ephy_snapshot_service_get_snapshot_path_for_url_finish (service, result, NULL);
+  if (path)
+    unlink (path);
+  g_free (path);
+}
+
+void
+ephy_snapshot_service_delete_snapshot_for_url (EphySnapshotService *service,
+                                               const char          *url)
+{
+  ephy_snapshot_service_get_snapshot_path_for_url_async (service,
+                                                         url,
+                                                         NULL,
+                                                         (GAsyncReadyCallback)got_snapshot_path_to_delete_cb,
+                                                         NULL);
+}
+
+void
+ephy_snapshot_service_delete_all_snapshots (EphySnapshotService *service)
+{
+  GError *error = NULL;
+  char *dir;
+
+  dir = thumbnail_directory ();
+
+  ephy_file_delete_dir_recursively (dir, &error);
+  if (error) {
+    g_warning ("Failed to delete thumbnail directory: %s", error->message);
+    g_error_free (error);
+  }
+
+  g_free (dir);
+}
diff --git a/lib/ephy-snapshot-service.h b/lib/ephy-snapshot-service.h
index ac80bc3..857ad1c 100644
--- a/lib/ephy-snapshot-service.h
+++ b/lib/ephy-snapshot-service.h
@@ -70,4 +70,9 @@ char                *ephy_snapshot_service_get_snapshot_path_finish         (Eph
                                                                              GAsyncResult *result,
                                                                              GError **error);
 
+void                 ephy_snapshot_service_delete_snapshot_for_url          (EphySnapshotService *service,
+                                                                             const char          *url);
+
+void                 ephy_snapshot_service_delete_all_snapshots             (EphySnapshotService *service);
+
 G_END_DECLS
diff --git a/src/ephy-history-dialog.c b/src/ephy-history-dialog.c
index 0e617d9..6c81ecc 100644
--- a/src/ephy-history-dialog.c
+++ b/src/ephy-history-dialog.c
@@ -28,6 +28,7 @@
 #include "ephy-prefs.h"
 #include "ephy-settings.h"
 #include "ephy-shell.h"
+#include "ephy-snapshot-service.h"
 #include "ephy-uri-helpers.h"
 #include "ephy-time-helpers.h"
 #include "ephy-window.h"
@@ -44,6 +45,7 @@
 struct _EphyHistoryDialog {
   GtkDialog parent_instance;
 
+  EphySnapshotService *snapshot_service;
   EphyHistoryService *history_service;
   GCancellable *cancellable;
 
@@ -232,6 +234,8 @@ confirmation_dialog_response_cb (GtkWidget         *dialog,
     ephy_history_service_clear (self->history_service,
                                 NULL, NULL, NULL);
     filter_now (self);
+
+    ephy_snapshot_service_delete_all_snapshots (self->snapshot_service);
   }
 }
 
@@ -357,6 +361,9 @@ delete_selected (EphyHistoryDialog *self)
   selected = get_selection (self);
   ephy_history_service_delete_urls (self->history_service, selected, self->cancellable,
                                     (EphyHistoryJobCallback)on_browse_history_deleted_cb, self);
+
+  for (GList *l = selected; l; l = l->next)
+    ephy_snapshot_service_delete_snapshot_for_url (self->snapshot_service, ((EphyHistoryURL *)l->data)->url);
 }
 
 static void
@@ -777,6 +784,7 @@ ephy_history_dialog_init (EphyHistoryDialog *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  self->snapshot_service = ephy_snapshot_service_get_default ();
   self->cancellable = g_cancellable_new ();
 
   self->urls = NULL;


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