[epiphany] snapshot-service: Fix stale snapshot replacement



commit a3dccb21a027956669ecf9318b751f45deb536a0
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Mon Feb 13 21:07:31 2017 -0600

    snapshot-service: Fix stale snapshot replacement
    
    Looks like I broke this in a refactoring, probably
    adc6c404f650d51bf2709ed3d6f70475a0. Snapshots loaded for the overview
    are almost always available in cache before a webpage is visited, so
    those pages would never get updated. We need to update stale snapshots
    in ephy_snapshot_service_get_snapshot_path_async() to avoid this. It
    *could* still happen that snapshot requests are scheduled multiple
    times in a row, but it's unlikely and harmless.

 lib/ephy-snapshot-service.c |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)
---
diff --git a/lib/ephy-snapshot-service.c b/lib/ephy-snapshot-service.c
index 43777a5..c61d9c3 100644
--- a/lib/ephy-snapshot-service.c
+++ b/lib/ephy-snapshot-service.c
@@ -568,6 +568,23 @@ ephy_snapshot_service_get_snapshot_path_for_url_async (EphySnapshotService *serv
   g_object_unref (task);
 }
 
+static void
+take_fresh_snapshot_in_background_if_stale (EphySnapshotService *service,
+                                            SnapshotAsyncData   *data)
+{
+  GTask *task;
+
+  /* We schedule a new snapshot now, which will complete eventually. It won't be
+   * used now. This is just to ensure we get a newer snapshot in the future. */
+  if (ephy_snapshot_service_lookup_snapshot_freshness (service, data->url) == SNAPSHOT_STALE) {
+    task = g_task_new (service, NULL, NULL, NULL);
+    g_task_set_task_data (task,
+                          data,
+                          (GDestroyNotify)snapshot_async_data_free);
+    ephy_snapshot_service_take_from_webview (task);
+  }
+}
+
 char *
 ephy_snapshot_service_get_snapshot_path_for_url_finish (EphySnapshotService *service,
                                                         GAsyncResult        *result,
@@ -588,20 +605,12 @@ got_snapshot_path_for_url (EphySnapshotService *service,
 
   path = ephy_snapshot_service_get_snapshot_path_for_url_finish (service, result, NULL);
   if (path) {
+    take_fresh_snapshot_in_background_if_stale (service, snapshot_async_data_copy (data));
     g_task_return_pointer (task, path, g_free);
     g_object_unref (task);
-
-    if (ephy_snapshot_service_lookup_snapshot_freshness (service, data->url) == SNAPSHOT_FRESH)
-      return;
-
-    /* Take a fresh snapshot in the background. */
-    task = g_task_new (service, NULL, NULL, NULL);
-    g_task_set_task_data (task,
-                          snapshot_async_data_copy (data),
-                          (GDestroyNotify)snapshot_async_data_free);
+  } else {
+    ephy_snapshot_service_take_from_webview (task);
   }
-
-  ephy_snapshot_service_take_from_webview (task);
 }
 
 void
@@ -626,6 +635,8 @@ ephy_snapshot_service_get_snapshot_path_async (EphySnapshotService *service,
   path = ephy_snapshot_service_lookup_cached_snapshot_path (service, uri);
 
   if (path) {
+    take_fresh_snapshot_in_background_if_stale (service,
+                                                snapshot_async_data_new (service, NULL, web_view, mtime, 
uri));
     g_task_return_pointer (task, g_strdup (path), g_free);
     g_object_unref (task);
   } else {


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