[gnome-online-accounts/wip/rishi/account-remove: 4/10] kerberos: Implement GoaProvider:remove_account for signing out



commit abf968df629829026bfacb067ff36f3c6061dc16
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri May 20 18:51:06 2016 +0200

    kerberos: Implement GoaProvider:remove_account for signing out
    
    ... instead of listening to GoaClient::account-removed.
    
    GoaClient::account-removed is emitted every time the goa-daemon
    process dies, which could be due to a crash or restart or something
    else. We only want to sign out the identity when the user has
    explicitly asked for it to be removed. We don't want to sign them out
    merely because goa-daemon died.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=766733

 src/goabackend/goakerberosprovider.c |   72 ++++++++++++++++++++++++++++++++++
 src/goaidentity/goaidentityservice.c |   43 --------------------
 2 files changed, 72 insertions(+), 43 deletions(-)
---
diff --git a/src/goabackend/goakerberosprovider.c b/src/goabackend/goakerberosprovider.c
index 87314bc..7c7698a 100644
--- a/src/goabackend/goakerberosprovider.c
+++ b/src/goabackend/goakerberosprovider.c
@@ -1441,6 +1441,76 @@ out:
   return credentials_ensured;
 }
 
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+remove_account_in_thread_func (GTask         *task,
+                               gpointer       source_object,
+                               gpointer       task_data,
+                               GCancellable  *cancellable)
+{
+  GError *error;
+  GoaAccount *account = NULL;
+  GoaObject *object = GOA_OBJECT (task_data);
+  const gchar *identifier;
+
+  ensure_identity_manager ();
+
+  account = goa_object_get_account (object);
+  identifier = goa_account_get_identity (account);
+
+  g_debug ("Kerberos account %s removed and should now be signed out", identifier);
+
+  error = NULL;
+  if (!goa_identity_service_manager_call_sign_out_sync (identity_manager, identifier, cancellable, &error))
+    {
+      g_task_return_error (task, error);
+      goto out;
+    }
+
+  g_task_return_boolean (task, TRUE);
+
+ out:
+  g_clear_object (&account);
+}
+
+static void
+remove_account (GoaProvider          *provider,
+                GoaObject            *object,
+                GCancellable         *cancellable,
+                GAsyncReadyCallback   callback,
+                gpointer              user_data)
+{
+  GoaKerberosProvider *self = GOA_KERBEROS_PROVIDER (provider);
+  GTask *task;
+
+  task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_source_tag (task, remove_account);
+
+  g_task_set_task_data (task, g_object_ref (object), g_object_unref);
+  g_task_run_in_thread (task, remove_account_in_thread_func);
+
+  g_object_unref (task);
+}
+
+static gboolean
+remove_account_finish (GoaProvider   *provider,
+                       GAsyncResult  *res,
+                       GError       **error)
+{
+  GoaKerberosProvider *self = GOA_KERBEROS_PROVIDER (provider);
+  GTask *task;
+
+  g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
+  task = G_TASK (res);
+
+  g_warn_if_fail (g_task_get_source_tag (task) == remove_account);
+
+  return g_task_propagate_boolean (task, error);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 static GoaIdentityServiceIdentity *
 get_identity_from_object_manager (GoaKerberosProvider *self,
                                   const char          *identifier)
@@ -1685,4 +1755,6 @@ goa_kerberos_provider_class_init (GoaKerberosProviderClass *kerberos_class)
   provider_class->add_account                = add_account;
   provider_class->refresh_account            = refresh_account;
   provider_class->ensure_credentials_sync    = ensure_credentials_sync;
+  provider_class->remove_account             = remove_account;
+  provider_class->remove_account_finish      = remove_account_finish;
 }
diff --git a/src/goaidentity/goaidentityservice.c b/src/goaidentity/goaidentityservice.c
index 7c4a1c8..393e7f0 100644
--- a/src/goaidentity/goaidentityservice.c
+++ b/src/goaidentity/goaidentityservice.c
@@ -1532,44 +1532,6 @@ on_account_interface_removed (GDBusObjectManager *manager,
 }
 
 static void
-on_account_removed (GoaClient          *client,
-                    GoaObject          *object,
-                    GoaIdentityService *self)
-{
-  GSimpleAsyncResult *result;
-  GoaAccount         *account;
-  const char         *provider_type;
-  const char         *account_identity;
-
-  account = goa_object_peek_account (object);
-
-  if (account == NULL)
-    return;
-
-  provider_type = goa_account_get_provider_type (account);
-
-  if (g_strcmp0 (provider_type, "kerberos") != 0)
-    return;
-
-  account_identity = goa_account_get_identity (account);
-
-  g_debug ("Kerberos account %s removed and should now be signed out", account_identity);
-
-  result = g_simple_async_result_new (G_OBJECT (self),
-                                      (GAsyncReadyCallback)
-                                      on_sign_out_for_account_change_done,
-                                      NULL,
-                                      on_account_removed);
-
-  goa_identity_manager_get_identity (self->priv->identity_manager,
-                                     account_identity,
-                                     NULL,
-                                     (GAsyncReadyCallback)
-                                     on_got_identity_for_sign_out,
-                                     result);
-}
-
-static void
 on_identities_listed (GoaIdentityManager *manager,
                       GAsyncResult       *result,
                       GoaIdentityService *self)
@@ -1602,11 +1564,6 @@ on_identities_listed (GoaIdentityManager *manager,
                     G_CALLBACK (on_identity_expired),
                     self);
 
-  g_signal_connect (G_OBJECT (self->priv->client),
-                    "account-removed",
-                    G_CALLBACK (on_account_removed),
-                    self);
-
   identities = goa_identity_manager_list_identities_finish (manager, result, &error);
 
   if (identities == NULL)


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