[epiphany/gnome-3-18] Save the correct thumbnail mtime in the history service



commit 799a336266def4bb539f917f68139aaa2950d886
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Fri Apr 29 09:14:47 2016 -0500

    Save the correct thumbnail mtime in the history service
    
    Save the thumbnail mtime when saving thumbnails so it actually reflects
    the mtime embedded in the thumbnail, not the time the page was saved in
    the history service. This regressed in 0433ac9. It's only noticeable now
    due to 9754735, which has resulted in thumbnails regularly disappearing
    from the overview.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763184

 embed/ephy-embed-shell.c    |   19 +++++++++--
 lib/ephy-snapshot-service.c |   71 +++++++++++++++++++++++++++++++++++++------
 2 files changed, 76 insertions(+), 14 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index b8fddf2..eca859a 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -395,10 +395,6 @@ ephy_embed_shell_set_thumbanil_path (EphyEmbedShell *shell,
 {
   GList *l;
 
-  ephy_history_service_set_url_thumbnail_time (shell->priv->global_history_service,
-                                               url, mtime,
-                                               NULL, NULL, NULL);
-
   for (l = shell->priv->web_extensions; l; l = g_list_next (l)) {
     EphyWebExtensionProxy *web_extension = (EphyWebExtensionProxy *)l->data;
 
@@ -445,6 +441,17 @@ ephy_embed_shell_get_global_history_service (EphyEmbedShell *shell)
   return G_OBJECT (shell->priv->global_history_service);
 }
 
+static void
+snapshot_saved_cb (EphySnapshotService *service,
+                   const char          *url,
+                   gint64               mtime,
+                   EphyEmbedShell      *shell)
+{
+  ephy_history_service_set_url_thumbnail_time (EPHY_HISTORY_SERVICE 
(ephy_embed_shell_get_global_history_service (shell)),
+                                               url, mtime,
+                                               NULL, NULL, NULL);
+}
+
 /**
  * ephy_embed_shell_get_encodings:
  * @shell: the #EphyEmbedShell
@@ -760,6 +767,10 @@ ephy_embed_shell_constructed (GObject *object)
     ephy_embed_shell_create_web_context (embed_shell);
     embed_shell->priv->user_content = webkit_user_content_manager_new ();
   }
+
+  g_signal_connect_object (ephy_snapshot_service_get_default (),
+                           "snapshot-saved", G_CALLBACK (snapshot_saved_cb),
+                           embed_shell, 0);
 }
 
 static void
diff --git a/lib/ephy-snapshot-service.c b/lib/ephy-snapshot-service.c
index 900c45a..a44bc93 100644
--- a/lib/ephy-snapshot-service.c
+++ b/lib/ephy-snapshot-service.c
@@ -42,6 +42,13 @@ struct _EphySnapshotServicePrivate
 
 G_DEFINE_TYPE (EphySnapshotService, ephy_snapshot_service, G_TYPE_OBJECT)
 
+enum {
+  SNAPSHOT_SAVED,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
 typedef enum {
   SNAPSHOT_STALE,
   SNAPSHOT_FRESH
@@ -62,7 +69,26 @@ snapshot_path_cached_data_free (SnapshotPathCachedData *data)
 static void
 ephy_snapshot_service_class_init (EphySnapshotServiceClass *klass)
 {
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
   g_type_class_add_private (klass, sizeof (EphySnapshotServicePrivate));
+
+  /**
+   * EphySnapshotService::snapshot-saved:
+   * @url: the URL the snapshot was saved for
+   * @mtime: the mtime embedded in the snapshot, needed to retrieve it
+   *
+   * The ::snapshot-saved signal is emitted when a new snapshot is saved.
+   **/
+  signals[SNAPSHOT_SAVED] = g_signal_new ("snapshot-saved",
+                                          G_OBJECT_CLASS_TYPE (object_class),
+                                          G_SIGNAL_RUN_LAST,
+                                          0,
+                                          NULL, NULL, NULL,
+                                          G_TYPE_NONE,
+                                          2,
+                                          G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
+                                          G_TYPE_INT64);
 }
 
 static void
@@ -661,33 +687,58 @@ ephy_snapshot_service_get_snapshot_finish (EphySnapshotService *service,
 }
 
 typedef struct {
+  EphySnapshotService *service;
   GdkPixbuf *snapshot;
   char *url;
   time_t mtime;
+  gint refcount;
 } SaveSnapshotAsyncData;
 
 static SaveSnapshotAsyncData *
-save_snapshot_async_data_new (GdkPixbuf *snapshot,
-                              const char *url,
-                              time_t mtime)
+save_snapshot_async_data_new (EphySnapshotService *service,
+                              GdkPixbuf           *snapshot,
+                              const char          *url,
+                              time_t               mtime)
 {
   SaveSnapshotAsyncData *data;
 
   data = g_slice_new0 (SaveSnapshotAsyncData);
+  data->service = g_object_ref (service);
   data->snapshot = g_object_ref (snapshot);
   data->url = g_strdup (url);
   data->mtime = mtime;
+  data->refcount = 1;
 
   return data;
 }
 
+static SaveSnapshotAsyncData *
+save_snapshot_async_data_ref (SaveSnapshotAsyncData *data)
+{
+  g_atomic_int_add (&data->refcount, 1);
+  return data;
+}
+
 static void
-save_snapshot_async_data_free (SaveSnapshotAsyncData *data)
+save_snapshot_async_data_unref (SaveSnapshotAsyncData *data)
 {
-  g_object_unref (data->snapshot);
-  g_free (data->url);
+  if (g_atomic_int_dec_and_test (&data->refcount)) {
+    g_object_unref (data->service);
+    g_object_unref (data->snapshot);
+    g_free (data->url);
+    g_slice_free (SaveSnapshotAsyncData, data);
+  }
+}
 
-  g_slice_free (SaveSnapshotAsyncData, data);
+static gboolean
+idle_emit_snapshot_saved (gpointer user_data)
+{
+  SaveSnapshotAsyncData *data = (SaveSnapshotAsyncData *)user_data;
+
+  g_signal_emit (data->service, signals[SNAPSHOT_SAVED], 0, data->url, data->mtime);
+
+  save_snapshot_async_data_unref (data);
+  return G_SOURCE_REMOVE;
 }
 
 static void
@@ -702,9 +753,9 @@ save_snapshot_thread (GTask *task,
                                                   data->snapshot,
                                                   data->url,
                                                   data->mtime);
+  g_idle_add (idle_emit_snapshot_saved, save_snapshot_async_data_ref (data));
 
   path = gnome_desktop_thumbnail_path_for_uri (data->url, GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
-
   cache_snapshot_data_in_idle (service, data->url, path, SNAPSHOT_FRESH);
 
   g_task_return_pointer (task, path, g_free);
@@ -728,8 +779,8 @@ ephy_snapshot_service_save_snapshot_async (EphySnapshotService *service,
   task = g_task_new (service, cancellable, callback, user_data);
   g_task_set_priority (task, G_PRIORITY_LOW);
   g_task_set_task_data (task,
-                        save_snapshot_async_data_new (snapshot, url, mtime),
-                        (GDestroyNotify)save_snapshot_async_data_free);
+                        save_snapshot_async_data_new (service, snapshot, url, mtime),
+                        (GDestroyNotify)save_snapshot_async_data_unref);
   g_task_run_in_thread (task, (GTaskThreadFunc)save_snapshot_thread);
   g_object_unref (task);
 }


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