[epiphany/wip/sync] sync-service: Fix the forced sign out at password change



commit 59d90795ce27ed9f1867c19d9b5e5957afd51c8f
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Sun Jun 25 02:40:33 2017 +0300

    sync-service: Fix the forced sign out at password change

 lib/sync/ephy-sync-service.c |   55 +++++++++++++++++++++++++++++++++++------
 lib/sync/ephy-sync-service.h |    3 +-
 src/prefs-dialog.c           |    2 +-
 3 files changed, 50 insertions(+), 10 deletions(-)
---
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index 7383193..ff19232 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -506,6 +506,28 @@ ephy_sync_service_send_storage_request (EphySyncService         *self,
   storage_request_async_data_free (data);
 }
 
+static void
+ephy_sync_service_send_all_storage_requests (EphySyncService *self)
+{
+  StorageRequestAsyncData *data;
+
+  g_assert (EPHY_IS_SYNC_SERVICE (self));
+
+  while (!g_queue_is_empty (self->storage_queue)) {
+    data = g_queue_pop_head (self->storage_queue);
+    ephy_sync_service_send_storage_request (self, data);
+  }
+}
+
+static void
+ephy_sync_service_clear_storage_queue (EphySyncService *self)
+{
+  g_assert (EPHY_IS_SYNC_SERVICE (self));
+
+  while (!g_queue_is_empty (self->storage_queue))
+    storage_request_async_data_free (g_queue_pop_head (self->storage_queue));
+}
+
 static gboolean
 ephy_sync_service_verify_certificate (EphySyncService *self,
                                       const char      *certificate)
@@ -754,19 +776,23 @@ get_storage_credentials_cb (SoupSession *session,
   self->storage_credentials_key = g_strdup (key);
   self->storage_credentials_expiry_time = duration + g_get_real_time () / 1000000;
 
-  while (!g_queue_is_empty (self->storage_queue))
-    ephy_sync_service_send_storage_request (self, g_queue_pop_head (self->storage_queue));
+  ephy_sync_service_send_all_storage_requests (self);
   goto out;
 
 out_error:
   message = _("Failed to obtain storage credentials.");
   suggestion = _("Please visit Preferences and sign in again to continue syncing.");
+
   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_sync_service_clear_storage_queue (self);
+
 out:
   self->locked = FALSE;
+
   if (node)
     json_node_unref (node);
   if (error)
@@ -862,7 +888,7 @@ get_signed_certificate_cb (SoupSession *session,
   if (json_object_get_int_member (json, "errno") == 110) {
     message = _("The password of your Firefox account seems to have been changed.");
     suggestion = _("Please visit Preferences and sign in with the new password to continue syncing.");
-    ephy_sync_service_sign_out (self);
+    ephy_sync_service_sign_out (self, FALSE);
   }
 
   g_warning ("Failed to sign certificate. Status code: %u, response: %s",
@@ -871,11 +897,15 @@ get_signed_certificate_cb (SoupSession *session,
 out_error:
   message = message ? message : _("Failed to obtain signed certificate.");
   suggestion = suggestion ? suggestion : _("Please visit Preferences and sign in again to continue 
syncing.");
+
   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_sync_service_clear_storage_queue (self);
   self->locked = FALSE;
+
 out_no_error:
   if (node)
     json_node_unref (node);
@@ -2301,8 +2331,7 @@ delete_open_tabs_record_cb (SoupSession *session,
   }
 
   /* This is the last storage message of this session, clear queue. */
-  while (!g_queue_is_empty (self->storage_queue))
-    storage_request_async_data_free (g_queue_pop_head (self->storage_queue));
+  ephy_sync_service_clear_storage_queue (self);
 }
 
 static void
@@ -2346,14 +2375,25 @@ ephy_sync_service_unregister_device (EphySyncService *self)
 }
 
 void
-ephy_sync_service_sign_out (EphySyncService *self)
+ephy_sync_service_sign_out (EphySyncService *self,
+                            gboolean         unregister_device)
 {
   g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
 
+  /* If we sign out without unregistering the device, then the current id of
+   * the device should not be cleared, but preserved for further use (Ephy will
+   * use the same id next time the user signs in). This way we prevent a zombie
+   * record in the clients collection on the Sync Storage Server.
+   */
+  if (unregister_device) {
+    ephy_sync_service_unregister_device (self);
+    ephy_sync_utils_set_device_id (NULL);
+  }
+
   ephy_sync_service_stop_periodical_sync (self);
-  ephy_sync_service_unregister_device (self);
   ephy_sync_service_destroy_session (self, NULL);
   ephy_sync_service_forget_secrets (self);
+  ephy_sync_service_clear_storage_queue (self);
   ephy_sync_service_clear_storage_credentials (self);
 
   /* Clear managers. */
@@ -2368,7 +2408,6 @@ ephy_sync_service_sign_out (EphySyncService *self)
   ephy_sync_utils_set_history_sync_is_initial (TRUE);
 
   ephy_sync_utils_set_sync_time (0);
-  ephy_sync_utils_set_device_id (NULL);
   ephy_sync_utils_set_sync_user (NULL);
 }
 
diff --git a/lib/sync/ephy-sync-service.h b/lib/sync/ephy-sync-service.h
index 4668e13..6b42604 100644
--- a/lib/sync/ephy-sync-service.h
+++ b/lib/sync/ephy-sync-service.h
@@ -37,7 +37,8 @@ void             ephy_sync_service_sign_in            (EphySyncService *self,
                                                        const char      *session_token,
                                                        const char      *key_fetch_token,
                                                        const char      *unwrap_kb);
-void             ephy_sync_service_sign_out           (EphySyncService *self);
+void             ephy_sync_service_sign_out           (EphySyncService *self,
+                                                       gboolean         unregister_device);
 void             ephy_sync_service_sync               (EphySyncService *self);
 void             ephy_sync_service_start_sync         (EphySyncService *self);
 void             ephy_sync_service_register_device    (EphySyncService *self,
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index f940ead..48b19b0 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -627,7 +627,7 @@ on_sync_sign_out_button_clicked (GtkWidget   *button,
                                  PrefsDialog *dialog)
 {
 
-  ephy_sync_service_sign_out (dialog->sync_service);
+  ephy_sync_service_sign_out (dialog->sync_service, TRUE);
 
   /* Show Firefox Accounts iframe. */
   sync_setup_firefox_iframe (dialog);


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