[epiphany] history/password-manager: Remove deleted records from memory too
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] history/password-manager: Remove deleted records from memory too
- Date: Tue, 15 Aug 2017 14:02:47 +0000 (UTC)
commit 32000a52343ccd2b13f75784b519faf8902201de
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date: Tue Aug 15 16:44:21 2017 +0300
history/password-manager: Remove deleted records from memory too
This ensures that records which have been deleted from disk but still
exist in memory are not taken into consideration while merging records
at sync time.
lib/sync/ephy-history-manager.c | 35 ++++++++++++++++++++++++++---------
lib/sync/ephy-password-manager.c | 34 +++++++++++++++++++++++++---------
2 files changed, 51 insertions(+), 18 deletions(-)
---
diff --git a/lib/sync/ephy-history-manager.c b/lib/sync/ephy-history-manager.c
index 2d0fd48..f436c2f 100644
--- a/lib/sync/ephy-history-manager.c
+++ b/lib/sync/ephy-history-manager.c
@@ -314,6 +314,20 @@ get_record_by_url (GSList *records,
return NULL;
}
+static GSList *
+delete_record_by_id (GSList *records,
+ const char *id)
+{
+ for (GSList *l = records; l && l->data; l = l->next) {
+ if (!g_strcmp0 (ephy_history_record_get_id (l->data), id)) {
+ g_object_unref (l->data);
+ return g_slist_delete_link (records, l);
+ }
+ }
+
+ return records;
+}
+
static void
ephy_history_manager_handle_different_id_same_url (EphyHistoryManager *self,
EphyHistoryRecord *local,
@@ -414,10 +428,10 @@ ephy_history_manager_handle_initial_merge (EphyHistoryManager *self,
}
static GSList *
-ephy_history_manager_handle_regular_merge (EphyHistoryManager *self,
- GSList *local_records,
- GSList *deleted_records,
- GSList *updated_records)
+ephy_history_manager_handle_regular_merge (EphyHistoryManager *self,
+ GSList **local_records,
+ GSList *deleted_records,
+ GSList *updated_records)
{
EphyHistoryRecord *record;
GSList *to_upload = NULL;
@@ -429,10 +443,13 @@ ephy_history_manager_handle_regular_merge (EphyHistoryManager *self,
g_assert (EPHY_IS_HISTORY_MANAGER (self));
for (GSList *l = deleted_records; l && l->data; l = l->next) {
- record = get_record_by_id (local_records, ephy_history_record_get_id (l->data));
- if (record)
+ remote_id = ephy_history_record_get_id (l->data);
+ record = get_record_by_id (*local_records, remote_id);
+ if (record) {
ephy_synchronizable_manager_remove (EPHY_SYNCHRONIZABLE_MANAGER (self),
EPHY_SYNCHRONIZABLE (record));
+ *local_records = delete_record_by_id (*local_records, remote_id);
+ }
}
/* See comment in ephy_history_manager_handle_initial_merge. */
@@ -441,7 +458,7 @@ ephy_history_manager_handle_regular_merge (EphyHistoryManager *self,
remote_url = ephy_history_record_get_uri (l->data);
remote_last_visit_time = ephy_history_record_get_last_visit_time (l->data);
- record = get_record_by_id (local_records, remote_id);
+ record = get_record_by_id (*local_records, remote_id);
if (record) {
/* Same ID, same URL. Update last visit time for the local record. */
local_last_visit_time = ephy_history_record_get_last_visit_time (record);
@@ -460,7 +477,7 @@ ephy_history_manager_handle_regular_merge (EphyHistoryManager *self,
remote_id, remote_last_visit_time,
EPHY_PAGE_VISIT_LINK, FALSE);
} else {
- record = get_record_by_url (local_records, remote_url);
+ record = get_record_by_url (*local_records, remote_url);
if (record) {
/* Different ID, same URL. Keep local ID. */
g_signal_emit_by_name (self, "synchronizable-deleted", l->data);
@@ -512,7 +529,7 @@ merge_history_cb (EphyHistoryService *service,
data->remotes_updated);
else
to_upload = ephy_history_manager_handle_regular_merge (data->manager,
- records,
+ &records,
data->remotes_deleted,
data->remotes_updated);
diff --git a/lib/sync/ephy-password-manager.c b/lib/sync/ephy-password-manager.c
index bd190a6..5c25220 100644
--- a/lib/sync/ephy-password-manager.c
+++ b/lib/sync/ephy-password-manager.c
@@ -887,6 +887,20 @@ get_record_by_parameters (GSList *records,
}
static GSList *
+delete_record_by_id (GSList *records,
+ const char *id)
+{
+ for (GSList *l = records; l && l->data; l = l->next) {
+ if (!g_strcmp0 (ephy_password_record_get_id (l->data), id)) {
+ g_object_unref (l->data);
+ return g_slist_delete_link (records, l);
+ }
+ }
+
+ return records;
+}
+
+static GSList *
ephy_password_manager_handle_initial_merge (EphyPasswordManager *self,
GSList *local_records,
GSList *remote_records)
@@ -987,10 +1001,10 @@ ephy_password_manager_handle_initial_merge (EphyPasswordManager *self,
}
static GSList *
-ephy_password_manager_handle_regular_merge (EphyPasswordManager *self,
- GSList *local_records,
- GSList *deleted_records,
- GSList *updated_records)
+ephy_password_manager_handle_regular_merge (EphyPasswordManager *self,
+ GSList **local_records,
+ GSList *deleted_records,
+ GSList *updated_records)
{
EphyPasswordRecord *record;
GSList *to_upload = NULL;
@@ -1006,9 +1020,11 @@ ephy_password_manager_handle_regular_merge (EphyPasswordManager *self,
for (GSList *l = deleted_records; l && l->data; l = l->next) {
remote_id = ephy_password_record_get_id (l->data);
- record = get_record_by_id (local_records, remote_id);
- if (record)
+ record = get_record_by_id (*local_records, remote_id);
+ if (record) {
ephy_password_manager_forget_record (self, record, NULL);
+ *local_records = delete_record_by_id (*local_records, remote_id);
+ }
}
/* See comment in ephy_password_manager_handle_initial_merge. */
@@ -1020,12 +1036,12 @@ ephy_password_manager_handle_regular_merge (EphyPasswordManager *self,
remote_password_field = ephy_password_record_get_password_field (l->data);
remote_timestamp = ephy_password_record_get_time_password_changed (l->data);
- record = get_record_by_id (local_records, remote_id);
+ record = get_record_by_id (*local_records, remote_id);
if (record) {
/* Same id. Overwrite local record. */
ephy_password_manager_forget_record (self, record, l->data);
} else {
- record = get_record_by_parameters (local_records,
+ record = get_record_by_parameters (*local_records,
remote_hostname,
remote_username,
remote_username_field,
@@ -1064,7 +1080,7 @@ merge_cb (GSList *records,
data->remotes_updated);
else
to_upload = ephy_password_manager_handle_regular_merge (data->manager,
- records,
+ &records,
data->remotes_deleted,
data->remotes_updated);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]