[epiphany] snapshot-service: Add a memory cache of snapshots paths saved
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] snapshot-service: Add a memory cache of snapshots paths saved
- Date: Mon, 3 Mar 2014 14:07:17 +0000 (UTC)
commit d6a7f9e214a3e60931367bdcbc010bdb546f41f1
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Fri Feb 28 12:16:09 2014 +0100
snapshot-service: Add a memory cache of snapshots paths saved
And add a method to query that cache.
https://bugzilla.gnome.org/show_bug.cgi?id=725393
lib/ephy-snapshot-service.c | 17 ++++++++++++++++-
lib/ephy-snapshot-service.h | 3 +++
2 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/lib/ephy-snapshot-service.c b/lib/ephy-snapshot-service.c
index 3fb7bbe..5c5f2bb 100644
--- a/lib/ephy-snapshot-service.c
+++ b/lib/ephy-snapshot-service.c
@@ -34,6 +34,7 @@
struct _EphySnapshotServicePrivate
{
GnomeDesktopThumbnailFactory *factory;
+ GHashTable *cache;
};
G_DEFINE_TYPE (EphySnapshotService, ephy_snapshot_service, G_TYPE_OBJECT)
@@ -50,9 +51,11 @@ ephy_snapshot_service_class_init (EphySnapshotServiceClass *klass)
static void
ephy_snapshot_service_init (EphySnapshotService *self)
{
-
self->priv = EPHY_SNAPSHOT_SERVICE_GET_PRIVATE (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)g_free);
}
typedef struct {
@@ -105,6 +108,8 @@ get_snapshot_for_url_thread (GSimpleAsyncResult *result,
return;
}
+ g_hash_table_insert (service->priv->cache, g_strdup (data->url), g_strdup (data->path));
+
data->snapshot = gdk_pixbuf_new_from_file (data->path, &error);
if (data->snapshot == NULL) {
g_simple_async_result_set_error (result,
@@ -317,6 +322,7 @@ save_snapshot_thread (GSimpleAsyncResult *result,
data->url,
data->mtime);
data->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 (data->path));
}
GQuark
@@ -638,3 +644,12 @@ ephy_snapshot_service_prepare_snapshot (cairo_surface_t *surface,
return scaled;
}
+
+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);
+}
diff --git a/lib/ephy-snapshot-service.h b/lib/ephy-snapshot-service.h
index c21282b..4971803 100644
--- a/lib/ephy-snapshot-service.h
+++ b/lib/ephy-snapshot-service.h
@@ -108,6 +108,9 @@ char *ephy_snapshot_service_save_snapshot_finish (EphySnap
GdkPixbuf *ephy_snapshot_service_prepare_snapshot (cairo_surface_t *surface,
cairo_surface_t *favicon);
+const char *ephy_snapshot_service_lookup_snapshot_path (EphySnapshotService *service,
+ const char *url);
+
G_END_DECLS
#endif /* _EPHY_SNAPSHOT_SERVICE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]