[epiphany/history-rewrite: 3/26] Add an API point for adding a list of page visits.
- From: Claudio Saavedra <csaavedra src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/history-rewrite: 3/26] Add an API point for adding a list of page visits.
- Date: Tue, 5 Jul 2011 17:25:49 +0000 (UTC)
commit bfe9e19e9033e143bed37b5ba576a8069093ec43
Author: Martin Robinson <mrobinson igalia com>
Date: Thu Apr 21 17:16:22 2011 -0700
Add an API point for adding a list of page visits.
Also fix some minor bugs when adding visits for pre-existing url table entries.
embed/history/ephy-history-service-urls-table.c | 4 +-
embed/history/ephy-history-service.c | 56 ++++++++++++++++++-----
embed/history/ephy-history-service.h | 2 +-
embed/history/ephy-history-types.c | 18 +++++++
embed/history/ephy-history-types.h | 4 ++
tests/ephy-history.c | 22 +++++++++
6 files changed, 91 insertions(+), 15 deletions(-)
---
diff --git a/embed/history/ephy-history-service-urls-table.c b/embed/history/ephy-history-service-urls-table.c
index 65bb9f6..018a5c7 100644
--- a/embed/history/ephy-history-service-urls-table.c
+++ b/embed/history/ephy-history-service-urls-table.c
@@ -142,8 +142,8 @@ ephy_history_service_update_url_row (EphyHistoryService *self, EphyHistoryURL *u
g_assert (priv->history_database != NULL);
statement = ephy_sqlite_connection_create_statement (priv->history_database,
- "UPDATE urls SET title=?, visit_count=?, typed_count=?, last_visit_time=? WHERE id=?"
- " VALUES (?, ?, ?, ?, ?, ?)", &error);
+ "UPDATE urls SET title=?, visit_count=?, typed_count=?, last_visit_time=? "
+ "WHERE id=?", &error);
if (NULL != error) {
g_error ("Could not build urls table modification statement: %s", error->message);
g_error_free (error);
diff --git a/embed/history/ephy-history-service.c b/embed/history/ephy-history-service.c
index 9d02895..2cc7c59 100644
--- a/embed/history/ephy-history-service.c
+++ b/embed/history/ephy-history-service.c
@@ -382,26 +382,19 @@ ephy_history_service_execute_job_on_history_thread (gpointer data)
return FALSE;
}
-static gpointer
-ephy_history_service_execute_add_visit (EphyHistoryService *self, EphyHistoryPageVisit *visit, gboolean *success)
+static gboolean
+ephy_history_service_execute_add_visit_helper (EphyHistoryService *self, EphyHistoryPageVisit *visit)
{
- EphyHistoryServicePrivate *priv = EPHY_HISTORY_SERVICE (self)->priv;
- EphyHistoryURL *url = NULL;
+ EphyHistoryURL *url = ephy_history_service_get_url_row (self, visit->url);
- g_assert (priv->history_thread == g_thread_self ());
-
- url = ephy_history_service_get_url_row (self, visit->url);
if (NULL == url) { /* This URL does not yet exist in the history table */
url = ephy_history_url_new (visit->url, "", 1, 0, visit->visit_time);
ephy_history_service_add_url_row (self, url);
if (url->id == -1) {
g_error ("Adding visit failed after failed URL addition.");
- *success = FALSE;
- return NULL;
+ return FALSE;
}
- visit->url_id = url->id;
-
} else {
url->visit_count++;
if (visit->visit_time > url->last_visit_time) {
@@ -410,9 +403,33 @@ ephy_history_service_execute_add_visit (EphyHistoryService *self, EphyHistoryPag
ephy_history_service_update_url_row (self, url);
}
+ visit->url_id = url->id;
+
ephy_history_service_add_visit_row (self, visit);
ephy_history_url_free (url);
- *success = visit->id != -1;
+ return visit->id != -1;
+}
+
+static gpointer
+ephy_history_service_execute_add_visit (EphyHistoryService *self, EphyHistoryPageVisit *visit, gboolean *success)
+{
+ g_assert (self->priv->history_thread == g_thread_self ());
+ *success = ephy_history_service_execute_add_visit_helper (self, visit);
+ ephy_history_service_schedule_commit (self);
+ return NULL;
+}
+
+static gpointer
+ephy_history_service_execute_add_visits (EphyHistoryService *self, GList *visits, gboolean *success)
+{
+ g_assert (self->priv->history_thread == g_thread_self ());
+
+ while (visits) {
+ *success = success && ephy_history_service_execute_add_visit_helper (self, (EphyHistoryPageVisit *) visits->data);
+ visits = visits->next;
+ }
+
+ ephy_history_service_schedule_commit (self);
return NULL;
}
@@ -429,3 +446,18 @@ ephy_history_service_add_visit (EphyHistoryService *self, EphyHistoryPageVisit *
ephy_history_service_execute_job_on_history_thread,
details);
}
+
+void
+ephy_history_service_add_visits (EphyHistoryService *self, GList *visits, EphyHistoryJobCallback callback)
+{
+ 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);
+ 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 d4db2bb..d0f4981 100644
--- a/embed/history/ephy-history-service.h
+++ b/embed/history/ephy-history-service.h
@@ -55,7 +55,7 @@ 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);
G_END_DECLS
diff --git a/embed/history/ephy-history-types.c b/embed/history/ephy-history-types.c
index 5954f48..21c0ec4 100644
--- a/embed/history/ephy-history-types.c
+++ b/embed/history/ephy-history-types.c
@@ -50,6 +50,24 @@ ephy_history_page_visit_copy (EphyHistoryPageVisit *visit)
return copy;
}
+GList *
+ephy_history_page_visit_list_copy (GList *original)
+{
+ GList *new = g_list_copy (original);
+ GList *current = new;
+ while (current) {
+ current->data = ephy_history_page_visit_copy ((EphyHistoryPageVisit *) current->data);
+ current = current->next;
+ }
+ return new;
+}
+
+void
+ephy_history_page_visit_list_free (GList *list)
+{
+ g_list_free_full (list, (GDestroyNotify) ephy_history_page_visit_free);
+}
+
EphyHistoryURL *
ephy_history_url_new (const char *url, const char *title, int visit_count, int typed_count, int last_visit_time)
{
diff --git a/embed/history/ephy-history-types.h b/embed/history/ephy-history-types.h
index 3d52aa0..4d8284d 100644
--- a/embed/history/ephy-history-types.h
+++ b/embed/history/ephy-history-types.h
@@ -59,6 +59,10 @@ typedef struct _EphyHistoryURL
EphyHistoryPageVisit * ephy_history_page_visit_new (const char *url, gint64 visit_time, EphyHistoryPageVisitType visit_type);
EphyHistoryPageVisit * ephy_history_page_visit_copy (EphyHistoryPageVisit *visit);
void ephy_history_page_visit_free (EphyHistoryPageVisit *visit);
+
+GList * ephy_history_page_visit_list_copy (GList* original);
+void ephy_history_page_visit_list_free (GList* list);
+
EphyHistoryURL * ephy_history_url_new (const char *url, const char* title, int visit_count, int typed_count, int last_visit_time);
EphyHistoryURL * ephy_history_url_copy (EphyHistoryURL *url);
void ephy_history_url_free (EphyHistoryURL *url);
diff --git a/tests/ephy-history.c b/tests/ephy-history.c
index 7e1d4a5..8220538 100644
--- a/tests/ephy-history.c
+++ b/tests/ephy-history.c
@@ -85,6 +85,27 @@ test_create_history_entry (void)
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_page_visit_free (visit);
+
+ gtk_main ();
+}
+
+static void
+test_create_history_entries (void)
+{
+ gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
+ EphyHistoryService *service = ensure_empty_history(temporary_file);
+
+ GList *visits = NULL;
+ visits = g_list_append (visits, ephy_history_page_visit_new ("http://www.gnome.org", 0, EphyPageVisitTypeTyped));
+ visits = g_list_append (visits, ephy_history_page_visit_new ("http://www.gnome.org", 3, EphyPageVisitTypeTyped));
+ visits = g_list_append (visits, ephy_history_page_visit_new ("http://www.gnome.org", 5, EphyPageVisitTypeTyped));
+ visits = g_list_append (visits, ephy_history_page_visit_new ("http://www.cuteoverload.com", 7, EphyPageVisitTypeTyped));
+ visits = g_list_append (visits, ephy_history_page_visit_new ("http://www.cuteoverload.com", 8, EphyPageVisitTypeTyped));
+
+ ephy_history_service_add_visits (service, visits, page_vist_created);
+
+ ephy_history_page_visit_list_free (visits);
gtk_main ();
}
@@ -98,6 +119,7 @@ main (int argc, char *argv[])
g_test_add_func ("/embed/history/test_create_history_service", test_create_history_service);
g_test_add_func ("/embed/history/test_create_history_service_and_destroy_later", test_create_history_service_and_destroy_later);
g_test_add_func ("/embed/history/test_create_history_entry", test_create_history_entry);
+ g_test_add_func ("/embed/history/test_create_history_entries", test_create_history_entries);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]