[epiphany/overview] ephy-overview-store: add a cancellable for the snapshot operation to the model



commit 555cf3e313d4c20a09fa2dd3d15348420e805f6a
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Fri Aug 10 16:32:44 2012 +0300

    ephy-overview-store: add a cancellable for the snapshot operation to the model
    
    Add a GCancellable to the model to allow cancelling snapshot
    operations if a row is removed or the url changes before the snapshot
    load has finished.
    
    Also add a wrapper for row removal in order to make sure that the
    cancellable is cancelled before it's removed from the store.

 lib/widgets/ephy-overview-store.c |   39 ++++++++++++++++++++++++++++++++++++-
 lib/widgets/ephy-overview-store.h |    4 +++
 src/ephy-active-store.c           |    3 +-
 src/ephy-frecent-store.c          |    2 +-
 4 files changed, 45 insertions(+), 3 deletions(-)
---
diff --git a/lib/widgets/ephy-overview-store.c b/lib/widgets/ephy-overview-store.c
index f1ec8e5..cbfd69f 100644
--- a/lib/widgets/ephy-overview-store.c
+++ b/lib/widgets/ephy-overview-store.c
@@ -125,6 +125,7 @@ ephy_overview_store_init (EphyOverviewStore *self)
   types[EPHY_OVERVIEW_STORE_SNAPSHOT] = GDK_TYPE_PIXBUF;
   types[EPHY_OVERVIEW_STORE_LAST_VISIT] = G_TYPE_LONG;
   types[EPHY_OVERVIEW_STORE_SELECTED] = G_TYPE_BOOLEAN;
+  types[EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE] = G_TYPE_CANCELLABLE;
 
   gtk_list_store_set_column_types (GTK_LIST_STORE (self),
                                    EPHY_OVERVIEW_STORE_NCOLS, types);
@@ -136,6 +137,7 @@ typedef struct {
   GtkTreeRowReference *ref;
   char *url;
   WebKitWebView *webview;
+  GCancellable *cancellable;
 } PeekContext;
 
 static void
@@ -145,6 +147,8 @@ peek_context_free (PeekContext *ctx)
   gtk_tree_row_reference_free (ctx->ref);
   if (ctx->webview)
     g_object_unref (ctx->webview);
+  if (ctx->cancellable)
+    g_object_unref (ctx->cancellable);
 
   g_slice_free (PeekContext, ctx);
 }
@@ -333,7 +337,7 @@ history_service_url_cb (gpointer service,
   timestamp = success ? (url->visit_count / 5) : 0;
 
   ephy_snapshot_service_get_snapshot_async (snapshot_service,
-                                            ctx->webview, ctx->url, timestamp, NULL,
+                                            ctx->webview, ctx->url, timestamp, ctx->cancellable,
                                             (GAsyncReadyCallback) on_snapshot_retrieved_cb,
                                             ctx);
   ephy_history_url_free (url);
@@ -347,11 +351,18 @@ ephy_overview_store_peek_snapshot (EphyOverviewStore *self,
   char *url;
   GtkTreePath *path;
   PeekContext *ctx;
+  GCancellable *cancellable;
 
   gtk_tree_model_get (GTK_TREE_MODEL (self), iter,
                       EPHY_OVERVIEW_STORE_URI, &url,
+                      EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE, &cancellable,
                       -1);
 
+  if (cancellable) {
+    g_cancellable_cancel (cancellable);
+    g_object_unref (cancellable);
+  }
+
   gtk_list_store_set (GTK_LIST_STORE (self), iter,
                       EPHY_OVERVIEW_STORE_SNAPSHOT,
                       self->priv->default_icon,
@@ -360,11 +371,17 @@ ephy_overview_store_peek_snapshot (EphyOverviewStore *self,
   if (url == NULL || g_strcmp0 (url, "about:blank") == 0)
     return;
 
+  cancellable = g_cancellable_new ();
+  gtk_list_store_set (GTK_LIST_STORE (self), iter,
+                      EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE,
+                      cancellable, -1);
+
   ctx = g_slice_new (PeekContext);
   path = gtk_tree_model_get_path (GTK_TREE_MODEL (self), iter);
   ctx->ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (self), path);
   ctx->url = url;
   ctx->webview = webview ? g_object_ref (webview) : NULL;
+  ctx->cancellable = cancellable;
   ephy_history_service_get_url (self->priv->history_service,
                                 url, NULL, (EphyHistoryJobCallback)history_service_url_cb,
                                 ctx);
@@ -413,3 +430,23 @@ ephy_overview_store_set_default_icon (EphyOverviewStore *store,
 
   g_object_notify (G_OBJECT (store), "default-icon");
 }
+
+gboolean
+ephy_overview_store_remove (EphyOverviewStore *store,
+                            GtkTreeIter *iter)
+{
+  GCancellable *cancellable;
+
+  g_return_val_if_fail (EPHY_IS_OVERVIEW_STORE (store), FALSE);
+
+  gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
+                      EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE,
+                      &cancellable,
+                      -1);
+  if (cancellable) {
+    g_cancellable_cancel (cancellable);
+    g_object_unref (cancellable);
+  }
+
+  return gtk_list_store_remove (GTK_LIST_STORE (store), iter);
+}
diff --git a/lib/widgets/ephy-overview-store.h b/lib/widgets/ephy-overview-store.h
index 0074975..22b363a 100644
--- a/lib/widgets/ephy-overview-store.h
+++ b/lib/widgets/ephy-overview-store.h
@@ -62,6 +62,7 @@ enum {
   EPHY_OVERVIEW_STORE_SNAPSHOT = GD_MAIN_COLUMN_ICON,
   EPHY_OVERVIEW_STORE_LAST_VISIT = GD_MAIN_COLUMN_MTIME,
   EPHY_OVERVIEW_STORE_SELECTED = GD_MAIN_COLUMN_SELECTED,
+  EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE,
   EPHY_OVERVIEW_STORE_NCOLS
 };
 
@@ -74,6 +75,9 @@ void ephy_overview_store_peek_snapshot (EphyOverviewStore *self,
 void ephy_overview_store_set_default_icon (EphyOverviewStore *store,
                                            GdkPixbuf *default_icon);
 
+gboolean ephy_overview_store_remove       (EphyOverviewStore *store,
+                                           GtkTreeIter       *iter);
+
 G_END_DECLS
 
 #endif /* _EPHY_OVERVIEW_STORE_H */
diff --git a/src/ephy-active-store.c b/src/ephy-active-store.c
index 2eababd..581e130 100644
--- a/src/ephy-active-store.c
+++ b/src/ephy-active-store.c
@@ -110,6 +110,7 @@ ephy_active_store_init (EphyActiveStore *self)
   types[EPHY_OVERVIEW_STORE_SNAPSHOT] = GDK_TYPE_PIXBUF;
   types[EPHY_OVERVIEW_STORE_LAST_VISIT] = G_TYPE_LONG;
   types[EPHY_OVERVIEW_STORE_SELECTED] = G_TYPE_BOOLEAN;
+  types[EPHY_OVERVIEW_STORE_SNAPSHOT_CANCELLABLE] = G_TYPE_CANCELLABLE;
   types[EPHY_ACTIVE_STORE_TAB_POS] = G_TYPE_UINT;
 
   gtk_list_store_set_column_types (GTK_LIST_STORE (self),
@@ -361,7 +362,7 @@ ephy_active_store_remove_embed (EphyActiveStore *store,
   iter = ctx->iter;
   g_slice_free (HelperCtx, ctx);
 
-  gtk_list_store_remove (GTK_LIST_STORE (store), &iter);
+  ephy_overview_store_remove (EPHY_OVERVIEW_STORE (store), &iter);
 
   bindings_drop (G_OBJECT (webview));
   bindings_drop (G_OBJECT (embed));
diff --git a/src/ephy-frecent-store.c b/src/ephy-frecent-store.c
index fa883cf..073a4a5 100644
--- a/src/ephy-frecent-store.c
+++ b/src/ephy-frecent-store.c
@@ -81,7 +81,7 @@ on_find_urls_cb (EphyHistoryService *service,
   g_list_free_full (urls, (GDestroyNotify)ephy_history_url_free);
 
   while (valid)
-    valid = gtk_list_store_remove (GTK_LIST_STORE (store), &treeiter);
+    valid = ephy_overview_store_remove (EPHY_OVERVIEW_STORE (store), &treeiter);
 }
 
 static void



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