[epiphany/mcatanzaro/#1233: 1/2] sync-service: use cancellable where required
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/mcatanzaro/#1233: 1/2] sync-service: use cancellable where required
- Date: Sat, 20 Jun 2020 21:45:31 +0000 (UTC)
commit 11800f015f5239e3125d89e83c7f016ea292326f
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sat Jun 20 16:36:33 2020 -0500
sync-service: use cancellable where required
EphySyncService has no protection against async callbacks being executed
after it has been destroyed. That's no good. Cancel async calls where
required.
lib/sync/ephy-sync-service.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index 24f5f433d..ec92cab94 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -41,6 +41,8 @@ struct _EphySyncService {
SoupSession *session;
guint source_id;
+ GCancellable *cancellable;
+
char *user;
char *crypto_keys;
GHashTable *secrets;
@@ -689,7 +691,8 @@ forget_secrets_cb (SecretService *service,
secret_service_clear_finish (service, result, &error);
if (error) {
- g_warning ("Failed to clear sync secrets: %s", error->message);
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Failed to clear sync secrets: %s", error->message);
g_error_free (error);
} else {
LOG ("Successfully cleared sync secrets");
@@ -711,7 +714,7 @@ ephy_sync_service_forget_secrets (EphySyncService *self)
attributes = secret_attributes_build (EPHY_SYNC_SECRET_SCHEMA,
EPHY_SYNC_SECRET_ACCOUNT_KEY, user,
NULL);
- secret_service_clear (NULL, EPHY_SYNC_SECRET_SCHEMA, attributes, NULL,
+ secret_service_clear (NULL, EPHY_SYNC_SECRET_SCHEMA, attributes, self->cancellable,
(GAsyncReadyCallback)forget_secrets_cb, NULL);
g_hash_table_remove_all (self->secrets);
@@ -1699,6 +1702,10 @@ load_secrets_cb (SecretService *service,
res = secret_service_search_finish (service, result, &error);
if (error) {
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ g_error_free (error);
+ goto out_no_error;
+ }
g_warning ("Failed to search for sync secrets: %s", error->message);
g_error_free (error);
message = _("Could not find the sync secrets for the current sync user.");
@@ -1768,7 +1775,7 @@ ephy_sync_service_load_secrets (EphySyncService *self)
NULL);
secret_service_search (NULL, EPHY_SYNC_SECRET_SCHEMA, attributes,
SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS,
- NULL, (GAsyncReadyCallback)load_secrets_cb, self);
+ self->cancellable, (GAsyncReadyCallback)load_secrets_cb, self);
g_hash_table_unref (attributes);
g_free (user);
@@ -1783,6 +1790,8 @@ store_secrets_cb (SecretService *service,
secret_service_store_finish (service, result, &error);
if (error) {
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ return;
g_warning ("Failed to store sync secrets: %s", error->message);
ephy_sync_service_destroy_session (self, NULL);
g_hash_table_remove_all (self->secrets);
@@ -1947,6 +1956,11 @@ ephy_sync_service_dispose (GObject *object)
g_clear_object (&self->session);
g_clear_pointer (&self->secrets, g_hash_table_unref);
+ if (self->cancellable) {
+ g_cancellable_cancel (self->cancellable);
+ g_clear_object (&self->cancellable);
+ }
+
G_OBJECT_CLASS (ephy_sync_service_parent_class)->dispose (object);
}
@@ -1973,6 +1987,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->cancellable = g_cancellable_new ();
if (ephy_sync_utils_user_is_signed_in ())
ephy_sync_service_load_secrets (self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]