summaryrefslogtreecommitdiff
path: root/lib/ephy-snapshot-service.c
diff options
context:
space:
mode:
authorClaudio Saavedra <csaavedra@igalia.com>2015-12-09 13:20:12 +0100
committerClaudio Saavedra <csaavedra@igalia.com>2015-12-09 14:07:12 +0100
commitc98857838c358d075096483f0a3b6b22e1a1ba95 (patch)
tree5c2b8a89ceecaf502f26fae4bbccb04b812ac60f /lib/ephy-snapshot-service.c
parentd77929696aabc8ce6d33dbcf4a2677c982d8303e (diff)
downloadepiphany-c98857838c358d075096483f0a3b6b22e1a1ba95.tar.gz
snapshot-service: do not update cache table from other threads
GLib hash tables are not thread-safe. Use a idle function to update the cache from the main thread. https://bugzilla.gnome.org/show_bug.cgi?id=759235
Diffstat (limited to 'lib/ephy-snapshot-service.c')
-rw-r--r--lib/ephy-snapshot-service.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/lib/ephy-snapshot-service.c b/lib/ephy-snapshot-service.c
index 599350842..946b5b98b 100644
--- a/lib/ephy-snapshot-service.c
+++ b/lib/ephy-snapshot-service.c
@@ -379,6 +379,23 @@ snapshot_for_url_async_data_free (SnapshotForURLAsyncData *data)
g_slice_free (SnapshotForURLAsyncData, data);
}
+typedef struct {
+ GHashTable *cache;
+ char *url;
+ 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->path);
+ g_hash_table_unref (data->cache);
+ g_free (data);
+
+ return G_SOURCE_REMOVE;
+}
+
static void
get_snapshot_for_url_thread (GTask *task,
EphySnapshotService *service,
@@ -387,6 +404,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) {
@@ -397,7 +415,11 @@ get_snapshot_for_url_thread (GTask *task,
return;
}
- g_hash_table_insert (service->priv->cache, g_strdup (data->url), g_strdup (data->path));
+ 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) {
@@ -544,7 +566,7 @@ ephy_snapshot_service_get_snapshot_async (EphySnapshotService *service,
(GAsyncReadyCallback)got_snapshot_for_url,
task);
else
- g_idle_add ((GSourceFunc)ephy_snapshot_service_take_from_webview, task);
+ g_idle_add (ephy_snapshot_service_take_from_webview, task);
}
/**
@@ -622,6 +644,7 @@ save_snapshot_thread (GTask *task,
GCancellable *cancellable)
{
char *path;
+ CacheData *cache_data;
gnome_desktop_thumbnail_factory_save_thumbnail (service->priv->factory,
data->snapshot,
@@ -629,7 +652,13 @@ save_snapshot_thread (GTask *task,
data->mtime);
path = gnome_desktop_thumbnail_path_for_uri (data->url, GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
- g_hash_table_insert (service->priv->cache, g_strdup (data->url), g_strdup (path));
+
+ 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);
}
@@ -683,6 +712,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) {
@@ -693,7 +723,12 @@ get_snapshot_path_for_url_thread (GTask *task,
return;
}
- g_hash_table_insert (service->priv->cache, g_strdup (data->url), g_strdup (path));
+ 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);
}