From 9ae7960ca8c3ca534ba07bb6d58b430ee9cda413 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 May 2003 19:39:09 +0000 Subject: Try to fix node removal problems. I cant repro crashes ... but they are 2003-05-25 Marco Pesenti Gritti * configure.in: * embed/ephy-favicon-cache.c: (ephy_favicon_cache_save): * embed/ephy-history.c: (ephy_history_save), (hosts_removed_cb), (pages_removed_cb), (unref_empty_host), (page_removed_from_host_cb), (connect_page_removed_from_host), (ephy_history_init), (ephy_history_add_host): * lib/ephy-file-helpers.c: (ephy_file_save_xml): * lib/ephy-file-helpers.h: * lib/ephy-node.c: (callback), (ephy_node_emit_signal), (real_remove_child), (ephy_node_dispose): * lib/ephy-node.h: * lib/ephy-state.c: (ephy_states_save): * lib/widgets/ephy-tree-model-node.c: (root_child_removed_cb): * src/bookmarks/ephy-bookmarks-export.c: (ephy_bookmarks_export_rdf): * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_save), (bookmarks_removed_cb), (topics_removed_cb): Try to fix node removal problems. I cant repro crashes ... but they are quite hard to reproduce. Use a save_xml helper that is low disk safe. * src/ephy-automation.c: (impl_ephy_automation_loadurl): Use OPEN_PAGE when an url is passed --- embed/ephy-favicon-cache.c | 2 +- embed/ephy-history.c | 61 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 17 deletions(-) (limited to 'embed') diff --git a/embed/ephy-favicon-cache.c b/embed/ephy-favicon-cache.c index 1391c5f5c..275348607 100644 --- a/embed/ephy-favicon-cache.c +++ b/embed/ephy-favicon-cache.c @@ -253,7 +253,7 @@ ephy_favicon_cache_save (EphyFaviconCache *eb) } ephy_node_thaw (eb->priv->icons); - xmlSaveFormatFile (eb->priv->xml_file, doc, 1); + ephy_file_save_xml (eb->priv->xml_file, doc); xmlFreeDoc (doc); } diff --git a/embed/ephy-history.c b/embed/ephy-history.c index c9541c618..525e13326 100644 --- a/embed/ephy-history.c +++ b/embed/ephy-history.c @@ -309,7 +309,7 @@ ephy_history_save (EphyHistory *eb) } ephy_node_thaw (eb->priv->pages); - xmlSaveFormatFile (eb->priv->xml_file, doc, 1); + ephy_file_save_xml (eb->priv->xml_file, doc); xmlFreeDoc(doc); } @@ -330,6 +330,7 @@ hosts_added_cb (EphyNode *node, static void hosts_removed_cb (EphyNode *node, EphyNode *child, + guint old_index, EphyHistory *eb) { g_static_rw_lock_writer_lock (eb->priv->hosts_hash_lock); @@ -357,29 +358,15 @@ pages_added_cb (EphyNode *node, static void pages_removed_cb (EphyNode *node, EphyNode *child, + guint old_index, EphyHistory *eb) { - EphyNode *host; - int host_id; - int children; - g_static_rw_lock_writer_lock (eb->priv->pages_hash_lock); g_hash_table_remove (eb->priv->pages_hash, ephy_node_get_property_string (child, EPHY_NODE_PAGE_PROP_LOCATION)); g_static_rw_lock_writer_unlock (eb->priv->pages_hash_lock); - - host_id = ephy_node_get_property_int (child, EPHY_NODE_PAGE_PROP_HOST_ID); - host = ephy_node_db_get_node_from_id (eb->priv->db, host_id); - children = ephy_node_get_n_children (host); - - LOG ("Check host children: %d", children) - - if (children == 0) - { - ephy_node_unref (host); - } } static gboolean @@ -391,6 +378,39 @@ periodic_save_cb (EphyHistory *eh) return TRUE; } +static gboolean +unref_empty_host (EphyNode *node) +{ + ephy_node_unref (node); + + return FALSE; +} + +static void +page_removed_from_host_cb (EphyNode *node, + EphyNode *child, + guint old_index, + EphyHistory *eb) +{ + if (ephy_node_get_n_children (node) == 0) + { + g_idle_add ((GSourceFunc)unref_empty_host, node); + } +} + +static void +connect_page_removed_from_host (char *url, + EphyNode *node, + EphyHistory *eb) +{ + if (node == eb->priv->pages) return; + + ephy_node_signal_connect_object (node, + EPHY_NODE_CHILD_REMOVED, + (EphyNodeCallback) page_removed_from_host_cb, + G_OBJECT (eb)); +} + static void ephy_history_init (EphyHistory *eb) { @@ -460,6 +480,10 @@ ephy_history_init (EphyHistory *eb) ephy_history_load (eb); ephy_history_emit_data_changed (eb); + g_hash_table_foreach (eb->priv->hosts_hash, + (GHFunc) connect_page_removed_from_host, + eb); + /* setup the periodic history saving callback */ eb->priv->autosave_timeout = g_timeout_add (HISTORY_SAVE_INTERVAL, @@ -614,6 +638,11 @@ ephy_history_add_host (EphyHistory *eh, EphyNode *page) if (!host) { host = ephy_node_new (eh->priv->db); + ephy_node_signal_connect_object (host, + EPHY_NODE_CHILD_REMOVED, + (EphyNodeCallback) page_removed_from_host_cb, + G_OBJECT (eh)); + g_value_init (&value, G_TYPE_STRING); g_value_set_string (&value, host_name); ephy_node_set_property (host, EPHY_NODE_PAGE_PROP_TITLE, -- cgit v1.2.3