[epiphany/gnome-3-18] Revert "snapshot-service: Take new snapshots after a restart"



commit 78bbf3d0645086331c955cec9b9015be1568c5b2
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Fri Apr 29 11:09:27 2016 -0500

    Revert "snapshot-service: Take new snapshots after a restart"
    
    This reverts commit 51d8d547b0260271ac342b350cde3c145e66dc5f.

 embed/ephy-web-view.c       |   19 ++++---
 lib/ephy-snapshot-service.c |  117 +++++++++++++++----------------------------
 2 files changed, 52 insertions(+), 84 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index de9764b..a7ef909 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -609,6 +609,9 @@ web_view_check_snapshot (WebKitWebView *web_view)
 
   view->priv->snapshot_timeout_id = 0;
 
+  if (ephy_snapshot_service_lookup_snapshot_path (service, url))
+    return FALSE;
+
   data = g_new (GetSnapshotPathAsyncData, 1);
   data->url = g_strdup (url);
   data->mtime = time (NULL);
@@ -1682,13 +1685,15 @@ load_changed_cb (WebKitWebView *web_view,
 
     if (!ephy_web_view_is_history_frozen (view) &&
         ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) != EPHY_EMBED_SHELL_MODE_INCOGNITO) {
-      /* FIXME: The 1s delay is a workaround to allow time to render the page and get a favicon.
-       * https://bugzilla.gnome.org/show_bug.cgi?id=761065
-       */
-      if (priv->snapshot_timeout_id == 0) {
-        priv->snapshot_timeout_id = g_timeout_add_seconds_full (G_PRIORITY_LOW, 1,
-                                                                (GSourceFunc)web_view_check_snapshot,
-                                                                web_view, NULL);
+      if (!ephy_snapshot_service_lookup_snapshot_path (ephy_snapshot_service_get_default (), 
webkit_web_view_get_uri (web_view))) {
+        /* FIXME: The 1s delay is a workaround to allow time to render the page and get a favicon.
+         * https://bugzilla.gnome.org/show_bug.cgi?id=761065
+         */
+        if (priv->snapshot_timeout_id == 0) {
+          priv->snapshot_timeout_id = g_timeout_add_seconds_full (G_PRIORITY_LOW, 1,
+                                                                  (GSourceFunc)web_view_check_snapshot,
+                                                                  web_view, NULL);
+        }
       }
     }
 
diff --git a/lib/ephy-snapshot-service.c b/lib/ephy-snapshot-service.c
index 900c45a..2841776 100644
--- a/lib/ephy-snapshot-service.c
+++ b/lib/ephy-snapshot-service.c
@@ -33,31 +33,13 @@
 
 struct _EphySnapshotServicePrivate
 {
-  /* Disk cache */
   GnomeDesktopThumbnailFactory *factory;
-
-  /* Memory cache */
   GHashTable *cache;
 };
 
 G_DEFINE_TYPE (EphySnapshotService, ephy_snapshot_service, G_TYPE_OBJECT)
 
-typedef enum {
-  SNAPSHOT_STALE,
-  SNAPSHOT_FRESH
-} EphySnapshotFreshness;
-
-typedef struct {
-  char *path;
-  EphySnapshotFreshness freshness;
-} SnapshotPathCachedData;
-
-static void
-snapshot_path_cached_data_free (SnapshotPathCachedData *data)
-{
-  g_free (data->path);
-  g_free (data);
-}
+/* GObject boilerplate methods. */
 
 static void
 ephy_snapshot_service_class_init (EphySnapshotServiceClass *klass)
@@ -65,6 +47,7 @@ ephy_snapshot_service_class_init (EphySnapshotServiceClass *klass)
   g_type_class_add_private (klass, sizeof (EphySnapshotServicePrivate));
 }
 
+
 static void
 ephy_snapshot_service_init (EphySnapshotService *self)
 {
@@ -72,7 +55,7 @@ ephy_snapshot_service_init (EphySnapshotService *self)
   self->priv->factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
   self->priv->cache = g_hash_table_new_full (g_str_hash, g_str_equal,
                                              (GDestroyNotify)g_free,
-                                             (GDestroyNotify)snapshot_path_cached_data_free);
+                                             (GDestroyNotify)g_free);
 }
 
 static GdkPixbuf *
@@ -366,30 +349,6 @@ ephy_snapshot_service_get_default (void)
   return service;
 }
 
-const char *
-ephy_snapshot_service_lookup_snapshot_path (EphySnapshotService *service,
-                                            const char          *url)
-{
-  SnapshotPathCachedData *data;
-
-  g_return_val_if_fail (EPHY_IS_SNAPSHOT_SERVICE (service), NULL);
-
-  data = g_hash_table_lookup (service->priv->cache, url);
-
-  return data == NULL ? NULL : data->path;
-}
-
-static EphySnapshotFreshness
-ephy_snapshot_service_lookup_snapshot_freshness (EphySnapshotService *service,
-                                                 const char          *url)
-{
-  SnapshotPathCachedData *data;
-
-  data = g_hash_table_lookup (service->priv->cache, url);
-
-  return data == NULL ? SNAPSHOT_STALE : data->freshness;
-}
-
 typedef struct {
   char *url;
   time_t mtime;
@@ -422,14 +381,14 @@ snapshot_for_url_async_data_free (SnapshotForURLAsyncData *data)
 typedef struct {
   GHashTable *cache;
   char *url;
-  SnapshotPathCachedData *data;
+  char *path;
 } CacheData;
 
 static gboolean
 idle_cache_snapshot_path (gpointer user_data)
 {
-  CacheData *data = (CacheData *)user_data;
-  g_hash_table_insert (data->cache, data->url, data->data);
+  CacheData* data = (CacheData*)user_data;
+  g_hash_table_insert (data->cache, data->url, data->path);
   g_hash_table_unref (data->cache);
   g_free (data);
 
@@ -437,22 +396,6 @@ idle_cache_snapshot_path (gpointer user_data)
 }
 
 static void
-cache_snapshot_data_in_idle (EphySnapshotService  *service,
-                             const char           *url,
-                             const char           *path,
-                             EphySnapshotFreshness freshness)
-{
-  CacheData *data;
-  data = g_new (CacheData, 1);
-  data->cache = g_hash_table_ref (service->priv->cache);
-  data->url = g_strdup (url);
-  data->data = g_new (SnapshotPathCachedData, 1);
-  data->data->path = g_strdup (path);
-  data->data->freshness = freshness;
-  g_idle_add (idle_cache_snapshot_path, data);
-}
-
-static void
 get_snapshot_for_url_thread (GTask *task,
                              EphySnapshotService *service,
                              SnapshotForURLAsyncData *data,
@@ -460,6 +403,7 @@ get_snapshot_for_url_thread (GTask *task,
 {
   GdkPixbuf *snapshot;
   GError *error = NULL;
+  CacheData *cache_data;
 
   data->path = gnome_desktop_thumbnail_factory_lookup (service->priv->factory, data->url, data->mtime);
   if (data->path == NULL) {
@@ -470,7 +414,11 @@ get_snapshot_for_url_thread (GTask *task,
     return;
   }
 
-  cache_snapshot_data_in_idle (service, data->url, data->path, SNAPSHOT_STALE);
+  cache_data = g_new (CacheData, 1);
+  cache_data->cache = g_hash_table_ref (service->priv->cache);
+  cache_data->url = g_strdup (data->url);
+  cache_data->path = g_strdup (data->path);
+  g_idle_add (idle_cache_snapshot_path, cache_data);
 
   snapshot = gdk_pixbuf_new_from_file (data->path, &error);
   if (snapshot == NULL) {
@@ -608,18 +556,15 @@ ephy_snapshot_service_get_snapshot_async (EphySnapshotService *service,
                         snapshot_async_data_new_for_snapshot (web_view, mtime),
                         (GDestroyNotify)snapshot_async_data_free);
 
-  /* Try to get the snapshot from the cache first if we have a URL, but only if
-   * the snapshot path is in memory cache; this is an indication that the
-   * snapshot is fresh. */
+  /* Try to get the snapshot from the cache first if we have a URL */
   uri = webkit_web_view_get_uri (web_view);
-  if (uri && ephy_snapshot_service_lookup_snapshot_freshness (service, uri) == SNAPSHOT_FRESH) {
+  if (uri)
     ephy_snapshot_service_get_snapshot_for_url_async (service,
                                                       uri, mtime, cancellable,
                                                       (GAsyncReadyCallback)got_snapshot_for_url,
                                                       task);
-  } else {
-    g_idle_add ((GSourceFunc)ephy_snapshot_service_take_from_webview, task);
-  }
+  else
+    g_idle_add (ephy_snapshot_service_take_from_webview, task);
 }
 
 /**
@@ -697,6 +642,7 @@ save_snapshot_thread (GTask *task,
                       GCancellable *cancellable)
 {
   char *path;
+  CacheData *cache_data;
 
   gnome_desktop_thumbnail_factory_save_thumbnail (service->priv->factory,
                                                   data->snapshot,
@@ -705,7 +651,11 @@ save_snapshot_thread (GTask *task,
 
   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);
+  cache_data = g_new (CacheData, 1);
+  cache_data->cache = g_hash_table_ref (service->priv->cache);
+  cache_data->url = g_strdup (data->url);
+  cache_data->path = g_strdup (path);
+  g_idle_add (idle_cache_snapshot_path, cache_data);
 
   g_task_return_pointer (task, path, g_free);
 }
@@ -744,6 +694,15 @@ ephy_snapshot_service_save_snapshot_finish (EphySnapshotService *service,
   return g_task_propagate_pointer (G_TASK (result), error);
 }
 
+const char *
+ephy_snapshot_service_lookup_snapshot_path (EphySnapshotService *service,
+                                            const char *url)
+{
+  g_return_val_if_fail (EPHY_IS_SNAPSHOT_SERVICE (service), NULL);
+
+  return g_hash_table_lookup (service->priv->cache, url);
+}
+
 static void
 get_snapshot_path_for_url_thread (GTask *task,
                                   EphySnapshotService *service,
@@ -751,6 +710,7 @@ get_snapshot_path_for_url_thread (GTask *task,
                                   GCancellable *cancellable)
 {
   char *path;
+  CacheData *cache_data;
 
   path = gnome_desktop_thumbnail_factory_lookup (service->priv->factory, data->url, data->mtime);
   if (!path) {
@@ -761,7 +721,11 @@ get_snapshot_path_for_url_thread (GTask *task,
     return;
   }
 
-  cache_snapshot_data_in_idle (service, data->url, path, SNAPSHOT_STALE);
+  cache_data = g_new (CacheData, 1);
+  cache_data->cache = g_hash_table_ref (service->priv->cache);
+  cache_data->url = g_strdup (data->url);
+  cache_data->path = g_strdup (path);
+  g_idle_add (idle_cache_snapshot_path, cache_data);
 
   g_task_return_pointer (task, path, g_free);
 }
@@ -782,8 +746,7 @@ ephy_snapshot_service_get_snapshot_path_for_url_async (EphySnapshotService *serv
 
   task = g_task_new (service, cancellable, callback, user_data);
 
-  path = ephy_snapshot_service_lookup_snapshot_path (service, url);
-
+  path = g_hash_table_lookup (service->priv->cache, url);
   if (path) {
     g_task_return_pointer (task, g_strdup (path), g_free);
     g_object_unref (task);
@@ -841,9 +804,9 @@ ephy_snapshot_service_get_snapshot_path_async (EphySnapshotService *service,
   task = g_task_new (service, cancellable, callback, user_data);
 
   uri = webkit_web_view_get_uri (web_view);
+  if (uri) {
+    const char *path = g_hash_table_lookup (service->priv->cache, uri);
 
-  if (uri && ephy_snapshot_service_lookup_snapshot_freshness (service, uri) == SNAPSHOT_FRESH) {
-    const char *path = ephy_snapshot_service_lookup_snapshot_path (service, uri);
     if (path) {
       g_task_return_pointer (task, g_strdup (path), g_free);
       g_object_unref (task);


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