[epiphany/wip/sync] sync: Move code to lib/
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/sync] sync: Move code to lib/
- Date: Thu, 20 Apr 2017 21:24:49 +0000 (UTC)
commit b6bf9a79a0e39a62d61fdeeb4fa2424454f59b5c
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Fri Apr 21 00:20:33 2017 +0300
sync: Move code to lib/
configure.ac | 1 +
lib/Makefile.am | 4 +-
lib/sync/Makefile.am | 51 ++++++
{src => lib}/sync/ephy-sync-crypto.c | 0
{src => lib}/sync/ephy-sync-crypto.h | 0
{src => lib}/sync/ephy-sync-passwords-manager.c | 0
{src => lib}/sync/ephy-sync-passwords-manager.h | 0
{src => lib}/sync/ephy-sync-passwords-record.c | 0
{src => lib}/sync/ephy-sync-passwords-record.h | 0
{src => lib}/sync/ephy-sync-secret.c | 0
{src => lib}/sync/ephy-sync-secret.h | 0
{src => lib}/sync/ephy-sync-service.c | 215 +++++++++++++----------
{src => lib}/sync/ephy-sync-service.h | 4 +
{src => lib}/sync/ephy-synchronizable-manager.c | 0
{src => lib}/sync/ephy-synchronizable-manager.h | 0
{src => lib}/sync/ephy-synchronizable.c | 1 +
{src => lib}/sync/ephy-synchronizable.h | 0
src/Makefile.am | 34 +----
src/ephy-shell.c | 43 +----
src/ephy-shell.h | 2 -
src/prefs-dialog.c | 19 ++
src/profile-migrator/Makefile.am | 2 +-
src/search-provider/Makefile.am | 2 +-
tests/Makefile.am | 2 +-
24 files changed, 209 insertions(+), 171 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 83cb44d..2af88a9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -210,6 +210,7 @@ libgd/Makefile
lib/Makefile
lib/egg/Makefile
lib/history/Makefile
+lib/sync/Makefile
lib/widgets/Makefile
embed/Makefile
embed/web-extension/Makefile
diff --git a/lib/Makefile.am b/lib/Makefile.am
index bd2767f..2aaca54 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = widgets egg history
+SUBDIRS = egg history sync widgets
pkglib_LTLIBRARIES = libephymisc.la
@@ -72,6 +72,7 @@ libephymisc_la_CPPFLAGS = \
-DTOP_SRC_DATADIR=\"$(top_srcdir)/data\" \
-I$(top_builddir)/lib \
-I$(top_srcdir)/lib/egg \
+ -I$(top_srcdir)/lib/sync \
$(CAIRO_CFLAGS) \
$(GDK_PIXBUF_CFLAGS) \
$(GDK_X11_CFLAGS) \
@@ -94,6 +95,7 @@ libephymisc_la_LDFLAGS = \
libephymisc_la_LIBADD = \
$(top_builddir)/lib/history/libephyhistory.la \
+ $(top_builddir)/lib/sync/libephysync.la \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(GDK_X11_LIBS) \
diff --git a/lib/sync/Makefile.am b/lib/sync/Makefile.am
new file mode 100644
index 0000000..42c8724
--- /dev/null
+++ b/lib/sync/Makefile.am
@@ -0,0 +1,51 @@
+noinst_LTLIBRARIES = libephysync.la
+
+libephysync_la_SOURCES = \
+ ephy-sync-crypto.c \
+ ephy-sync-crypto.h \
+ ephy-sync-passwords-manager.c \
+ ephy-sync-passwords-manager.h \
+ ephy-sync-passwords-record.c \
+ ephy-sync-passwords-record.h \
+ ephy-sync-secret.c \
+ ephy-sync-secret.h \
+ ephy-sync-service.c \
+ ephy-sync-service.h \
+ ephy-synchronizable.c \
+ ephy-synchronizable.h \
+ ephy-synchronizable-manager.c \
+ ephy-synchronizable-manager.h
+
+libephysync_la_CFLAGS = \
+ $(WARN_CFLAGS)
+
+libephysync_la_CPPFLAGS = \
+ -I$(top_builddir)/lib \
+ -I$(top_builddir)/lib/sync \
+ -I$(top_srcdir)/embed \
+ -I$(top_srcdir)/lib \
+ -I$(top_srcdir)/lib/history \
+ -I$(top_srcdir)/lib/widgets \
+ $(GLIB_CFLAGS) \
+ $(GTK_CFLAGS) \
+ $(HOGWEED_CFLAGS) \
+ $(JSON_GLIB_CFLAGS) \
+ $(LIBNOTIFY_CFLAGS) \
+ $(LIBSECRET_CFLAGS) \
+ $(LIBSOUP_CFLAGS) \
+ $(NETTLE_CFLAGS) \
+ $(WEBKIT2GTK_CFLAGS)
+
+libephysync_la_LDFLAGS = \
+ $(WARN_LDFLAGS)
+
+libephysync_la_LIBADD = \
+ $(GLIB_LIBS) \
+ $(GTK_LIBS) \
+ $(HOGWEED_LIBS) \
+ $(JSON_GLIB_LIBS) \
+ $(LIBNOTIFY_LIBS) \
+ $(LIBSECRET_LIBS) \
+ $(LIBSOUP_LIBS) \
+ $(NETTLE_LIBS) \
+ $(WEBKIT2GTK_LIBS)
diff --git a/src/sync/ephy-sync-crypto.c b/lib/sync/ephy-sync-crypto.c
similarity index 100%
rename from src/sync/ephy-sync-crypto.c
rename to lib/sync/ephy-sync-crypto.c
diff --git a/src/sync/ephy-sync-crypto.h b/lib/sync/ephy-sync-crypto.h
similarity index 100%
rename from src/sync/ephy-sync-crypto.h
rename to lib/sync/ephy-sync-crypto.h
diff --git a/src/sync/ephy-sync-passwords-manager.c b/lib/sync/ephy-sync-passwords-manager.c
similarity index 100%
rename from src/sync/ephy-sync-passwords-manager.c
rename to lib/sync/ephy-sync-passwords-manager.c
diff --git a/src/sync/ephy-sync-passwords-manager.h b/lib/sync/ephy-sync-passwords-manager.h
similarity index 100%
rename from src/sync/ephy-sync-passwords-manager.h
rename to lib/sync/ephy-sync-passwords-manager.h
diff --git a/src/sync/ephy-sync-passwords-record.c b/lib/sync/ephy-sync-passwords-record.c
similarity index 100%
rename from src/sync/ephy-sync-passwords-record.c
rename to lib/sync/ephy-sync-passwords-record.c
diff --git a/src/sync/ephy-sync-passwords-record.h b/lib/sync/ephy-sync-passwords-record.h
similarity index 100%
rename from src/sync/ephy-sync-passwords-record.h
rename to lib/sync/ephy-sync-passwords-record.h
diff --git a/src/sync/ephy-sync-secret.c b/lib/sync/ephy-sync-secret.c
similarity index 100%
rename from src/sync/ephy-sync-secret.c
rename to lib/sync/ephy-sync-secret.c
diff --git a/src/sync/ephy-sync-secret.h b/lib/sync/ephy-sync-secret.h
similarity index 100%
rename from src/sync/ephy-sync-secret.h
rename to lib/sync/ephy-sync-secret.h
diff --git a/src/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
similarity index 92%
rename from src/sync/ephy-sync-service.c
rename to lib/sync/ephy-sync-service.c
index 80f9c9e..781cf70 100644
--- a/src/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -25,7 +25,6 @@
#include "ephy-embed-prefs.h"
#include "ephy-notification.h"
#include "ephy-settings.h"
-#include "ephy-shell.h"
#include "ephy-sync-crypto.h"
#include "ephy-sync-secret.h"
@@ -48,6 +47,7 @@ struct _EphySyncService {
char *user_email;
GHashTable *secrets;
+ GHashTable *managers;
gboolean locked;
char *storage_endpoint;
@@ -99,24 +99,26 @@ typedef struct {
} StorageRequestAsyncData;
typedef struct {
- char *email;
- char *uid;
- char *sessionToken;
- char *unwrapBKey;
- char *tokenID_hex;
- guint8 *reqHMACkey;
- guint8 *respHMACkey;
- guint8 *respXORkey;
+ EphySyncService *service;
+ char *email;
+ char *uid;
+ char *sessionToken;
+ char *unwrapBKey;
+ char *tokenID_hex;
+ guint8 *reqHMACkey;
+ guint8 *respHMACkey;
+ guint8 *respXORkey;
} SignInAsyncData;
typedef struct {
+ EphySyncService *service;
EphySynchronizableManager *manager;
gboolean is_initial;
- guint collection_index;
- guint num_collections;
+ gboolean is_last;
} SyncCollectionAsyncData;
typedef struct {
+ EphySyncService *service;
EphySynchronizableManager *manager;
EphySynchronizable *synchronizable;
} SyncAsyncData;
@@ -156,18 +158,20 @@ storage_request_async_data_free (StorageRequestAsyncData *data)
}
static SignInAsyncData *
-sign_in_async_data_new (const char *email,
- const char *uid,
- const char *sessionToken,
- const char *unwrapBKey,
- const char *tokenID_hex,
- const guint8 *reqHMACkey,
- const guint8 *respHMACkey,
- const guint8 *respXORkey)
+sign_in_async_data_new (EphySyncService *service,
+ const char *email,
+ const char *uid,
+ const char *sessionToken,
+ const char *unwrapBKey,
+ const char *tokenID_hex,
+ const guint8 *reqHMACkey,
+ const guint8 *respHMACkey,
+ const guint8 *respXORkey)
{
SignInAsyncData *data;
data = g_slice_new (SignInAsyncData);
+ data->service = g_object_ref (service);
data->email = g_strdup (email);
data->uid = g_strdup (uid);
data->sessionToken = g_strdup (sessionToken);
@@ -186,8 +190,9 @@ sign_in_async_data_new (const char *email,
static void
sign_in_async_data_free (SignInAsyncData *data)
{
- g_assert (data != NULL);
+ g_assert (data);
+ g_object_unref (data->service);
g_free (data->email);
g_free (data->uid);
g_free (data->sessionToken);
@@ -196,23 +201,22 @@ sign_in_async_data_free (SignInAsyncData *data)
g_free (data->reqHMACkey);
g_free (data->respHMACkey);
g_free (data->respXORkey);
-
g_slice_free (SignInAsyncData, data);
}
static SyncCollectionAsyncData *
-sync_collection_async_data_new (EphySynchronizableManager *manager,
+sync_collection_async_data_new (EphySyncService *service,
+ EphySynchronizableManager *manager,
gboolean is_initial,
- guint collection_index,
- guint num_collections)
+ gboolean is_last)
{
SyncCollectionAsyncData *data;
data = g_slice_new (SyncCollectionAsyncData);
+ data->service = g_object_ref (service);
data->manager = g_object_ref (manager);
data->is_initial = is_initial;
- data->collection_index = collection_index;
- data->num_collections = num_collections;
+ data->is_last = is_last;
return data;
}
@@ -222,17 +226,20 @@ sync_collection_async_data_free (SyncCollectionAsyncData *data)
{
g_assert (data);
+ g_object_unref (data->service);
g_object_unref (data->manager);
g_slice_free (SyncCollectionAsyncData, data);
}
static SyncAsyncData *
-sync_async_data_new (EphySynchronizableManager *manager,
+sync_async_data_new (EphySyncService *service,
+ EphySynchronizableManager *manager,
EphySynchronizable *synchronizable)
{
SyncAsyncData *data;
data = g_slice_new (SyncAsyncData);
+ data->service = g_object_ref (service);
data->manager = g_object_ref (manager);
data->synchronizable = g_object_ref (synchronizable);
@@ -244,6 +251,7 @@ sync_async_data_free (SyncAsyncData *data)
{
g_assert (data);
+ g_object_unref (data->service);
g_object_unref (data->manager);
g_object_unref (data->synchronizable);
g_slice_free (SyncAsyncData, data);
@@ -577,7 +585,7 @@ obtain_storage_credentials_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- EphySyncService *self;
+ EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
JsonNode *node = NULL;
JsonObject *json = NULL;
GError *error = NULL;
@@ -586,8 +594,6 @@ obtain_storage_credentials_cb (SoupSession *session,
const char *key;
int duration;
- self = ephy_shell_get_sync_service (ephy_shell_get_default ());
-
if (msg->status_code != 200) {
g_warning ("Failed to obtain storage credentials. Status code: %u, response: %s",
msg->status_code, msg->response_body->data);
@@ -684,7 +690,7 @@ ephy_sync_service_obtain_storage_credentials (EphySyncService *self)
* recognize accounts that were previously used to sync Firefox data too. */
soup_message_headers_append (msg->request_headers, "X-Client-State", client_state);
soup_message_headers_append (msg->request_headers, "authorization", authorization);
- soup_session_queue_message (self->session, msg, obtain_storage_credentials_cb, NULL);
+ soup_session_queue_message (self->session, msg, obtain_storage_credentials_cb, self);
g_free (kB);
g_free (hashed_kB);
@@ -699,7 +705,7 @@ obtain_signed_certificate_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- EphySyncService *self;
+ EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
JsonNode *node = NULL;
JsonObject *json = NULL;
GError *error = NULL;
@@ -707,8 +713,6 @@ obtain_signed_certificate_cb (SoupSession *session,
const char *message = NULL;
const char *certificate = NULL;
- self = ephy_shell_get_sync_service (ephy_shell_get_default ());
-
node = json_from_string (msg->response_body->data, &error);
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
@@ -800,7 +804,7 @@ ephy_sync_service_obtain_signed_certificate (EphySyncService *self)
request_body = json_to_string (node, FALSE);
ephy_sync_service_fxa_hawk_post_async (self, "certificate/sign", tokenID_hex,
reqHMACkey, TOKEN_LENGTH, request_body,
- obtain_signed_certificate_cb, NULL);
+ obtain_signed_certificate_cb, self);
g_free (request_body);
json_object_unref (object_body);
@@ -855,19 +859,15 @@ download_synchronizable_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- EphySyncService *self;
+ SyncAsyncData *data = (SyncAsyncData *)user_data;
EphySynchronizable *synchronizable;
SyncCryptoKeyBundle *bundle = NULL;
- SyncAsyncData *data;
JsonNode *node = NULL;
GError *error = NULL;
GType type;
const char *collection;
gboolean is_deleted;
- data = (SyncAsyncData *)user_data;
- self = ephy_shell_get_sync_service (ephy_shell_get_default ());
-
if (msg->status_code != 200) {
g_warning ("Failed to download object. Status code: %u, response: %s",
msg->status_code, msg->response_body->data);
@@ -880,7 +880,7 @@ download_synchronizable_cb (SoupSession *session,
}
type = ephy_synchronizable_manager_get_synchronizable_type (data->manager);
collection = ephy_synchronizable_manager_get_collection_name (data->manager);
- bundle = ephy_sync_service_get_key_bundle (self, collection);
+ bundle = ephy_sync_service_get_key_bundle (data->service, collection);
synchronizable = EPHY_SYNCHRONIZABLE (ephy_synchronizable_from_bso (node, type, bundle, &is_deleted));
if (!synchronizable) {
g_warning ("Failed to create synchronizable object from BSO");
@@ -923,7 +923,7 @@ ephy_sync_service_download_synchronizable (EphySyncService *self,
id = ephy_synchronizable_get_id (synchronizable);
collection = ephy_synchronizable_manager_get_collection_name (manager);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id);
- data = sync_async_data_new (manager, synchronizable);
+ data = sync_async_data_new (self, manager, synchronizable);
LOG ("Downloading object with id %s...", id);
ephy_sync_service_queue_storage_request (self, endpoint,
@@ -938,18 +938,14 @@ upload_synchronizable_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- EphySyncService *self;
- SyncAsyncData *data;
+ SyncAsyncData *data = (SyncAsyncData *)user_data;
double time_modified;
- data = (SyncAsyncData *)user_data;
- self = ephy_shell_get_sync_service (ephy_shell_get_default ());
-
/* Code 412 means that there is a more recent version of the object
* on the server. Download it. */
if (msg->status_code == 412) {
LOG ("Found a newer version of the object on the server, downloading it...");
- ephy_sync_service_download_synchronizable (self, data->manager, data->synchronizable);
+ ephy_sync_service_download_synchronizable (data->service, data->manager, data->synchronizable);
} else if (msg->status_code == 200) {
LOG ("Successfully uploaded to server");
time_modified = g_ascii_strtod (msg->response_body->data, NULL);
@@ -986,7 +982,7 @@ ephy_sync_service_upload_synchronizable (EphySyncService *self,
bso = ephy_synchronizable_to_bso (synchronizable, bundle);
id = ephy_synchronizable_get_id (synchronizable);
endpoint = g_strdup_printf ("storage/%s/%s", collection, id);
- data = sync_async_data_new (manager, synchronizable);
+ data = sync_async_data_new (self, manager, synchronizable);
body = json_to_string (bso, FALSE);
LOG ("Uploading object with id %s...", id);
@@ -1005,8 +1001,7 @@ sync_collection_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- EphySyncService *self;
- SyncCollectionAsyncData *data;
+ SyncCollectionAsyncData *data = (SyncCollectionAsyncData *)user_data;
EphySynchronizable *remote;
SyncCryptoKeyBundle *bundle;
JsonNode *node = NULL;
@@ -1020,8 +1015,6 @@ sync_collection_cb (SoupSession *session,
const char *timestamp;
gboolean is_deleted;
- self = ephy_shell_get_sync_service (ephy_shell_get_default ());
- data = (SyncCollectionAsyncData *)user_data;
collection = ephy_synchronizable_manager_get_collection_name (data->manager);
/* Code 304 means that the collection has not been modified. */
@@ -1046,7 +1039,7 @@ sync_collection_cb (SoupSession *session,
}
type = ephy_synchronizable_manager_get_synchronizable_type (data->manager);
- bundle = ephy_sync_service_get_key_bundle (self, collection);
+ bundle = ephy_sync_service_get_key_bundle (data->service, collection);
for (guint i = 0; i < json_array_get_length (array); i++) {
remote = EPHY_SYNCHRONIZABLE (ephy_synchronizable_from_bso (json_array_get_element (array, i),
type, bundle, &is_deleted));
@@ -1064,7 +1057,7 @@ merge_remotes:
to_upload = ephy_synchronizable_manager_merge_remotes (data->manager, data->is_initial,
remotes_deleted, remotes_updated);
for (GList *l = to_upload; l && l->data; l = l->next)
- ephy_sync_service_upload_synchronizable (self, data->manager, EPHY_SYNCHRONIZABLE (l->data));
+ ephy_sync_service_upload_synchronizable (data->service, data->manager, EPHY_SYNCHRONIZABLE (l->data));
/* Update sync time. */
timestamp = soup_message_headers_get_one (msg->response_headers, "X-Weave-Timestamp");
@@ -1072,8 +1065,8 @@ merge_remotes:
ephy_synchronizable_manager_set_is_initial_sync (data->manager, FALSE);
out:
- if (data->collection_index == data->num_collections)
- g_signal_emit (self, signals[SYNC_FINISHED], 0);
+ if (data->is_last)
+ g_signal_emit (data->service, signals[SYNC_FINISHED], 0);
if (to_upload)
g_list_free_full (to_upload, g_object_unref);
@@ -1091,8 +1084,7 @@ out:
static void
ephy_sync_service_sync_collection (EphySyncService *self,
EphySynchronizableManager *manager,
- guint collection_index,
- guint num_collections)
+ gboolean is_last)
{
SyncCollectionAsyncData *data;
const char *collection;
@@ -1105,7 +1097,7 @@ ephy_sync_service_sync_collection (EphySyncService *self,
collection = ephy_synchronizable_manager_get_collection_name (manager);
endpoint = g_strdup_printf ("storage/%s?full=true", collection);
is_initial = ephy_synchronizable_manager_is_initial_sync (manager);
- data = sync_collection_async_data_new (manager, is_initial, collection_index, num_collections);
+ data = sync_collection_async_data_new (self, manager, is_initial, is_last);
LOG ("Syncing %s collection%s...", collection, is_initial ? " first time" : "");
ephy_sync_service_queue_storage_request (self, endpoint, SOUP_METHOD_GET, NULL,
@@ -1119,23 +1111,23 @@ static gboolean
ephy_sync_service_sync (gpointer user_data)
{
EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
- GList *managers = NULL;
-
- managers = ephy_shell_get_synchronizable_managers (ephy_shell_get_default ());
- if (managers) {
- guint num_managers = g_list_length (managers);
- guint index = 1;
-
- for (GList *l = managers; l && l->data; l = l->next, index++)
- ephy_sync_service_sync_collection (self,
- EPHY_SYNCHRONIZABLE_MANAGER (l->data),
- index, num_managers);
+ GHashTableIter iter;
+ gpointer key;
+ gpointer value;
+ guint index = 0;
+ guint num_managers = g_hash_table_size (self->managers);
- g_list_free (managers);
- } else {
+ if (num_managers == 0) {
g_signal_emit (self, signals[SYNC_FINISHED], 0);
+ return G_SOURCE_CONTINUE;
}
+ g_hash_table_iter_init (&iter, self->managers);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ ephy_sync_service_sync_collection (self,
+ EPHY_SYNCHRONIZABLE_MANAGER (key),
+ ++index == num_managers);
+
return G_SOURCE_CONTINUE;
}
@@ -1268,6 +1260,20 @@ sync_secrets_store_finished_cb (EphySyncService *self,
}
static void
+sync_secrets_load_finished_cb (EphySyncService *self,
+ GError *error)
+{
+ g_assert (EPHY_IS_SYNC_SERVICE (self));
+
+ if (error) {
+ const char *text = _("Please visit Preferences and sign in again to continue syncing.");
+ ephy_notification_show (ephy_notification_new (error->message, text));
+ } else {
+ ephy_sync_service_start_periodical_sync (self);
+ }
+}
+
+static void
ephy_sync_service_finalize (GObject *object)
{
EphySyncService *self = EPHY_SYNC_SERVICE (object);
@@ -1275,8 +1281,9 @@ ephy_sync_service_finalize (GObject *object)
if (self->keypair)
ephy_sync_crypto_rsa_key_pair_free (self->keypair);
- g_queue_free_full (self->storage_queue, (GDestroyNotify) storage_request_async_data_free);
+ g_queue_free_full (self->storage_queue, (GDestroyNotify)storage_request_async_data_free);
g_hash_table_destroy (self->secrets);
+ g_hash_table_destroy (self->managers);
G_OBJECT_CLASS (ephy_sync_service_parent_class)->finalize (object);
}
@@ -1353,6 +1360,7 @@ ephy_sync_service_init (EphySyncService *self)
self->session = soup_session_new ();
self->storage_queue = g_queue_new ();
self->secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ self->managers = g_hash_table_new (g_direct_hash, g_direct_equal);
settings = ephy_embed_prefs_get_settings ();
user_agent = webkit_settings_get_user_agent (settings);
@@ -1368,6 +1376,9 @@ ephy_sync_service_init (EphySyncService *self)
g_signal_connect (self, "sync-secrets-store-finished",
G_CALLBACK (sync_secrets_store_finished_cb),
NULL);
+ g_signal_connect (self, "sync-secrets-load-finished",
+ G_CALLBACK (sync_secrets_load_finished_cb),
+ NULL);
g_signal_connect (self, "sync-frequency-changed",
G_CALLBACK (sync_frequency_changed_cb),
NULL);
@@ -1428,6 +1439,26 @@ ephy_sync_service_set_secret (EphySyncService *self,
g_hash_table_replace (self->secrets, g_strdup (name), g_strdup (value));
}
+void
+ephy_sync_service_register_manager (EphySyncService *self,
+ EphySynchronizableManager *manager)
+{
+ g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
+ g_return_if_fail (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager));
+
+ g_hash_table_add (self->managers, manager);
+}
+
+void
+ephy_sync_service_unregister_manager (EphySyncService *self,
+ EphySynchronizableManager *manager)
+{
+ g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
+ g_return_if_fail (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager));
+
+ g_hash_table_remove (self->managers, manager);
+}
+
static void
ephy_sync_service_report_sign_in_error (EphySyncService *self,
const char *message,
@@ -1490,7 +1521,7 @@ obtain_crypto_keys_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- EphySyncService *self;
+ EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
SyncCryptoKeyBundle *bundle = NULL;
JsonNode *node = NULL;
JsonObject *json = NULL;
@@ -1499,8 +1530,6 @@ obtain_crypto_keys_cb (SoupSession *session,
char *crypto_keys = NULL;
guint8 *kB = NULL;
- self = ephy_shell_get_sync_service (ephy_shell_get_default ());
-
if (msg->status_code == 404) {
crypto_keys = ephy_sync_service_upload_crypto_keys_record (self);
goto store_secrets;
@@ -1562,7 +1591,7 @@ ephy_sync_service_obtain_crypto_keys (EphySyncService *self)
ephy_sync_service_queue_storage_request (self, "storage/crypto/keys",
SOUP_METHOD_GET, NULL, -1, -1,
- obtain_crypto_keys_cb, NULL);
+ obtain_crypto_keys_cb, self);
}
static JsonObject *
@@ -1637,7 +1666,7 @@ check_storage_version_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- EphySyncService *self;
+ EphySyncService *self = EPHY_SYNC_SERVICE (user_data);
JsonParser *parser = NULL;
JsonObject *json = NULL;
GError *error = NULL;
@@ -1645,8 +1674,6 @@ check_storage_version_cb (SoupSession *session,
char *message = NULL;
int storage_version;
- self = ephy_shell_get_sync_service (ephy_shell_get_default ());
-
if (msg->status_code == 404) {
ephy_sync_service_upload_meta_global_record (self);
goto obtain_crypto_keys;
@@ -1720,7 +1747,7 @@ ephy_sync_service_check_storage_version (EphySyncService *self)
ephy_sync_service_queue_storage_request (self, "storage/meta/global",
SOUP_METHOD_GET, NULL, -1, -1,
- check_storage_version_cb, NULL);
+ check_storage_version_cb, self);
}
static void
@@ -1769,17 +1796,13 @@ get_account_keys_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- EphySyncService *self;
- SignInAsyncData *data;
+ SignInAsyncData *data = (SignInAsyncData *)user_data;
JsonNode *node = NULL;
JsonObject *json = NULL;
GError *error = NULL;
const char *bundle;
- self = ephy_shell_get_sync_service (ephy_shell_get_default ());
- data = (SignInAsyncData *)user_data;
node = json_from_string (msg->response_body->data, &error);
-
if (error) {
g_warning ("Response is not a valid JSON: %s", error->message);
goto out_error;
@@ -1797,7 +1820,7 @@ get_account_keys_cb (SoupSession *session,
goto out_error;
}
/* Extract the master sync keys from the bundle and save tokens. */
- ephy_sync_service_conclude_sign_in (self, data, bundle);
+ ephy_sync_service_conclude_sign_in (data->service, data, bundle);
goto out_no_error;
}
@@ -1805,9 +1828,9 @@ get_account_keys_cb (SoupSession *session,
* verification has completed. */
if (json_object_get_int_member (json, "errno") == 104) {
LOG ("Account not verified, retrying...");
- ephy_sync_service_fxa_hawk_get_async (self, "account/keys", data->tokenID_hex,
- data->reqHMACkey, TOKEN_LENGTH,
- get_account_keys_cb, data);
+ ephy_sync_service_fxa_hawk_get_async (data->service, "account/keys",
+ data->tokenID_hex, data->reqHMACkey,
+ TOKEN_LENGTH, get_account_keys_cb, data);
goto out_no_error;
}
@@ -1815,7 +1838,8 @@ get_account_keys_cb (SoupSession *session,
msg->status_code, msg->response_body->data);
out_error:
- ephy_sync_service_report_sign_in_error (self, _("Failed to retrieve the Sync Key"),
+ ephy_sync_service_report_sign_in_error (data->service,
+ _("Failed to retrieve the Sync Key"),
data->sessionToken, FALSE);
sign_in_async_data_free (data);
out_no_error:
@@ -1857,9 +1881,10 @@ ephy_sync_service_do_sign_in (EphySyncService *self,
tokenID_hex = ephy_sync_crypto_encode_hex (tokenID, TOKEN_LENGTH);
/* Get the master sync key bundle from the /account/keys endpoint. */
- data = sign_in_async_data_new (email, uid, sessionToken,
- unwrapBKey, tokenID_hex,
- reqHMACkey, respHMACkey, respXORkey);
+ data = sign_in_async_data_new (self, email, uid,
+ sessionToken, unwrapBKey,
+ tokenID_hex, reqHMACkey,
+ respHMACkey, respXORkey);
ephy_sync_service_fxa_hawk_get_async (self, "account/keys", tokenID_hex,
reqHMACkey, TOKEN_LENGTH,
get_account_keys_cb, data);
diff --git a/src/sync/ephy-sync-service.h b/lib/sync/ephy-sync-service.h
similarity index 88%
rename from src/sync/ephy-sync-service.h
rename to lib/sync/ephy-sync-service.h
index 8c7d938..a8a2f4e 100644
--- a/src/sync/ephy-sync-service.h
+++ b/lib/sync/ephy-sync-service.h
@@ -40,6 +40,10 @@ const char *ephy_sync_service_get_secret (EphySyncService
void ephy_sync_service_set_secret (EphySyncService *self,
const char *name,
const char *value);
+void ephy_sync_service_register_manager (EphySyncService *self,
+ EphySynchronizableManager *manager);
+void ephy_sync_service_unregister_manager (EphySyncService *self,
+ EphySynchronizableManager *manager);
void ephy_sync_service_do_sign_in (EphySyncService *self,
const char *email,
const char *uid,
diff --git a/src/sync/ephy-synchronizable-manager.c b/lib/sync/ephy-synchronizable-manager.c
similarity index 100%
rename from src/sync/ephy-synchronizable-manager.c
rename to lib/sync/ephy-synchronizable-manager.c
diff --git a/src/sync/ephy-synchronizable-manager.h b/lib/sync/ephy-synchronizable-manager.h
similarity index 100%
rename from src/sync/ephy-synchronizable-manager.h
rename to lib/sync/ephy-synchronizable-manager.h
diff --git a/src/sync/ephy-synchronizable.c b/lib/sync/ephy-synchronizable.c
similarity index 99%
rename from src/sync/ephy-synchronizable.c
rename to lib/sync/ephy-synchronizable.c
index 1b4fdca..1160ea5 100644
--- a/src/sync/ephy-synchronizable.c
+++ b/lib/sync/ephy-synchronizable.c
@@ -27,6 +27,7 @@ static void
ephy_synchronizable_default_init (EphySynchronizableInterface *iface)
{
iface->get_id = ephy_synchronizable_get_id;
+ iface->set_id = ephy_synchronizable_set_id;
iface->get_time_modified = ephy_synchronizable_get_time_modified;
iface->set_time_modified = ephy_synchronizable_set_time_modified;
iface->is_uploaded = ephy_synchronizable_is_uploaded;
diff --git a/src/sync/ephy-synchronizable.h b/lib/sync/ephy-synchronizable.h
similarity index 100%
rename from src/sync/ephy-synchronizable.h
rename to lib/sync/ephy-synchronizable.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 61f6e93..7192f78 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -72,21 +72,7 @@ libephymain_la_SOURCES = \
prefs-dialog.c \
prefs-dialog.h \
window-commands.c \
- window-commands.h \
- sync/ephy-sync-crypto.c \
- sync/ephy-sync-crypto.h \
- sync/ephy-sync-passwords-manager.c \
- sync/ephy-sync-passwords-manager.h \
- sync/ephy-sync-passwords-record.c \
- sync/ephy-sync-passwords-record.h \
- sync/ephy-sync-secret.c \
- sync/ephy-sync-secret.h \
- sync/ephy-sync-service.c \
- sync/ephy-sync-service.h \
- sync/ephy-synchronizable.c \
- sync/ephy-synchronizable.h \
- sync/ephy-synchronizable-manager.c \
- sync/ephy-synchronizable-manager.h
+ window-commands.h
nodist_libephymain_la_SOURCES = \
$(TYPES_SOURCE)
@@ -100,22 +86,18 @@ libephymain_la_CPPFLAGS = \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/lib/egg \
-I$(top_srcdir)/lib/history \
+ -I$(top_srcdir)/lib/sync \
-I$(top_srcdir)/lib/widgets \
-I$(top_srcdir)/src/bookmarks \
- -I$(top_srcdir)/src/sync \
-DLOCALEDIR=\"$(localedir)\" \
-DPKGDATADIR=\"$(pkgdatadir)\" \
$(GDK_CFLAGS) \
$(GIO_CFLAGS) \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
- $(HOGWEED_CFLAGS) \
$(JSON_GLIB_CFLAGS) \
- $(LIBNOTIFY_CFLAGS) \
$(LIBSECRET_CFLAGS) \
- $(LIBSOUP_CFLAGS) \
$(LIBXML_CFLAGS) \
- $(NETTLE_CFLAGS) \
$(WEBKIT2GTK_CFLAGS)
libephymain_la_CFLAGS = \
@@ -134,13 +116,9 @@ libephymain_la_LIBADD = \
$(GIO_LIBS) \
$(GLIB_LIBS) \
$(GTK_LIBS) \
- $(HOGWEED_LIBS) \
$(JSON_GLIB_LIBS) \
- $(LIBNOTIFY_LIBS) \
$(LIBSECRET_LIBS) \
- $(LIBSOUP_LIBS) \
$(LIBXML_LIBS) \
- $(NETTLE_LIBS) \
$(WEBKIT2GTK_LIBS)
RESOURCE_FILES = \
@@ -200,19 +178,16 @@ epiphany_CPPFLAGS = \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/lib/egg \
-I$(top_srcdir)/lib/history \
+ -I$(top_srcdir)/lib/sync \
-I$(top_srcdir)/lib/widgets \
-I$(top_builddir)/lib/widgets \
-I$(top_srcdir)/src/bookmarks \
- -I$(top_srcdir)/src/sync \
-DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
-DLOCALEDIR=\"$(localedir)\" \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
- $(HOGWEED_CFLAGS) \
$(JSON_GLIB_CFLAGS) \
- $(LIBNOTIFY_CFLAGS) \
$(LIBXML_CFLAGS) \
- $(NETTLE_CFLAGS) \
$(WEBKIT2GTK_CFLAGS)
epiphany_LDADD = \
@@ -220,11 +195,8 @@ epiphany_LDADD = \
libephymain.la \
$(GLIB_LIBS) \
$(GTK_LIBS) \
- $(HOGWEED_LIBS) \
$(JSON_GLIB_LIBS) \
- $(LIBNOTIFY_LIBS) \
$(LIBXML_LIBS) \
- $(NETTLE_LIBS) \
$(WEBKIT2GTK_LIBS)
epiphany_LDFLAGS = \
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 520840a..74de6c5 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -308,27 +308,6 @@ download_started_cb (WebKitWebContext *web_context,
}
static void
-sync_secrets_load_finished_cb (EphySyncService *service,
- GError *error,
- gpointer user_data)
-{
- EphyNotification *notification;
-
- g_assert (EPHY_IS_SYNC_SERVICE (service));
-
- /* If the sync secrets 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);
- } else {
- notification = ephy_notification_new (error->message,
- _("Please visit Preferences and sign in "
- "again to continue the sync process."));
- ephy_notification_show (notification);
- }
-}
-
-static void
ephy_shell_startup (GApplication *application)
{
EphyEmbedShell *embed_shell = EPHY_EMBED_SHELL (application);
@@ -366,11 +345,11 @@ ephy_shell_startup (GApplication *application)
G_BINDING_SYNC_CREATE);
}
- /* Create the sync service. */
+ /* Create the sync service and register synchronizable managers. */
ephy_shell->sync_service = ephy_sync_service_new ();
- g_signal_connect (ephy_shell->sync_service,
- "sync-secrets-load-finished",
- G_CALLBACK (sync_secrets_load_finished_cb), NULL);
+ if (g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_BOOKMARKS_ENABLED))
+ ephy_sync_service_register_manager (ephy_shell->sync_service,
+ EPHY_SYNCHRONIZABLE_MANAGER (ephy_shell_get_bookmarks_manager
(ephy_shell)));
gtk_application_set_app_menu (GTK_APPLICATION (application),
G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
@@ -886,20 +865,6 @@ ephy_shell_get_prefs_dialog (EphyShell *shell)
return shell->prefs_dialog;
}
-GList *
-ephy_shell_get_synchronizable_managers (EphyShell *shell)
-{
- GList *managers = NULL;
-
- g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL);
-
- if (g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_BOOKMARKS_ENABLED))
- managers = g_list_prepend (managers,
- EPHY_SYNCHRONIZABLE_MANAGER (ephy_shell_get_bookmarks_manager (shell)));
-
- return managers;
-}
-
void
_ephy_shell_create_instance (EphyEmbedShellMode mode)
{
diff --git a/src/ephy-shell.h b/src/ephy-shell.h
index f3fa42a..bd79449 100644
--- a/src/ephy-shell.h
+++ b/src/ephy-shell.h
@@ -108,8 +108,6 @@ GtkWidget *ephy_shell_get_history_dialog (EphyShell *shell);
GObject *ephy_shell_get_prefs_dialog (EphyShell *shell);
-GList *ephy_shell_get_synchronizable_managers (EphyShell *shell);
-
guint ephy_shell_get_n_windows (EphyShell *shell);
gboolean ephy_shell_close_all_windows (EphyShell *shell);
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index fc5c034..4fb68b7 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -175,6 +175,22 @@ prefs_dialog_finalize (GObject *object)
}
static void
+sync_bookmarks_toggled_cb (GtkToggleButton *button,
+ PrefsDialog *dialog)
+{
+ EphyBookmarksManager *manager;
+
+ manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
+
+ if (gtk_toggle_button_get_active (button))
+ ephy_sync_service_register_manager (dialog->sync_service,
+ EPHY_SYNCHRONIZABLE_MANAGER (manager));
+ else
+ ephy_sync_service_unregister_manager (dialog->sync_service,
+ EPHY_SYNCHRONIZABLE_MANAGER (manager));
+}
+
+static void
sync_finished_cb (EphySyncService *service,
PrefsDialog *dialog)
{
@@ -1622,6 +1638,9 @@ setup_sync_page (PrefsDialog *dialog)
g_signal_connect_object (dialog->sync_service, "sync-finished",
G_CALLBACK (sync_finished_cb),
dialog, 0);
+ g_signal_connect_object (dialog->sync_bookmarks_checkbutton, "toggled",
+ G_CALLBACK (sync_bookmarks_toggled_cb),
+ dialog, 0);
g_settings_bind (sync_settings,
EPHY_PREFS_SYNC_WITH_FIREFOX,
diff --git a/src/profile-migrator/Makefile.am b/src/profile-migrator/Makefile.am
index 24a2709..457d9d9 100644
--- a/src/profile-migrator/Makefile.am
+++ b/src/profile-migrator/Makefile.am
@@ -11,9 +11,9 @@ ephy_profile_migrator_CPPFLAGS = \
-I$(top_srcdir)/embed \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/lib/history \
+ -I$(top_srcdir)/lib/sync \
-I$(top_srcdir)/src/ \
-I$(top_srcdir)/src/bookmarks \
- -I$(top_srcdir)/src/sync \
-DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
-DLOCALEDIR=\"$(localedir)\" \
$(GLIB_CFLAGS) \
diff --git a/src/search-provider/Makefile.am b/src/search-provider/Makefile.am
index 8141527..8292d67 100644
--- a/src/search-provider/Makefile.am
+++ b/src/search-provider/Makefile.am
@@ -22,9 +22,9 @@ epiphany_search_provider_CPPFLAGS = \
-I$(top_srcdir)/embed \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/lib/history \
+ -I$(top_srcdir)/lib/sync \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/bookmarks \
- -I$(top_srcdir)/src/sync \
-DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
-DLOCALEDIR=\"$(localedir)\" \
$(GIO_CFLAGS) \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a996062..3cd5ed7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -87,11 +87,11 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/embed \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/lib/history \
+ -I$(top_srcdir)/lib/sync \
-I$(top_srcdir)/lib/widgets \
-I$(top_builddir)/lib/widgets \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/bookmarks \
- -I$(top_srcdir)/src/sync \
-DTEST_DIR=\"$(srcdir)\" \
$(GDK_CFLAGS) \
$(GLIB_CFLAGS) \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]