[epiphany/wip/sync: 76/83] sync-service: Delete old sync functions
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/sync: 76/83] sync-service: Delete old sync functions
- Date: Mon, 3 Apr 2017 13:14:19 +0000 (UTC)
commit e69e5703fc4eb80d3b8c07c4cf3959e8627b9870
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Wed Mar 29 15:58:54 2017 +0300
sync-service: Delete old sync functions
data/org.gnome.epiphany.gschema.xml | 5 -
lib/ephy-prefs.h | 1 -
src/bookmarks/ephy-bookmark-properties-grid.c | 4 +-
src/bookmarks/ephy-bookmark.c | 90 -----
src/bookmarks/ephy-bookmark.h | 5 -
src/ephy-shell.c | 2 +-
src/prefs-dialog.c | 5 +-
src/sync/ephy-sync-service.c | 476 +------------------------
src/sync/ephy-sync-service.h | 17 +-
9 files changed, 9 insertions(+), 596 deletions(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index c2f2c26..bc4dc4e 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -272,11 +272,6 @@
<summary>Currently signed in sync user</summary>
<description>The email linked to the Firefox Account used to sync data with Mozilla’s
servers.</description>
</key>
- <key type="d" name="sync-time">
- <default>0</default>
- <summary>Sync timestamp</summary>
- <description>The timestamp at which last sync was made.</description>
- </key>
<key type="d" name="bookmarks-sync-time">
<default>0</default>
<summary>Bookmarks sync timestamp</summary>
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index 6c2a2f9..b329ed5 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -151,7 +151,6 @@ static const char * const ephy_prefs_web_schema[] = {
#define EPHY_PREFS_SYNC_SCHEMA "org.gnome.Epiphany.sync"
#define EPHY_PREFS_SYNC_USER "sync-user"
-#define EPHY_PREFS_SYNC_TIME "sync-time"
#define EPHY_PREFS_SYNC_BOOKMARKS_SYNC_TIME "bookmarks-sync-time"
static struct {
diff --git a/src/bookmarks/ephy-bookmark-properties-grid.c b/src/bookmarks/ephy-bookmark-properties-grid.c
index 081d3e7..f7473d6 100644
--- a/src/bookmarks/ephy-bookmark-properties-grid.c
+++ b/src/bookmarks/ephy-bookmark-properties-grid.c
@@ -250,7 +250,9 @@ ephy_bookmarks_properties_grid_actions_remove_bookmark (GSimpleAction *action,
#ifdef ENABLE_SYNC
service = ephy_shell_get_sync_service (ephy_shell_get_default ());
- ephy_sync_service_delete_bookmark (service, self->bookmark, FALSE);
+ ephy_sync_service_delete_synchronizable (service,
+ EPHY_SYNCHRONIZABLE_MANAGER (self->manager),
+ EPHY_SYNCHRONIZABLE (self->bookmark));
#endif
ephy_bookmarks_manager_remove_bookmark (self->manager, self->bookmark);
diff --git a/src/bookmarks/ephy-bookmark.c b/src/bookmarks/ephy-bookmark.c
index a039aaa..83b6e4f 100644
--- a/src/bookmarks/ephy-bookmark.c
+++ b/src/bookmarks/ephy-bookmark.c
@@ -703,93 +703,3 @@ ephy_bookmark_tags_compare (const char *tag1, const char *tag2)
return result;
}
-
-#ifdef ENABLE_SYNC
-char *
-ephy_bookmark_to_bso (EphyBookmark *self)
-{
- EphySyncService *service;
- guint8 *encrypted;
- guint8 *sync_key;
- char *serialized;
- char *payload;
- char *bso;
- gsize length;
-
- g_return_val_if_fail (EPHY_IS_BOOKMARK (self), NULL);
-
- /* Convert a Bookmark object to a BSO (Basic Store Object). That is a generic
- * JSON wrapper around all items passed into and out of the SyncStorage server.
- * The current flow is:
- * 1. Serialize the Bookmark to a JSON string.
- * 2. Encrypt the JSON string using the sync key from the sync service.
- * 3. Encode the encrypted bytes to base64 url safe.
- * 4. Create a new JSON string that contains the id of the Bookmark and the
- encoded bytes as payload. This is actually the BSO that is going to be
- stored on the SyncStorage server.
- * See https://docs.services.mozilla.com/storage/apis-1.5.html
- */
-
- service = ephy_shell_get_sync_service (ephy_shell_get_default ());
- sync_key = ephy_sync_crypto_decode_hex (ephy_sync_service_get_token (service, TOKEN_KB));
- serialized = json_gobject_to_data (G_OBJECT (self), NULL);
- encrypted = ephy_sync_crypto_aes_256 (AES_256_MODE_ENCRYPT, sync_key,
- (guint8 *)serialized, strlen (serialized), &length);
- payload = ephy_sync_crypto_base64_urlsafe_encode (encrypted, length, FALSE);
- bso = ephy_sync_utils_create_bso_json (self->id, payload);
-
- g_free (sync_key);
- g_free (serialized);
- g_free (encrypted);
- g_free (payload);
-
- return bso;
-}
-
-EphyBookmark *
-ephy_bookmark_from_bso (JsonObject *bso)
-{
- EphySyncService *service;
- EphyBookmark *bookmark = NULL;
- GObject *object;
- GError *error = NULL;
- guint8 *sync_key;
- guint8 *decoded;
- gsize decoded_len;
- char *decrypted;
-
- g_return_val_if_fail (bso != NULL, NULL);
-
- /* Convert a BSO to a Bookmark object. The flow is similar to the one from
- * ephy_bookmark_to_bso(), only that the steps are reversed:
- * 1. Decode the payload from base64 url safe to raw bytes.
- * 2. Decrypt the bytes using the sync key to obtain the serialized Bookmark.
- * 3. Deserialize the JSON string into a Bookmark object.
- */
-
- service = ephy_shell_get_sync_service (ephy_shell_get_default ());
- sync_key = ephy_sync_crypto_decode_hex (ephy_sync_service_get_token (service, TOKEN_KB));
- decoded = ephy_sync_crypto_base64_urlsafe_decode (json_object_get_string_member (bso, "payload"),
- &decoded_len, FALSE);
- decrypted = (char *)ephy_sync_crypto_aes_256 (AES_256_MODE_DECRYPT, sync_key,
- decoded, decoded_len, NULL);
- object = json_gobject_from_data (EPHY_TYPE_BOOKMARK, decrypted, strlen (decrypted), &error);
-
- if (object == NULL) {
- g_warning ("Failed to create GObject from data: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- bookmark = EPHY_BOOKMARK (object);
- ephy_bookmark_set_id (bookmark, json_object_get_string_member (bso, "id"));
- ephy_bookmark_set_modification_time (bookmark, json_object_get_double_member (bso, "modified"));
- ephy_bookmark_set_is_uploaded (bookmark, TRUE);
-
-out:
- g_free (decoded);
- g_free (decrypted);
-
- return bookmark;
-}
-#endif
diff --git a/src/bookmarks/ephy-bookmark.h b/src/bookmarks/ephy-bookmark.h
index 9eeb9eb..8763365 100644
--- a/src/bookmarks/ephy-bookmark.h
+++ b/src/bookmarks/ephy-bookmark.h
@@ -71,9 +71,4 @@ int ephy_bookmark_bookmarks_compare_func (EphyBookmark *bookm
int ephy_bookmark_tags_compare (const char *tag1,
const char *tag2);
-#ifdef ENABLE_SYNC
-char *ephy_bookmark_to_bso (EphyBookmark *self);
-EphyBookmark *ephy_bookmark_from_bso (JsonObject *bso);
-#endif
-
G_END_DECLS
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index decc08b..d580831 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -325,7 +325,7 @@ sync_tokens_load_finished_cb (EphySyncService *service,
/* If the tokens were successfully loaded, start the periodical sync.
* Otherwise, notify the user to sign in again. */
if (error == NULL) {
- ephy_sync_service_start_periodical_sync (service, TRUE);
+ ephy_sync_service_start_periodical_sync (service);
} else {
notification = ephy_notification_new (error->message,
_("Please visit Preferences and sign in "
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index ea883eb..bd2d20c 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -234,9 +234,8 @@ sync_tokens_store_finished_cb (EphySyncService *service,
EPHY_PREFS_SYNC_USER,
ephy_sync_service_get_user_email (service));
- /* Do a first time sync and set a periodical sync to be executed. */
- ephy_sync_service_sync_bookmarks (service, TRUE);
- ephy_sync_service_start_periodical_sync (service, FALSE);
+ /* Start syncing. */
+ ephy_sync_service_start_periodical_sync (service);
} else {
/* Destroy the current session. */
ephy_sync_service_destroy_session (service, NULL);
diff --git a/src/sync/ephy-sync-service.c b/src/sync/ephy-sync-service.c
index fd3f397..f2d4d00 100644
--- a/src/sync/ephy-sync-service.c
+++ b/src/sync/ephy-sync-service.c
@@ -21,8 +21,6 @@
#include "config.h"
#include "ephy-sync-service.h"
-#include "ephy-bookmark.h"
-#include "ephy-bookmarks-manager.h"
#include "ephy-debug.h"
#include "ephy-embed-prefs.h"
#include "ephy-notification.h"
@@ -37,7 +35,6 @@
#define MOZILLA_TOKEN_SERVER_URL "https://token.services.mozilla.com/1.0/sync/1.5"
#define MOZILLA_FXA_SERVER_URL "https://api.accounts.firefox.com/v1/"
-#define EPHY_BOOKMARKS_COLLECTION "ephy-bookmarks"
#define SYNC_FREQUENCY (15 * 60) /* seconds */
#define CERTIFICATE_DURATION (60 * 60 * 1000) /* milliseconds, limited to 24 hours */
#define ASSERTION_DURATION (5 * 60) /* seconds */
@@ -784,29 +781,6 @@ ephy_sync_service_set_user_email (EphySyncService *self,
self->user_email = g_strdup (email);
}
-double
-ephy_sync_service_get_sync_time (EphySyncService *self)
-{
- g_return_val_if_fail (EPHY_IS_SYNC_SERVICE (self), 0);
-
- if (self->sync_time != 0)
- return self->sync_time;
-
- self->sync_time = g_settings_get_double (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_TIME);
- return self->sync_time;
-}
-
-
-void
-ephy_sync_service_set_sync_time (EphySyncService *self,
- double time)
-{
- g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
-
- self->sync_time = time;
- g_settings_set_double (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_TIME, time);
-}
-
const char *
ephy_sync_service_get_token (EphySyncService *self,
EphySyncTokenType type)
@@ -1187,442 +1161,11 @@ ephy_sync_service_do_sign_out (EphySyncService *self)
ephy_sync_service_clear_tokens (self);
ephy_sync_secret_forget_tokens ();
ephy_sync_service_set_user_email (self, NULL);
- ephy_sync_service_set_sync_time (self, 0);
g_settings_set_string (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_USER, "");
}
static void
-upload_bookmark_cb (SoupSession *session,
- SoupMessage *msg,
- gpointer user_data)
-{
- EphySyncService *service;
- EphyBookmarksManager *manager;
- EphyBookmark *bookmark;
- double last_modified;
-
- service = ephy_shell_get_sync_service (ephy_shell_get_default ());
- manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
- bookmark = EPHY_BOOKMARK (user_data);
-
- if (msg->status_code == 200) {
- last_modified = g_ascii_strtod (msg->response_body->data, NULL);
- ephy_bookmark_set_modification_time (bookmark, last_modified);
- ephy_bookmark_set_is_uploaded (bookmark, TRUE);
- ephy_bookmarks_manager_save_to_file_async (manager, NULL, NULL, NULL);
- LOG ("Successfully uploaded bookmark");
- } else if (msg->status_code == 412) {
- ephy_sync_service_download_bookmark (service, bookmark);
- } else {
- g_warning ("Failed to upload bookmark. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
- }
-
- ephy_sync_service_send_next_storage_request (service);
-}
-
-void
-ephy_sync_service_upload_bookmark (EphySyncService *self,
- EphyBookmark *bookmark,
- gboolean force)
-{
- char *endpoint;
- char *bso;
- double modified;
-
- g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
- g_return_if_fail (ephy_sync_service_is_signed_in (self));
- g_return_if_fail (EPHY_IS_BOOKMARK (bookmark));
-
- endpoint = g_strdup_printf ("storage/%s/%s",
- EPHY_BOOKMARKS_COLLECTION,
- ephy_bookmark_get_id (bookmark));
- bso = ephy_bookmark_to_bso (bookmark);
- modified = ephy_bookmark_get_modification_time (bookmark);
- ephy_sync_service_queue_storage_request (self, endpoint,
- SOUP_METHOD_PUT, bso, -1,
- force ? -1 : modified,
- upload_bookmark_cb, bookmark);
-
- g_free (endpoint);
- g_free (bso);
-}
-
-static void
-download_bookmark_cb (SoupSession *session,
- SoupMessage *msg,
- gpointer user_data)
-{
- EphySyncService *service;
- EphyBookmarksManager *manager;
- EphyBookmark *bookmark;
- GSequenceIter *iter;
- JsonParser *parser;
- JsonObject *bso;
- const char *id;
-
- if (msg->status_code != 200) {
- g_warning ("Failed to download bookmark. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
- goto out;
- }
-
- parser = json_parser_new ();
- json_parser_load_from_data (parser, msg->response_body->data, -1, NULL);
- bso = json_node_get_object (json_parser_get_root (parser));
- bookmark = ephy_bookmark_from_bso (bso);
- id = ephy_bookmark_get_id (bookmark);
-
- /* Overwrite any local bookmark. */
- manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
- ephy_bookmarks_manager_remove_bookmark (manager,
- ephy_bookmarks_manager_get_bookmark_by_id (manager, id));
- ephy_bookmarks_manager_add_bookmark (manager, bookmark);
-
- /* We have to manually add the tags to the bookmarks manager. */
- for (iter = g_sequence_get_begin_iter (ephy_bookmark_get_tags (bookmark));
- !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter))
- ephy_bookmarks_manager_create_tag (manager, g_sequence_get (iter));
-
- LOG ("Successfully downloaded bookmark");
- g_object_unref (bookmark);
- g_object_unref (parser);
-
-out:
- service = ephy_shell_get_sync_service (ephy_shell_get_default ());
- ephy_sync_service_send_next_storage_request (service);
-}
-
-void
-ephy_sync_service_download_bookmark (EphySyncService *self,
- EphyBookmark *bookmark)
-{
- char *endpoint;
-
- g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
- g_return_if_fail (ephy_sync_service_is_signed_in (self));
- g_return_if_fail (EPHY_IS_BOOKMARK (bookmark));
-
- endpoint = g_strdup_printf ("storage/%s/%s",
- EPHY_BOOKMARKS_COLLECTION,
- ephy_bookmark_get_id (bookmark));
- ephy_sync_service_queue_storage_request (self, endpoint,
- SOUP_METHOD_GET, NULL, -1, -1,
- download_bookmark_cb, NULL);
-
- g_free (endpoint);
-}
-
-static void
-delete_bookmark_conditional_cb (SoupSession *session,
- SoupMessage *msg,
- gpointer user_data)
-{
- EphySyncService *service;
- EphyBookmark *bookmark;
- EphyBookmarksManager *manager;
-
- bookmark = EPHY_BOOKMARK (user_data);
- manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
-
- if (msg->status_code == 404)
- ephy_bookmarks_manager_remove_bookmark (manager, bookmark);
- else if (msg->status_code == 200)
- LOG ("The bookmark still exists on the server");
- else
- g_warning ("Failed to delete bookmark. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
-
- service = ephy_shell_get_sync_service (ephy_shell_get_default ());
- ephy_sync_service_send_next_storage_request (service);
-}
-
-static void
-delete_bookmark_cb (SoupSession *session,
- SoupMessage *msg,
- gpointer user_data)
-{
- EphySyncService *service;
-
- if (msg->status_code != 200)
- g_warning ("Failed to delete bookmark. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
- else
- LOG ("Successfully deleted bookmark");
-
- service = ephy_shell_get_sync_service (ephy_shell_get_default ());
- ephy_sync_service_send_next_storage_request (service);
-}
-
-void
-ephy_sync_service_delete_bookmark (EphySyncService *self,
- EphyBookmark *bookmark,
- gboolean conditional)
-{
- char *endpoint;
-
- g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
- g_return_if_fail (ephy_sync_service_is_signed_in (self));
- g_return_if_fail (EPHY_IS_BOOKMARK (bookmark));
-
- endpoint = g_strdup_printf ("storage/%s/%s",
- EPHY_BOOKMARKS_COLLECTION,
- ephy_bookmark_get_id (bookmark));
-
- /* If the bookmark does not exist on the server, delete it from the local
- * instance too. */
- if (conditional) {
- ephy_sync_service_queue_storage_request (self, endpoint,
- SOUP_METHOD_GET, NULL, -1, -1,
- delete_bookmark_conditional_cb,
- bookmark);
- } else {
- ephy_sync_service_queue_storage_request (self, endpoint,
- SOUP_METHOD_DELETE, NULL, -1, -1,
- delete_bookmark_cb, NULL);
- }
-
- g_free (endpoint);
-}
-
-static void
-sync_bookmarks_first_time_cb (SoupSession *session,
- SoupMessage *msg,
- gpointer user_data)
-{
- EphySyncService *service;
- EphyBookmarksManager *manager;
- GSequence *bookmarks;
- GSequenceIter *iter;
- GHashTable *marked;
- JsonParser *parser;
- JsonArray *array;
- const char *timestamp;
- double server_time;
-
- if (msg->status_code != 200) {
- g_warning ("Failed to first time sync bookmarks. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
- goto out;
- }
-
- service = ephy_shell_get_sync_service (ephy_shell_get_default ());
- manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
- bookmarks = ephy_bookmarks_manager_get_bookmarks (manager);
- marked = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
- parser = json_parser_new ();
- json_parser_load_from_data (parser, msg->response_body->data, -1, NULL);
-
- array = json_node_get_array (json_parser_get_root (parser));
- for (gsize i = 0; i < json_array_get_length (array); i++) {
- JsonObject *bso = json_array_get_object_element (array, i);
- EphyBookmark *remote = ephy_bookmark_from_bso (bso);
- EphyBookmark *local;
-
- if (!remote)
- continue;
-
- local = ephy_bookmarks_manager_get_bookmark_by_id (manager, ephy_bookmark_get_id (remote));
-
- if (!local) {
- local = ephy_bookmarks_manager_get_bookmark_by_url (manager, ephy_bookmark_get_url (remote));
-
- /* If there is no local equivalent of the remote bookmark, then add it to
- * the local instance together with its tags. */
- if (!local) {
- ephy_bookmarks_manager_add_bookmark (manager, remote);
-
- /* We have to manually add the tags to the bookmarks manager. */
- for (iter = g_sequence_get_begin_iter (ephy_bookmark_get_tags (remote));
- !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter))
- ephy_bookmarks_manager_create_tag (manager, g_sequence_get (iter));
-
- g_hash_table_add (marked, g_object_ref (remote));
- }
- /* If there is a local bookmark with the same url as the remote one, then
- * merge tags into the local one, keep the remote id and upload it to the
- * server. */
- else {
- for (iter = g_sequence_get_begin_iter (ephy_bookmark_get_tags (remote));
- !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter)) {
- ephy_bookmark_add_tag (local, g_sequence_get (iter));
- ephy_bookmarks_manager_create_tag (manager, g_sequence_get (iter));
- }
-
- ephy_bookmark_set_id (local, ephy_bookmark_get_id (remote));
- ephy_sync_service_upload_bookmark (service, local, TRUE);
- g_hash_table_add (marked, g_object_ref (local));
- }
- }
- /* Having a local bookmark with the same id as the remote one means that the
- * bookmark has been synced before in the past. Keep the one with the most
- * recent modified timestamp. */
- else {
- if (ephy_bookmark_get_modification_time (remote) > ephy_bookmark_get_modification_time (local)) {
- ephy_bookmarks_manager_remove_bookmark (manager, local);
- ephy_bookmarks_manager_add_bookmark (manager, remote);
-
- /* We have to manually add the tags to the bookmarks manager. */
- for (iter = g_sequence_get_begin_iter (ephy_bookmark_get_tags (remote));
- !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter))
- ephy_bookmarks_manager_create_tag (manager, g_sequence_get (iter));
-
- g_hash_table_add (marked, g_object_ref (remote));
- } else {
- if (ephy_bookmark_get_modification_time (local) > ephy_bookmark_get_modification_time (remote))
- ephy_sync_service_upload_bookmark (service, local, TRUE);
-
- g_hash_table_add (marked, g_object_ref (local));
- }
- }
-
- g_object_unref (remote);
- }
-
- /* Upload the remaining local bookmarks to the server. */
- for (iter = g_sequence_get_begin_iter (bookmarks);
- !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter)) {
- EphyBookmark *bookmark = g_sequence_get (iter);
-
- if (!g_hash_table_contains (marked, bookmark))
- ephy_sync_service_upload_bookmark (service, bookmark, TRUE);
- }
-
- /* Save changes to file. */
- ephy_bookmarks_manager_save_to_file_async (manager, NULL, NULL, NULL);
-
- /* Set the sync time. */
- timestamp = soup_message_headers_get_one (msg->response_headers, "X-Weave-Timestamp");
- server_time = g_ascii_strtod (timestamp, NULL);
- ephy_sync_service_set_sync_time (service, server_time);
-
- g_object_unref (parser);
- g_hash_table_unref (marked);
-
-out:
- ephy_sync_service_send_next_storage_request (service);
-}
-
-static void
-sync_bookmarks_cb (SoupSession *session,
- SoupMessage *msg,
- gpointer user_data)
-{
- EphySyncService *service;
- EphyBookmarksManager *manager;
- GSequence *bookmarks;
- GSequenceIter *iter;
- JsonParser *parser;
- JsonArray *array;
- const char *timestamp;
- double server_time;
-
- service = ephy_shell_get_sync_service (ephy_shell_get_default ());
- manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
- bookmarks = ephy_bookmarks_manager_get_bookmarks (manager);
-
- /* Code 304 indicates that the resource has not been modified. Therefore,
- * only upload the local bookmarks that were not uploaded. */
- if (msg->status_code == 304)
- goto handle_local_bookmarks;
-
- if (msg->status_code != 200) {
- g_warning ("Failed to sync bookmarks. Status code: %u, response: %s",
- msg->status_code, msg->response_body->data);
- goto out;
- }
-
- parser = json_parser_new ();
- json_parser_load_from_data (parser, msg->response_body->data, -1, NULL);
- array = json_node_get_array (json_parser_get_root (parser));
-
- for (gsize i = 0; i < json_array_get_length (array); i++) {
- JsonObject *bso = json_array_get_object_element (array, i);
- EphyBookmark *remote = ephy_bookmark_from_bso (bso);
- EphyBookmark *local;
-
- if (!remote)
- continue;
-
- local = ephy_bookmarks_manager_get_bookmark_by_id (manager, ephy_bookmark_get_id (remote));
-
- if (!local) {
- ephy_bookmarks_manager_add_bookmark (manager, remote);
-
- /* We have to manually add the tags to the bookmarks manager. */
- for (iter = g_sequence_get_begin_iter (ephy_bookmark_get_tags (remote));
- !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter))
- ephy_bookmarks_manager_create_tag (manager, g_sequence_get (iter));
- } else {
- if (ephy_bookmark_get_modification_time (remote) > ephy_bookmark_get_modification_time (local)) {
- ephy_bookmarks_manager_remove_bookmark (manager, local);
- ephy_bookmarks_manager_add_bookmark (manager, remote);
-
- /* We have to manually add the tags to the bookmarks manager. */
- for (iter = g_sequence_get_begin_iter (ephy_bookmark_get_tags (remote));
- !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter))
- ephy_bookmarks_manager_create_tag (manager, g_sequence_get (iter));
- } else {
- if (ephy_bookmark_get_modification_time (local) > ephy_bookmark_get_modification_time (remote))
- ephy_sync_service_upload_bookmark (service, local, TRUE);
-
- g_object_unref (remote);
- }
- }
- }
-
- g_object_unref (parser);
-
-handle_local_bookmarks:
- for (iter = g_sequence_get_begin_iter (bookmarks);
- !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter)) {
- EphyBookmark *bookmark = EPHY_BOOKMARK (g_sequence_get (iter));
-
- if (ephy_bookmark_is_uploaded (bookmark))
- ephy_sync_service_delete_bookmark (service, bookmark, TRUE);
- else
- ephy_sync_service_upload_bookmark (service, bookmark, FALSE);
- }
-
- /* Save changes to file. */
- ephy_bookmarks_manager_save_to_file_async (manager, NULL, NULL, NULL);
-
- /* Set the sync time. */
- timestamp = soup_message_headers_get_one (msg->response_headers, "X-Weave-Timestamp");
- server_time = g_ascii_strtod (timestamp, NULL);
- ephy_sync_service_set_sync_time (service, server_time);
-
-out:
- ephy_sync_service_send_next_storage_request (service);
-}
-
-void
-ephy_sync_service_sync_bookmarks (EphySyncService *self,
- gboolean first)
-{
- char *endpoint;
-
- g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
- g_return_if_fail (ephy_sync_service_is_signed_in (self));
-
- endpoint = g_strdup_printf ("storage/%s?full=true", EPHY_BOOKMARKS_COLLECTION);
-
- if (first) {
- ephy_sync_service_queue_storage_request (self, endpoint,
- SOUP_METHOD_GET, NULL, -1, -1,
- sync_bookmarks_first_time_cb, NULL);
- } else {
- ephy_sync_service_queue_storage_request (self, endpoint,
- SOUP_METHOD_GET, NULL,
- ephy_sync_service_get_sync_time (self), -1,
- sync_bookmarks_cb, NULL);
- }
-
- g_free (endpoint);
-}
-
-static void
test_and_remove_synchronizable_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
@@ -2129,28 +1672,13 @@ ephy_sync_service_obtain_sync_key_bundles (EphySyncService *self)
obtain_sync_key_bundles_cb, NULL);
}
-static gboolean
-do_periodical_sync (gpointer user_data)
-{
- EphySyncService *service;
-
- service = ephy_shell_get_sync_service (ephy_shell_get_default ());
- ephy_sync_service_sync_bookmarks (service, FALSE);
-
- return G_SOURCE_CONTINUE;
-}
-
void
-ephy_sync_service_start_periodical_sync (EphySyncService *self,
- gboolean now)
+ephy_sync_service_start_periodical_sync (EphySyncService *self)
{
g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
g_return_if_fail (ephy_sync_service_is_signed_in (self));
- if (now)
- do_periodical_sync (self);
-
- self->source_id = g_timeout_add_seconds (SYNC_FREQUENCY, do_periodical_sync, NULL);
+ /* TODO: Re-implement this. */
}
void
diff --git a/src/sync/ephy-sync-service.h b/src/sync/ephy-sync-service.h
index 2d1f371..f677ba4 100644
--- a/src/sync/ephy-sync-service.h
+++ b/src/sync/ephy-sync-service.h
@@ -20,7 +20,6 @@
#pragma once
-#include "ephy-bookmark.h"
#include "ephy-sync-crypto.h"
#include "ephy-sync-utils.h"
#include "ephy-synchronizable-manager.h"
@@ -39,9 +38,6 @@ gboolean ephy_sync_service_is_signed_in (EphySyncServi
const char *ephy_sync_service_get_user_email (EphySyncService *self);
void ephy_sync_service_set_user_email (EphySyncService *self,
const char *email);
-double ephy_sync_service_get_sync_time (EphySyncService *self);
-void ephy_sync_service_set_sync_time (EphySyncService *self,
- double time);
const char *ephy_sync_service_get_token (EphySyncService *self,
EphySyncTokenType type);
void ephy_sync_service_set_token (EphySyncService *self,
@@ -67,18 +63,7 @@ void ephy_sync_service_do_sign_out (EphySyncServi
void ephy_sync_service_delete_synchronizable (EphySyncService *self,
EphySynchronizableManager *manager,
EphySynchronizable
*synchronizable);
-void ephy_sync_service_upload_bookmark (EphySyncService *self,
- EphyBookmark *bookmark,
- gboolean force);
-void ephy_sync_service_download_bookmark (EphySyncService *self,
- EphyBookmark *bookmark);
-void ephy_sync_service_delete_bookmark (EphySyncService *self,
- EphyBookmark *bookmark,
- gboolean conditional);
-void ephy_sync_service_sync_bookmarks (EphySyncService *self,
- gboolean first);
-void ephy_sync_service_start_periodical_sync (EphySyncService *self,
- gboolean now);
+void ephy_sync_service_start_periodical_sync (EphySyncService *self);
void ephy_sync_service_stop_periodical_sync (EphySyncService *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]