[epiphany/wip/sync: 2/4] sync: Use wrapper functions to access GSettings



commit e0c5376c0cc7b5a3326837b394b57d31d2d17173
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Wed Jun 7 19:02:10 2017 +0300

    sync: Use wrapper functions to access GSettings

 embed/web-extension/ephy-web-extension.c |   32 ++----
 lib/ephy-sync-utils.c                    |  160 +++++++++++++++++++++++++++++-
 lib/ephy-sync-utils.h                    |   69 ++++++++++----
 lib/sync/debug/ephy-sync-debug.c         |   11 +-
 lib/sync/ephy-history-manager.c          |   20 +---
 lib/sync/ephy-open-tabs-manager.c        |   12 +--
 lib/sync/ephy-password-manager.c         |   20 +---
 lib/sync/ephy-sync-service.c             |   95 ++++++++----------
 lib/sync/ephy-sync-service.h             |   34 +++----
 src/bookmarks/ephy-bookmarks-manager.c   |   19 +---
 src/ephy-shell.c                         |    9 +-
 src/prefs-dialog.c                       |   61 +++++------
 12 files changed, 333 insertions(+), 209 deletions(-)
---
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index 74a271b..e8e1bae 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -31,6 +31,7 @@
 #include "ephy-prefs.h"
 #include "ephy-settings.h"
 #include "ephy-sync-service.h"
+#include "ephy-sync-utils.h"
 #include "ephy-uri-helpers.h"
 #include "ephy-uri-tester.h"
 #include "ephy-web-dom-utils.h"
@@ -1447,7 +1448,7 @@ static const GDBusInterfaceVTable interface_vtable = {
 };
 
 static void
-ephy_prefs_sync_passwords_enabled_cb (GSettings *settings,
+ephy_prefs_passwords_sync_enabled_cb (GSettings *settings,
                                       char      *key,
                                       gpointer   user_data)
 {
@@ -1475,11 +1476,11 @@ ephy_web_extension_create_sync_service (EphyWebExtension *extension)
   extension->sync_service = ephy_sync_service_new (FALSE);
   manager = EPHY_SYNCHRONIZABLE_MANAGER (extension->password_manager);
 
-  if (g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_PASSWORDS_ENABLED))
+  if (ephy_sync_utils_passwords_sync_is_enabled ())
     ephy_sync_service_register_manager (extension->sync_service, manager);
 
   g_signal_connect (EPHY_SETTINGS_SYNC, "changed::"EPHY_PREFS_SYNC_PASSWORDS_ENABLED,
-                    G_CALLBACK (ephy_prefs_sync_passwords_enabled_cb), extension);
+                    G_CALLBACK (ephy_prefs_passwords_sync_enabled_cb), extension);
 }
 
 static void
@@ -1494,7 +1495,7 @@ ephy_web_extension_destroy_sync_service (EphyWebExtension *extension)
   manager = EPHY_SYNCHRONIZABLE_MANAGER (extension->password_manager);
   ephy_sync_service_unregister_manager (extension->sync_service, manager);
   g_signal_handlers_disconnect_by_func (EPHY_SETTINGS_SYNC,
-                                        ephy_prefs_sync_passwords_enabled_cb,
+                                        ephy_prefs_passwords_sync_enabled_cb,
                                         extension);
 
   g_clear_object (&extension->sync_service);
@@ -1505,26 +1506,17 @@ ephy_prefs_sync_user_cb (GSettings *settings,
                          char      *key,
                          gpointer   user_data)
 {
-  EphyWebExtension *extension;
-  char *sync_user;
+  EphyWebExtension *extension = EPHY_WEB_EXTENSION (user_data);
 
   /* If the sync user has changed we need to destroy the previous sync service
    * (which is no longer valid because the user specific data has been cleared)
    * and create a new one which will load the new user specific data. This way
    * we will correctly upload new saved passwords in the future.
    */
-  extension = EPHY_WEB_EXTENSION (user_data);
-  sync_user = g_settings_get_string (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_USER);
-
-  if (!g_strcmp0 (sync_user, "")) {
-    /* Signed out. */
-    ephy_web_extension_destroy_sync_service (extension);
-  } else {
-    /* Signed in. */
+  if (ephy_sync_utils_user_is_signed_in ())
     ephy_web_extension_create_sync_service (extension);
-  }
-
-  g_free (sync_user);
+  else
+    ephy_web_extension_destroy_sync_service (extension);
 }
 
 static void
@@ -1651,17 +1643,13 @@ ephy_web_extension_initialize (EphyWebExtension   *extension,
 
   extension->extension = g_object_ref (wk_extension);
   if (!is_private_profile) {
-    char *sync_user = g_settings_get_string (EPHY_SETTINGS_SYNC,
-                                             EPHY_PREFS_SYNC_USER);
     extension->password_manager = ephy_password_manager_new ();
 
-    if (g_strcmp0 (sync_user, ""))
+    if (ephy_sync_utils_user_is_signed_in ())
       ephy_web_extension_create_sync_service (extension);
 
     g_signal_connect (EPHY_SETTINGS_SYNC, "changed::"EPHY_PREFS_SYNC_USER,
                       G_CALLBACK (ephy_prefs_sync_user_cb), extension);
-
-    g_free (sync_user);
   }
 
   extension->permissions_manager = ephy_permissions_manager_new ();
diff --git a/lib/ephy-sync-utils.c b/lib/ephy-sync-utils.c
index dc4f9d7..bc4ff58 100644
--- a/lib/ephy-sync-utils.c
+++ b/lib/ephy-sync-utils.c
@@ -232,8 +232,7 @@ ephy_sync_utils_get_random_sync_id (void)
 void
 ephy_sync_utils_set_device_id (const char *id)
 {
-  g_return_if_fail (id);
-
+  id = id ? id : "";
   g_settings_set_string (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_DEVICE_ID, id);
 }
 
@@ -254,8 +253,7 @@ ephy_sync_utils_get_device_id (void)
 void
 ephy_sync_utils_set_device_name (const char *name)
 {
-  g_return_if_fail (name);
-
+  name = name ? name : "";
   g_settings_set_string (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_DEVICE_NAME, name);
 }
 
@@ -273,3 +271,157 @@ ephy_sync_utils_get_device_name (void)
 
   return name;
 }
+
+void
+ephy_sync_utils_set_sync_user (const char *user)
+{
+  user = user ? user : "";
+  g_settings_set_string (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_USER, user);
+}
+
+char *
+ephy_sync_utils_get_sync_user (void)
+{
+  char *user = g_settings_get_string (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_USER);
+
+  if (!g_strcmp0 (user, "")) {
+    g_free (user);
+    return NULL;
+  }
+
+  return user;
+}
+
+gboolean
+ephy_sync_utils_user_is_signed_in (void)
+{
+  char *user = ephy_sync_utils_get_sync_user ();
+
+  if (user) {
+    g_free (user);
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+guint
+ephy_sync_utils_get_sync_frequency (void)
+{
+  /* Minutes. */
+  return g_settings_get_uint (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_FREQUENCY);
+}
+
+gboolean
+ephy_sync_utils_sync_with_firefox (void)
+{
+  return g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_WITH_FIREFOX);
+}
+
+gboolean
+ephy_sync_utils_bookmarks_sync_is_enabled (void)
+{
+  return g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_BOOKMARKS_ENABLED);
+}
+
+void
+ephy_sync_utils_set_bookmarks_sync_time (double time)
+{
+  g_settings_set_double (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_BOOKMARKS_TIME, time);
+}
+
+double
+ephy_sync_utils_get_bookmarks_sync_time (void)
+{
+  return g_settings_get_double (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_BOOKMARKS_TIME);
+}
+
+void
+ephy_sync_utils_set_bookmarks_sync_is_initial (double is_initial)
+{
+  g_settings_set_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_BOOKMARKS_INITIAL, is_initial);
+}
+
+gboolean
+ephy_sync_utils_get_bookmarks_sync_is_initial (void)
+{
+  return g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_BOOKMARKS_INITIAL);
+}
+
+gboolean
+ephy_sync_utils_passwords_sync_is_enabled (void)
+{
+  return g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_PASSWORDS_ENABLED);
+}
+
+void
+ephy_sync_utils_set_passwords_sync_time (double time)
+{
+  g_settings_set_double (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_PASSWORDS_TIME, time);
+}
+
+double
+ephy_sync_utils_get_passwords_sync_time (void)
+{
+  return g_settings_get_double (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_PASSWORDS_TIME);
+}
+
+void
+ephy_sync_utils_set_passwords_sync_is_initial (double is_initial)
+{
+  g_settings_set_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_PASSWORDS_INITIAL, is_initial);
+}
+
+gboolean
+ephy_sync_utils_get_passwords_sync_is_initial (void)
+{
+  return g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_PASSWORDS_INITIAL);
+}
+
+gboolean
+ephy_sync_utils_history_sync_is_enabled (void)
+{
+  return g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_HISTORY_ENABLED);
+}
+
+void
+ephy_sync_utils_set_history_sync_time (double time)
+{
+  g_settings_set_double (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_HISTORY_TIME, time);
+}
+
+double
+ephy_sync_utils_get_history_sync_time (void)
+{
+  return g_settings_get_double (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_HISTORY_TIME);
+}
+
+void
+ephy_sync_utils_set_history_sync_is_initial (double is_initial)
+{
+  g_settings_set_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_HISTORY_INITIAL, is_initial);
+}
+
+gboolean
+ephy_sync_utils_get_history_sync_is_initial (void)
+{
+  return g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_HISTORY_INITIAL);
+}
+
+gboolean
+ephy_sync_utils_open_tabs_sync_is_enabled (void)
+{
+  return g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_OPEN_TABS_ENABLED);
+}
+
+void
+ephy_sync_utils_set_open_tabs_sync_time (double time)
+{
+  g_settings_set_double (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_OPEN_TABS_TIME, time);
+}
+
+double
+ephy_sync_utils_get_open_tabs_sync_time (void)
+{
+  return g_settings_get_double (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_OPEN_TABS_TIME);
+}
diff --git a/lib/ephy-sync-utils.h b/lib/ephy-sync-utils.h
index 2bd7392..f741a91 100644
--- a/lib/ephy-sync-utils.h
+++ b/lib/ephy-sync-utils.h
@@ -33,23 +33,56 @@ const SecretSchema *ephy_sync_utils_get_secret_schema (void) G_GNUC_CONST;
 #define TOKEN_SERVER_URL "https://token.services.mozilla.com/1.0/sync/1.5";
 #define FIREFOX_ACCOUNTS_SERVER_URL "https://api.accounts.firefox.com/v1";
 
-char   *ephy_sync_utils_encode_hex                  (const guint8 *data,
-                                                     gsize         data_len);
-guint8 *ephy_sync_utils_decode_hex                  (const char   *hex);
-char   *ephy_sync_utils_base64_urlsafe_encode       (const guint8 *data,
-                                                     gsize         data_len,
-                                                     gboolean      should_strip);
-guint8 *ephy_sync_utils_base64_urlsafe_decode       (const char   *text,
-                                                     gsize        *out_len,
-                                                     gboolean      should_fill);
-void    ephy_sync_utils_generate_random_bytes       (void         *random_ctx,
-                                                     gsize         num_bytes,
-                                                     guint8       *out);
-char   *ephy_sync_utils_get_audience                (const char   *url);
-char   *ephy_sync_utils_get_random_sync_id          (void);
-void    ephy_sync_utils_set_device_id               (const char   *id);
-char   *ephy_sync_utils_get_device_id               (void);
-void    ephy_sync_utils_set_device_name             (const char   *name);
-char   *ephy_sync_utils_get_device_name             (void);
+char     *ephy_sync_utils_encode_hex                    (const guint8 *data,
+                                                         gsize         data_len);
+guint8   *ephy_sync_utils_decode_hex                    (const char   *hex);
+
+char     *ephy_sync_utils_base64_urlsafe_encode         (const guint8 *data,
+                                                         gsize         data_len,
+                                                         gboolean      should_strip);
+guint8   *ephy_sync_utils_base64_urlsafe_decode         (const char *text,
+                                                         gsize      *out_len,
+                                                         gboolean    should_fill);
+
+void      ephy_sync_utils_generate_random_bytes         (void   *random_ctx,
+                                                         gsize   num_bytes,
+                                                         guint8 *out);
+char     *ephy_sync_utils_get_audience                  (const char *url);
+char     *ephy_sync_utils_get_random_sync_id            (void);
+
+void      ephy_sync_utils_set_device_id                 (const char *id);
+char     *ephy_sync_utils_get_device_id                 (void);
+
+void      ephy_sync_utils_set_device_name               (const char *name);
+char     *ephy_sync_utils_get_device_name               (void);
+
+void      ephy_sync_utils_set_sync_user                 (const char *user);
+char     *ephy_sync_utils_get_sync_user                 (void);
+gboolean  ephy_sync_utils_user_is_signed_in             (void);
+
+guint     ephy_sync_utils_get_sync_frequency            (void);
+gboolean  ephy_sync_utils_sync_with_firefox             (void);
+
+gboolean  ephy_sync_utils_bookmarks_sync_is_enabled     (void);
+void      ephy_sync_utils_set_bookmarks_sync_time       (double time);
+double    ephy_sync_utils_get_bookmarks_sync_time       (void);
+void      ephy_sync_utils_set_bookmarks_sync_is_initial (double is_initial);
+gboolean  ephy_sync_utils_get_bookmarks_sync_is_initial (void);
+
+gboolean  ephy_sync_utils_passwords_sync_is_enabled     (void);
+void      ephy_sync_utils_set_passwords_sync_time       (double time);
+double    ephy_sync_utils_get_passwords_sync_time       (void);
+void      ephy_sync_utils_set_passwords_sync_is_initial (double is_initial);
+gboolean  ephy_sync_utils_get_passwords_sync_is_initial (void);
+
+gboolean  ephy_sync_utils_history_sync_is_enabled       (void);
+void      ephy_sync_utils_set_history_sync_time         (double time);
+double    ephy_sync_utils_get_history_sync_time         (void);
+void      ephy_sync_utils_set_history_sync_is_initial   (double is_initial);
+gboolean  ephy_sync_utils_get_history_sync_is_initial   (void);
+
+gboolean  ephy_sync_utils_open_tabs_sync_is_enabled     (void);
+void      ephy_sync_utils_set_open_tabs_sync_time       (double time);
+double    ephy_sync_utils_get_open_tabs_sync_time       (void);
 
 G_END_DECLS
diff --git a/lib/sync/debug/ephy-sync-debug.c b/lib/sync/debug/ephy-sync-debug.c
index 0ff87a9..edb5723 100644
--- a/lib/sync/debug/ephy-sync-debug.c
+++ b/lib/sync/debug/ephy-sync-debug.c
@@ -41,10 +41,10 @@ ephy_sync_debug_load_secrets (void)
   GList *result;
   char *user;
 
-  user = g_settings_get_string (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_USER);
-  if (!g_strcmp0 (user, "")) {
+  user = ephy_sync_utils_get_sync_user ();
+  if (!user) {
     LOG ("There is no sync user signed in.");
-    goto free_user;
+    return NULL;
   }
 
   attributes = secret_attributes_build (EPHY_SYNC_SECRET_SCHEMA,
@@ -59,7 +59,7 @@ ephy_sync_debug_load_secrets (void)
   if (error) {
     LOG ("Error searching sync secrets: %s", error->message);
     g_error_free (error);
-    goto free_result;
+    goto free_attributes;
   }
 
   value = secret_item_get_secret ((SecretItem *)result->data);
@@ -75,10 +75,9 @@ ephy_sync_debug_load_secrets (void)
   json_node_unref (node);
 free_value:
   secret_value_unref (value);
-free_result:
   g_list_free_full (result, g_object_unref);
+free_attributes:
   g_hash_table_unref (attributes);
-free_user:
   g_free (user);
 
   return secrets;
diff --git a/lib/sync/ephy-history-manager.c b/lib/sync/ephy-history-manager.c
index 1d21a63..6ad07d6 100644
--- a/lib/sync/ephy-history-manager.c
+++ b/lib/sync/ephy-history-manager.c
@@ -22,6 +22,7 @@
 #include "ephy-history-manager.h"
 
 #include "ephy-settings.h"
+#include "ephy-sync-utils.h"
 #include "ephy-synchronizable-manager.h"
 
 struct _EphyHistoryManager {
@@ -204,10 +205,7 @@ ephy_history_manager_new (EphyHistoryService *service)
 static const char *
 synchronizable_manager_get_collection_name (EphySynchronizableManager *manager)
 {
-  gboolean sync_with_firefox = g_settings_get_boolean (EPHY_SETTINGS_SYNC,
-                                                       EPHY_PREFS_SYNC_WITH_FIREFOX);
-
-  return sync_with_firefox ? "history" : "ephy-history";
+  return ephy_sync_utils_sync_with_firefox () ? "history" : "ephy-history";
 }
 
 static GType
@@ -219,33 +217,27 @@ synchronizable_manager_get_synchronizable_type (EphySynchronizableManager *manag
 static gboolean
 synchronizable_manager_is_initial_sync (EphySynchronizableManager *manager)
 {
-  return g_settings_get_boolean (EPHY_SETTINGS_SYNC,
-                                 EPHY_PREFS_SYNC_HISTORY_INITIAL);
+  return ephy_sync_utils_get_history_sync_is_initial ();
 }
 
 static void
 synchronizable_manager_set_is_initial_sync (EphySynchronizableManager *manager,
                                             gboolean                   is_initial)
 {
-  g_settings_set_boolean (EPHY_SETTINGS_SYNC,
-                          EPHY_PREFS_SYNC_HISTORY_INITIAL,
-                          is_initial);
+  ephy_sync_utils_set_history_sync_is_initial (is_initial);
 }
 
 static double
 synchronizable_manager_get_sync_time (EphySynchronizableManager *manager)
 {
-  return g_settings_get_double (EPHY_SETTINGS_SYNC,
-                                EPHY_PREFS_SYNC_HISTORY_TIME);
+  return ephy_sync_utils_get_history_sync_time ();
 }
 
 static void
 synchronizable_manager_set_sync_time (EphySynchronizableManager *manager,
                                       double                     sync_time)
 {
-  g_settings_set_double (EPHY_SETTINGS_SYNC,
-                         EPHY_PREFS_SYNC_HISTORY_TIME,
-                         sync_time);
+  ephy_sync_utils_set_history_sync_time (sync_time);
 }
 
 static void
diff --git a/lib/sync/ephy-open-tabs-manager.c b/lib/sync/ephy-open-tabs-manager.c
index 5331816..5b5d2be 100644
--- a/lib/sync/ephy-open-tabs-manager.c
+++ b/lib/sync/ephy-open-tabs-manager.c
@@ -139,10 +139,7 @@ ephy_open_tabs_manager_clear_cache (EphyOpenTabsManager *self)
 const char *
 synchronizable_manager_get_collection_name (EphySynchronizableManager *manager)
 {
-  gboolean sync_with_firefox = g_settings_get_boolean (EPHY_SETTINGS_SYNC,
-                                                       EPHY_PREFS_SYNC_WITH_FIREFOX);
-
-  return sync_with_firefox ? "tabs" : "ephy-tabs";
+  return ephy_sync_utils_sync_with_firefox () ? "tabs" : "ephy-tabs";
 }
 
 static GType
@@ -170,17 +167,14 @@ synchronizable_manager_set_is_initial_sync (EphySynchronizableManager *manager,
 static double
 synchronizable_manager_get_sync_time (EphySynchronizableManager *manager)
 {
-  return g_settings_get_double (EPHY_SETTINGS_SYNC,
-                                EPHY_PREFS_SYNC_OPEN_TABS_TIME);
+  return ephy_sync_utils_get_open_tabs_sync_time ();
 }
 
 static void
 synchronizable_manager_set_sync_time (EphySynchronizableManager *manager,
                                       double                     sync_time)
 {
-  g_settings_set_double (EPHY_SETTINGS_SYNC,
-                         EPHY_PREFS_SYNC_OPEN_TABS_TIME,
-                         sync_time);
+  ephy_sync_utils_set_open_tabs_sync_time (sync_time);
 }
 
 static void
diff --git a/lib/sync/ephy-password-manager.c b/lib/sync/ephy-password-manager.c
index a84ddfd..83db2b4 100644
--- a/lib/sync/ephy-password-manager.c
+++ b/lib/sync/ephy-password-manager.c
@@ -23,6 +23,7 @@
 
 #include "ephy-debug.h"
 #include "ephy-settings.h"
+#include "ephy-sync-utils.h"
 #include "ephy-synchronizable-manager.h"
 #include "ephy-uri-helpers.h"
 
@@ -745,10 +746,7 @@ ephy_password_manager_forget_all (EphyPasswordManager *self)
 static const char *
 synchronizable_manager_get_collection_name (EphySynchronizableManager *manager)
 {
-  gboolean sync_with_firefox = g_settings_get_boolean (EPHY_SETTINGS_SYNC,
-                                                       EPHY_PREFS_SYNC_WITH_FIREFOX);
-
-  return sync_with_firefox ? "passwords" : "ephy-passwords";
+  return ephy_sync_utils_sync_with_firefox () ? "passwords" : "ephy-passwords";
 }
 
 static GType
@@ -760,33 +758,27 @@ synchronizable_manager_get_synchronizable_type (EphySynchronizableManager *manag
 static gboolean
 synchronizable_manager_is_initial_sync (EphySynchronizableManager *manager)
 {
-  return g_settings_get_boolean (EPHY_SETTINGS_SYNC,
-                                 EPHY_PREFS_SYNC_PASSWORDS_INITIAL);
+  return ephy_sync_utils_get_passwords_sync_is_initial ();
 }
 
 static void
 synchronizable_manager_set_is_initial_sync (EphySynchronizableManager *manager,
                                             gboolean                   is_initial)
 {
-  g_settings_set_boolean (EPHY_SETTINGS_SYNC,
-                          EPHY_PREFS_SYNC_PASSWORDS_INITIAL,
-                          is_initial);
+  ephy_sync_utils_set_passwords_sync_is_initial (is_initial);
 }
 
 static double
 synchronizable_manager_get_sync_time (EphySynchronizableManager *manager)
 {
-  return g_settings_get_double (EPHY_SETTINGS_SYNC,
-                                EPHY_PREFS_SYNC_PASSWORDS_TIME);
+  return ephy_sync_utils_get_passwords_sync_time ();
 }
 
 static void
 synchronizable_manager_set_sync_time (EphySynchronizableManager *manager,
                                       double                     sync_time)
 {
-  g_settings_set_double (EPHY_SETTINGS_SYNC,
-                         EPHY_PREFS_SYNC_PASSWORDS_TIME,
-                         sync_time);
+  ephy_sync_utils_set_passwords_sync_time (sync_time);
 }
 
 static void
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index 168377d..b371f1e 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -40,7 +40,7 @@ struct _EphySyncService {
   SoupSession *session;
   guint        source_id;
 
-  char        *account;
+  char        *user;
   GHashTable  *secrets;
   GSList      *managers;
 
@@ -681,7 +681,7 @@ ephy_sync_service_report_sign_in_error (EphySyncService *self,
   ephy_sync_service_destroy_session (self, session_token);
 
   if (clear_secrets) {
-    g_clear_pointer (&self->account, g_free);
+    g_clear_pointer (&self->user, g_free);
     g_hash_table_remove_all (self->secrets);
   }
 
@@ -743,7 +743,7 @@ out_error:
   if (self->is_signing_in)
     ephy_sync_service_report_sign_in_error (self, message, NULL, TRUE);
   else
-  ephy_notification_show (ephy_notification_new (message, suggestion));
+    ephy_notification_show (ephy_notification_new (message, suggestion));
 out:
   self->locked = FALSE;
   if (node)
@@ -983,7 +983,7 @@ ephy_sync_service_delete_synchronizable (EphySyncService           *self,
   g_assert (EPHY_IS_SYNC_SERVICE (self));
   g_assert (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager));
   g_assert (EPHY_IS_SYNCHRONIZABLE (synchronizable));
-  g_assert (ephy_sync_service_is_signed_in (self));
+  g_assert (ephy_sync_utils_user_is_signed_in ());
 
   collection = ephy_synchronizable_manager_get_collection_name (manager);
   id = ephy_synchronizable_get_id (synchronizable);
@@ -1086,7 +1086,7 @@ ephy_sync_service_download_synchronizable (EphySyncService           *self,
   g_assert (EPHY_IS_SYNC_SERVICE (self));
   g_assert (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager));
   g_assert (EPHY_IS_SYNCHRONIZABLE (synchronizable));
-  g_assert (ephy_sync_service_is_signed_in (self));
+  g_assert (ephy_sync_utils_user_is_signed_in ());
 
   id = ephy_synchronizable_get_id (synchronizable);
   collection = ephy_synchronizable_manager_get_collection_name (manager);
@@ -1150,7 +1150,7 @@ ephy_sync_service_upload_synchronizable (EphySyncService           *self,
   g_assert (EPHY_IS_SYNC_SERVICE (self));
   g_assert (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager));
   g_assert (EPHY_IS_SYNCHRONIZABLE (synchronizable));
-  g_assert (ephy_sync_service_is_signed_in (self));
+  g_assert (ephy_sync_utils_user_is_signed_in ());
 
   collection = ephy_synchronizable_manager_get_collection_name (manager);
   bundle = ephy_sync_service_get_key_bundle (self, collection);
@@ -1282,7 +1282,7 @@ ephy_sync_service_sync_collection (EphySyncService           *self,
 
   g_assert (EPHY_IS_SYNC_SERVICE (self));
   g_assert (EPHY_IS_SYNCHRONIZABLE_MANAGER (manager));
-  g_assert (ephy_sync_service_is_signed_in (self));
+  g_assert (ephy_sync_utils_user_is_signed_in ());
 
   collection = ephy_synchronizable_manager_get_collection_name (manager);
   is_initial = ephy_synchronizable_manager_is_initial_sync (manager);
@@ -1310,7 +1310,7 @@ ephy_sync_service_sync (gpointer user_data)
   guint index = 0;
   guint num_managers;
 
-  g_assert (ephy_sync_service_is_signed_in (self));
+  g_assert (ephy_sync_utils_user_is_signed_in ());
 
   if (!self->managers) {
     g_signal_emit (self, signals[SYNC_FINISHED], 0);
@@ -1342,7 +1342,7 @@ ephy_sync_service_schedule_periodical_sync (EphySyncService *self)
 
   g_assert (EPHY_IS_SYNC_SERVICE (self));
 
-  seconds = g_settings_get_uint (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_FREQUENCY) * 60;
+  seconds = ephy_sync_utils_get_sync_frequency () * 60;
   self->source_id = g_timeout_add_seconds (seconds, ephy_sync_service_sync, self);
 
   LOG ("Scheduled new sync with frequency %u minutes", seconds / 60);
@@ -1377,18 +1377,21 @@ static void
 ephy_sync_service_forget_secrets (EphySyncService *self)
 {
   GHashTable *attributes;
+  char *user;
 
   g_assert (EPHY_IS_SYNC_SERVICE (self));
   g_assert (self->secrets);
 
+  user = ephy_sync_utils_get_sync_user ();
   attributes = secret_attributes_build (EPHY_SYNC_SECRET_SCHEMA,
-                                        ACCOUNT_KEY, self->account,
+                                        ACCOUNT_KEY, user,
                                         NULL);
   secret_service_clear (NULL, EPHY_SYNC_SECRET_SCHEMA, attributes, NULL,
                         (GAsyncReadyCallback)forget_secrets_cb, NULL);
   g_hash_table_remove_all (self->secrets);
 
   g_hash_table_unref (attributes);
+  g_free (user);
 }
 
 static void
@@ -1452,18 +1455,21 @@ static void
 ephy_sync_service_load_secrets (EphySyncService *self)
 {
   GHashTable *attributes;
+  char *user;
 
   g_assert (EPHY_IS_SYNC_SERVICE (self));
   g_assert (self->secrets);
 
+  user = ephy_sync_utils_get_sync_user ();
   attributes = secret_attributes_build (EPHY_SYNC_SECRET_SCHEMA,
-                                        ACCOUNT_KEY, self->account,
+                                        ACCOUNT_KEY, user,
                                         NULL);
   secret_service_search (NULL, EPHY_SYNC_SECRET_SCHEMA, attributes,
                          SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS,
                          NULL, (GAsyncReadyCallback)load_secrets_cb, self);
 
   g_hash_table_unref (attributes);
+  g_free (user);
 }
 
 static void
@@ -1477,15 +1483,16 @@ store_secrets_cb (SecretService   *service,
   if (error) {
     g_warning ("Failed to store sync secrets: %s", error->message);
     ephy_sync_service_destroy_session (self, NULL);
-    g_clear_pointer (&self->account, g_free);
     g_hash_table_remove_all (self->secrets);
   } else {
+    ephy_sync_utils_set_sync_user (self->user);
     ephy_sync_service_register_device (self, NULL);
   }
 
   g_signal_emit (self, signals[STORE_FINISHED], 0, error);
   self->is_signing_in = FALSE;
 
+  g_clear_pointer (&self->user, g_free);
   if (error)
     g_error_free (error);
 }
@@ -1505,7 +1512,7 @@ ephy_sync_service_store_secrets (EphySyncService *self)
 
   g_assert (EPHY_IS_SYNC_SERVICE (self));
   g_assert (self->secrets);
-  g_assert (self->account);
+  g_assert (self->user);
 
   node = json_node_new (JSON_NODE_OBJECT);
   object = json_object_new ();
@@ -1517,10 +1524,10 @@ ephy_sync_service_store_secrets (EphySyncService *self)
 
   secret = secret_value_new (json_string, -1, "text/plain");
   attributes = secret_attributes_build (EPHY_SYNC_SECRET_SCHEMA,
-                                        ACCOUNT_KEY, self->account,
+                                        ACCOUNT_KEY, self->user,
                                         NULL);
   /* Translators: %s is the email of the user. */
-  label = g_strdup_printf (_("The sync secrets of %s"), self->account);
+  label = g_strdup_printf (_("The sync secrets of %s"), self->user);
 
   secret_service_store (NULL, EPHY_SYNC_SECRET_SCHEMA,
                         attributes, NULL, label, secret, NULL,
@@ -1539,12 +1546,11 @@ ephy_sync_service_dispose (GObject *object)
 {
   EphySyncService *self = EPHY_SYNC_SERVICE (object);
 
-  if (ephy_sync_service_is_signed_in (self))
+  if (ephy_sync_utils_user_is_signed_in ())
     ephy_sync_service_stop_periodical_sync (self);
 
   ephy_sync_service_clear_storage_credentials (self);
   g_clear_object (&self->session);
-  g_clear_pointer (&self->account, g_free);
   g_clear_pointer (&self->rsa_key_pair, ephy_sync_crypto_rsa_key_pair_free);
   g_clear_pointer (&self->secrets, g_hash_table_destroy);
   g_clear_pointer (&self->managers, g_slist_free);
@@ -1576,19 +1582,12 @@ ephy_sync_service_constructed (GObject *object)
 static void
 ephy_sync_service_init (EphySyncService *self)
 {
-  char *account;
-
   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);
 
-  account = g_settings_get_string (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_USER);
-  if (g_strcmp0 (account, "")) {
-    self->account = g_strdup (account);
+  if (ephy_sync_utils_user_is_signed_in ())
     ephy_sync_service_load_secrets (self);
-  }
-
-  g_free (account);
 }
 
 static void
@@ -1642,22 +1641,6 @@ ephy_sync_service_new (gboolean sync_periodically)
                                           NULL));
 }
 
-gboolean
-ephy_sync_service_is_signed_in (EphySyncService *self)
-{
-  g_return_val_if_fail (EPHY_IS_SYNC_SERVICE (self), FALSE);
-
-  return self->account != NULL;
-}
-
-const char *
-ephy_sync_service_get_sync_user (EphySyncService *self)
-{
-  g_return_val_if_fail (EPHY_IS_SYNC_SERVICE (self), NULL);
-
-  return self->account;
-}
-
 static char *
 ephy_sync_service_upload_crypto_keys_record (EphySyncService *self)
 {
@@ -1958,8 +1941,15 @@ ephy_sync_service_conclude_sign_in (EphySyncService *self,
     goto out;
   }
 
-  /* Save email and tokens. */
-  self->account = g_strdup (data->email);
+  /* Cache the user email until the secrets are stored. We cannot use
+   * ephy_sync_utils_set_sync_user() here because that will trigger the
+   * 'changed' signal of EPHY_PREFS_SYNC_USER which in turn will cause
+   * the web extension to destroy its own sync service and create a new
+   * one. That new sync service will fail to load the sync secrets from
+   * disk because the secrets are not yet stored at this point, thus it
+   * will be unable to operate.
+   */
+  self->user = g_strdup (data->email);
   ephy_sync_service_set_secret (self, secrets[UID], data->uid);
   ephy_sync_service_set_secret (self, secrets[SESSION_TOKEN], data->session_token);
   key_b_hex = ephy_sync_utils_encode_hex (key_b, 32);
@@ -2091,7 +2081,7 @@ synchronizable_deleted_cb (EphySynchronizableManager *manager,
   g_assert (EPHY_IS_SYNCHRONIZABLE (synchronizable));
   g_assert (EPHY_IS_SYNC_SERVICE (self));
 
-  if (!ephy_sync_service_is_signed_in (self))
+  if (!ephy_sync_utils_user_is_signed_in ())
     return;
 
   ephy_sync_service_delete_synchronizable (self, manager, synchronizable);
@@ -2107,7 +2097,7 @@ synchronizable_modified_cb (EphySynchronizableManager *manager,
   g_assert (EPHY_IS_SYNCHRONIZABLE (synchronizable));
   g_assert (EPHY_IS_SYNC_SERVICE (self));
 
-  if (!ephy_sync_service_is_signed_in (self))
+  if (!ephy_sync_utils_user_is_signed_in ())
     return;
 
   ephy_sync_service_upload_synchronizable (self, manager, synchronizable, should_force);
@@ -2240,7 +2230,7 @@ ephy_sync_service_unregister_device (EphySyncService *self)
   ephy_sync_service_queue_storage_request (self, endpoint, SOUP_METHOD_DELETE,
                                            NULL, -1, -1, NULL, NULL);
 
-  ephy_sync_utils_set_device_id ("");
+  ephy_sync_utils_set_device_id (NULL);
 
   g_free (endpoint);
   g_free (id);
@@ -2256,7 +2246,6 @@ ephy_sync_service_do_sign_out (EphySyncService *self)
   ephy_sync_service_destroy_session (self, NULL);
   ephy_sync_service_clear_storage_credentials (self);
   ephy_sync_service_forget_secrets (self);
-  g_clear_pointer (&self->account, g_free);
 
   /* Clear storage messages queue. */
   while (!g_queue_is_empty (self->storage_queue))
@@ -2269,17 +2258,17 @@ ephy_sync_service_do_sign_out (EphySyncService *self)
   }
   g_clear_pointer (&self->managers, g_slist_free);
 
-  g_settings_set_string (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_USER, "");
-  g_settings_set_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_BOOKMARKS_INITIAL, TRUE);
-  g_settings_set_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_PASSWORDS_INITIAL, TRUE);
-  g_settings_set_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_HISTORY_INITIAL, TRUE);
+  ephy_sync_utils_set_sync_user (NULL);
+  ephy_sync_utils_set_bookmarks_sync_is_initial (TRUE);
+  ephy_sync_utils_set_passwords_sync_is_initial (TRUE);
+  ephy_sync_utils_set_history_sync_is_initial (TRUE);
 }
 
 void
 ephy_sync_service_do_sync (EphySyncService *self)
 {
   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_sync_utils_user_is_signed_in ());
 
   ephy_sync_service_sync (self);
 }
@@ -2288,7 +2277,7 @@ void
 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));
+  g_return_if_fail (ephy_sync_utils_user_is_signed_in ());
   g_return_if_fail (self->sync_periodically);
 
   ephy_sync_service_sync (self);
diff --git a/lib/sync/ephy-sync-service.h b/lib/sync/ephy-sync-service.h
index 30f9cbc..3fdba70 100644
--- a/lib/sync/ephy-sync-service.h
+++ b/lib/sync/ephy-sync-service.h
@@ -30,23 +30,21 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EphySyncService, ephy_sync_service, EPHY, SYNC_SERVICE, GObject)
 
-EphySyncService   *ephy_sync_service_new                    (gboolean sync_periodically);
-gboolean           ephy_sync_service_is_signed_in           (EphySyncService *self);
-const char        *ephy_sync_service_get_sync_user          (EphySyncService *self);
-void               ephy_sync_service_do_sign_in             (EphySyncService *self,
-                                                             const char      *email,
-                                                             const char      *uid,
-                                                             const char      *session_token,
-                                                             const char      *key_fetch_token,
-                                                             const char      *unwrap_b_key);
-void               ephy_sync_service_do_sign_out            (EphySyncService *self);
-void               ephy_sync_service_do_sync                (EphySyncService *self);
-void               ephy_sync_service_start_periodical_sync  (EphySyncService *self);
-void               ephy_sync_service_register_device        (EphySyncService *self,
-                                                             const char      *device_name);
-void               ephy_sync_service_register_manager       (EphySyncService           *self,
-                                                             EphySynchronizableManager *manager);
-void               ephy_sync_service_unregister_manager     (EphySyncService           *self,
-                                                             EphySynchronizableManager *manager);
+EphySyncService *ephy_sync_service_new                    (gboolean sync_periodically);
+void             ephy_sync_service_do_sign_in             (EphySyncService *self,
+                                                           const char      *email,
+                                                           const char      *uid,
+                                                           const char      *session_token,
+                                                           const char      *key_fetch_token,
+                                                           const char      *unwrap_b_key);
+void             ephy_sync_service_do_sign_out            (EphySyncService *self);
+void             ephy_sync_service_do_sync                (EphySyncService *self);
+void             ephy_sync_service_start_periodical_sync  (EphySyncService *self);
+void             ephy_sync_service_register_device        (EphySyncService *self,
+                                                           const char      *device_name);
+void             ephy_sync_service_register_manager       (EphySyncService           *self,
+                                                           EphySynchronizableManager *manager);
+void             ephy_sync_service_unregister_manager     (EphySyncService           *self,
+                                                           EphySynchronizableManager *manager);
 
 G_END_DECLS
diff --git a/src/bookmarks/ephy-bookmarks-manager.c b/src/bookmarks/ephy-bookmarks-manager.c
index cabd623..70201e3 100644
--- a/src/bookmarks/ephy-bookmarks-manager.c
+++ b/src/bookmarks/ephy-bookmarks-manager.c
@@ -663,10 +663,7 @@ list_model_iface_init (GListModelInterface *iface)
 static const char *
 synchronizable_manager_get_collection_name (EphySynchronizableManager *manager)
 {
-  gboolean sync_with_firefox = g_settings_get_boolean (EPHY_SETTINGS_SYNC,
-                                                       EPHY_PREFS_SYNC_WITH_FIREFOX);
-
-  return sync_with_firefox ? "bookmarks" : "ephy-bookmarks";
+  return ephy_sync_utils_sync_with_firefox () ? "bookmarks" : "ephy-bookmarks";
 }
 
 static GType
@@ -678,33 +675,27 @@ synchronizable_manager_get_synchronizable_type (EphySynchronizableManager *manag
 static gboolean
 synchronizable_manager_is_initial_sync (EphySynchronizableManager *manager)
 {
-  return g_settings_get_boolean (EPHY_SETTINGS_SYNC,
-                                 EPHY_PREFS_SYNC_BOOKMARKS_INITIAL);
+  return ephy_sync_utils_get_bookmarks_sync_is_initial ();
 }
 
 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,
-                          is_initial);
+  ephy_sync_utils_set_bookmarks_sync_is_initial (is_initial);
 }
 
 static double
 synchronizable_manager_get_sync_time (EphySynchronizableManager *manager)
 {
-  return g_settings_get_double (EPHY_SETTINGS_SYNC,
-                                EPHY_PREFS_SYNC_BOOKMARKS_TIME);
+  return ephy_sync_utils_get_bookmarks_sync_time ();
 }
 
 static void
 synchronizable_manager_set_sync_time (EphySynchronizableManager *manager,
                                       double                     sync_time)
 {
-  g_settings_set_double (EPHY_SETTINGS_SYNC,
-                         EPHY_PREFS_SYNC_BOOKMARKS_TIME,
-                         sync_time);
+  ephy_sync_utils_set_bookmarks_sync_time (sync_time);
 }
 
 static void
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 4b70a61..e6e26eb 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -36,6 +36,7 @@
 #include "ephy-prefs.h"
 #include "ephy-session.h"
 #include "ephy-settings.h"
+#include "ephy-sync-utils.h"
 #include "ephy-title-box.h"
 #include "ephy-title-widget.h"
 #include "ephy-type-builtins.h"
@@ -350,22 +351,22 @@ ephy_shell_startup (GApplication *application)
                               G_BINDING_SYNC_CREATE);
 
       /* Register the synchronizable managers. */
-      if (g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_BOOKMARKS_ENABLED)) {
+      if (ephy_sync_utils_bookmarks_sync_is_enabled ()) {
         manager = EPHY_SYNCHRONIZABLE_MANAGER (ephy_shell_get_bookmarks_manager (shell));
         ephy_sync_service_register_manager (ephy_shell_get_sync_service (shell), manager);
       }
 
-      if (g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_PASSWORDS_ENABLED)) {
+      if (ephy_sync_utils_passwords_sync_is_enabled ()) {
         manager = EPHY_SYNCHRONIZABLE_MANAGER (ephy_shell_get_password_manager (shell));
         ephy_sync_service_register_manager (ephy_shell_get_sync_service (shell), manager);
       }
 
-      if (g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_HISTORY_ENABLED)) {
+      if (ephy_sync_utils_history_sync_is_enabled ()) {
         manager = EPHY_SYNCHRONIZABLE_MANAGER (ephy_shell_get_history_manager (shell));
         ephy_sync_service_register_manager (ephy_shell_get_sync_service (shell), manager);
       }
 
-      if (g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_OPEN_TABS_ENABLED)) {
+      if (ephy_sync_utils_open_tabs_sync_is_enabled ()) {
         manager = EPHY_SYNCHRONIZABLE_MANAGER (ephy_shell_get_open_tabs_manager (shell));
         ephy_sync_service_register_manager (ephy_shell_get_sync_service (shell), manager);
       }
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 656d217..5bd79df 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -177,7 +177,7 @@ prefs_dialog_finalize (GObject *object)
   }
 
   if (dialog->sync_service != NULL) {
-    if (ephy_sync_service_is_signed_in (dialog->sync_service) && !dialog->sync_was_signed_in)
+    if (ephy_sync_utils_user_is_signed_in () && !dialog->sync_was_signed_in)
       ephy_sync_service_start_periodical_sync (dialog->sync_service);
   }
 
@@ -217,15 +217,13 @@ sync_with_firefox_toggled_cb (GtkToggleButton *button,
                               PrefsDialog     *dialog)
 {
   gboolean button_is_active = gtk_toggle_button_get_active (button);
-  gboolean sync_with_firefox = g_settings_get_boolean (EPHY_SETTINGS_SYNC,
-                                                       EPHY_PREFS_SYNC_WITH_FIREFOX);
 
   /* Make sure this is called only when the button was toggled by the user. */
-  g_assert (button_is_active != sync_with_firefox);
+  g_assert (button_is_active != ephy_sync_utils_sync_with_firefox ());
 
-  g_settings_set_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_BOOKMARKS_INITIAL, TRUE);
-  g_settings_set_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_PASSWORDS_INITIAL, TRUE);
-  g_settings_set_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_HISTORY_INITIAL, TRUE);
+  ephy_sync_utils_set_bookmarks_sync_is_initial (TRUE);
+  ephy_sync_utils_set_passwords_sync_is_initial (TRUE);
+  ephy_sync_utils_set_history_sync_is_initial (TRUE);
 }
 
 static void
@@ -282,7 +280,7 @@ sync_secrets_store_finished_cb (EphySyncService *service,
     char *user;
 
     /* Show sync options panel. */
-    user = g_strdup_printf ("<b>%s</b>", ephy_sync_service_get_sync_user (service));
+    user = g_strdup_printf ("<b>%s</b>", ephy_sync_utils_get_sync_user ());
     /* Translators: the %s refers to the email of the currently logged in user. */
     text = g_strdup_printf (_("Currently logged in as %s"), user);
     gtk_label_set_markup (GTK_LABEL (dialog->sync_firefox_account_label), text);
@@ -295,23 +293,19 @@ sync_secrets_store_finished_cb (EphySyncService *service,
                         dialog->sync_options_box,
                         FALSE, FALSE, 0);
 
-    g_settings_set_string (EPHY_SETTINGS_SYNC,
-                           EPHY_PREFS_SYNC_USER,
-                           ephy_sync_service_get_sync_user (service));
-
-    if (g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_BOOKMARKS_ENABLED)) {
+    if (ephy_sync_utils_bookmarks_sync_is_enabled ()) {
       manager = EPHY_SYNCHRONIZABLE_MANAGER (ephy_shell_get_bookmarks_manager (shell));
       ephy_sync_service_register_manager (service, manager);
     }
-    if (g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_PASSWORDS_ENABLED)) {
+    if (ephy_sync_utils_passwords_sync_is_enabled ()) {
       manager = EPHY_SYNCHRONIZABLE_MANAGER (ephy_shell_get_password_manager (shell));
       ephy_sync_service_register_manager (service, manager);
     }
-    if (g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_HISTORY_ENABLED)) {
+    if (ephy_sync_utils_history_sync_is_enabled ()) {
       manager = EPHY_SYNCHRONIZABLE_MANAGER (ephy_shell_get_history_manager (shell));
       ephy_sync_service_register_manager (service, manager);
     }
-    if (g_settings_get_boolean (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_OPEN_TABS_ENABLED)) {
+    if (ephy_sync_utils_open_tabs_sync_is_enabled ()) {
       manager = EPHY_SYNCHRONIZABLE_MANAGER (ephy_shell_get_open_tabs_manager (shell));
       ephy_sync_service_register_manager (service, manager);
     }
@@ -1757,37 +1751,35 @@ setup_sync_page (PrefsDialog *dialog)
 {
   GSettings *sync_settings;
   char *user;
-  char *text;
   char *name;
 
-  sync_settings = ephy_settings_get (EPHY_PREFS_SYNC_SCHEMA);
-  dialog->sync_service = ephy_shell_get_sync_service (ephy_shell_get_default ());
-  dialog->sync_was_signed_in = ephy_sync_service_is_signed_in (dialog->sync_service);
-
-  name = ephy_sync_utils_get_device_name ();
-  gtk_entry_set_text (GTK_ENTRY (dialog->sync_device_name_entry), name);
-  g_free (name);
-
-  if (!dialog->sync_was_signed_in) {
+  user = ephy_sync_utils_get_sync_user ();
+  if (!user) {
     sync_setup_firefox_iframe (dialog);
     gtk_container_remove (GTK_CONTAINER (dialog->sync_page_box),
                           dialog->sync_firefox_account_box);
     gtk_container_remove (GTK_CONTAINER (dialog->sync_page_box),
                           dialog->sync_options_box);
   } else {
-    gtk_container_remove (GTK_CONTAINER (dialog->sync_page_box),
-                          dialog->sync_firefox_iframe_box);
-
-    user = g_strdup_printf ("<b>%s</b>",
-                            ephy_sync_service_get_sync_user (dialog->sync_service));
+    char *email = g_strdup_printf ("<b>%s</b>", user);
     /* Translators: the %s refers to the email of the currently logged in user. */
-    text = g_strdup_printf (_("Currently logged in as %s"), user);
+    char *text = g_strdup_printf (_("Currently logged in as %s"), email);
+
     gtk_label_set_markup (GTK_LABEL (dialog->sync_firefox_account_label), text);
+    gtk_container_remove (GTK_CONTAINER (dialog->sync_page_box),
+                          dialog->sync_firefox_iframe_box);
 
+    g_free (email);
     g_free (text);
-    g_free (user);
   }
 
+  name = ephy_sync_utils_get_device_name ();
+  gtk_entry_set_text (GTK_ENTRY (dialog->sync_device_name_entry), name);
+
+  sync_settings = ephy_settings_get (EPHY_PREFS_SYNC_SCHEMA);
+  dialog->sync_service = ephy_shell_get_sync_service (ephy_shell_get_default ());
+  dialog->sync_was_signed_in = user != NULL;
+
   g_settings_bind (sync_settings,
                    EPHY_PREFS_SYNC_WITH_FIREFOX,
                    dialog->sync_with_firefox_checkbutton,
@@ -1878,6 +1870,9 @@ setup_sync_page (PrefsDialog *dialog)
   g_signal_connect_object (dialog->sync_open_tabs_checkbutton, "toggled",
                            G_CALLBACK (sync_collection_toggled_cb),
                            dialog, 0);
+
+  g_free (user);
+  g_free (name);
 }
 
 static void



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