[epiphany/wip/sync: 4/5] sync-service: Fix FIXME in upload_synchronizable_cb
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/sync: 4/5] sync-service: Fix FIXME in upload_synchronizable_cb
- Date: Wed, 3 May 2017 22:57:27 +0000 (UTC)
commit 88b4ee2f98a85f33f1b7ab59bf4e6dfd1effbf6a
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Wed May 3 20:45:38 2017 +0300
sync-service: Fix FIXME in upload_synchronizable_cb
lib/sync/ephy-password-manager.c | 73 ++++++++++++++++++-------------
lib/sync/ephy-sync-service.c | 2 +-
lib/sync/ephy-synchronizable-manager.c | 27 ++++++++++++
lib/sync/ephy-synchronizable-manager.h | 4 ++
src/bookmarks/ephy-bookmarks-manager.c | 12 +++++
5 files changed, 86 insertions(+), 32 deletions(-)
---
diff --git a/lib/sync/ephy-password-manager.c b/lib/sync/ephy-password-manager.c
index 0c0b219..3ce2a2c 100644
--- a/lib/sync/ephy-password-manager.c
+++ b/lib/sync/ephy-password-manager.c
@@ -793,6 +793,47 @@ synchronizable_manager_remove (EphySynchronizableManager *manager,
ephy_password_manager_forget_record (self, record);
}
+static void
+replace_record_cb (GSList *records,
+ gpointer user_data)
+{
+ ReplaceRecordAsyncData *data = (ReplaceRecordAsyncData *)user_data;
+
+ /* We only expect one matching record here. */
+ g_assert (g_slist_length (records) == 1);
+
+ ephy_password_manager_forget_record (data->manager, records->data);
+ ephy_password_manger_store_record (data->manager, data->record);
+
+ replace_record_async_data_free (data);
+}
+
+static void
+ephy_password_manager_replace_record (EphyPasswordManager *self,
+ EphyPasswordRecord *record)
+{
+ g_assert (EPHY_IS_PASSWORD_MANAGER (self));
+ g_assert (EPHY_IS_PASSWORD_RECORD (record));
+
+ ephy_password_manager_query (self,
+ ephy_password_record_get_hostname (record),
+ ephy_password_record_get_username (record),
+ ephy_password_record_get_username_field (record),
+ ephy_password_record_get_password_field (record),
+ replace_record_cb,
+ replace_record_async_data_new (self, record));
+}
+
+static void
+synchronizable_manager_save (EphySynchronizableManager *manager,
+ EphySynchronizable *synchronizable)
+{
+ EphyPasswordManager *self = EPHY_PASSWORD_MANAGER (manager);
+ EphyPasswordRecord *record = EPHY_PASSWORD_RECORD (synchronizable);
+
+ ephy_password_manager_replace_record (self, record);
+}
+
static EphyPasswordRecord *
get_record_by_id (GSList *records,
const char *id)
@@ -825,37 +866,6 @@ get_record_by_parameters (GSList *records,
return NULL;
}
-static void
-replace_record_cb (GSList *records,
- gpointer user_data)
-{
- ReplaceRecordAsyncData *data = (ReplaceRecordAsyncData *)user_data;
-
- /* We only expect one matching record here. */
- g_assert (g_slist_length (records) == 1);
-
- ephy_password_manager_forget_record (data->manager, records->data);
- ephy_password_manger_store_record (data->manager, data->record);
-
- replace_record_async_data_free (data);
-}
-
-static void
-ephy_password_manager_replace_record (EphyPasswordManager *self,
- EphyPasswordRecord *record)
-{
- g_assert (EPHY_IS_PASSWORD_MANAGER (self));
- g_assert (EPHY_IS_PASSWORD_RECORD (record));
-
- ephy_password_manager_query (self,
- ephy_password_record_get_hostname (record),
- ephy_password_record_get_username (record),
- ephy_password_record_get_username_field (record),
- ephy_password_record_get_password_field (record),
- replace_record_cb,
- replace_record_async_data_new (self, record));
-}
-
static GSList *
ephy_password_manager_handle_initial_merge (EphyPasswordManager *self,
GSList *local_records,
@@ -1053,5 +1063,6 @@ ephy_synchronizable_manager_iface_init (EphySynchronizableManagerInterface *ifac
iface->set_sync_time = synchronizable_manager_set_sync_time;
iface->add = synchronizable_manager_add;
iface->remove = synchronizable_manager_remove;
+ iface->save = synchronizable_manager_save;
iface->merge = synchronizable_manager_merge;
}
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index 657f1d9..0729179 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -1139,8 +1139,8 @@ upload_synchronizable_cb (SoupSession *session,
} else if (msg->status_code == 200) {
LOG ("Successfully uploaded to server");
time_modified = g_ascii_strtod (msg->response_body->data, NULL);
- /* FIXME: Make sure the synchronizable manager commits this change to file/database. */
ephy_synchronizable_set_server_time_modified (data->synchronizable, time_modified);
+ ephy_synchronizable_manager_save (data->manager, data->synchronizable);
} else {
g_warning ("Failed to upload object. Status code: %u, response: %s",
msg->status_code, msg->response_body->data);
diff --git a/lib/sync/ephy-synchronizable-manager.c b/lib/sync/ephy-synchronizable-manager.c
index 01c27f1..60212b7 100644
--- a/lib/sync/ephy-synchronizable-manager.c
+++ b/lib/sync/ephy-synchronizable-manager.c
@@ -42,6 +42,7 @@ ephy_synchronizable_manager_default_init (EphySynchronizableManagerInterface *if
iface->set_sync_time = ephy_synchronizable_manager_set_sync_time;
iface->add = ephy_synchronizable_manager_add;
iface->remove = ephy_synchronizable_manager_remove;
+ iface->save = ephy_synchronizable_manager_save;
iface->merge = ephy_synchronizable_manager_merge;
signals[SYNCHRONIZABLE_DELETED] =
@@ -219,6 +220,32 @@ ephy_synchronizable_manager_remove (EphySynchronizableManager *manager,
}
/**
+ * ephy_synchronizable_manager_save:
+ * @manager: an #EphySynchronizableManager
+ * @synchronizable: (transfer none): an #EphySynchronizable
+ *
+ * Saves @synchronizable in the local storage (e.g. file, database, secret schema).
+ * This should only be called on a synchronizable object that already exists in
+ * in @manager's collection (i.e. previously added with ephy_synchronizable_manager_add)
+ * as the @manager expects it to be present. Normally ephy_synchronizable_manager_add
+ * saves the object in the local storage, so the only use case of this function
+ * is to save an existing object which was modified outside the manager (i.e. modified
+ * by the sync service).
+ **/
+void
+ephy_synchronizable_manager_save (EphySynchronizableManager *manager,
+ EphySynchronizable *synchronizable)
+{
+ EphySynchronizableManagerInterface *iface;
+
+ g_return_if_fail (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager));
+ g_return_if_fail (EPHY_IS_SYNCHRONIZABLE (synchronizable));
+
+ iface = EPHY_SYNCHRONIZABLE_MANAGER_GET_IFACE (manager);
+ iface->save (manager, synchronizable);
+}
+
+/**
* ephy_synchronizable_manager_merge:
* @manager: an #EphySynchronizableManager
* @is_initial: a boolean saying whether the collection managed by @manager
diff --git a/lib/sync/ephy-synchronizable-manager.h b/lib/sync/ephy-synchronizable-manager.h
index e848b94..8c36332 100644
--- a/lib/sync/ephy-synchronizable-manager.h
+++ b/lib/sync/ephy-synchronizable-manager.h
@@ -47,6 +47,8 @@ struct _EphySynchronizableManagerInterface {
EphySynchronizable *synchronizable);
void (*remove) (EphySynchronizableManager *manager,
EphySynchronizable *synchronizable);
+ void (*save) (EphySynchronizableManager *manager,
+ EphySynchronizable *synchronizable);
void (*merge) (EphySynchronizableManager *manager,
gboolean is_initial,
GSList *remotes_deleted,
@@ -67,6 +69,8 @@ void ephy_synchronizable_manager_add (EphySyn
EphySynchronizable
*synchronizable);
void ephy_synchronizable_manager_remove (EphySynchronizableManager *manager,
EphySynchronizable
*synchronizable);
+void ephy_synchronizable_manager_save (EphySynchronizableManager *manager,
+ EphySynchronizable
*synchronizable);
void ephy_synchronizable_manager_merge (EphySynchronizableManager
*manager,
gboolean
is_initial,
GSList
*remotes_deleted,
diff --git a/src/bookmarks/ephy-bookmarks-manager.c b/src/bookmarks/ephy-bookmarks-manager.c
index 58c34a8..5eb20b3 100644
--- a/src/bookmarks/ephy-bookmarks-manager.c
+++ b/src/bookmarks/ephy-bookmarks-manager.c
@@ -727,6 +727,17 @@ synchronizable_manager_remove (EphySynchronizableManager *manager,
ephy_bookmarks_manager_remove_bookmark_internal (self, bookmark);
}
+static void
+synchronizable_manager_save (EphySynchronizableManager *manager,
+ EphySynchronizable *synchronizable)
+{
+ EphyBookmarksManager *self = EPHY_BOOKMARKS_MANAGER (manager);
+
+ ephy_bookmarks_manager_save_to_file_async (self, NULL,
+
(GAsyncReadyCallback)ephy_bookmarks_manager_save_to_file_warn_on_error_cb,
+ NULL);
+}
+
static GSList *
ephy_bookmarks_manager_handle_initial_merge (EphyBookmarksManager *self,
GSList *remote_bookmarks)
@@ -921,5 +932,6 @@ ephy_synchronizable_manager_iface_init (EphySynchronizableManagerInterface *ifac
iface->set_sync_time = synchronizable_manager_set_sync_time;
iface->add = synchronizable_manager_add;
iface->remove = synchronizable_manager_remove;
+ iface->save = synchronizable_manager_save;
iface->merge = synchronizable_manager_merge;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]