[epiphany/wip/sync: 68/86] sync-service: Add _do_sign_out() function



commit 0c0ad28bb48fa098d73dfcadcb71b6e8cb4234b4
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Sat Mar 11 14:01:58 2017 +0200

    sync-service: Add _do_sign_out() function

 src/prefs-dialog.c           |   12 +-----------
 src/sync/ephy-sync-service.c |   25 +++++++++++++++++++++++--
 src/sync/ephy-sync-service.h |    1 +
 3 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 72ebd13..46e9fa5 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -406,17 +406,7 @@ on_sync_sign_out_button_clicked (GtkWidget   *button,
   EphySyncService *service;
 
   service = ephy_shell_get_sync_service (ephy_shell_get_default ());
-
-  /* Destroy session and delete tokens. */
-  ephy_sync_service_stop_periodical_sync (service);
-  ephy_sync_service_destroy_session (service, NULL);
-  ephy_sync_service_clear_storage_credentials (service);
-  ephy_sync_service_clear_tokens (service);
-  ephy_sync_secret_forget_tokens ();
-  ephy_sync_service_set_user_email (service, NULL);
-  ephy_sync_service_set_sync_time (service, 0);
-
-  g_settings_set_string (EPHY_SETTINGS_MAIN, EPHY_PREFS_SYNC_USER, "");
+  ephy_sync_service_do_sign_out (service);
 
   /* Show sign in box. */
   if (dialog->fxa_web_view == NULL)
diff --git a/src/sync/ephy-sync-service.c b/src/sync/ephy-sync-service.c
index 9103bde..cc03407 100644
--- a/src/sync/ephy-sync-service.c
+++ b/src/sync/ephy-sync-service.c
@@ -844,9 +844,13 @@ ephy_sync_service_destroy_session (EphySyncService *self,
 
   g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
 
-  if (!sessionToken)
+  if (!sessionToken) {
     sessionToken = ephy_sync_service_get_token (self, TOKEN_SESSIONTOKEN);
-  g_return_if_fail (sessionToken);
+    if (!sessionToken) {
+      g_warning ("Cannot destroy session: missing sessionToken");
+      return;
+    }
+  }
 
   url = g_strdup_printf ("%s%s", MOZILLA_FXA_SERVER_URL, endpoint);
   ephy_sync_crypto_process_session_token (sessionToken, &tokenID, &reqHMACkey, &requestKey);
@@ -1171,6 +1175,23 @@ ephy_sync_service_do_sign_in (EphySyncService *self,
   g_free (tokenID_hex);
 }
 
+void
+ephy_sync_service_do_sign_out (EphySyncService *self)
+{
+  g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
+
+  /* Destroy session and delete tokens. */
+  ephy_sync_service_stop_periodical_sync (self);
+  ephy_sync_service_destroy_session (self, NULL);
+  ephy_sync_service_clear_storage_credentials (self);
+  ephy_sync_service_clear_tokens (self);
+  ephy_sync_secret_forget_tokens ();
+  ephy_sync_service_set_user_email (self, NULL);
+  ephy_sync_service_set_sync_time (self, 0);
+
+  g_settings_set_string (EPHY_SETTINGS_MAIN, EPHY_PREFS_SYNC_USER, "");
+}
+
 static void
 upload_bookmark_cb (SoupSession *session,
                     SoupMessage *msg,
diff --git a/src/sync/ephy-sync-service.h b/src/sync/ephy-sync-service.h
index e459b4f..55c6f58 100644
--- a/src/sync/ephy-sync-service.h
+++ b/src/sync/ephy-sync-service.h
@@ -55,6 +55,7 @@ void              ephy_sync_service_do_sign_in                 (EphySyncService
                                                                 const char        *sessionToken,
                                                                 const char        *keyFetchToken,
                                                                 const char        *unwrapBKey);
+void              ephy_sync_service_do_sign_out                (EphySyncService   *self);
 void              ephy_sync_service_upload_bookmark            (EphySyncService   *self,
                                                                 EphyBookmark      *bookmark,
                                                                 gboolean           force);


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