[epiphany/gnome-3-20] snapshot-service: Always return snapshots immediately if available



commit 7cf764587e47311ae034203c5fd936ea864a424f
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Wed Apr 13 17:05:19 2016 -0500

    snapshot-service: Always return snapshots immediately if available
    
    Return a stale snapshot, then schedule creation of a new snapshot. This
    way, we show a preexisting snapshot even if snapshot creation fails. The
    new snapshot will be used only for future requests.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763184

 lib/ephy-snapshot-service.c |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/lib/ephy-snapshot-service.c b/lib/ephy-snapshot-service.c
index e60acf1..df9ddcc 100644
--- a/lib/ephy-snapshot-service.c
+++ b/lib/ephy-snapshot-service.c
@@ -596,6 +596,28 @@ got_snapshot_for_url (EphySnapshotService *service,
   ephy_snapshot_service_take_from_webview (task);
 }
 
+/* We want to return an existing snapshot immediately, even if it is stale,
+ * because snapshot creation is best-effort and often fails (e.g. if the user
+ * navigates away from the page too soon), and we must be sure to return an old
+ * result if a new one does not yet exist.
+ */
+static void
+ensure_snapshot_freshness_for_web_view (EphySnapshotService *service,
+                                        WebKitWebView       *web_view)
+{
+  GTask *task;
+  const char *uri;
+
+  uri = webkit_web_view_get_uri (web_view);
+  if (ephy_snapshot_service_lookup_snapshot_freshness (service, uri) != SNAPSHOT_FRESH) {
+    task = g_task_new (service, NULL, NULL, NULL);
+    g_task_set_task_data (task,
+                          snapshot_async_data_new (web_view, time (NULL)),
+                          (GDestroyNotify)snapshot_async_data_free);
+    g_idle_add ((GSourceFunc)ephy_snapshot_service_take_from_webview, task);
+  }
+}
+
 /**
  * ephy_snapshot_service_get_snapshot_async:
  * @service: a #EphySnapshotService
@@ -632,11 +654,12 @@ ephy_snapshot_service_get_snapshot_async (EphySnapshotService *service,
    * the snapshot path is in memory cache; this is an indication that the
    * snapshot is fresh. */
   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);
+    ensure_snapshot_freshness_for_web_view (service, web_view);
   } else {
     g_idle_add ((GSourceFunc)ephy_snapshot_service_take_from_webview, task);
   }
@@ -885,7 +908,7 @@ 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 && ephy_snapshot_service_lookup_snapshot_freshness (service, uri) == SNAPSHOT_FRESH) {
+  if (uri) {
     const char *path = ephy_snapshot_service_lookup_snapshot_path (service, uri);
 
     if (path) {
@@ -900,6 +923,8 @@ ephy_snapshot_service_get_snapshot_path_async (EphySnapshotService *service,
                                                              (GAsyncReadyCallback)got_snapshot_path_for_url,
                                                              task);
     }
+
+    ensure_snapshot_freshness_for_web_view (service, web_view);
   } else {
     g_task_set_task_data (task,
                           snapshot_async_data_new (web_view, mtime),


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