mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-22 20:58:52 +00:00
Port Service and Session to GTask
GSimpleAsyncResult is deprecated in favor of the simpler GTask, so use that instead. This cuts down on the deprecation warnings. I wanted to do both separately, but porting one without the other led to some faulty casts from GSimpleAsyncResult to GTask (and vice versa).
This commit is contained in:
parent
103ff88f6d
commit
f165f721d8
@ -310,17 +310,21 @@ on_real_prompt_completed (GObject *source,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
GTask *task = G_TASK (user_data);
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GVariant *retval;
|
GVariant *retval;
|
||||||
|
|
||||||
retval = secret_prompt_perform_finish (SECRET_PROMPT (source), result, &error);
|
retval = secret_prompt_perform_finish (SECRET_PROMPT (source),
|
||||||
|
result,
|
||||||
|
&error);
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
g_simple_async_result_set_op_res_gpointer (res, retval, (GDestroyNotify)g_variant_unref);
|
g_task_return_pointer (task,
|
||||||
if (error != NULL)
|
g_steal_pointer (&retval),
|
||||||
g_simple_async_result_take_error (res, error);
|
(GDestroyNotify) g_variant_unref);
|
||||||
g_simple_async_result_complete (res);
|
else
|
||||||
g_object_unref (res);
|
g_task_return_error (task, g_steal_pointer (&error));
|
||||||
|
|
||||||
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -331,16 +335,16 @@ secret_service_real_prompt_async (SecretService *self,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
|
|
||||||
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
task = g_task_new (self, cancellable, callback, user_data);
|
||||||
secret_service_real_prompt_async);
|
g_task_set_source_tag (task, secret_service_real_prompt_async);
|
||||||
|
|
||||||
secret_prompt_perform (prompt, 0, return_type, cancellable,
|
secret_prompt_perform (prompt, 0, return_type, cancellable,
|
||||||
on_real_prompt_completed,
|
on_real_prompt_completed,
|
||||||
g_object_ref (res));
|
g_object_ref (task));
|
||||||
|
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GVariant *
|
static GVariant *
|
||||||
@ -348,21 +352,19 @@ secret_service_real_prompt_finish (SecretService *self,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
|
||||||
GVariant *retval;
|
GVariant *retval;
|
||||||
|
|
||||||
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
g_return_val_if_fail (g_task_is_valid (result, self), NULL);
|
||||||
secret_service_real_prompt_async), NULL);
|
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
|
||||||
|
secret_service_real_prompt_async, NULL);
|
||||||
|
|
||||||
res = G_SIMPLE_ASYNC_RESULT (result);
|
retval = g_task_propagate_pointer (G_TASK (result), error);
|
||||||
if (_secret_util_propagate_error (res, error))
|
if (!retval) {
|
||||||
|
_secret_util_strip_remote_error (error);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
retval = g_simple_async_result_get_op_res_gpointer (res);
|
return g_variant_ref_sink (retval);
|
||||||
if (retval == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return g_variant_ref (retval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -562,7 +564,6 @@ secret_service_class_init (SecretServiceClass *klass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GCancellable *cancellable;
|
|
||||||
SecretServiceFlags flags;
|
SecretServiceFlags flags;
|
||||||
} InitClosure;
|
} InitClosure;
|
||||||
|
|
||||||
@ -570,7 +571,6 @@ static void
|
|||||||
init_closure_free (gpointer data)
|
init_closure_free (gpointer data)
|
||||||
{
|
{
|
||||||
InitClosure *closure = data;
|
InitClosure *closure = data;
|
||||||
g_clear_object (&closure->cancellable);
|
|
||||||
g_slice_free (InitClosure, closure);
|
g_slice_free (InitClosure, closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,15 +596,16 @@ on_load_collections (GObject *source,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
GTask *task = G_TASK (user_data);
|
||||||
SecretService *self = SECRET_SERVICE (source);
|
SecretService *self = SECRET_SERVICE (source);
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!secret_service_load_collections_finish (self, result, &error))
|
if (!secret_service_load_collections_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_boolean (task, TRUE);
|
||||||
|
|
||||||
g_simple_async_result_complete (res);
|
g_object_unref (task);
|
||||||
g_object_unref (res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -612,45 +613,47 @@ on_ensure_session (GObject *source,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
GTask *task = G_TASK (user_data);
|
||||||
InitClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
InitClosure *closure = g_task_get_task_data (task);
|
||||||
SecretService *self = SECRET_SERVICE (source);
|
SecretService *self = SECRET_SERVICE (source);
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!secret_service_ensure_session_finish (self, result, &error)) {
|
if (!secret_service_ensure_session_finish (self, result, &error)) {
|
||||||
g_simple_async_result_take_error (res, error);
|
g_task_return_error (task, g_steal_pointer (&error));
|
||||||
g_simple_async_result_complete (res);
|
|
||||||
|
|
||||||
} else if (closure->flags & SECRET_SERVICE_LOAD_COLLECTIONS) {
|
} else if (closure->flags & SECRET_SERVICE_LOAD_COLLECTIONS) {
|
||||||
secret_service_load_collections (self, closure->cancellable,
|
secret_service_load_collections (self, g_task_get_cancellable (task),
|
||||||
on_load_collections, g_object_ref (res));
|
on_load_collections,
|
||||||
|
g_object_ref (task));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
g_simple_async_result_complete_in_idle (res);
|
g_task_return_boolean (task, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
service_ensure_for_flags_async (SecretService *self,
|
service_ensure_for_flags_async (SecretService *self,
|
||||||
SecretServiceFlags flags,
|
SecretServiceFlags flags,
|
||||||
GSimpleAsyncResult *res)
|
GTask *task)
|
||||||
{
|
{
|
||||||
InitClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
InitClosure *closure = g_task_get_task_data (task);
|
||||||
|
|
||||||
closure->flags = flags;
|
closure->flags = flags;
|
||||||
|
|
||||||
if (closure->flags & SECRET_SERVICE_OPEN_SESSION)
|
if (closure->flags & SECRET_SERVICE_OPEN_SESSION)
|
||||||
secret_service_ensure_session (self, closure->cancellable,
|
secret_service_ensure_session (self, g_task_get_cancellable (task),
|
||||||
on_ensure_session, g_object_ref (res));
|
on_ensure_session,
|
||||||
|
g_object_ref (task));
|
||||||
|
|
||||||
else if (closure->flags & SECRET_SERVICE_LOAD_COLLECTIONS)
|
else if (closure->flags & SECRET_SERVICE_LOAD_COLLECTIONS)
|
||||||
secret_service_load_collections (self, closure->cancellable,
|
secret_service_load_collections (self, g_task_get_cancellable (task),
|
||||||
on_load_collections, g_object_ref (res));
|
on_load_collections,
|
||||||
|
g_object_ref (task));
|
||||||
|
|
||||||
else
|
else
|
||||||
g_simple_async_result_complete_in_idle (res);
|
g_task_return_boolean (task, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -680,19 +683,18 @@ on_init_base (GObject *source,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
GTask *task = G_TASK (user_data);
|
||||||
SecretService *self = SECRET_SERVICE (source);
|
SecretService *self = SECRET_SERVICE (source);
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!secret_service_async_initable_parent_iface->init_finish (G_ASYNC_INITABLE (self),
|
if (!secret_service_async_initable_parent_iface->init_finish (G_ASYNC_INITABLE (self),
|
||||||
result, &error)) {
|
result, &error)) {
|
||||||
g_simple_async_result_take_error (res, error);
|
g_task_return_error (task, error);
|
||||||
g_simple_async_result_complete (res);
|
|
||||||
} else {
|
} else {
|
||||||
service_ensure_for_flags_async (self, self->pv->init_flags, res);
|
service_ensure_for_flags_async (self, self->pv->init_flags, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -702,21 +704,21 @@ secret_service_async_initable_init_async (GAsyncInitable *initable,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
InitClosure *closure;
|
InitClosure *closure;
|
||||||
|
|
||||||
res = g_simple_async_result_new (G_OBJECT (initable), callback, user_data,
|
task = g_task_new (initable, cancellable, callback, user_data);
|
||||||
secret_service_async_initable_init_async);
|
g_task_set_source_tag (task, secret_service_async_initable_init_async);
|
||||||
closure = g_slice_new0 (InitClosure);
|
closure = g_slice_new0 (InitClosure);
|
||||||
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
g_task_set_task_data (task, closure, init_closure_free);
|
||||||
g_simple_async_result_set_op_res_gpointer (res, closure, init_closure_free);
|
|
||||||
|
|
||||||
secret_service_async_initable_parent_iface->init_async (initable, io_priority,
|
secret_service_async_initable_parent_iface->init_async (initable,
|
||||||
|
io_priority,
|
||||||
cancellable,
|
cancellable,
|
||||||
on_init_base,
|
on_init_base,
|
||||||
g_object_ref (res));
|
g_object_ref (task));
|
||||||
|
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -724,11 +726,12 @@ secret_service_async_initable_init_finish (GAsyncInitable *initable,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (initable),
|
g_return_val_if_fail (g_task_is_valid (result, initable), FALSE);
|
||||||
secret_service_async_initable_init_async), 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 FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -776,7 +779,7 @@ secret_service_get (SecretServiceFlags flags,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
SecretService *service = NULL;
|
SecretService *service = NULL;
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
InitClosure *closure;
|
InitClosure *closure;
|
||||||
|
|
||||||
service = service_get_instance ();
|
service = service_get_instance ();
|
||||||
@ -796,17 +799,16 @@ secret_service_get (SecretServiceFlags flags,
|
|||||||
|
|
||||||
/* Just have to ensure that the service matches flags */
|
/* Just have to ensure that the service matches flags */
|
||||||
} else {
|
} else {
|
||||||
res = g_simple_async_result_new (G_OBJECT (service), callback,
|
task = g_task_new (service, cancellable, callback, user_data);
|
||||||
user_data, secret_service_get);
|
g_task_set_source_tag (task, secret_service_get);
|
||||||
closure = g_slice_new0 (InitClosure);
|
closure = g_slice_new0 (InitClosure);
|
||||||
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
||||||
closure->flags = flags;
|
closure->flags = flags;
|
||||||
g_simple_async_result_set_op_res_gpointer (res, closure, init_closure_free);
|
g_task_set_task_data (task, closure, init_closure_free);
|
||||||
|
|
||||||
service_ensure_for_flags_async (service, flags, res);
|
service_ensure_for_flags_async (service, flags, task);
|
||||||
|
|
||||||
g_object_unref (service);
|
g_object_unref (service);
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -825,18 +827,26 @@ SecretService *
|
|||||||
secret_service_get_finish (GAsyncResult *result,
|
secret_service_get_finish (GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
|
GTask *task;
|
||||||
GObject *service = NULL;
|
GObject *service = NULL;
|
||||||
GObject *source_object;
|
GObject *source_object;
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
source_object = g_async_result_get_source_object (result);
|
task = G_TASK (result);
|
||||||
|
source_object = g_task_get_source_object (task);
|
||||||
|
|
||||||
|
g_return_val_if_fail (g_task_is_valid (result, source_object), NULL);
|
||||||
|
|
||||||
/* Just ensuring that the service matches flags */
|
/* Just ensuring that the service matches flags */
|
||||||
if (g_simple_async_result_is_valid (result, source_object, secret_service_get)) {
|
if (g_task_get_source_tag (task) == secret_service_get) {
|
||||||
if (!_secret_util_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
if (g_task_had_error (task)) {
|
||||||
|
g_task_propagate_pointer (task, error);
|
||||||
|
_secret_util_strip_remote_error (error);
|
||||||
|
} else {
|
||||||
service = g_object_ref (source_object);
|
service = g_object_ref (source_object);
|
||||||
|
}
|
||||||
|
|
||||||
/* Creating a whole new service */
|
/* Creating a whole new service */
|
||||||
} else {
|
} else {
|
||||||
@ -845,9 +855,6 @@ secret_service_get_finish (GAsyncResult *result,
|
|||||||
service_cache_instance (SECRET_SERVICE (service));
|
service_cache_instance (SECRET_SERVICE (service));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source_object)
|
|
||||||
g_object_unref (source_object);
|
|
||||||
|
|
||||||
if (service == NULL)
|
if (service == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -1275,7 +1282,7 @@ secret_service_ensure_session (SecretService *self,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
SecretSession *session;
|
SecretSession *session;
|
||||||
|
|
||||||
g_return_if_fail (SECRET_IS_SERVICE (self));
|
g_return_if_fail (SECRET_IS_SERVICE (self));
|
||||||
@ -1289,10 +1296,10 @@ secret_service_ensure_session (SecretService *self,
|
|||||||
_secret_session_open (self, cancellable, callback, user_data);
|
_secret_session_open (self, cancellable, callback, user_data);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
task = g_task_new (self, cancellable, callback, user_data);
|
||||||
secret_service_ensure_session);
|
g_task_set_source_tag (task, secret_service_ensure_session);
|
||||||
g_simple_async_result_complete_in_idle (res);
|
g_task_return_boolean (task, TRUE);
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1315,10 +1322,11 @@ secret_service_ensure_session_finish (SecretService *self,
|
|||||||
g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||||
|
|
||||||
if (!g_simple_async_result_is_valid (result, G_OBJECT (self),
|
if (!g_task_is_valid (result, self)) {
|
||||||
secret_service_ensure_session)) {
|
if (!g_task_propagate_boolean (G_TASK (result), error)) {
|
||||||
if (!_secret_session_open_finish (result, error))
|
_secret_util_strip_remote_error (error);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_return_val_if_fail (self->pv->session != NULL, FALSE);
|
g_return_val_if_fail (self->pv->session != NULL, FALSE);
|
||||||
@ -1413,7 +1421,6 @@ service_update_collections (SecretService *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GCancellable *cancellable;
|
|
||||||
GHashTable *collections;
|
GHashTable *collections;
|
||||||
gint collections_loading;
|
gint collections_loading;
|
||||||
} EnsureClosure;
|
} EnsureClosure;
|
||||||
@ -1429,7 +1436,6 @@ static void
|
|||||||
ensure_closure_free (gpointer data)
|
ensure_closure_free (gpointer data)
|
||||||
{
|
{
|
||||||
EnsureClosure *closure = data;
|
EnsureClosure *closure = data;
|
||||||
g_clear_object (&closure->cancellable);
|
|
||||||
g_hash_table_unref (closure->collections);
|
g_hash_table_unref (closure->collections);
|
||||||
g_slice_free (EnsureClosure, closure);
|
g_slice_free (EnsureClosure, closure);
|
||||||
}
|
}
|
||||||
@ -1439,9 +1445,9 @@ on_ensure_collection (GObject *source,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
GTask *task = G_TASK (user_data);
|
||||||
SecretService *self = SECRET_SERVICE (g_async_result_get_source_object (user_data));
|
SecretService *self = SECRET_SERVICE (g_async_result_get_source_object (user_data));
|
||||||
EnsureClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
EnsureClosure *closure = g_task_get_task_data (task);
|
||||||
SecretCollection *collection;
|
SecretCollection *collection;
|
||||||
const gchar *path;
|
const gchar *path;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
@ -1450,21 +1456,21 @@ on_ensure_collection (GObject *source,
|
|||||||
|
|
||||||
collection = secret_collection_new_for_dbus_path_finish (result, &error);
|
collection = secret_collection_new_for_dbus_path_finish (result, &error);
|
||||||
|
|
||||||
if (error != NULL)
|
if (error != NULL) {
|
||||||
g_simple_async_result_take_error (res, error);
|
g_task_return_error (task, g_steal_pointer (&error));
|
||||||
|
|
||||||
if (collection != NULL) {
|
} else if (collection != NULL) {
|
||||||
path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
||||||
g_hash_table_insert (closure->collections, g_strdup (path), collection);
|
g_hash_table_insert (closure->collections, g_strdup (path), collection);
|
||||||
}
|
|
||||||
|
|
||||||
if (closure->collections_loading == 0) {
|
if (closure->collections_loading == 0) {
|
||||||
service_update_collections (self, closure->collections);
|
service_update_collections (self, closure->collections);
|
||||||
g_simple_async_result_complete (res);
|
g_task_return_boolean (task, TRUE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (self);
|
g_object_unref (self);
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1492,7 +1498,7 @@ secret_service_load_collections (SecretService *self,
|
|||||||
{
|
{
|
||||||
EnsureClosure *closure;
|
EnsureClosure *closure;
|
||||||
SecretCollection *collection;
|
SecretCollection *collection;
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
const gchar *path;
|
const gchar *path;
|
||||||
GVariant *paths;
|
GVariant *paths;
|
||||||
GVariantIter iter;
|
GVariantIter iter;
|
||||||
@ -1503,12 +1509,11 @@ secret_service_load_collections (SecretService *self,
|
|||||||
paths = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Collections");
|
paths = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Collections");
|
||||||
g_return_if_fail (paths != NULL);
|
g_return_if_fail (paths != NULL);
|
||||||
|
|
||||||
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
task = g_task_new (self, cancellable, callback, user_data);
|
||||||
secret_service_load_collections);
|
g_task_set_source_tag (task, secret_service_load_collections);
|
||||||
closure = g_slice_new0 (EnsureClosure);
|
closure = g_slice_new0 (EnsureClosure);
|
||||||
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
||||||
closure->collections = collections_table_new ();
|
closure->collections = collections_table_new ();
|
||||||
g_simple_async_result_set_op_res_gpointer (res, closure, ensure_closure_free);
|
g_task_set_task_data (task, closure, ensure_closure_free);
|
||||||
|
|
||||||
g_variant_iter_init (&iter, paths);
|
g_variant_iter_init (&iter, paths);
|
||||||
while (g_variant_iter_loop (&iter, "&o", &path)) {
|
while (g_variant_iter_loop (&iter, "&o", &path)) {
|
||||||
@ -1516,8 +1521,11 @@ secret_service_load_collections (SecretService *self,
|
|||||||
|
|
||||||
/* No such collection yet create a new one */
|
/* No such collection yet create a new one */
|
||||||
if (collection == NULL) {
|
if (collection == NULL) {
|
||||||
secret_collection_new_for_dbus_path (self, path, SECRET_COLLECTION_LOAD_ITEMS,
|
secret_collection_new_for_dbus_path (self, path,
|
||||||
cancellable, on_ensure_collection, g_object_ref (res));
|
SECRET_COLLECTION_LOAD_ITEMS,
|
||||||
|
cancellable,
|
||||||
|
on_ensure_collection,
|
||||||
|
g_object_ref (task));
|
||||||
closure->collections_loading++;
|
closure->collections_loading++;
|
||||||
} else {
|
} else {
|
||||||
g_hash_table_insert (closure->collections, g_strdup (path), collection);
|
g_hash_table_insert (closure->collections, g_strdup (path), collection);
|
||||||
@ -1526,11 +1534,11 @@ secret_service_load_collections (SecretService *self,
|
|||||||
|
|
||||||
if (closure->collections_loading == 0) {
|
if (closure->collections_loading == 0) {
|
||||||
service_update_collections (self, closure->collections);
|
service_update_collections (self, closure->collections);
|
||||||
g_simple_async_result_complete_in_idle (res);
|
g_task_return_boolean (task, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_variant_unref (paths);
|
g_variant_unref (paths);
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1551,11 +1559,14 @@ secret_service_load_collections_finish (SecretService *self,
|
|||||||
{
|
{
|
||||||
g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
|
g_return_val_if_fail (SECRET_IS_SERVICE (self), FALSE);
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, 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),
|
g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
|
||||||
secret_service_load_collections), FALSE);
|
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
|
||||||
|
secret_service_load_collections, 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 FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,6 @@ response_open_session_plain (SecretSession *session,
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GCancellable *cancellable;
|
|
||||||
SecretSession *session;
|
SecretSession *session;
|
||||||
} OpenSessionClosure;
|
} OpenSessionClosure;
|
||||||
|
|
||||||
@ -215,7 +214,6 @@ open_session_closure_free (gpointer data)
|
|||||||
{
|
{
|
||||||
OpenSessionClosure *closure = data;
|
OpenSessionClosure *closure = data;
|
||||||
g_assert (closure);
|
g_assert (closure);
|
||||||
g_clear_object (&closure->cancellable);
|
|
||||||
_secret_session_free (closure->session);
|
_secret_session_free (closure->session);
|
||||||
g_free (closure);
|
g_free (closure);
|
||||||
}
|
}
|
||||||
@ -225,8 +223,8 @@ on_service_open_session_plain (GObject *source,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
GTask *task = G_TASK (user_data);
|
||||||
OpenSessionClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
OpenSessionClosure *closure = g_task_get_task_data (task);
|
||||||
SecretService *service = SECRET_SERVICE (source);
|
SecretService *service = SECRET_SERVICE (source);
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GVariant *response;
|
GVariant *response;
|
||||||
@ -238,21 +236,20 @@ on_service_open_session_plain (GObject *source,
|
|||||||
if (response_open_session_plain (closure->session, response)) {
|
if (response_open_session_plain (closure->session, response)) {
|
||||||
_secret_service_take_session (service, closure->session);
|
_secret_service_take_session (service, closure->session);
|
||||||
closure->session = NULL;
|
closure->session = NULL;
|
||||||
|
g_task_return_boolean (task, TRUE);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
g_simple_async_result_set_error (res, SECRET_ERROR, SECRET_ERROR_PROTOCOL,
|
g_task_return_new_error (task, SECRET_ERROR, SECRET_ERROR_PROTOCOL,
|
||||||
_("Couldn’t communicate with the secret storage"));
|
_("Couldn’t communicate with the secret storage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_simple_async_result_complete (res);
|
|
||||||
g_variant_unref (response);
|
g_variant_unref (response);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
g_simple_async_result_take_error (res, error);
|
g_task_return_error (task, g_steal_pointer (&error));
|
||||||
g_simple_async_result_complete (res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_GCRYPT
|
#ifdef WITH_GCRYPT
|
||||||
@ -262,8 +259,8 @@ on_service_open_session_aes (GObject *source,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
GTask *task = G_TASK (user_data);
|
||||||
OpenSessionClosure * closure = g_simple_async_result_get_op_res_gpointer (res);
|
OpenSessionClosure * closure = g_task_get_task_data (task);
|
||||||
SecretService *service = SECRET_SERVICE (source);
|
SecretService *service = SECRET_SERVICE (source);
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GVariant *response;
|
GVariant *response;
|
||||||
@ -275,13 +272,13 @@ on_service_open_session_aes (GObject *source,
|
|||||||
if (response_open_session_aes (closure->session, response)) {
|
if (response_open_session_aes (closure->session, response)) {
|
||||||
_secret_service_take_session (service, closure->session);
|
_secret_service_take_session (service, closure->session);
|
||||||
closure->session = NULL;
|
closure->session = NULL;
|
||||||
|
g_task_return_boolean (task, TRUE);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
g_simple_async_result_set_error (res, SECRET_ERROR, SECRET_ERROR_PROTOCOL,
|
g_task_return_new_error (task, SECRET_ERROR, SECRET_ERROR_PROTOCOL,
|
||||||
_("Couldn’t communicate with the secret storage"));
|
_("Couldn’t communicate with the secret storage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_simple_async_result_complete (res);
|
|
||||||
g_variant_unref (response);
|
g_variant_unref (response);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -290,18 +287,18 @@ on_service_open_session_aes (GObject *source,
|
|||||||
g_dbus_proxy_call (G_DBUS_PROXY (source), "OpenSession",
|
g_dbus_proxy_call (G_DBUS_PROXY (source), "OpenSession",
|
||||||
request_open_session_plain (closure->session),
|
request_open_session_plain (closure->session),
|
||||||
G_DBUS_CALL_FLAGS_NONE, -1,
|
G_DBUS_CALL_FLAGS_NONE, -1,
|
||||||
closure->cancellable, on_service_open_session_plain,
|
g_task_get_cancellable (task),
|
||||||
g_object_ref (res));
|
on_service_open_session_plain,
|
||||||
|
g_object_ref (task));
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
|
||||||
/* Other errors result in a failure */
|
/* Other errors result in a failure */
|
||||||
} else {
|
} else {
|
||||||
g_simple_async_result_take_error (res, error);
|
g_task_return_error (task, g_steal_pointer (&error));
|
||||||
g_simple_async_result_complete (res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* WITH_GCRYPT */
|
#endif /* WITH_GCRYPT */
|
||||||
@ -313,15 +310,14 @@ _secret_session_open (SecretService *service,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
OpenSessionClosure *closure;
|
OpenSessionClosure *closure;
|
||||||
|
|
||||||
res = g_simple_async_result_new (G_OBJECT (service), callback, user_data,
|
task = g_task_new (service, cancellable, callback, user_data);
|
||||||
_secret_session_open);
|
g_task_set_source_tag (task, _secret_session_open);
|
||||||
closure = g_new (OpenSessionClosure, 1);
|
closure = g_new (OpenSessionClosure, 1);
|
||||||
closure->cancellable = cancellable ? g_object_ref (cancellable) : cancellable;
|
|
||||||
closure->session = g_new0 (SecretSession, 1);
|
closure->session = g_new0 (SecretSession, 1);
|
||||||
g_simple_async_result_set_op_res_gpointer (res, closure, open_session_closure_free);
|
g_task_set_task_data (task, closure, open_session_closure_free);
|
||||||
|
|
||||||
g_dbus_proxy_call (G_DBUS_PROXY (service), "OpenSession",
|
g_dbus_proxy_call (G_DBUS_PROXY (service), "OpenSession",
|
||||||
#ifdef WITH_GCRYPT
|
#ifdef WITH_GCRYPT
|
||||||
@ -333,17 +329,19 @@ _secret_session_open (SecretService *service,
|
|||||||
G_DBUS_CALL_FLAGS_NONE, -1,
|
G_DBUS_CALL_FLAGS_NONE, -1,
|
||||||
cancellable, on_service_open_session_plain,
|
cancellable, on_service_open_session_plain,
|
||||||
#endif
|
#endif
|
||||||
g_object_ref (res));
|
g_object_ref (task));
|
||||||
|
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
_secret_session_open_finish (GAsyncResult *result,
|
_secret_session_open_finish (GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
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 FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user