[epiphany/wip/sync: 2/2] sync-service: Add functionality to register/unregister synchronizable managers



commit 2ca2e75a84bb3395e1bc755256bde84e16927088
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Tue Mar 28 15:34:50 2017 +0300

    sync-service: Add functionality to register/unregister synchronizable managers

 src/sync/ephy-sync-service.c |   30 +++++++++++++++
 src/sync/ephy-sync-service.h |   81 ++++++++++++++++++++++-------------------
 2 files changed, 73 insertions(+), 38 deletions(-)
---
diff --git a/src/sync/ephy-sync-service.c b/src/sync/ephy-sync-service.c
index 57c79dd..390efee 100644
--- a/src/sync/ephy-sync-service.c
+++ b/src/sync/ephy-sync-service.c
@@ -54,6 +54,8 @@ struct _EphySyncService {
   char        *kB;
   GHashTable  *key_bundles;
 
+  GHashTable  *managers;
+
   char        *user_email;
   double       sync_time;
   gint64       auth_at;
@@ -614,6 +616,7 @@ ephy_sync_service_finalize (GObject *object)
 
   g_queue_free_full (self->storage_queue, (GDestroyNotify) storage_request_async_data_free);
   g_hash_table_destroy (self->key_bundles);
+  g_hash_table_destroy (self->managers);
 
   G_OBJECT_CLASS (ephy_sync_service_parent_class)->finalize (object);
 }
@@ -678,6 +681,7 @@ ephy_sync_service_init (EphySyncService *self)
   self->storage_queue = g_queue_new ();
   self->key_bundles = g_hash_table_new_full (g_str_hash, g_str_equal,
                                              NULL, (GDestroyNotify)ephy_sync_crypto_key_bundle_free);
+  self->managers = g_hash_table_new (g_str_hash, g_str_equal);
 
   settings = ephy_embed_prefs_get_settings ();
   user_agent = webkit_settings_get_user_agent (settings);
@@ -809,6 +813,32 @@ ephy_sync_service_get_key_bundle (EphySyncService *self,
 }
 
 void
+ephy_sync_service_register_manager (EphySyncService           *self,
+                                    EphySynchronizableManager *manager)
+{
+  const char *collection;
+
+  g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
+  g_return_if_fail (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager));
+
+  collection = ephy_synchronizable_manager_get_collection_name (manager);
+  g_hash_table_insert (self->managers, (char *)collection, manager);
+}
+
+void
+ephy_sync_service_unregister_manager (EphySyncService           *self,
+                                      EphySynchronizableManager *manager)
+{
+  const char *collection;
+
+  g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
+  g_return_if_fail (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager));
+
+  collection = ephy_synchronizable_manager_get_collection_name (manager);
+  g_hash_table_remove (self->managers, collection);
+}
+
+void
 ephy_sync_service_clear_storage_credentials (EphySyncService *self)
 {
   g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
diff --git a/src/sync/ephy-sync-service.h b/src/sync/ephy-sync-service.h
index f29cca8..e0ca799 100644
--- a/src/sync/ephy-sync-service.h
+++ b/src/sync/ephy-sync-service.h
@@ -23,6 +23,7 @@
 #include "ephy-bookmark.h"
 #include "ephy-sync-crypto.h"
 #include "ephy-sync-utils.h"
+#include "ephy-synchronizable-manager.h"
 
 #include <glib-object.h>
 #include <libsoup/soup.h>
@@ -34,43 +35,47 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (EphySyncService, ephy_sync_service, EPHY, SYNC_SERVICE, GObject)
 
 EphySyncService     *ephy_sync_service_new                        (void);
-gboolean             ephy_sync_service_is_signed_in               (EphySyncService   *self);
-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,
-                                                                   const char        *value,
-                                                                   EphySyncTokenType  type);
-SyncCryptoKeyBundle *ephy_sync_service_get_key_bundle             (EphySyncService   *self,
-                                                                   const char        *collection);
-void                 ephy_sync_service_clear_storage_credentials  (EphySyncService   *self);
-void                 ephy_sync_service_clear_tokens               (EphySyncService   *self);
-void                 ephy_sync_service_destroy_session            (EphySyncService   *self,
-                                                                   const char        *sessionToken);
-void                 ephy_sync_service_do_sign_in                 (EphySyncService   *self,
-                                                                   const char        *email,
-                                                                   const char        *uid,
-                                                                   const char        *sessionToken,
-                                                                   const char        *keyFetchToken,
-                                                                   const char        *unwrapBKey);
-void                 ephy_sync_service_do_sign_out                (EphySyncService   *self);
-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_stop_periodical_sync       (EphySyncService   *self);
+gboolean             ephy_sync_service_is_signed_in               (EphySyncService           *self);
+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,
+                                                                   const char                *value,
+                                                                   EphySyncTokenType          type);
+SyncCryptoKeyBundle *ephy_sync_service_get_key_bundle             (EphySyncService           *self,
+                                                                   const char                *collection);
+void                 ephy_sync_service_register_manager           (EphySyncService           *self,
+                                                                   EphySynchronizableManager *manager);
+void                 ephy_sync_service_unregister_manager         (EphySyncService           *self,
+                                                                   EphySynchronizableManager *manager);
+void                 ephy_sync_service_clear_storage_credentials  (EphySyncService           *self);
+void                 ephy_sync_service_clear_tokens               (EphySyncService           *self);
+void                 ephy_sync_service_destroy_session            (EphySyncService           *self,
+                                                                   const char                *sessionToken);
+void                 ephy_sync_service_do_sign_in                 (EphySyncService           *self,
+                                                                   const char                *email,
+                                                                   const char                *uid,
+                                                                   const char                *sessionToken,
+                                                                   const char                *keyFetchToken,
+                                                                   const char                *unwrapBKey);
+void                 ephy_sync_service_do_sign_out                (EphySyncService           *self);
+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_stop_periodical_sync       (EphySyncService           *self);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]