[epiphany/wip/sync: 13/13] sync: Use GSettings to decide if an initial sync is required
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/sync: 13/13] sync: Use GSettings to decide if an initial sync is required
- Date: Wed, 29 Mar 2017 17:45:15 +0000 (UTC)
commit b8c2b3fddf9375be8491c42b00ea4b2b0b63830a
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Wed Mar 29 17:02:15 2017 +0300
sync: Use GSettings to decide if an initial sync is required
data/org.gnome.epiphany.gschema.xml | 5 +++++
lib/ephy-prefs.h | 7 ++++---
src/bookmarks/ephy-bookmarks-manager.c | 21 +++++++++++++++++++--
src/prefs-dialog.c | 3 +++
src/sync/ephy-sync-service.c | 25 +++++++++++++------------
src/sync/ephy-synchronizable-manager.c | 25 +++++++++++++++++++++++++
src/sync/ephy-synchronizable-manager.h | 7 +++++++
7 files changed, 76 insertions(+), 17 deletions(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index bc4dc4e..73a55ac 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -277,6 +277,11 @@
<summary>Bookmarks sync timestamp</summary>
<description>The timestamp at which last bookmarks sync was made.</description>
</key>
+ <key type="b" name="bookmarks-initial-sync">
+ <default>true</default>
+ <summary>Initial sync or normal sync</summary>
+ <description>TRUE if bookmarks collection needs to be synced for the first time,
FALSE otherwise.</description>
+ </key>
</schema>
<enum id="org.gnome.Epiphany.Permission">
<value nick="undecided" value="-1"/>
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index b329ed5..904540a 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -149,9 +149,10 @@ static const char * const ephy_prefs_web_schema[] = {
#define EPHY_PREFS_LOCKDOWN_PRINTING "disable-printing"
#define EPHY_PREFS_LOCKDOWN_QUIT "disable-quit"
-#define EPHY_PREFS_SYNC_SCHEMA "org.gnome.Epiphany.sync"
-#define EPHY_PREFS_SYNC_USER "sync-user"
-#define EPHY_PREFS_SYNC_BOOKMARKS_SYNC_TIME "bookmarks-sync-time"
+#define EPHY_PREFS_SYNC_SCHEMA "org.gnome.Epiphany.sync"
+#define EPHY_PREFS_SYNC_USER "sync-user"
+#define EPHY_PREFS_SYNC_BOOKMARKS_SYNC_TIME "bookmarks-sync-time"
+#define EPHY_PREFS_SYNC_BOOKMARKS_INITIAL_SYNC "bookmarks-initial-sync"
static struct {
const char *schema;
diff --git a/src/bookmarks/ephy-bookmarks-manager.c b/src/bookmarks/ephy-bookmarks-manager.c
index 359c8e3..b471930 100644
--- a/src/bookmarks/ephy-bookmarks-manager.c
+++ b/src/bookmarks/ephy-bookmarks-manager.c
@@ -254,6 +254,21 @@ synchronizable_manager_get_synchronizable_type (EphySynchronizableManager *manag
return EPHY_TYPE_BOOKMARK;
}
+static gboolean
+synchronizable_manager_is_initial_sync (EphySynchronizableManager *manager)
+{
+ return g_settings_get_boolean (EPHY_SETTINGS_SYNC,
+ EPHY_PREFS_SYNC_BOOKMARKS_INITIAL_SYNC);
+}
+
+static void
+synchronizable_manager_set_is_initial_sync (EphySynchronizableManager *manager,
+ gboolean is_initial)
+{
+ g_settings_set_boolean (EPHY_SETTINGS_SYNC,
+ EPHY_PREFS_SYNC_BOOKMARKS_INITIAL_SYNC, is_initial);
+}
+
static double
synchronizable_manager_get_sync_time (EphySynchronizableManager *manager)
{
@@ -290,7 +305,7 @@ synchronizable_manager_remove (EphySynchronizableManager *manager,
static void
synchronizable_manager_merge_remotes (EphySynchronizableManager *manager,
- gboolean first_time,
+ gboolean is_initial,
GList *remotes,
GList **to_upload,
GList **to_test)
@@ -357,7 +372,7 @@ handle_local_bookmarks:
!g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter)) {
local = EPHY_BOOKMARK (g_sequence_get (iter));
if (!g_hash_table_contains (handled, local)) {
- if (first_time) {
+ if (is_initial) {
/* In case of a first time sync, upload all remaining locals to server. */
*to_upload = g_list_prepend (*to_upload, local);
} else {
@@ -384,6 +399,8 @@ ephy_synchronizable_manager_iface_init (EphySynchronizableManagerInterface *ifac
{
iface->get_collection_name = synchronizable_manager_get_collection_name;
iface->get_synchronizable_type = synchronizable_manager_get_synchronizable_type;
+ iface->is_initial_sync = synchronizable_manager_is_initial_sync;
+ iface->set_is_initial_sync = synchronizable_manager_set_is_initial_sync;
iface->get_sync_time = synchronizable_manager_get_sync_time;
iface->set_sync_time = synchronizable_manager_set_sync_time;
iface->add = synchronizable_manager_add;
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index bd2d20c..f05471f 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -233,6 +233,9 @@ sync_tokens_store_finished_cb (EphySyncService *service,
g_settings_set_string (EPHY_SETTINGS_SYNC,
EPHY_PREFS_SYNC_USER,
ephy_sync_service_get_user_email (service));
+ g_settings_set_boolean (EPHY_SETTINGS_SYNC,
+ EPHY_PREFS_SYNC_BOOKMARKS_INITIAL_SYNC,
+ TRUE);
/* Start syncing. */
ephy_sync_service_start_periodical_sync (service);
diff --git a/src/sync/ephy-sync-service.c b/src/sync/ephy-sync-service.c
index c09ea7b..fa5c6ba 100644
--- a/src/sync/ephy-sync-service.c
+++ b/src/sync/ephy-sync-service.c
@@ -102,7 +102,7 @@ typedef struct {
typedef struct {
EphySynchronizableManager *manager;
- gboolean first_time;
+ gboolean is_initial;
} SyncCollectionAsyncData;
typedef struct {
@@ -193,13 +193,13 @@ sign_in_async_data_free (SignInAsyncData *data)
static SyncCollectionAsyncData *
sync_collection_async_data_new (EphySynchronizableManager *manager,
- gboolean first_time)
+ gboolean is_initial)
{
SyncCollectionAsyncData *data;
data = g_slice_new (SyncCollectionAsyncData);
data->manager = g_object_ref (manager);
- data->first_time = first_time;
+ data->is_initial = is_initial;
return data;
}
@@ -1479,7 +1479,7 @@ sync_collection_cb (SoupSession *session,
}
merge_remotes:
- ephy_synchronizable_manager_merge_remotes (data->manager, data->first_time,
+ ephy_synchronizable_manager_merge_remotes (data->manager, data->is_initial,
remotes, &to_upload, &to_test);
if (to_upload) {
@@ -1498,6 +1498,7 @@ merge_remotes:
}
}
+ ephy_synchronizable_manager_set_is_initial_sync (data->manager, FALSE);
/* Update sync time. */
timestamp = soup_message_headers_get_one (msg->response_headers, "X-Weave-Timestamp");
ephy_synchronizable_manager_set_sync_time (data->manager, g_ascii_strtod (timestamp, NULL));
@@ -1515,24 +1516,24 @@ out:
static void
ephy_sync_service_sync_collection (EphySyncService *self,
- EphySynchronizableManager *manager,
- gboolean first_time)
+ EphySynchronizableManager *manager)
{
SyncCollectionAsyncData *data;
const char *collection;
char *endpoint;
+ gboolean is_initial;
g_assert (EPHY_IS_SYNC_SERVICE (self));
g_assert (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager));
- data = sync_collection_async_data_new (manager, first_time);
collection = ephy_synchronizable_manager_get_collection_name (manager);
- LOG ("Syncing %s collection...", collection);
-
endpoint = g_strdup_printf ("storage/%s?full=true", collection);
- ephy_sync_service_queue_storage_request (self, endpoint,
- SOUP_METHOD_GET, NULL,
- first_time ? -1 : ephy_synchronizable_manager_get_sync_time
(manager),
+ is_initial = ephy_synchronizable_manager_is_initial_sync (manager);
+ data = sync_collection_async_data_new (manager, is_initial);
+
+ LOG ("Syncing %s collection...", collection);
+ ephy_sync_service_queue_storage_request (self, endpoint, SOUP_METHOD_GET, NULL,
+ is_initial ? -1 : ephy_synchronizable_manager_get_sync_time
(manager),
-1, sync_collection_cb, data);
g_free (endpoint);
diff --git a/src/sync/ephy-synchronizable-manager.c b/src/sync/ephy-synchronizable-manager.c
index 099e1a0..a30d4b4 100644
--- a/src/sync/ephy-synchronizable-manager.c
+++ b/src/sync/ephy-synchronizable-manager.c
@@ -28,6 +28,8 @@ ephy_synchronizable_manager_default_init (EphySynchronizableManagerInterface *if
{
iface->get_collection_name = ephy_synchronizable_manager_get_collection_name;
iface->get_synchronizable_type = ephy_synchronizable_manager_get_synchronizable_type;
+ iface->is_initial_sync = ephy_synchronizable_manager_is_initial_sync;
+ iface->set_is_initial_sync = ephy_synchronizable_manager_set_is_initial_sync;
iface->get_sync_time = ephy_synchronizable_manager_get_sync_time;
iface->set_sync_time = ephy_synchronizable_manager_set_sync_time;
iface->add = ephy_synchronizable_manager_add;
@@ -57,6 +59,29 @@ ephy_synchronizable_manager_get_synchronizable_type (EphySynchronizableManager *
return iface->get_synchronizable_type (manager);
}
+gboolean
+ephy_synchronizable_manager_is_initial_sync (EphySynchronizableManager *manager)
+{
+ EphySynchronizableManagerInterface *iface;
+
+ g_return_val_if_fail (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager), FALSE);
+
+ iface = EPHY_SYNCHRONIZABLE_MANAGER_GET_IFACE (manager);
+ return iface->is_initial_sync (manager);
+}
+
+void
+ephy_synchronizable_manager_set_is_initial_sync (EphySynchronizableManager *manager,
+ gboolean is_initial)
+{
+ EphySynchronizableManagerInterface *iface;
+
+ g_return_if_fail (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager));
+
+ iface = EPHY_SYNCHRONIZABLE_MANAGER_GET_IFACE (manager);
+ iface->set_is_initial_sync (manager, is_initial);
+}
+
double
ephy_synchronizable_manager_get_sync_time (EphySynchronizableManager *manager)
{
diff --git a/src/sync/ephy-synchronizable-manager.h b/src/sync/ephy-synchronizable-manager.h
index 766d4f2..b7a5438 100644
--- a/src/sync/ephy-synchronizable-manager.h
+++ b/src/sync/ephy-synchronizable-manager.h
@@ -36,6 +36,10 @@ struct _EphySynchronizableManagerInterface {
const char * (*get_collection_name) (EphySynchronizableManager *manager);
GType (*get_synchronizable_type) (EphySynchronizableManager *manager);
+ gboolean (*is_initial_sync) (EphySynchronizableManager *manager);
+ void (*set_is_initial_sync) (EphySynchronizableManager *manager,
+ gboolean is_initial);
+
double (*get_sync_time) (EphySynchronizableManager *manager);
void (*set_sync_time) (EphySynchronizableManager *manager,
double sync_time);
@@ -54,6 +58,9 @@ struct _EphySynchronizableManagerInterface {
const char *ephy_synchronizable_manager_get_collection_name (EphySynchronizableManager
*manager);
GType ephy_synchronizable_manager_get_synchronizable_type (EphySynchronizableManager
*manager);
+gboolean ephy_synchronizable_manager_is_initial_sync (EphySynchronizableManager
*manager);
+void ephy_synchronizable_manager_set_is_initial_sync (EphySynchronizableManager *manager,
+ gboolean
is_initial);
double ephy_synchronizable_manager_get_sync_time (EphySynchronizableManager
*manager);
void ephy_synchronizable_manager_set_sync_time (EphySynchronizableManager *manager,
double
sync_time);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]