[epiphany/history-rewrite: 6/45] Add support for user data parameter in all EphyHistoryService callbacks.



commit 0af9975e363ebc7af03d3745751966ac32e6f6c0
Author: Martin Robinson <mrobinson igalia com>
Date:   Thu May 12 16:38:05 2011 -0700

    Add support for user data parameter in all EphyHistoryService callbacks.

 embed/history/ephy-history-service.c |   19 +++++++++++--------
 embed/history/ephy-history-service.h |    8 ++++----
 tests/ephy-history.c                 |   23 ++++++++++++++---------
 3 files changed, 29 insertions(+), 21 deletions(-)
---
diff --git a/embed/history/ephy-history-service.c b/embed/history/ephy-history-service.c
index a95101d..c020c71 100644
--- a/embed/history/ephy-history-service.c
+++ b/embed/history/ephy-history-service.c
@@ -322,6 +322,7 @@ typedef struct _EphyHistoryThreadJobDetails
   gpointer *method_argument;
   gboolean success;
   gpointer result;
+  gpointer user_data;
   GDestroyNotify method_argument_cleanup;
   EphyHistoryJobCallback callback;
 } EphyHistoryThreadJobDetails;
@@ -331,13 +332,15 @@ ephy_history_thread_job_details_new (EphyHistoryService *service,
                                      EphyHistoryJobMethod method,
                                      gpointer method_argument,
                                      GDestroyNotify method_argument_cleanup,
-                                     EphyHistoryJobCallback callback)
+                                     EphyHistoryJobCallback callback,
+                                     gpointer user_data)
 {
   EphyHistoryThreadJobDetails *details = g_slice_alloc0 (sizeof (EphyHistoryThreadJobDetails));
   details->service = service; 
   details->method = method;
   details->method_argument = method_argument;
   details->callback = callback;
+  details->user_data = user_data;
   return details;
 }
 
@@ -355,7 +358,7 @@ ephy_history_service_execute_job_callback (gpointer data)
 {
   EphyHistoryThreadJobDetails *details = (EphyHistoryThreadJobDetails*) data;
   g_assert (details->callback);
-  details->callback (details->service, details->success, details->result);
+  details->callback (details->service, details->success, details->result, details->user_data);
   ephy_history_thread_job_details_free (details);
 
   return FALSE;
@@ -455,28 +458,28 @@ ephy_history_service_execute_find_visits_in_time (EphyHistoryService *self, gint
 }
 
 void
-ephy_history_service_add_visit (EphyHistoryService *self, EphyHistoryPageVisit *visit, EphyHistoryJobCallback callback)
+ephy_history_service_add_visit (EphyHistoryService *self, EphyHistoryPageVisit *visit, EphyHistoryJobCallback callback, gpointer user_data)
 {
   EphyHistoryThreadJobDetails *details = 
       ephy_history_thread_job_details_new (self, 
                                            (EphyHistoryJobMethod) ephy_history_service_execute_add_visit, 
                                            ephy_history_page_visit_copy (visit),
                                            (GDestroyNotify) ephy_history_page_visit_free,
-                                           callback);
+                                           callback, user_data);
   ephy_history_service_schedule_idle (self, G_PRIORITY_DEFAULT, 
                                       ephy_history_service_execute_job_on_history_thread, 
                                       details);
 }
 
 void
-ephy_history_service_add_visits (EphyHistoryService *self, GList *visits, EphyHistoryJobCallback callback)
+ephy_history_service_add_visits (EphyHistoryService *self, GList *visits, EphyHistoryJobCallback callback, gpointer user_data)
 {
   EphyHistoryThreadJobDetails *details = 
       ephy_history_thread_job_details_new (self, 
                                            (EphyHistoryJobMethod) ephy_history_service_execute_add_visits, 
                                            ephy_history_page_visit_list_copy (visits),
                                            (GDestroyNotify) ephy_history_page_visit_list_free,
-                                           callback);
+                                           callback, user_data);
   ephy_history_service_schedule_idle (self, G_PRIORITY_DEFAULT, 
                                       ephy_history_service_execute_job_on_history_thread, 
                                       details);
@@ -484,7 +487,7 @@ ephy_history_service_add_visits (EphyHistoryService *self, GList *visits, EphyHi
 }
 
 void
-ephy_history_service_find_visits_in_time (EphyHistoryService *self, gint64 from, gint64 to, EphyHistoryJobCallback callback)
+ephy_history_service_find_visits_in_time (EphyHistoryService *self, gint64 from, gint64 to, EphyHistoryJobCallback callback, gpointer user_data)
 {
   EphyHistoryThreadJobDetails *details;
 
@@ -494,7 +497,7 @@ ephy_history_service_find_visits_in_time (EphyHistoryService *self, gint64 from,
 
   details = ephy_history_thread_job_details_new (self, 
                                                  (EphyHistoryJobMethod) ephy_history_service_execute_find_visits_in_time,
-                                                 times, g_free, callback);
+                                                 times, g_free, callback, user_data);
   ephy_history_service_schedule_idle (self, G_PRIORITY_DEFAULT, 
                                       ephy_history_service_execute_job_on_history_thread, 
                                       details);
diff --git a/embed/history/ephy-history-service.h b/embed/history/ephy-history-service.h
index ee065f9..5b7cac1 100644
--- a/embed/history/ephy-history-service.h
+++ b/embed/history/ephy-history-service.h
@@ -38,7 +38,7 @@ typedef struct _EphyHistoryService                EphyHistoryService;
 typedef struct _EphyHistoryServiceClass           EphyHistoryServiceClass;
 typedef struct _EphyHistoryServicePrivate         EphyHistoryServicePrivate;
 
-typedef void   (*EphyHistoryJobCallback)          (EphyHistoryService *service, gboolean result, gpointer data);
+typedef void   (*EphyHistoryJobCallback)          (EphyHistoryService *service, gboolean success, gpointer result_data, gpointer user_data);
 
 struct _EphyHistoryService {
      GObject parent;
@@ -54,9 +54,9 @@ 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);
-void                     ephy_history_service_add_visits              (EphyHistoryService *self, GList *visits, EphyHistoryJobCallback callback);
-void                     ephy_history_service_find_visits_in_time     (EphyHistoryService *self, gint64 from, gint64 to, EphyHistoryJobCallback callback);
+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);
 
 G_END_DECLS
 
diff --git a/tests/ephy-history.c b/tests/ephy-history.c
index e20c4ac..177a8ea 100644
--- a/tests/ephy-history.c
+++ b/tests/ephy-history.c
@@ -69,10 +69,11 @@ test_create_history_service_and_destroy_later (void)
 }
 
 static void
-page_vist_created (EphyHistoryService *service, gboolean success, gpointer result)
+page_vist_created (EphyHistoryService *service, gboolean success, gpointer result_data, gpointer user_data)
 {
   g_object_unref (service);
-  g_assert (result == NULL);
+  g_assert (result_data == NULL);
+  g_assert (user_data == NULL);
   g_assert (success);
   gtk_main_quit ();
 }
@@ -84,7 +85,7 @@ test_create_history_entry (void)
   EphyHistoryService *service = ensure_empty_history(temporary_file);
 
   EphyHistoryPageVisit *visit = ephy_history_page_visit_new ("http://www.gnome.org";, 0, EphyPageVisitTypeTyped);
-  ephy_history_service_add_visit (service, visit, page_vist_created);
+  ephy_history_service_add_visit (service, visit, page_vist_created, NULL);
   ephy_history_page_visit_free (visit);
 
   gtk_main ();
@@ -105,13 +106,14 @@ create_test_page_visit_list ()
 }
 
 static void
-verify_create_history_entry_cb (EphyHistoryService *service, gboolean success, gpointer result)
+verify_create_history_entry_cb (EphyHistoryService *service, gboolean success, gpointer result_data, gpointer user_data)
 {
-  GList *visits = (GList *) result;
+  GList *visits = (GList *) result_data;
   GList *baseline_visits = create_test_page_visit_list ();
   GList *current = visits;
   GList *current_baseline = baseline_visits;
 
+  g_assert (user_data == NULL);
   g_assert (success);
   g_assert (visits != NULL);
   g_assert_cmpint (g_list_length (visits), ==, g_list_length (baseline_visits));
@@ -140,11 +142,12 @@ verify_create_history_entry_cb (EphyHistoryService *service, gboolean success, g
 }
 
 static void
-verify_create_history_entry (EphyHistoryService *service, gboolean success, gpointer result)
+verify_create_history_entry (EphyHistoryService *service, gboolean success, gpointer result_data, gpointer user_data)
 {
-  g_assert (result == NULL);
+  g_assert (result_data == NULL);
+  g_assert_cmpint (42, ==, GPOINTER_TO_INT(user_data)); 
   g_assert (success);
-  ephy_history_service_find_visits_in_time (service, 0, 8, verify_create_history_entry_cb);
+  ephy_history_service_find_visits_in_time (service, 0, 8, verify_create_history_entry_cb, NULL);
 }
 
 static void
@@ -154,7 +157,9 @@ test_create_history_entries (void)
   EphyHistoryService *service = ensure_empty_history(temporary_file);
 
   GList *visits = create_test_page_visit_list ();
-  ephy_history_service_add_visits (service, visits, verify_create_history_entry);
+
+  /* We use 42 here just to verify that user_data is passed properly to the callback */
+  ephy_history_service_add_visits (service, visits, verify_create_history_entry, GINT_TO_POINTER(42));
   ephy_history_page_visit_list_free (visits);
 
   gtk_main ();



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