diff --git a/libsecret/secret-collection.c b/libsecret/secret-collection.c index 0d800bd..4e27422 100644 --- a/libsecret/secret-collection.c +++ b/libsecret/secret-collection.c @@ -569,50 +569,39 @@ secret_collection_initable_iface (GInitableIface *iface) iface->init = secret_collection_initable_init; } -typedef struct { - GCancellable *cancellable; -} InitClosure; - -static void -init_closure_free (gpointer data) -{ - InitClosure *closure = data; - g_clear_object (&closure->cancellable); - g_slice_free (InitClosure, closure); -} - static void on_ensure_items (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); + GTask *task = G_TASK (user_data); SecretCollection *self = SECRET_COLLECTION (source); GError *error = NULL; if (!secret_collection_load_items_finish (self, result, &error)) - g_simple_async_result_take_error (res, error); + g_task_return_error (task, g_steal_pointer (&error)); + else + g_task_return_pointer (task, self, g_object_unref); - g_simple_async_result_complete (res); - g_object_unref (res); + g_clear_object (&task); } static void collection_ensure_for_flags_async (SecretCollection *self, SecretCollectionFlags flags, - GCancellable *cancellable, - GSimpleAsyncResult *async) + GTask *task) { + GCancellable *cancellable = g_task_get_cancellable (task); SecretCollectionFlags want_flags; want_flags = flags & ~secret_collection_get_flags (self); if (want_flags & SECRET_COLLECTION_LOAD_ITEMS) { secret_collection_load_items (self, cancellable, - on_ensure_items, g_object_ref (async)); + on_ensure_items, g_object_ref (task)); } else { - g_simple_async_result_complete (async); + g_task_return_pointer (task, self, g_object_unref); } } @@ -621,25 +610,21 @@ on_init_service (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - SecretCollection *self = SECRET_COLLECTION (g_async_result_get_source_object (user_data)); - InitClosure *init = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + SecretCollection *self = SECRET_COLLECTION (g_task_get_source_object (task)); SecretService *service; GError *error = NULL; service = secret_service_get_finish (result, &error); if (error == NULL) { - collection_take_service (self, service); - collection_ensure_for_flags_async (self, self->pv->init_flags, - init->cancellable, async); + collection_take_service (self, g_steal_pointer (&service)); + collection_ensure_for_flags_async (self, self->pv->init_flags, task); } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (self); - g_object_unref (async); + g_clear_object (&task); } static void @@ -647,33 +632,31 @@ on_init_base (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); + GTask *task = G_TASK (user_data); + GCancellable *cancellable = g_task_get_cancellable (task); SecretCollection *self = SECRET_COLLECTION (source); - InitClosure *init = g_simple_async_result_get_op_res_gpointer (res); GDBusProxy *proxy = G_DBUS_PROXY (self); GError *error = NULL; if (!secret_collection_async_initable_parent_iface->init_finish (G_ASYNC_INITABLE (self), result, &error)) { - g_simple_async_result_take_error (res, error); - g_simple_async_result_complete (res); + g_task_return_error (task, g_steal_pointer (&error)); } else if (!_secret_util_have_cached_properties (proxy)) { - g_simple_async_result_set_error (res, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, - "No such secret collection at path: %s", - g_dbus_proxy_get_object_path (proxy)); - g_simple_async_result_complete (res); + g_task_return_new_error (task, G_DBUS_ERROR, + G_DBUS_ERROR_UNKNOWN_METHOD, + "No such secret collection at path: %s", + g_dbus_proxy_get_object_path (proxy)); } else if (self->pv->service == NULL) { - secret_service_get (SECRET_SERVICE_NONE, init->cancellable, - on_init_service, g_object_ref (res)); + secret_service_get (SECRET_SERVICE_NONE, cancellable, + on_init_service, g_steal_pointer (&task)); } else { - collection_ensure_for_flags_async (self, self->pv->init_flags, - init->cancellable, res); + collection_ensure_for_flags_async (self, self->pv->init_flags, task); } - g_object_unref (res); + g_clear_object (&task); } static void @@ -683,21 +666,18 @@ secret_collection_async_initable_init_async (GAsyncInitable *initable, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; - InitClosure *closure; + GTask *task; - res = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, - secret_collection_async_initable_init_async); - closure = g_slice_new0 (InitClosure); - closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - g_simple_async_result_set_op_res_gpointer (res, closure, init_closure_free); + task = g_task_new (initable, cancellable, callback, user_data); + g_task_set_source_tag (task, secret_collection_async_initable_init_async); - secret_collection_async_initable_parent_iface->init_async (initable, io_priority, + secret_collection_async_initable_parent_iface->init_async (initable, + io_priority, cancellable, on_init_base, - g_object_ref (res)); + g_steal_pointer (&task)); - g_object_unref (res); + g_clear_object (&task); } static gboolean @@ -707,11 +687,13 @@ secret_collection_async_initable_init_finish (GAsyncInitable *initable, { SecretCollection *self = SECRET_COLLECTION (initable); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (initable), - secret_collection_async_initable_init_async), FALSE); + g_return_val_if_fail (g_task_is_valid (result, initable), FALSE); - if (_secret_util_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) + // XXX maybe we still need to ref? + if (!g_task_propagate_pointer (G_TASK (result), error)) { + _secret_util_strip_remote_error (error); return FALSE; + } self->pv->constructing = FALSE; return TRUE; @@ -727,7 +709,6 @@ secret_collection_async_initable_iface (GAsyncInitableIface *iface) } typedef struct { - GCancellable *cancellable; GHashTable *items; gint items_loading; } ItemsClosure; @@ -736,7 +717,6 @@ static void items_closure_free (gpointer data) { ItemsClosure *closure = data; - g_clear_object (&closure->cancellable); g_hash_table_unref (closure->items); g_slice_free (ItemsClosure, closure); } @@ -746,9 +726,9 @@ on_load_item (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); - ItemsClosure *closure = g_simple_async_result_get_op_res_gpointer (res); - SecretCollection *self = SECRET_COLLECTION (g_async_result_get_source_object (user_data)); + GTask *task = G_TASK (user_data); + ItemsClosure *closure = g_task_get_task_data (task); + SecretCollection *self = SECRET_COLLECTION (g_task_get_source_object (task)); const gchar *path; GError *error = NULL; SecretItem *item; @@ -757,8 +737,11 @@ on_load_item (GObject *source, item = secret_item_new_for_dbus_path_finish (result, &error); - if (error != NULL) - g_simple_async_result_take_error (res, error); + if (error != NULL) { + g_task_return_error (task, g_steal_pointer (&error)); + g_clear_object (&task); + return; + } if (item != NULL) { path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (item)); @@ -767,11 +750,10 @@ on_load_item (GObject *source, if (closure->items_loading == 0) { collection_update_items (self, closure->items); - g_simple_async_result_complete_in_idle (res); + g_task_return_boolean (task, TRUE); } - g_object_unref (self); - g_object_unref (res); + g_clear_object (&task); } /** @@ -798,7 +780,7 @@ secret_collection_load_items (SecretCollection *self, { ItemsClosure *closure; SecretItem *item; - GSimpleAsyncResult *res; + GTask *task; const gchar *path; GVariant *paths; GVariantIter iter; @@ -809,12 +791,11 @@ secret_collection_load_items (SecretCollection *self, paths = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Items"); g_return_if_fail (paths != NULL); - res = g_simple_async_result_new (G_OBJECT (self), callback, user_data, - secret_collection_load_items); + task = g_task_new (self, cancellable, callback, user_data); + g_task_set_source_tag (task, secret_collection_load_items); closure = g_slice_new0 (ItemsClosure); - closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL; closure->items = items_table_new (); - g_simple_async_result_set_op_res_gpointer (res, closure, items_closure_free); + g_task_set_task_data (task, closure, items_closure_free); g_variant_iter_init (&iter, paths); while (g_variant_iter_loop (&iter, "&o", &path)) { @@ -822,8 +803,10 @@ secret_collection_load_items (SecretCollection *self, /* No such collection yet create a new one */ if (item == NULL) { - secret_item_new_for_dbus_path (self->pv->service, path, SECRET_ITEM_NONE, - cancellable, on_load_item, g_object_ref (res)); + secret_item_new_for_dbus_path (self->pv->service, path, + SECRET_ITEM_NONE, + cancellable, on_load_item, + g_object_ref (task)); closure->items_loading++; } else { @@ -833,11 +816,11 @@ secret_collection_load_items (SecretCollection *self, if (closure->items_loading == 0) { collection_update_items (self, closure->items); - g_simple_async_result_complete_in_idle (res); + g_task_return_boolean (task, TRUE); } g_variant_unref (paths); - g_object_unref (res); + g_clear_object (&task); } /** @@ -858,11 +841,12 @@ secret_collection_load_items_finish (SecretCollection *self, { g_return_val_if_fail (SECRET_IS_COLLECTION (self), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self), - secret_collection_load_items), FALSE); + g_return_val_if_fail (g_task_is_valid (result, self), FALSE); - if (_secret_util_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) + if (!g_task_propagate_boolean (G_TASK (result), error)) { + _secret_util_strip_remote_error (error); return FALSE; + } return TRUE; } @@ -953,7 +937,6 @@ secret_collection_refresh (SecretCollection *self) } typedef struct { - GCancellable *cancellable; SecretCollection *collection; GHashTable *properties; gchar *alias; @@ -964,7 +947,6 @@ static void create_closure_free (gpointer data) { CreateClosure *closure = data; - g_clear_object (&closure->cancellable); g_clear_object (&closure->collection); g_hash_table_unref (closure->properties); g_free (closure->alias); @@ -976,16 +958,17 @@ on_create_collection (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); - CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res); + GTask *task = G_TASK (user_data); + SecretCollection *collection; GError *error = NULL; - closure->collection = secret_collection_new_for_dbus_path_finish (result, &error); + collection = secret_collection_new_for_dbus_path_finish (result, &error); if (error != NULL) - g_simple_async_result_take_error (res, error); + g_task_return_error (task, g_steal_pointer (&error)); + else + g_task_return_pointer (task, collection, g_object_unref); - g_simple_async_result_complete (res); - g_object_unref (res); + g_clear_object (&task); } static void @@ -993,8 +976,8 @@ on_create_path (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); - CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res); + GTask *task = G_TASK (user_data); + GCancellable *cancellable = g_task_get_cancellable (task); SecretService *service = SECRET_SERVICE (source); GError *error = NULL; gchar *path; @@ -1002,15 +985,14 @@ on_create_path (GObject *source, path = secret_service_create_collection_dbus_path_finish (service, result, &error); if (error == NULL) { secret_collection_new_for_dbus_path (service, path, SECRET_COLLECTION_LOAD_ITEMS, - closure->cancellable, - on_create_collection, g_object_ref (res)); + cancellable, on_create_collection, + g_steal_pointer (&task)); } else { - g_simple_async_result_take_error (res, error); - g_simple_async_result_complete (res); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (res); g_free (path); + g_clear_object (&task); } static void @@ -1018,8 +1000,9 @@ on_create_service (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - CreateClosure *create = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + CreateClosure *create = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); GError *error = NULL; SecretService *service; @@ -1027,16 +1010,15 @@ on_create_service (GObject *source, if (error == NULL) { secret_service_create_collection_dbus_path (service, create->properties, create->alias, create->flags, - create->cancellable, - on_create_path, g_object_ref (async)); + cancellable, on_create_path, + g_steal_pointer (&task)); g_object_unref (service); } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (async); + g_clear_object (&task); } GHashTable * @@ -1079,7 +1061,6 @@ _secret_collection_properties_new (const gchar *label) * * If @service is %NULL, then secret_service_get() will be called to get * the default #SecretService proxy. - * */ void secret_collection_create (SecretService *service, @@ -1090,34 +1071,33 @@ secret_collection_create (SecretService *service, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; CreateClosure *closure; g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service)); g_return_if_fail (label != NULL); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); - res = g_simple_async_result_new (NULL, callback, user_data, - secret_collection_create); + task = g_task_new (NULL, cancellable, callback, user_data); + g_task_set_source_tag (task, secret_collection_create); closure = g_slice_new0 (CreateClosure); - closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL; closure->properties = _secret_collection_properties_new (label); closure->alias = g_strdup (alias); closure->flags = flags; - g_simple_async_result_set_op_res_gpointer (res, closure, create_closure_free); + g_task_set_task_data (task, closure, create_closure_free); if (service == NULL) { secret_service_get (SECRET_SERVICE_NONE, cancellable, - on_create_service, g_object_ref (res)); + on_create_service, g_steal_pointer (&task)); } else { secret_service_create_collection_dbus_path (service, closure->properties, closure->alias, closure->flags, - closure->cancellable, - on_create_path, g_object_ref (res)); + cancellable, on_create_path, + g_steal_pointer (&task)); } - g_object_unref (res); + g_clear_object (&task); } /** @@ -1134,23 +1114,18 @@ SecretCollection * secret_collection_create_finish (GAsyncResult *result, GError **error) { - GSimpleAsyncResult *res; - CreateClosure *closure; + SecretCollection *collection; - g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL, - secret_collection_create), NULL); + g_return_val_if_fail (g_task_is_valid (result, NULL), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - res = G_SIMPLE_ASYNC_RESULT (result); - - if (_secret_util_propagate_error (res, error)) + collection = g_task_propagate_pointer (G_TASK (result), error); + if (!collection) { + _secret_util_strip_remote_error (error); return NULL; + } - closure = g_simple_async_result_get_op_res_gpointer (res); - if (closure->collection == NULL) - return NULL; - - return g_object_ref (closure->collection); + return collection; } /** @@ -1229,7 +1204,6 @@ secret_collection_create_sync (SecretService *service, typedef struct { SecretCollection *collection; - GCancellable *cancellable; GHashTable *items; gchar **paths; guint loading; @@ -1241,7 +1215,6 @@ search_closure_free (gpointer data) { SearchClosure *closure = data; g_object_unref (closure->collection); - g_clear_object (&closure->cancellable); g_hash_table_unref (closure->items); g_strfreev (closure->paths); g_slice_free (SearchClosure, closure); @@ -1260,13 +1233,13 @@ on_search_secrets (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); + GTask *task = G_TASK (user_data); /* Note that we ignore any unlock failure */ secret_item_load_secrets_finish (result, NULL); - g_simple_async_result_complete (async); - g_object_unref (async); + g_task_return_boolean (task, TRUE); + g_clear_object (&task); } static void @@ -1274,8 +1247,9 @@ on_search_unlocked (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - SearchClosure *search = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + SearchClosure *search = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); GList *items; /* Note that we ignore any unlock failure */ @@ -1284,42 +1258,43 @@ on_search_unlocked (GObject *source, /* If loading secrets ... locked items automatically ignored */ if (search->flags & SECRET_SEARCH_LOAD_SECRETS) { items = g_hash_table_get_values (search->items); - secret_item_load_secrets (items, search->cancellable, - on_search_secrets, g_object_ref (async)); + secret_item_load_secrets (items, cancellable, + on_search_secrets, g_object_ref (task)); g_list_free (items); /* No additional options, just complete */ } else { - g_simple_async_result_complete (async); + g_task_return_boolean (task, TRUE); } - g_object_unref (async); + g_clear_object (&task); } static void -secret_search_unlock_load_or_complete (GSimpleAsyncResult *async, +secret_search_unlock_load_or_complete (GTask *task, SearchClosure *search) { GList *items; + GCancellable *cancellable = g_task_get_cancellable (task); /* If unlocking then unlock all the locked items */ if (search->flags & SECRET_SEARCH_UNLOCK) { items = g_hash_table_get_values (search->items); secret_service_unlock (secret_collection_get_service (search->collection), - items, search->cancellable, - on_search_unlocked, g_object_ref (async)); + items, cancellable, + on_search_unlocked, g_object_ref (task)); g_list_free (items); /* If loading secrets ... locked items automatically ignored */ } else if (search->flags & SECRET_SEARCH_LOAD_SECRETS) { items = g_hash_table_get_values (search->items); - secret_item_load_secrets (items, search->cancellable, - on_search_secrets, g_object_ref (async)); + secret_item_load_secrets (items, cancellable, + on_search_secrets, g_object_ref (task)); g_list_free (items); /* No additional options, just complete */ } else { - g_simple_async_result_complete (async); + g_task_return_boolean (task, TRUE); } } @@ -1328,25 +1303,28 @@ on_search_loaded (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - SearchClosure *search = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + SearchClosure *search = g_task_get_task_data (task); GError *error = NULL; SecretItem *item; search->loading--; item = secret_item_new_for_dbus_path_finish (result, &error); - if (error != NULL) - g_simple_async_result_take_error (async, error); + if (error != NULL) { + g_task_return_error (task, g_steal_pointer (&error)); + g_clear_object (&task); + return; + } if (item != NULL) search_closure_take_item (search, item); /* We're done loading, lets go to the next step */ if (search->loading == 0) - secret_search_unlock_load_or_complete (async, search); + secret_search_unlock_load_or_complete (task, search); - g_object_unref (async); + g_clear_object (&task); } static void @@ -1354,8 +1332,9 @@ on_search_paths (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - SearchClosure *search = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + SearchClosure *search = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); SecretCollection *self = search->collection; SecretService *service = secret_collection_get_service (self); GError *error = NULL; @@ -1364,34 +1343,34 @@ on_search_paths (GObject *source, gint i; search->paths = secret_collection_search_for_dbus_paths_finish (self, result, &error); - if (error == NULL) { - want = 1; - if (search->flags & SECRET_SEARCH_ALL) - want = G_MAXINT; - - for (i = 0; i < want && search->paths[i] != NULL; i++) { - item = _secret_collection_find_item_instance (self, search->paths[i]); - if (item == NULL) { - secret_item_new_for_dbus_path (service, search->paths[i], SECRET_ITEM_NONE, - search->cancellable, on_search_loaded, - g_object_ref (async)); - search->loading++; - } else { - search_closure_take_item (search, item); - } - - } - - /* No items loading, complete operation now */ - if (search->loading == 0) - secret_search_unlock_load_or_complete (async, search); - - } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + if (error != NULL) { + g_task_return_error (task, g_steal_pointer (&error)); + g_clear_object (&task); + return; } - g_object_unref (async); + want = 1; + if (search->flags & SECRET_SEARCH_ALL) + want = G_MAXINT; + + for (i = 0; i < want && search->paths[i] != NULL; i++) { + item = _secret_collection_find_item_instance (self, search->paths[i]); + if (item == NULL) { + secret_item_new_for_dbus_path (service, search->paths[i], SECRET_ITEM_NONE, + cancellable, on_search_loaded, + g_object_ref (task)); + search->loading++; + } else { + search_closure_take_item (search, item); + } + + } + + /* No items loading, complete operation now */ + if (search->loading == 0) + secret_search_unlock_load_or_complete (task, search); + + g_clear_object (&task); } /** @@ -1429,7 +1408,7 @@ secret_collection_search (SecretCollection *self, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *async; + GTask *task; SearchClosure *search; g_return_if_fail (SECRET_IS_COLLECTION (self)); @@ -1440,20 +1419,19 @@ secret_collection_search (SecretCollection *self, if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE)) return; - async = g_simple_async_result_new (G_OBJECT (self), callback, user_data, - secret_collection_search); + task = g_task_new (self, cancellable, callback, user_data); + g_task_set_source_tag (task, secret_collection_search); search = g_slice_new0 (SearchClosure); search->collection = g_object_ref (self); - search->cancellable = cancellable ? g_object_ref (cancellable) : NULL; search->items = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); search->flags = flags; - g_simple_async_result_set_op_res_gpointer (async, search, search_closure_free); + g_task_set_task_data (task, search, search_closure_free); secret_collection_search_for_dbus_paths (self, schema, attributes, cancellable, on_search_paths, - g_object_ref (async)); + g_steal_pointer (&task)); - g_object_unref (async); + g_clear_object (&task); } /** @@ -1472,7 +1450,6 @@ secret_collection_search_finish (SecretCollection *self, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *async; SearchClosure *search; GList *items = NULL; SecretItem *item; @@ -1480,14 +1457,14 @@ secret_collection_search_finish (SecretCollection *self, g_return_val_if_fail (SECRET_IS_COLLECTION (self), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self), - secret_collection_search), NULL); + g_return_val_if_fail (g_task_is_valid (result, self), NULL); - async = G_SIMPLE_ASYNC_RESULT (result); - if (_secret_util_propagate_error (async, error)) + if (!g_task_propagate_boolean (G_TASK (result), error)) { + _secret_util_strip_remote_error (error); return NULL; + } - search = g_simple_async_result_get_op_res_gpointer (async); + search = g_task_get_task_data (G_TASK (result)); for (i = 0; search->paths[i]; i++) { item = g_hash_table_lookup (search->items, search->paths[i]); @@ -1613,15 +1590,18 @@ on_service_delete_path (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); + GTask *task = G_TASK (user_data); GError *error = NULL; _secret_service_delete_path_finish (SECRET_SERVICE (source), result, &error); if (error != NULL) - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); - g_object_unref (async); + g_task_return_error (task, g_steal_pointer (&error)); + else + g_task_return_boolean (task, TRUE); + + g_clear_object (&task); } + /** * secret_collection_delete: * @self: a collection @@ -1641,21 +1621,21 @@ secret_collection_delete (SecretCollection *self, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *async; + GTask *task; const gchar *object_path; g_return_if_fail (SECRET_IS_COLLECTION (self)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); - async = g_simple_async_result_new (G_OBJECT (self), callback, user_data, - secret_collection_delete); + task = g_task_new (self, cancellable, callback, user_data); + g_task_set_source_tag (task, secret_collection_delete); object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (self)); _secret_service_delete_path (self->pv->service, object_path, FALSE, cancellable, on_service_delete_path, - g_object_ref (async)); + g_steal_pointer (&task)); - g_object_unref (async); + g_clear_object (&task); } /** @@ -1675,11 +1655,12 @@ secret_collection_delete_finish (SecretCollection *self, { g_return_val_if_fail (SECRET_IS_COLLECTION (self), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self), - secret_collection_delete), FALSE); + g_return_val_if_fail (g_task_is_valid (result, self), FALSE); - if (_secret_util_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) + if (!g_task_propagate_boolean (G_TASK (result), error)) { + _secret_util_strip_remote_error (error); return FALSE; + } return TRUE; } @@ -1997,10 +1978,8 @@ secret_collection_get_modified (SecretCollection *self) typedef struct { - GCancellable *cancellable; gchar *alias; SecretCollectionFlags flags; - SecretCollection *collection; } ReadClosure; static void @@ -2008,10 +1987,6 @@ read_closure_free (gpointer data) { ReadClosure *read = data; g_free (read->alias); - if (read->collection) - g_object_unref (read->collection); - if (read->cancellable) - g_object_unref (read->cancellable); g_slice_free (ReadClosure, read); } @@ -2020,16 +1995,17 @@ on_read_alias_collection (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - ReadClosure *read = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + SecretCollection *collection; GError *error = NULL; - read->collection = secret_collection_new_for_dbus_path_finish (result, &error); + collection = secret_collection_new_for_dbus_path_finish (result, &error); if (error != NULL) - g_simple_async_result_take_error (async, error); + g_task_return_error (task, g_steal_pointer (&error)); + else + g_task_return_pointer (task, collection, g_object_unref); - g_simple_async_result_complete (async); - g_object_unref (async); + g_clear_object (&task); } static void @@ -2037,8 +2013,9 @@ on_read_alias_path (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - ReadClosure *read = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + ReadClosure *read = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); SecretService *self = SECRET_SERVICE (source); GError *error = NULL; gchar *collection_path; @@ -2048,34 +2025,35 @@ on_read_alias_path (GObject *source, /* No collection for this alias */ if (collection_path == NULL) { - g_simple_async_result_complete (async); + g_task_return_pointer (task, NULL, NULL); } else { - read->collection = _secret_service_find_collection_instance (self, - collection_path); - if (read->collection != NULL) { + SecretCollection *collection; + collection = _secret_service_find_collection_instance (self, + collection_path); + if (collection != NULL) { /* Make sure collection has necessary flags */ - collection_ensure_for_flags_async (read->collection, read->flags, - read->cancellable, async); + collection_ensure_for_flags_async (collection, + read->flags, + task); /* No collection loaded, but valid path, load */ } else { secret_collection_new_for_dbus_path (self, collection_path, read->flags, - read->cancellable, + cancellable, on_read_alias_collection, - g_object_ref (async)); + g_steal_pointer (&task)); } } } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } g_free (collection_path); - g_object_unref (async); + g_clear_object (&task); } static void @@ -2083,23 +2061,24 @@ on_read_alias_service (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - ReadClosure *read = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + ReadClosure *read = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); SecretService *service; GError *error = NULL; service = secret_service_get_finish (result, &error); if (error == NULL) { - secret_service_read_alias_dbus_path (service, read->alias, read->cancellable, - on_read_alias_path, g_object_ref (async)); + secret_service_read_alias_dbus_path (service, read->alias, cancellable, + on_read_alias_path, + g_steal_pointer (&task)); g_object_unref (service); } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (async); + g_clear_object (&task); } /** @@ -2127,30 +2106,30 @@ secret_collection_for_alias (SecretService *service, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *async; + GTask *task; ReadClosure *read; g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service)); g_return_if_fail (alias != NULL); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); - async = g_simple_async_result_new (NULL, callback, user_data, - secret_collection_for_alias); + task = g_task_new (NULL, cancellable, callback, user_data); + g_task_set_source_tag (task, secret_collection_for_alias); read = g_slice_new0 (ReadClosure); - read->cancellable = cancellable ? g_object_ref (cancellable) : NULL; read->alias = g_strdup (alias); read->flags = flags; - g_simple_async_result_set_op_res_gpointer (async, read, read_closure_free); + g_task_set_task_data (task, read, read_closure_free); if (service == NULL) { secret_service_get (SECRET_SERVICE_NONE, cancellable, - on_read_alias_service, g_object_ref (async)); + on_read_alias_service, g_object_ref (task)); } else { - secret_service_read_alias_dbus_path (service, read->alias, read->cancellable, - on_read_alias_path, g_object_ref (async)); + secret_service_read_alias_dbus_path (service, read->alias, cancellable, + on_read_alias_path, + g_steal_pointer (&task)); } - g_object_unref (async); + g_clear_object (&task); } /** @@ -2167,20 +2146,18 @@ SecretCollection * secret_collection_for_alias_finish (GAsyncResult *result, GError **error) { - GSimpleAsyncResult *async; - ReadClosure *read; + SecretCollection *collection; - g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL, - secret_collection_for_alias), NULL); + g_return_val_if_fail (g_task_is_valid (result, NULL), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - async = G_SIMPLE_ASYNC_RESULT (result); - if (_secret_util_propagate_error (async, error)) + collection = g_task_propagate_pointer (G_TASK (result), error); + if (error && *error) { + _secret_util_strip_remote_error (error); return NULL; - read = g_simple_async_result_get_op_res_gpointer (async); - if (read->collection) - g_object_ref (read->collection); - return read->collection; + } + + return collection; } /** diff --git a/libsecret/secret-methods.c b/libsecret/secret-methods.c index e0ccce4..c4decf8 100644 --- a/libsecret/secret-methods.c +++ b/libsecret/secret-methods.c @@ -38,7 +38,6 @@ typedef struct { SecretService *service; - GCancellable *cancellable; GHashTable *items; gchar **unlocked; gchar **locked; @@ -52,7 +51,6 @@ search_closure_free (gpointer data) { SearchClosure *closure = data; g_clear_object (&closure->service); - g_clear_object (&closure->cancellable); g_hash_table_unref (closure->items); g_variant_unref (closure->attributes); g_strfreev (closure->unlocked); @@ -90,13 +88,13 @@ on_search_secrets (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); + GTask *task = G_TASK (user_data); /* Note that we ignore any unlock failure */ secret_item_load_secrets_finish (result, NULL); + g_task_return_boolean (task, TRUE); - g_simple_async_result_complete (async); - g_object_unref (async); + g_clear_object (&task); } static void @@ -104,8 +102,9 @@ on_search_unlocked (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - SearchClosure *search = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + SearchClosure *search = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); GList *items; /* Note that we ignore any unlock failure */ @@ -114,41 +113,42 @@ on_search_unlocked (GObject *source, /* If loading secrets ... locked items automatically ignored */ if (search->flags & SECRET_SEARCH_LOAD_SECRETS) { items = g_hash_table_get_values (search->items); - secret_item_load_secrets (items, search->cancellable, - on_search_secrets, g_object_ref (async)); + secret_item_load_secrets (items, cancellable, + on_search_secrets, g_object_ref (task)); g_list_free (items); /* No additional options, just complete */ } else { - g_simple_async_result_complete (async); + g_task_return_boolean (task, TRUE); } - g_object_unref (async); + g_clear_object (&task); } static void -secret_search_unlock_load_or_complete (GSimpleAsyncResult *async, +secret_search_unlock_load_or_complete (GTask *task, SearchClosure *search) { + GCancellable *cancellable = g_task_get_cancellable (task); GList *items; /* If unlocking then unlock all the locked items */ if (search->flags & SECRET_SEARCH_UNLOCK) { items = search_closure_build_items (search, search->locked); - secret_service_unlock (search->service, items, search->cancellable, - on_search_unlocked, g_object_ref (async)); + secret_service_unlock (search->service, items, cancellable, + on_search_unlocked, g_object_ref (task)); g_list_free_full (items, g_object_unref); /* If loading secrets ... locked items automatically ignored */ } else if (search->flags & SECRET_SEARCH_LOAD_SECRETS) { items = g_hash_table_get_values (search->items); - secret_item_load_secrets (items, search->cancellable, - on_search_secrets, g_object_ref (async)); + secret_item_load_secrets (items, cancellable, + on_search_secrets, g_object_ref (task)); g_list_free (items); /* No additional options, just complete */ } else { - g_simple_async_result_complete (async); + g_task_return_boolean (task, TRUE); } } @@ -157,39 +157,43 @@ on_search_loaded (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); - SearchClosure *closure = g_simple_async_result_get_op_res_gpointer (res); + GTask *task = G_TASK (user_data); + SearchClosure *closure = g_task_get_task_data (task); GError *error = NULL; SecretItem *item; closure->loading--; item = secret_item_new_for_dbus_path_finish (result, &error); - if (error != NULL) - g_simple_async_result_take_error (res, error); + if (error != NULL) { + g_task_return_error (task, g_steal_pointer (&error)); + g_clear_object (&task); + return; + } if (item != NULL) search_closure_take_item (closure, item); /* We're done loading, lets go to the next step */ if (closure->loading == 0) - secret_search_unlock_load_or_complete (res, closure); + secret_search_unlock_load_or_complete (task, closure); - g_object_unref (res); + g_clear_object (&task); } static void search_load_item_async (SecretService *self, - GSimpleAsyncResult *res, + GTask *task, SearchClosure *closure, const gchar *path) { + GCancellable *cancellable = g_task_get_cancellable (task); SecretItem *item; item = _secret_service_find_item_instance (self, path); if (item == NULL) { - secret_item_new_for_dbus_path (self, path, SECRET_ITEM_NONE, closure->cancellable, - on_search_loaded, g_object_ref (res)); + secret_item_new_for_dbus_path (self, path, SECRET_ITEM_NONE, cancellable, + on_search_loaded, g_object_ref (task)); closure->loading++; } else { search_closure_take_item (closure, item); @@ -201,8 +205,8 @@ on_search_paths (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); - SearchClosure *closure = g_simple_async_result_get_op_res_gpointer (res); + GTask *task = G_TASK (user_data); + SearchClosure *closure = g_task_get_task_data (task); SecretService *self = closure->service; GError *error = NULL; gint want = 1; @@ -218,20 +222,19 @@ on_search_paths (GObject *source, count = 0; for (i = 0; count < want && closure->unlocked[i] != NULL; i++, count++) - search_load_item_async (self, res, closure, closure->unlocked[i]); + search_load_item_async (self, task, closure, closure->unlocked[i]); for (i = 0; count < want && closure->locked[i] != NULL; i++, count++) - search_load_item_async (self, res, closure, closure->locked[i]); + search_load_item_async (self, task, closure, closure->locked[i]); /* No items loading, complete operation now */ if (closure->loading == 0) - secret_search_unlock_load_or_complete (res, closure); + secret_search_unlock_load_or_complete (task, closure); } else { - g_simple_async_result_take_error (res, error); - g_simple_async_result_complete (res); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (res); + g_clear_object (&task); } static void @@ -239,22 +242,22 @@ on_search_service (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - SearchClosure *search = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + SearchClosure *search = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); GError *error = NULL; search->service = secret_service_get_finish (result, &error); if (error == NULL) { _secret_service_search_for_paths_variant (search->service, search->attributes, - search->cancellable, on_search_paths, - g_object_ref (async)); + cancellable, on_search_paths, + g_steal_pointer (&task)); } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (async); + g_clear_object (&task); } /** @@ -295,7 +298,7 @@ secret_service_search (SecretService *service, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; SearchClosure *closure; const gchar *schema_name = NULL; @@ -310,28 +313,27 @@ secret_service_search (SecretService *service, if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME)) schema_name = schema->name; - res = g_simple_async_result_new (G_OBJECT (service), callback, user_data, - secret_service_search); + task = g_task_new (service, cancellable, callback, user_data); + g_task_set_source_tag (task, secret_service_search); closure = g_slice_new0 (SearchClosure); - closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL; closure->items = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); closure->flags = flags; closure->attributes = _secret_attributes_to_variant (attributes, schema_name); g_variant_ref_sink (closure->attributes); - g_simple_async_result_set_op_res_gpointer (res, closure, search_closure_free); + g_task_set_task_data (task, closure, search_closure_free); if (service) { closure->service = g_object_ref (service); _secret_service_search_for_paths_variant (closure->service, closure->attributes, - closure->cancellable, on_search_paths, - g_object_ref (res)); + cancellable, on_search_paths, + g_steal_pointer (&task)); } else { secret_service_get (SECRET_SERVICE_NONE, cancellable, - on_search_service, g_object_ref (res)); + on_search_service, g_steal_pointer (&task)); } - g_object_unref (res); + g_clear_object (&task); } /** @@ -350,21 +352,19 @@ secret_service_search_finish (SecretService *service, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *res; SearchClosure *closure; GList *items = NULL; g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service), - secret_service_search), NULL); + g_return_val_if_fail (g_task_is_valid (result, service), NULL); - res = G_SIMPLE_ASYNC_RESULT (result); - - if (_secret_util_propagate_error (res, error)) + if (!g_task_propagate_boolean (G_TASK (result), error)) { + _secret_util_strip_remote_error (error); return NULL; + } - closure = g_simple_async_result_get_op_res_gpointer (res); + closure = g_task_get_task_data (G_TASK (result)); if (closure->unlocked) items = search_closure_build_items (closure, closure->unlocked); if (closure->locked) @@ -566,11 +566,9 @@ _secret_service_decode_get_secrets_all (SecretService *self, } typedef struct { - GCancellable *cancellable; GPtrArray *paths; GHashTable *objects; gchar **xlocked; - guint count; gboolean locking; } XlockClosure; @@ -578,8 +576,6 @@ static void xlock_closure_free (gpointer data) { XlockClosure *closure = data; - if (closure->cancellable) - g_object_unref (closure->cancellable); g_ptr_array_free (closure->paths, TRUE); g_strfreev (closure->xlocked); g_hash_table_unref (closure->objects); @@ -591,15 +587,17 @@ on_xlock_paths (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - XlockClosure *xlock = g_simple_async_result_get_op_res_gpointer (async); + SecretService *service = SECRET_SERVICE (source); + GTask *task = G_TASK (user_data); + XlockClosure *xlock = g_task_get_task_data (task); GVariant *lockval; GDBusProxy *object; GError *error = NULL; + gint count; gint i; - xlock->count = _secret_service_xlock_paths_finish (SECRET_SERVICE (source), result, - &xlock->xlocked, &error); + count = _secret_service_xlock_paths_finish (service, result, + &xlock->xlocked, &error); if (error == NULL) { /* @@ -615,13 +613,13 @@ on_xlock_paths (GObject *source, g_dbus_proxy_set_cached_property (object, "Locked", lockval); } g_variant_unref (lockval); + g_task_return_int (task, count); } else { - g_simple_async_result_take_error (async, error); + g_task_return_error (task, g_steal_pointer (&error)); } - g_simple_async_result_complete (async); - g_object_unref (async); + g_clear_object (&task); } static void @@ -629,8 +627,9 @@ on_xlock_service (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - XlockClosure *xlock = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + XlockClosure *xlock = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); GError *error = NULL; SecretService *service; @@ -638,16 +637,15 @@ on_xlock_service (GObject *source, if (error == NULL) { _secret_service_xlock_paths_async (service, xlock->locking ? "Lock" : "Unlock", (const gchar **)xlock->paths->pdata, - xlock->cancellable, on_xlock_paths, - g_object_ref (async)); + cancellable, on_xlock_paths, + g_steal_pointer (&task)); g_object_unref (service); } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (async); + g_clear_object (&task); } static void @@ -658,17 +656,16 @@ service_xlock_async (SecretService *service, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *async; + GTask *task; XlockClosure *xlock; const gchar *path; GList *l; - async = g_simple_async_result_new (G_OBJECT (service), callback, user_data, - service_xlock_async); + task = g_task_new (service, cancellable, callback, user_data); + g_task_set_source_tag (task, service_xlock_async); xlock = g_slice_new0 (XlockClosure); xlock->objects = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); xlock->locking = locking; - xlock->cancellable = cancellable ? g_object_ref (cancellable) : NULL; xlock->paths = g_ptr_array_new (); for (l = objects; l != NULL; l = g_list_next (l)) { @@ -678,19 +675,19 @@ service_xlock_async (SecretService *service, } g_ptr_array_add (xlock->paths, NULL); - g_simple_async_result_set_op_res_gpointer (async, xlock, xlock_closure_free); + g_task_set_task_data (task, xlock, xlock_closure_free); if (service == NULL) { secret_service_get (SECRET_SERVICE_NONE, cancellable, - on_xlock_service, g_object_ref (async)); + on_xlock_service, g_steal_pointer (&task)); } else { _secret_service_xlock_paths_async (service, xlock->locking ? "Lock" : "Unlock", (const gchar **)xlock->paths->pdata, - xlock->cancellable, on_xlock_paths, - g_object_ref (async)); + cancellable, on_xlock_paths, + g_steal_pointer (&task)); } - g_object_unref (async); + g_clear_object (&task); } static gint @@ -699,19 +696,20 @@ service_xlock_finish (SecretService *service, GList **xlocked, GError **error) { - GSimpleAsyncResult *async; XlockClosure *xlock; GDBusProxy *object; + gint count; gint i; - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service), - service_xlock_async), -1); + g_return_val_if_fail (g_task_is_valid (result, service), -1); - async = G_SIMPLE_ASYNC_RESULT (result); - if (_secret_util_propagate_error (async, error)) + count = g_task_propagate_int (G_TASK (result), error); + if (count == -1) { + _secret_util_strip_remote_error (error); return -1; + } - xlock = g_simple_async_result_get_op_res_gpointer (async); + xlock = g_task_get_task_data (G_TASK (result)); if (xlocked) { *xlocked = NULL; for (i = 0; xlock->xlocked[i] != NULL; i++) { @@ -721,7 +719,7 @@ service_xlock_finish (SecretService *service, } } - return xlock->count; + return count; } /** @@ -953,7 +951,6 @@ secret_service_unlock_sync (SecretService *service, } typedef struct { - GCancellable *cancellable; gchar *collection_path; SecretValue *value; GHashTable *properties; @@ -965,8 +962,6 @@ static void store_closure_free (gpointer data) { StoreClosure *store = data; - if (store->cancellable) - g_object_unref (store->cancellable); g_free (store->collection_path); secret_value_unref (store->value); g_hash_table_unref (store->properties); @@ -983,9 +978,10 @@ on_store_keyring (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - StoreClosure *store = g_simple_async_result_get_op_res_gpointer (async); SecretService *service = SECRET_SERVICE (source); + GTask *task = G_TASK (user_data); + StoreClosure *store = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); GError *error = NULL; gchar *path; @@ -994,15 +990,16 @@ on_store_keyring (GObject *source, store->created_collection = TRUE; secret_service_create_item_dbus_path (service, store->collection_path, store->properties, store->value, - SECRET_ITEM_CREATE_REPLACE, store->cancellable, - on_store_create, g_object_ref (async)); + SECRET_ITEM_CREATE_REPLACE, + cancellable, + on_store_create, + g_steal_pointer (&task)); } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (async); g_free (path); + g_clear_object (&task); } static void @@ -1010,9 +1007,10 @@ on_store_unlock (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - StoreClosure *store = g_simple_async_result_get_op_res_gpointer (async); SecretService *service = SECRET_SERVICE (source); + GTask *task = G_TASK (user_data); + StoreClosure *store = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); GError *error = NULL; secret_service_unlock_dbus_paths_finish (service, result, NULL, &error); @@ -1020,14 +1018,15 @@ on_store_unlock (GObject *source, store->unlocked_collection = TRUE; secret_service_create_item_dbus_path (service, store->collection_path, store->properties, store->value, - SECRET_ITEM_CREATE_REPLACE, store->cancellable, - on_store_create, g_object_ref (async)); + SECRET_ITEM_CREATE_REPLACE, + cancellable, + on_store_create, + g_steal_pointer (&task)); } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (async); + g_clear_object (&task); } static void @@ -1035,9 +1034,10 @@ on_store_create (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - StoreClosure *store = g_simple_async_result_get_op_res_gpointer (async); SecretService *service = SECRET_SERVICE (source); + GTask *task = G_TASK (user_data); + StoreClosure *store = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); GError *error = NULL; GHashTable *properties; @@ -1054,24 +1054,32 @@ on_store_create (GObject *source, g_strcmp0 (store->collection_path, SECRET_ALIAS_PREFIX "default") == 0) { properties = _secret_collection_properties_new (_("Default keyring")); secret_service_create_collection_dbus_path (service, properties, "default", - SECRET_COLLECTION_CREATE_NONE, store->cancellable, - on_store_keyring, g_object_ref (async)); + SECRET_COLLECTION_CREATE_NONE, + cancellable, + on_store_keyring, + g_steal_pointer (&task)); g_hash_table_unref (properties); g_error_free (error); - - } else if (!store->unlocked_collection && - g_error_matches (error, SECRET_ERROR, SECRET_ERROR_IS_LOCKED)) { - const gchar *paths[2] = { store->collection_path, NULL }; - secret_service_unlock_dbus_paths (service, paths, store->cancellable, - on_store_unlock, g_object_ref (async)); - g_error_free (error); - } else { - if (error != NULL) - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_clear_object (&task); + return; } - g_object_unref (async); + if (!store->unlocked_collection && + g_error_matches (error, SECRET_ERROR, SECRET_ERROR_IS_LOCKED)) { + const gchar *paths[2] = { store->collection_path, NULL }; + secret_service_unlock_dbus_paths (service, paths, cancellable, + on_store_unlock, g_steal_pointer (&task)); + g_error_free (error); + g_clear_object (&task); + return; + } + + if (error != NULL) + g_task_return_error (task, g_steal_pointer (&error)); + else + g_task_return_boolean (task, TRUE); + + g_clear_object (&task); } static void @@ -1079,8 +1087,9 @@ on_store_service (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - StoreClosure *store = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + StoreClosure *store = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); SecretService *service; GError *error = NULL; @@ -1088,16 +1097,17 @@ on_store_service (GObject *source, if (error == NULL) { secret_service_create_item_dbus_path (service, store->collection_path, store->properties, store->value, - SECRET_ITEM_CREATE_REPLACE, store->cancellable, - on_store_create, g_object_ref (async)); + SECRET_ITEM_CREATE_REPLACE, + cancellable, + on_store_create, + g_steal_pointer (&task)); g_object_unref (service); } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (async); + g_clear_object (&task); } /** @@ -1140,7 +1150,7 @@ secret_service_store (SecretService *service, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *async; + GTask *task; StoreClosure *store; const gchar *schema_name; GVariant *propval; @@ -1155,11 +1165,10 @@ secret_service_store (SecretService *service, if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE)) return; - async = g_simple_async_result_new (G_OBJECT (service), callback, user_data, - secret_service_store); + task = g_task_new (service, cancellable, callback, user_data); + g_task_set_source_tag (task, secret_service_store); store = g_slice_new0 (StoreClosure); store->collection_path = _secret_util_collection_to_path (collection); - store->cancellable = cancellable ? g_object_ref (cancellable) : NULL; store->value = secret_value_ref (value); store->properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)g_variant_unref); @@ -1176,20 +1185,22 @@ secret_service_store (SecretService *service, SECRET_ITEM_INTERFACE ".Attributes", g_variant_ref_sink (propval)); - g_simple_async_result_set_op_res_gpointer (async, store, store_closure_free); + g_task_set_task_data (task, store, store_closure_free); if (service == NULL) { secret_service_get (SECRET_SERVICE_OPEN_SESSION, cancellable, - on_store_service, g_object_ref (async)); + on_store_service, g_steal_pointer (&task)); } else { secret_service_create_item_dbus_path (service, store->collection_path, store->properties, store->value, - SECRET_ITEM_CREATE_REPLACE, store->cancellable, - on_store_create, g_object_ref (async)); + SECRET_ITEM_CREATE_REPLACE, + cancellable, + on_store_create, + g_steal_pointer (&task)); } - g_object_unref (async); + g_clear_object (&task); } /** @@ -1208,12 +1219,13 @@ secret_service_store_finish (SecretService *service, GError **error) { g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service), - secret_service_store), FALSE); + g_return_val_if_fail (g_task_is_valid (result, service), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - if (_secret_util_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) + if (!g_task_propagate_boolean (G_TASK (result), error)) { + _secret_util_strip_remote_error (error); return FALSE; + } return TRUE; } @@ -1289,39 +1301,23 @@ secret_service_store_sync (SecretService *service, return ret; } -typedef struct { - GVariant *attributes; - SecretValue *value; - GCancellable *cancellable; -} LookupClosure; - -static void -lookup_closure_free (gpointer data) -{ - LookupClosure *closure = data; - g_variant_unref (closure->attributes); - if (closure->value) - secret_value_unref (closure->value); - g_clear_object (&closure->cancellable); - g_slice_free (LookupClosure, closure); -} - static void on_lookup_get_secret (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); - LookupClosure *closure = g_simple_async_result_get_op_res_gpointer (res); + GTask *task = G_TASK (user_data); SecretService *self = SECRET_SERVICE (source); + SecretValue *value; GError *error = NULL; - closure->value = secret_service_get_secret_for_dbus_path_finish (self, result, &error); + value = secret_service_get_secret_for_dbus_path_finish (self, result, &error); if (error != NULL) - g_simple_async_result_take_error (res, error); + g_task_return_error (task, g_steal_pointer (&error)); + else + g_task_return_pointer (task, value, secret_value_unref); - g_simple_async_result_complete (res); - g_object_unref (res); + g_clear_object (&task); } static void @@ -1329,30 +1325,28 @@ on_lookup_unlocked (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); - LookupClosure *closure = g_simple_async_result_get_op_res_gpointer (res); SecretService *self = SECRET_SERVICE (source); + GTask *task = G_TASK (user_data); + GCancellable *cancellable = g_task_get_cancellable (task); GError *error = NULL; gchar **unlocked = NULL; - secret_service_unlock_dbus_paths_finish (SECRET_SERVICE (source), - result, &unlocked, &error); + secret_service_unlock_dbus_paths_finish (self, result, &unlocked, &error); if (error != NULL) { - g_simple_async_result_take_error (res, error); - g_simple_async_result_complete (res); + g_task_return_error (task, g_steal_pointer (&error)); } else if (unlocked && unlocked[0]) { secret_service_get_secret_for_dbus_path (self, unlocked[0], - closure->cancellable, + cancellable, on_lookup_get_secret, - g_object_ref (res)); + g_steal_pointer (&task)); } else { - g_simple_async_result_complete (res); + g_task_return_pointer (task, NULL, NULL); } g_strfreev (unlocked); - g_object_unref (res); + g_clear_object (&task); } static void @@ -1360,38 +1354,37 @@ on_lookup_searched (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); - LookupClosure *closure = g_simple_async_result_get_op_res_gpointer (res); SecretService *self = SECRET_SERVICE (source); + GTask *task = G_TASK (user_data); + GCancellable *cancellable = g_task_get_cancellable (task); GError *error = NULL; gchar **unlocked = NULL; gchar **locked = NULL; secret_service_search_for_dbus_paths_finish (self, result, &unlocked, &locked, &error); if (error != NULL) { - g_simple_async_result_take_error (res, error); - g_simple_async_result_complete (res); + g_task_return_error (task, g_steal_pointer (&error)); } else if (unlocked && unlocked[0]) { secret_service_get_secret_for_dbus_path (self, unlocked[0], - closure->cancellable, + cancellable, on_lookup_get_secret, - g_object_ref (res)); + g_steal_pointer (&task)); } else if (locked && locked[0]) { const gchar *paths[] = { locked[0], NULL }; secret_service_unlock_dbus_paths (self, paths, - closure->cancellable, + cancellable, on_lookup_unlocked, - g_object_ref (res)); + g_steal_pointer (&task)); } else { - g_simple_async_result_complete (res); + g_task_return_pointer (task, NULL, NULL); } g_strfreev (unlocked); g_strfreev (locked); - g_object_unref (res); + g_clear_object (&task); } static void @@ -1399,24 +1392,25 @@ on_lookup_service (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - LookupClosure *lookup = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + GVariant *attributes = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); SecretService *service; GError *error = NULL; service = secret_service_get_finish (result, &error); if (error == NULL) { - _secret_service_search_for_paths_variant (service, lookup->attributes, - lookup->cancellable, - on_lookup_searched, g_object_ref (async)); + _secret_service_search_for_paths_variant (service, attributes, + cancellable, + on_lookup_searched, + g_steal_pointer (&task)); g_object_unref (service); } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (async); + g_clear_object (&task); } /** @@ -1446,8 +1440,8 @@ secret_service_lookup (SecretService *service, gpointer user_data) { const gchar *schema_name = NULL; - GSimpleAsyncResult *res; - LookupClosure *closure; + GTask *task; + GVariant *attributes_v; g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service)); g_return_if_fail (attributes != NULL); @@ -1460,24 +1454,24 @@ secret_service_lookup (SecretService *service, if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME)) schema_name = schema->name; - res = g_simple_async_result_new (G_OBJECT (service), callback, user_data, - secret_service_lookup); - closure = g_slice_new0 (LookupClosure); - closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - closure->attributes = _secret_attributes_to_variant (attributes, schema_name); - g_variant_ref_sink (closure->attributes); - g_simple_async_result_set_op_res_gpointer (res, closure, lookup_closure_free); + task = g_task_new (service, cancellable, callback, user_data); + g_task_set_source_tag (task, secret_service_lookup); + + attributes_v = _secret_attributes_to_variant (attributes, schema_name); + g_variant_ref_sink (attributes_v); + g_task_set_task_data (task, attributes_v, (GDestroyNotify) g_variant_unref); if (service == NULL) { secret_service_get (SECRET_SERVICE_OPEN_SESSION, cancellable, - on_lookup_service, g_object_ref (res)); + on_lookup_service, g_steal_pointer (&task)); } else { - _secret_service_search_for_paths_variant (service, closure->attributes, - closure->cancellable, - on_lookup_searched, g_object_ref (res)); + _secret_service_search_for_paths_variant (service, attributes_v, + cancellable, + on_lookup_searched, + g_steal_pointer (&task)); } - g_object_unref (res); + g_clear_object (&task); } /** @@ -1498,22 +1492,18 @@ secret_service_lookup_finish (SecretService *service, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *res; - LookupClosure *closure; SecretValue *value; g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service), - secret_service_lookup), NULL); + g_return_val_if_fail (g_task_is_valid (result, service), NULL); - res = G_SIMPLE_ASYNC_RESULT (result); - if (_secret_util_propagate_error (res, error)) + value = g_task_propagate_pointer (G_TASK (result), error); + if (!value) { + _secret_util_strip_remote_error (error); return NULL; + } - closure = g_simple_async_result_get_op_res_gpointer (res); - value = closure->value; - closure->value = NULL; return value; } @@ -1573,7 +1563,6 @@ secret_service_lookup_sync (SecretService *service, } typedef struct { - GCancellable *cancellable; SecretService *service; GVariant *attributes; gint deleted; @@ -1587,7 +1576,6 @@ delete_closure_free (gpointer data) if (closure->service) g_object_unref (closure->service); g_variant_unref (closure->attributes); - g_clear_object (&closure->cancellable); g_slice_free (DeleteClosure, closure); } @@ -1596,23 +1584,24 @@ on_delete_password_complete (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); - DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (res); + SecretService *service = SECRET_SERVICE (source); + GTask *task = G_TASK (user_data); + DeleteClosure *closure = g_task_get_task_data (task); GError *error = NULL; gboolean deleted; closure->deleting--; - deleted = _secret_service_delete_path_finish (SECRET_SERVICE (source), result, &error); + deleted = _secret_service_delete_path_finish (service, result, &error); if (error != NULL) - g_simple_async_result_take_error (res, error); + g_task_return_error (task, g_steal_pointer (&error)); if (deleted) closure->deleted++; if (closure->deleting <= 0) - g_simple_async_result_complete (res); + g_task_return_boolean (task, TRUE); - g_object_unref (res); + g_clear_object (&task); } static void @@ -1620,31 +1609,32 @@ on_delete_searched (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); - DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (res); + SecretService *service = SECRET_SERVICE (source); + GTask *task = G_TASK (user_data); + DeleteClosure *closure = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); GError *error = NULL; gchar **unlocked = NULL; gint i; - secret_service_search_for_dbus_paths_finish (SECRET_SERVICE (source), result, &unlocked, NULL, &error); + secret_service_search_for_dbus_paths_finish (service, result, &unlocked, NULL, &error); if (error == NULL) { for (i = 0; unlocked[i] != NULL; i++) { _secret_service_delete_path (closure->service, unlocked[i], TRUE, - closure->cancellable, + cancellable, on_delete_password_complete, - g_object_ref (res)); + g_object_ref (task)); closure->deleting++; } if (closure->deleting == 0) - g_simple_async_result_complete (res); + g_task_return_boolean (task, FALSE); } else { - g_simple_async_result_take_error (res, error); - g_simple_async_result_complete (res); + g_task_return_error (task, g_steal_pointer (&error)); } g_strfreev (unlocked); - g_object_unref (res); + g_clear_object (&task); } static void @@ -1652,22 +1642,22 @@ on_delete_service (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + DeleteClosure *closure = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); GError *error = NULL; closure->service = secret_service_get_finish (result, &error); if (error == NULL) { _secret_service_search_for_paths_variant (closure->service, closure->attributes, - closure->cancellable, - on_delete_searched, g_object_ref (async)); + cancellable, + on_delete_searched, g_steal_pointer (&task)); } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (async); + g_clear_object (&task); } /** @@ -1697,7 +1687,7 @@ secret_service_clear (SecretService *service, gpointer user_data) { const gchar *schema_name = NULL; - GSimpleAsyncResult *res; + GTask *task; DeleteClosure *closure; g_return_if_fail (service == NULL || SECRET_SERVICE (service)); @@ -1711,28 +1701,27 @@ secret_service_clear (SecretService *service, if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME)) schema_name = schema->name; - res = g_simple_async_result_new (G_OBJECT (service), callback, user_data, - secret_service_clear); + task = g_task_new (service, cancellable, callback, user_data); + g_task_set_source_tag (task, secret_service_clear); closure = g_slice_new0 (DeleteClosure); - closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL; closure->attributes = _secret_attributes_to_variant (attributes, schema_name); g_variant_ref_sink (closure->attributes); - g_simple_async_result_set_op_res_gpointer (res, closure, delete_closure_free); + g_task_set_task_data (task, closure, delete_closure_free); /* A double check to make sure we don't delete everything, should have been checked earlier */ g_assert (g_variant_n_children (closure->attributes) > 0); if (service == NULL) { secret_service_get (SECRET_SERVICE_NONE, cancellable, - on_delete_service, g_object_ref (res)); + on_delete_service, g_steal_pointer (&task)); } else { closure->service = g_object_ref (service); _secret_service_search_for_paths_variant (closure->service, closure->attributes, - closure->cancellable, - on_delete_searched, g_object_ref (res)); + cancellable, + on_delete_searched, g_steal_pointer (&task)); } - g_object_unref (res); + g_clear_object (&task); } /** @@ -1751,20 +1740,16 @@ secret_service_clear_finish (SecretService *service, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *res; - DeleteClosure *closure; - g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service), - secret_service_clear), FALSE); + g_return_val_if_fail (g_task_is_valid (result, service), FALSE); - res = G_SIMPLE_ASYNC_RESULT (result); - if (_secret_util_propagate_error (res, error)) + if (!g_task_propagate_boolean (G_TASK (result), error)) { + _secret_util_strip_remote_error (error); return FALSE; + } - closure = g_simple_async_result_get_op_res_gpointer (res); - return closure->deleted > 0; + return TRUE; } /** @@ -1822,7 +1807,6 @@ secret_service_clear_sync (SecretService *service, } typedef struct { - GCancellable *cancellable; gchar *alias; gchar *collection_path; } SetClosure; @@ -1831,8 +1815,6 @@ static void set_closure_free (gpointer data) { SetClosure *set = data; - if (set->cancellable) - g_object_unref (set->cancellable); g_free (set->alias); g_free (set->collection_path); g_slice_free (SetClosure, set); @@ -1843,15 +1825,17 @@ on_set_alias_done (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); + GTask *task = G_TASK (user_data); + SecretService *service = SECRET_SERVICE (source); GError *error = NULL; - secret_service_set_alias_to_dbus_path_finish (SECRET_SERVICE (source), result, &error); - if (error != NULL) - g_simple_async_result_take_error (async, error); + if (secret_service_set_alias_to_dbus_path_finish (service, result, &error)) { + g_task_return_boolean (task, TRUE); + } else { + g_task_return_error (task, g_steal_pointer (&error)); + } - g_simple_async_result_complete (async); - g_object_unref (async); + g_clear_object (&task); } static void @@ -1859,8 +1843,9 @@ on_set_alias_service (GObject *source, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); - SetClosure *set = g_simple_async_result_get_op_res_gpointer (async); + GTask *task = G_TASK (user_data); + SetClosure *set = g_task_get_task_data (task); + GCancellable *cancellable = g_task_get_cancellable (task); SecretService *service; GError *error = NULL; @@ -1868,17 +1853,16 @@ on_set_alias_service (GObject *source, if (error == NULL) { secret_service_set_alias_to_dbus_path (service, set->alias, set->collection_path, - set->cancellable, + cancellable, on_set_alias_done, - g_object_ref (async)); + g_steal_pointer (&task)); g_object_unref (service); } else { - g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (async); + g_task_return_error (task, g_steal_pointer (&error)); } - g_object_unref (async); + g_clear_object (&task); } /** @@ -1906,7 +1890,7 @@ secret_service_set_alias (SecretService *service, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *async; + GTask *task; SetClosure *set; const gchar *path; @@ -1915,10 +1899,9 @@ secret_service_set_alias (SecretService *service, g_return_if_fail (collection == NULL || SECRET_IS_COLLECTION (collection)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); - async = g_simple_async_result_new (G_OBJECT (service), callback, user_data, - secret_service_set_alias); + task = g_task_new (service, cancellable, callback, user_data); + g_task_set_source_tag (task, secret_service_set_alias); set = g_slice_new0 (SetClosure); - set->cancellable = cancellable ? g_object_ref (cancellable) : NULL; set->alias = g_strdup (alias); if (collection) { @@ -1929,20 +1912,20 @@ secret_service_set_alias (SecretService *service, } set->collection_path = g_strdup (path); - g_simple_async_result_set_op_res_gpointer (async, set, set_closure_free); + g_task_set_task_data (task, set, set_closure_free); if (service == NULL) { secret_service_get (SECRET_SERVICE_NONE, cancellable, - on_set_alias_service, g_object_ref (async)); + on_set_alias_service, g_steal_pointer (&task)); } else { secret_service_set_alias_to_dbus_path (service, set->alias, set->collection_path, - set->cancellable, + cancellable, on_set_alias_done, - g_object_ref (async)); + g_steal_pointer (&task)); } - g_object_unref (async); + g_clear_object (&task); } /** @@ -1961,12 +1944,13 @@ secret_service_set_alias_finish (SecretService *service, GError **error) { g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service), - secret_service_set_alias), FALSE); + g_return_val_if_fail (g_task_is_valid (result, service), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - if (_secret_util_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) + if (!g_task_propagate_boolean (G_TASK (result), error)) { + _secret_util_strip_remote_error (error); return FALSE; + } return TRUE; }