aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorClaudio Saavedra <csaavedra@igalia.com>2012-03-13 17:02:09 +0800
committerClaudio Saavedra <csaavedra@igalia.com>2012-03-13 18:33:41 +0800
commit637e046e0666576c71d1efa116d8148450b35db6 (patch)
treef83df81046290bbe1cb314bcde95ef2899e21289 /lib
parentf4ed0fb98f033727eb22f62ddb3ba60424c8cc91 (diff)
downloadgsoc2013-epiphany-637e046e0666576c71d1efa116d8148450b35db6.tar
gsoc2013-epiphany-637e046e0666576c71d1efa116d8148450b35db6.tar.gz
gsoc2013-epiphany-637e046e0666576c71d1efa116d8148450b35db6.tar.bz2
gsoc2013-epiphany-637e046e0666576c71d1efa116d8148450b35db6.tar.lz
gsoc2013-epiphany-637e046e0666576c71d1efa116d8148450b35db6.tar.xz
gsoc2013-epiphany-637e046e0666576c71d1efa116d8148450b35db6.tar.zst
gsoc2013-epiphany-637e046e0666576c71d1efa116d8148450b35db6.zip
ephy-history-service: make the async API cancellable
The main purpose of the cancellable API in ephy-history-service is to let the user notify when the results of the operation are no longer needed and the callback call can be omitted. Since performing a read operation, in such cases, makes no sense, we cancel them altogether. However, given the nature of the service, we don't cancel write operations. https://bugzilla.gnome.org/show_bug.cgi?id=671901
Diffstat (limited to 'lib')
-rw-r--r--lib/ephy-profile-migrator.c2
-rw-r--r--lib/history/ephy-history-service.c84
-rw-r--r--lib/history/ephy-history-service.h33
3 files changed, 78 insertions, 41 deletions
diff --git a/lib/ephy-profile-migrator.c b/lib/ephy-profile-migrator.c
index 55fa8a2f8..f7a34069a 100644
--- a/lib/ephy-profile-migrator.c
+++ b/lib/ephy-profile-migrator.c
@@ -594,7 +594,7 @@ migrate_history ()
g_input_stream_close (G_INPUT_STREAM (input), NULL, NULL);
g_object_unref (input);
- ephy_history_service_add_visits (history_service, parse_data.visits, (EphyHistoryJobCallback)visit_cb, NULL);
+ ephy_history_service_add_visits (history_service, parse_data.visits, NULL, (EphyHistoryJobCallback)visit_cb, NULL);
ephy_history_page_visit_list_free (parse_data.visits);
while (!all_done)
diff --git a/lib/history/ephy-history-service.c b/lib/history/ephy-history-service.c
index 3a6c3fa25..f7b468b9e 100644
--- a/lib/history/ephy-history-service.c
+++ b/lib/history/ephy-history-service.c
@@ -60,6 +60,7 @@ typedef struct _EphyHistoryServiceMessage {
gboolean success;
gpointer result;
gpointer user_data;
+ GCancellable *cancellable;
GDestroyNotify method_argument_cleanup;
EphyHistoryJobCallback callback;
} EphyHistoryServiceMessage;
@@ -132,7 +133,7 @@ impl_visit_url (EphyHistoryService *self, const char *url)
time (NULL),
EPHY_PAGE_VISIT_TYPED);
ephy_history_service_add_visit (self,
- visit, NULL, NULL);
+ visit, NULL, NULL, NULL);
ephy_history_page_visit_free (visit);
return FALSE;
@@ -390,6 +391,7 @@ ephy_history_service_message_new (EphyHistoryService *service,
EphyHistoryServiceMessageType type,
gpointer method_argument,
GDestroyNotify method_argument_cleanup,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
@@ -399,6 +401,7 @@ ephy_history_service_message_new (EphyHistoryService *service,
message->type = type;
message->method_argument = method_argument;
message->method_argument_cleanup = method_argument_cleanup;
+ message->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
message->callback = callback;
message->user_data = user_data;
@@ -411,6 +414,9 @@ ephy_history_service_message_free (EphyHistoryServiceMessage *message)
if (message->method_argument_cleanup)
message->method_argument_cleanup (message->method_argument);
+ if (message->cancellable)
+ g_object_unref (message->cancellable);
+
g_slice_free1 (sizeof (EphyHistoryServiceMessage), message);
}
@@ -420,6 +426,11 @@ ephy_history_service_execute_job_callback (gpointer data)
EphyHistoryServiceMessage *message = (EphyHistoryServiceMessage*) data;
g_assert (message->callback);
+
+ if (g_cancellable_is_cancelled (message->cancellable)) {
+ ephy_history_service_message_free (message);
+ return FALSE;
+ }
message->callback (message->service, message->success, message->result, message->user_data);
if (message->type == CLEAR)
@@ -546,7 +557,7 @@ ephy_history_service_execute_query_hosts (EphyHistoryService *self,
}
void
-ephy_history_service_add_visit (EphyHistoryService *self, EphyHistoryPageVisit *visit, EphyHistoryJobCallback callback, gpointer user_data)
+ephy_history_service_add_visit (EphyHistoryService *self, EphyHistoryPageVisit *visit, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data)
{
EphyHistoryServiceMessage *message;
@@ -556,12 +567,12 @@ ephy_history_service_add_visit (EphyHistoryService *self, EphyHistoryPageVisit *
message = ephy_history_service_message_new (self, ADD_VISIT,
ephy_history_page_visit_copy (visit),
(GDestroyNotify) ephy_history_page_visit_free,
- callback, user_data);
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
void
-ephy_history_service_add_visits (EphyHistoryService *self, GList *visits, EphyHistoryJobCallback callback, gpointer user_data)
+ephy_history_service_add_visits (EphyHistoryService *self, GList *visits, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data)
{
EphyHistoryServiceMessage *message;
@@ -571,12 +582,12 @@ ephy_history_service_add_visits (EphyHistoryService *self, GList *visits, EphyHi
message = ephy_history_service_message_new (self, ADD_VISITS,
ephy_history_page_visit_list_copy (visits),
(GDestroyNotify) ephy_history_page_visit_list_free,
- callback, user_data);
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
void
-ephy_history_service_find_visits_in_time (EphyHistoryService *self, gint64 from, gint64 to, EphyHistoryJobCallback callback, gpointer user_data)
+ephy_history_service_find_visits_in_time (EphyHistoryService *self, gint64 from, gint64 to, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data)
{
EphyHistoryQuery *query;
@@ -586,12 +597,12 @@ ephy_history_service_find_visits_in_time (EphyHistoryService *self, gint64 from,
query->from = from;
query->to = to;
- ephy_history_service_query_visits (self, query, callback, user_data);
+ ephy_history_service_query_visits (self, query, cancellable, callback, user_data);
ephy_history_query_free (query);
}
void
-ephy_history_service_query_visits (EphyHistoryService *self, EphyHistoryQuery *query, EphyHistoryJobCallback callback, gpointer user_data)
+ephy_history_service_query_visits (EphyHistoryService *self, EphyHistoryQuery *query, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data)
{
EphyHistoryServiceMessage *message;
@@ -599,7 +610,7 @@ ephy_history_service_query_visits (EphyHistoryService *self, EphyHistoryQuery *q
g_return_if_fail (query != NULL);
message = ephy_history_service_message_new (self, QUERY_VISITS,
- ephy_history_query_copy (query), (GDestroyNotify) ephy_history_query_free, callback, user_data);
+ ephy_history_query_copy (query), (GDestroyNotify) ephy_history_query_free, cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -614,7 +625,7 @@ ephy_history_service_execute_query_urls (EphyHistoryService *self, EphyHistoryQu
}
void
-ephy_history_service_query_urls (EphyHistoryService *self, EphyHistoryQuery *query, EphyHistoryJobCallback callback, gpointer user_data)
+ephy_history_service_query_urls (EphyHistoryService *self, EphyHistoryQuery *query, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data)
{
EphyHistoryServiceMessage *message;
@@ -622,12 +633,14 @@ ephy_history_service_query_urls (EphyHistoryService *self, EphyHistoryQuery *que
g_return_if_fail (query != NULL);
message = ephy_history_service_message_new (self, QUERY_URLS,
- ephy_history_query_copy (query), (GDestroyNotify) ephy_history_query_free, callback, user_data);
+ ephy_history_query_copy (query), (GDestroyNotify) ephy_history_query_free,
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
void
ephy_history_service_get_hosts (EphyHistoryService *self,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
@@ -636,7 +649,7 @@ ephy_history_service_get_hosts (EphyHistoryService *self,
g_return_if_fail (EPHY_IS_HISTORY_SERVICE (self));
message = ephy_history_service_message_new (self, GET_HOSTS,
- NULL, NULL,
+ NULL, NULL, cancellable,
callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -644,6 +657,7 @@ ephy_history_service_get_hosts (EphyHistoryService *self,
void
ephy_history_service_query_hosts (EphyHistoryService *self,
EphyHistoryQuery *query,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
@@ -654,7 +668,7 @@ ephy_history_service_query_hosts (EphyHistoryService *self,
message = ephy_history_service_message_new (self, QUERY_HOSTS,
ephy_history_query_copy (query),
(GDestroyNotify) ephy_history_query_free,
- callback, user_data);
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -682,6 +696,7 @@ void
ephy_history_service_set_url_title (EphyHistoryService *self,
const char *orig_url,
const char *title,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
@@ -694,7 +709,7 @@ ephy_history_service_set_url_title (EphyHistoryService *self,
url = ephy_history_url_new (orig_url, title, 0, 0, 0);
message = ephy_history_service_message_new (self, SET_URL_TITLE,
url, (GDestroyNotify) ephy_history_url_free,
- callback, user_data);
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -725,6 +740,7 @@ void
ephy_history_service_set_url_zoom_level (EphyHistoryService *self,
const char *url,
const double zoom_level,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
@@ -738,7 +754,7 @@ ephy_history_service_set_url_zoom_level (EphyHistoryService *self,
message = ephy_history_service_message_new (self, SET_URL_ZOOM_LEVEL,
variant, (GDestroyNotify)g_variant_unref,
- callback, user_data);
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -759,6 +775,7 @@ ephy_history_service_execute_get_url (EphyHistoryService *self,
void
ephy_history_service_get_url (EphyHistoryService *self,
const char *url,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
@@ -769,7 +786,7 @@ ephy_history_service_get_url (EphyHistoryService *self,
message = ephy_history_service_message_new (self, GET_URL,
g_strdup (url), g_free,
- callback, user_data);
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -791,6 +808,7 @@ ephy_history_service_execute_get_host_for_url (EphyHistoryService *self,
void
ephy_history_service_get_host_for_url (EphyHistoryService *self,
const char *url,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
@@ -801,7 +819,7 @@ ephy_history_service_get_host_for_url (EphyHistoryService *self,
message = ephy_history_service_message_new (self, GET_HOST_FOR_URL,
g_strdup (url), g_free,
- callback, user_data);
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -851,6 +869,7 @@ ephy_history_service_execute_clear (EphyHistoryService *self,
void
ephy_history_service_delete_urls (EphyHistoryService *self,
GList *urls,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
@@ -861,25 +880,27 @@ ephy_history_service_delete_urls (EphyHistoryService *self,
message = ephy_history_service_message_new (self, DELETE_URLS,
ephy_history_url_list_copy (urls), (GDestroyNotify)ephy_history_url_list_free,
- callback, user_data);
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
void
ephy_history_service_delete_host (EphyHistoryService *self,
EphyHistoryHost *host,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
EphyHistoryServiceMessage *message =
ephy_history_service_message_new (self, DELETE_HOST,
ephy_history_host_copy (host), (GDestroyNotify)ephy_history_host_free,
- callback, user_data);
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
void
ephy_history_service_clear (EphyHistoryService *self,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
@@ -889,7 +910,7 @@ ephy_history_service_clear (EphyHistoryService *self,
message = ephy_history_service_message_new (self, CLEAR,
NULL, NULL,
- callback, user_data);
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -900,7 +921,7 @@ ephy_history_service_quit (EphyHistoryService *self,
{
EphyHistoryServiceMessage *message =
ephy_history_service_message_new (self, QUIT,
- NULL, NULL,
+ NULL, NULL, NULL,
callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -922,6 +943,12 @@ static EphyHistoryServiceMethod methods[] = {
(EphyHistoryServiceMethod)ephy_history_service_execute_query_hosts
};
+static gboolean
+ephy_history_service_message_is_write (EphyHistoryServiceMessage *message)
+{
+ return message->type < QUIT;
+}
+
static void
ephy_history_service_process_message (EphyHistoryService *self,
EphyHistoryServiceMessage *message)
@@ -930,6 +957,12 @@ ephy_history_service_process_message (EphyHistoryService *self,
g_assert (self->priv->history_thread == g_thread_self ());
+ if (g_cancellable_is_cancelled (message->cancellable) &&
+ !ephy_history_service_message_is_write (message)) {
+ ephy_history_service_message_free (message);
+ return;
+ }
+
method = methods[message->type];
message->result = NULL;
message->success = method (message->service, message->method_argument, &message->result);
@@ -949,6 +982,7 @@ ephy_history_service_find_urls (EphyHistoryService *self,
gint64 from, gint64 to,
guint limit, gint host,
GList *substring_list,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
@@ -967,7 +1001,8 @@ ephy_history_service_find_urls (EphyHistoryService *self,
query->limit = limit;
ephy_history_service_query_urls (self,
- query, callback, user_data);
+ query, cancellable,
+ callback, user_data);
ephy_history_query_free (query);
}
@@ -986,6 +1021,7 @@ ephy_history_service_visit_url (EphyHistoryService *self,
void
ephy_history_service_find_hosts (EphyHistoryService *self,
gint64 from, gint64 to,
+ GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
{
@@ -998,7 +1034,7 @@ ephy_history_service_find_hosts (EphyHistoryService *self,
query->from = from;
query->to = to;
- ephy_history_service_query_hosts (self,
- query, callback, user_data);
+ ephy_history_service_query_hosts (self, query,
+ cancellable, callback, user_data);
ephy_history_query_free (query);
}
diff --git a/lib/history/ephy-history-service.h b/lib/history/ephy-history-service.h
index 8e36d6317..c2e2093db 100644
--- a/lib/history/ephy-history-service.h
+++ b/lib/history/ephy-history-service.h
@@ -22,6 +22,7 @@
#define EPHY_HISTORY_SERVICE_H
#include <glib-object.h>
+#include <gio/gio.h>
#include "ephy-history-types.h"
G_BEGIN_DECLS
@@ -58,23 +59,23 @@ struct _EphyHistoryServiceClass {
GType ephy_history_service_get_type (void);
EphyHistoryService * ephy_history_service_new (const char *history_filename);
-void ephy_history_service_add_visit (EphyHistoryService *self, EphyHistoryPageVisit *visit, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_add_visits (EphyHistoryService *self, GList *visits, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_find_visits_in_time (EphyHistoryService *self, gint64 from, gint64 to, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_query_visits (EphyHistoryService *self, EphyHistoryQuery *query, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_query_urls (EphyHistoryService *self, EphyHistoryQuery *query, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_set_url_title (EphyHistoryService *self, const char *url, const char *title, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_set_url_zoom_level (EphyHistoryService *self, const char *url, const double zoom_level, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_get_host_for_url (EphyHistoryService *self, const char *url, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_get_hosts (EphyHistoryService *self, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_query_hosts (EphyHistoryService *self, EphyHistoryQuery *query, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_delete_host (EphyHistoryService *self, EphyHistoryHost *host, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_get_url (EphyHistoryService *self, const char *url, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_delete_urls (EphyHistoryService *self, GList *urls, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_find_urls (EphyHistoryService *self, gint64 from, gint64 to, guint limit, gint host, GList *substring_list, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_add_visit (EphyHistoryService *self, EphyHistoryPageVisit *visit, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_add_visits (EphyHistoryService *self, GList *visits, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_find_visits_in_time (EphyHistoryService *self, gint64 from, gint64 to, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_query_visits (EphyHistoryService *self, EphyHistoryQuery *query, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_query_urls (EphyHistoryService *self, EphyHistoryQuery *query, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_set_url_title (EphyHistoryService *self, const char *url, const char *title, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_set_url_zoom_level (EphyHistoryService *self, const char *url, const double zoom_level, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_get_host_for_url (EphyHistoryService *self, const char *url, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_get_hosts (EphyHistoryService *self, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_query_hosts (EphyHistoryService *self, EphyHistoryQuery *query, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_delete_host (EphyHistoryService *self, EphyHistoryHost *host, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_get_url (EphyHistoryService *self, const char *url, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_delete_urls (EphyHistoryService *self, GList *urls, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_find_urls (EphyHistoryService *self, gint64 from, gint64 to, guint limit, gint host, GList *substring_list, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
void ephy_history_service_visit_url (EphyHistoryService *self, const char *orig_url);
-void ephy_history_service_clear (EphyHistoryService *self, EphyHistoryJobCallback callback, gpointer user_data);
-void ephy_history_service_find_hosts (EphyHistoryService *self, gint64 from, gint64 to, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_clear (EphyHistoryService *self, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
+void ephy_history_service_find_hosts (EphyHistoryService *self, gint64 from, gint64 to, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
G_END_DECLS