[evolution-data-server] Make authentication asynchronous in the Google Contacts backend
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Make authentication asynchronous in the Google Contacts backend
- Date: Wed, 19 Jan 2011 12:11:23 +0000 (UTC)
commit a7ba1bb9fd9b97e54735a25f65948c72ada01f62
Author: Philip Withnall <philip tecnocode co uk>
Date: Sat Nov 20 21:54:23 2010 +0000
Make authentication asynchronous in the Google Contacts backend
.../backends/google/e-book-backend-google.c | 78 +++++++++++--------
1 files changed, 45 insertions(+), 33 deletions(-)
---
diff --git a/addressbook/backends/google/e-book-backend-google.c b/addressbook/backends/google/e-book-backend-google.c
index a12ee2f..47b8b5c 100644
--- a/addressbook/backends/google/e-book-backend-google.c
+++ b/addressbook/backends/google/e-book-backend-google.c
@@ -1225,13 +1225,51 @@ proxy_settings_changed (EProxy *proxy, EBookBackend *backend)
g_free (uri);
}
+typedef struct {
+ EBookBackend *backend;
+ EDataBook *book;
+ guint32 opid;
+} AuthenticateUserData;
+
+static void
+authenticate_user_cb (GDataService *service, GAsyncResult *result, AuthenticateUserData *data)
+{
+ GError *gdata_error = NULL;
+ GError *book_error = NULL;
+
+ __debug__ (G_STRFUNC);
+
+ /* Finish authenticating */
+ if (!gdata_service_authenticate_finish (service, result, &gdata_error))
+ goto finish;
+
+ /* Update the cache if necessary */
+ cache_refresh_if_needed (data->backend, &gdata_error);
+ if (gdata_error)
+ goto finish;
+
+finish:
+ if (gdata_error) {
+ data_book_error_from_gdata_error (&book_error, gdata_error);
+ __debug__ ("Authentication failed: %s", gdata_error->message);
+ g_error_free (gdata_error);
+ }
+
+ e_book_backend_notify_writable (data->backend, (!gdata_error) ? TRUE : FALSE);
+ e_data_book_respond_authenticate_user (data->book, data->opid, book_error);
+
+ g_object_unref (data->book);
+ g_object_unref (data->backend);
+ g_slice_free (AuthenticateUserData, data);
+}
+
static void
e_book_backend_google_authenticate_user (EBookBackend *backend, EDataBook *book, guint32 opid,
const gchar *username, const gchar *password, const gchar *auth_method)
{
EBookBackendGooglePrivate *priv = E_BOOK_BACKEND_GOOGLE (backend)->priv;
- GError *our_error = NULL;
gboolean match;
+ AuthenticateUserData *data;
__debug__ (G_STRFUNC);
@@ -1271,39 +1309,13 @@ e_book_backend_google_authenticate_user (EBookBackend *backend, EDataBook *book,
g_signal_connect (priv->proxy, "changed", G_CALLBACK (proxy_settings_changed), backend);
}
- /* Authenticate with the server */
- if (!gdata_service_authenticate (priv->service, priv->username, password, NULL, &our_error)) {
- GError *error = NULL;
-
- g_object_unref (priv->service);
- priv->service = NULL;
- g_object_unref (priv->proxy);
- priv->proxy = NULL;
-
- data_book_error_from_gdata_error (&error, our_error);
- __debug__ ("Authentication failed: %s", our_error->message);
- g_error_free (our_error);
-
- e_data_book_respond_authenticate_user (book, opid, error);
- return;
- }
-
- /* Update the cache if neccessary */
- cache_refresh_if_needed (backend, &our_error);
-
- if (our_error) {
- GError *error = NULL;
-
- data_book_error_from_gdata_error (&error, our_error);
- __debug__ ("Authentication failed: %s", our_error->message);
- g_error_free (our_error);
-
- e_data_book_respond_authenticate_user (book, opid, error);
- return;
- }
+ /* Authenticate with the server asynchronously */
+ data = g_slice_new (AuthenticateUserData);
+ data->backend = g_object_ref (backend);
+ data->book = g_object_ref (book);
+ data->opid = opid;
- e_book_backend_notify_writable (backend, TRUE);
- e_data_book_respond_authenticate_user (book, opid, NULL);
+ gdata_service_authenticate_async (priv->service, priv->username, password, NULL, (GAsyncReadyCallback) authenticate_user_cb, data);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]