[gnome-online-accounts/wip/rishi/libsecret-workaround: 5/5] backend, daemon: ...



commit c7c05211f4277467a7be1085025bf828e590093c
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Jul 3 18:18:13 2017 +0200

    backend, daemon: ...
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784944

 src/daemon/Makefile.am                  |    2 +
 src/daemon/goadaemon.c                  |   63 ++++++++++++++++++++++++++----
 src/daemon/goadaemon.h                  |    1 +
 src/daemon/main.c                       |    8 +++-
 src/goabackend/Makefile.am              |    4 ++
 src/goabackend/goaexchangeprovider.c    |    1 +
 src/goabackend/goaimapsmtpprovider.c    |    1 +
 src/goabackend/goakerberosprovider.c    |    4 ++
 src/goabackend/goalastfmprovider.c      |    1 +
 src/goabackend/goamediaserverprovider.c |    1 +
 src/goabackend/goaoauth2provider.c      |    4 ++
 src/goabackend/goaoauthprovider.c       |    4 ++
 src/goabackend/goaowncloudprovider.c    |    1 +
 src/goabackend/goaprovider-priv.h       |    4 ++
 src/goabackend/goaprovider.c            |   23 ++++++++++-
 src/goabackend/goautils.c               |   23 +++++++----
 src/goabackend/goautils.h               |    7 ++-
 17 files changed, 128 insertions(+), 24 deletions(-)
---
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
index 5f9a231..b9807bb 100644
--- a/src/daemon/Makefile.am
+++ b/src/daemon/Makefile.am
@@ -34,6 +34,7 @@ goa_daemon_CFLAGS =                                           \
        $(GLIB_CFLAGS)                                          \
        $(GTK_CFLAGS)                                           \
        $(REST_CFLAGS)                                          \
+       $(SECRET_CFLAGS)                                        \
        $(NULL)
 
 goa_daemon_LDADD =                                             \
@@ -42,6 +43,7 @@ goa_daemon_LDADD =                                            \
        $(top_builddir)/src/goabackend/libgoa-backend-1.0.la    \
        $(GTK_LIBS)                                             \
        $(REST_LIBS)                                            \
+       $(SECRET_LIBS)                                          \
        $(NULL)
 
 clean-local :
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index af9913f..4ae5a1c 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -24,6 +24,7 @@
 #include <gio/gio.h>
 #include <glib/gi18n.h>
 #include <rest/rest-proxy.h>
+#include <libsecret/secret.h>
 #include <libsoup/soup.h>
 
 #include "goadaemon.h"
@@ -51,6 +52,9 @@ struct _GoaDaemon
   GQueue *ensure_credentials_queue;
   gboolean ensure_credentials_running;
 
+  SecretService *secret_service;
+  gchar *secret_service_bus_name;
+
   guint config_timeout_id;
   guint credentials_timeout_id;
 };
@@ -58,7 +62,8 @@ struct _GoaDaemon
 enum
 {
   PROP_0,
-  PROP_CONNECTION
+  PROP_CONNECTION,
+  PROP_SECRET_SERVICE_BUS_NAME
 };
 
 static void on_file_monitor_changed (GFileMonitor     *monitor,
@@ -147,9 +152,6 @@ goa_daemon_constructed (GObject *object)
 
   G_OBJECT_CLASS (goa_daemon_parent_class)->constructed (object);
 
-  /* prime the list of accounts */
-  goa_daemon_reload_configuration (self);
-
   /* Export objects */
   g_dbus_object_manager_server_set_connection (self->object_manager, self->connection);
 }
@@ -182,6 +184,8 @@ goa_daemon_finalize (GObject *object)
     }
 
   g_free (self->home_conf_file_path);
+  g_free (self->secret_service_bus_name);
+  g_clear_object (&self->secret_service);
   g_object_unref (self->manager);
   g_object_unref (self->object_manager);
   g_object_unref (self->connection);
@@ -201,6 +205,10 @@ goa_daemon_set_property (GObject *object, guint prop_id, const GValue *value, GP
       self->connection = G_DBUS_CONNECTION (g_value_dup_object (value));
       break;
 
+    case PROP_SECRET_SERVICE_BUS_NAME:
+      self->secret_service_bus_name = g_value_dup_string (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -390,12 +398,39 @@ goa_daemon_class_init (GoaDaemonClass *klass)
                                                         G_PARAM_CONSTRUCT_ONLY |
                                                         G_PARAM_STATIC_STRINGS |
                                                         G_PARAM_WRITABLE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_SECRET_SERVICE_BUS_NAME,
+                                   g_param_spec_string ("secret-service-bus-name",
+                                                        "Secret service bus name",
+                                                        "The D-Bus service name of the secret service",
+                                                        NULL,
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_STATIC_STRINGS |
+                                                        G_PARAM_WRITABLE));
 }
 
 static gboolean
 goa_daemon_initable_init (GInitable *initable, GCancellable *cancellable, GError **error)
 {
-  return TRUE;
+  GoaDaemon *self = GOA_DAEMON (initable);
+  gboolean ret_val = FALSE;
+
+  self->secret_service = secret_service_open_sync (SECRET_TYPE_SERVICE,
+                                                   self->secret_service_bus_name,
+                                                   SECRET_SERVICE_OPEN_SESSION,
+                                                   cancellable,
+                                                   error);
+  if (self->secret_service == NULL)
+    goto out;
+
+  /* prime the list of accounts */
+  goa_daemon_reload_configuration (self);
+
+  ret_val = TRUE;
+
+ out:
+  return ret_val;
 }
 
 static void
@@ -405,13 +440,22 @@ goa_daemon_initable_iface_init (GInitableIface *iface)
 }
 
 GoaDaemon *
-goa_daemon_new (GDBusConnection *connection, GCancellable *cancellable, GError **error)
+goa_daemon_new (GDBusConnection   *connection,
+                const gchar       *secret_service_bus_name,
+                GCancellable      *cancellable,
+                GError           **error)
 {
   g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
+  g_return_val_if_fail (secret_service_bus_name != NULL && secret_service_bus_name[0] != '\0', NULL);
   g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-  return GOA_DAEMON (g_initable_new (GOA_TYPE_DAEMON, cancellable, error, "connection", connection, NULL));
+  return GOA_DAEMON (g_initable_new (GOA_TYPE_DAEMON,
+                                     cancellable,
+                                     error,
+                                     "connection", connection,
+                                     "secret-service-bus-name", secret_service_bus_name,
+                                     NULL));
 }
 
 
@@ -597,7 +641,7 @@ add_config_file (GoaDaemon     *self,
                   needs_update = g_key_file_remove_group (key_file, groups[n], NULL);
 
                   error = NULL;
-                  if (!goa_utils_delete_credentials_for_id_sync (provider, id, NULL, &error))
+                  if (!goa_utils_delete_credentials_for_id_sync (self->secret_service, provider, id, NULL, 
&error))
                     {
                       g_warning ("Unable to clean-up stale keyring entries: %s", error->message);
                       g_error_free (error);
@@ -1478,7 +1522,7 @@ on_account_handle_remove (GoaAccount            *account,
     }
 
   error = NULL;
-  if (!goa_utils_delete_credentials_for_account_sync (provider, account, NULL, &error))
+  if (!goa_utils_delete_credentials_for_account_sync (self->secret_service, provider, account, NULL, &error))
     {
       g_dbus_method_invocation_take_error (invocation, error);
       goto out;
@@ -1657,6 +1701,7 @@ ensure_credentials_queue_check (GoaDaemon *self)
 
   goa_provider_ensure_credentials (provider,
                                    data->object,
+                                   self->secret_service,
                                    NULL, /* GCancellable */
                                    ensure_credentials_queue_collector,
                                    task);
diff --git a/src/daemon/goadaemon.h b/src/daemon/goadaemon.h
index 88e737c..87b84d2 100644
--- a/src/daemon/goadaemon.h
+++ b/src/daemon/goadaemon.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GoaDaemon, goa_daemon, GOA, DAEMON, GObject);
 
 GoaDaemon          *goa_daemon_new                (GDBusConnection   *connection,
+                                                   const gchar       *secret_service_bus_name,
                                                    GCancellable      *cancellable,
                                                    GError           **error);
 
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 22d114b..3794f54 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -39,6 +39,8 @@ static GOptionEntry opt_entries[] =
   {NULL }
 };
 static GoaDaemon *the_daemon = NULL;
+static const gchar *SECRET_SERVICE_BUS_NAME = "org.freedesktop.secrets";
+static const gchar *secret_service_bus_name = NULL;
 
 static void
 on_bus_acquired (GDBusConnection *connection,
@@ -53,7 +55,7 @@ on_bus_acquired (GDBusConnection *connection,
   g_debug ("Connected to the session bus");
 
   error = NULL;
-  the_daemon = goa_daemon_new (connection, NULL, &error);
+  the_daemon = goa_daemon_new (connection, secret_service_bus_name, NULL, &error);
   if (error != NULL)
     {
       g_warning ("Unable to initialize GoaDaemon: %s (%s, %d)",
@@ -121,6 +123,10 @@ main (int    argc,
       goto out;
     }
 
+  secret_service_bus_name = g_getenv ("SECRET_SERVICE_BUS_NAME");
+  if (secret_service_bus_name == NULL)
+    secret_service_bus_name = SECRET_SERVICE_BUS_NAME;
+
   g_message ("goa-daemon version %s starting", PACKAGE_VERSION);
 
   loop = g_main_loop_new (NULL, FALSE);
diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am
index 40b76dc..5369593 100644
--- a/src/goabackend/Makefile.am
+++ b/src/goabackend/Makefile.am
@@ -162,13 +162,17 @@ libgoawebextension_la_SOURCES =                                           \
        $(NULL)
 
 libgoawebextension_la_CFLAGS =                                         \
+       $(GLIB_CFLAGS)                                                  \
        $(REST_CFLAGS)                                                  \
+       $(SECRET_CFLAGS)                                                \
        $(WEBKIT_GTK_CFLAGS)                                            \
        $(NULL)
 
 libgoawebextension_la_LIBADD =                                         \
        libgoa-backend-1.0.la                                           \
+       $(GLIB_LIBS)                                                    \
        $(REST_LIBS)                                                    \
+       $(SECRET_LIBS)                                                  \
        $(WEBKIT_GTK_LIBS)                                              \
        $(NULL)
 
diff --git a/src/goabackend/goaexchangeprovider.c b/src/goabackend/goaexchangeprovider.c
index e67bb36..478f84b 100644
--- a/src/goabackend/goaexchangeprovider.c
+++ b/src/goabackend/goaexchangeprovider.c
@@ -198,6 +198,7 @@ build_object (GoaProvider         *provider,
 static gboolean
 ensure_credentials_sync (GoaProvider         *provider,
                          GoaObject           *object,
+                         SecretService       *secret_service,
                          gint                *out_expires_in,
                          GCancellable        *cancellable,
                          GError             **error)
diff --git a/src/goabackend/goaimapsmtpprovider.c b/src/goabackend/goaimapsmtpprovider.c
index 8a2677e..2bfc200 100644
--- a/src/goabackend/goaimapsmtpprovider.c
+++ b/src/goabackend/goaimapsmtpprovider.c
@@ -287,6 +287,7 @@ get_tls_type_from_string_id (const gchar *str)
 static gboolean
 ensure_credentials_sync (GoaProvider         *provider,
                          GoaObject           *object,
+                         SecretService       *secret_service,
                          gint                *out_expires_in,
                          GCancellable        *cancellable,
                          GError             **error)
diff --git a/src/goabackend/goakerberosprovider.c b/src/goabackend/goakerberosprovider.c
index 2d9db95..2b5317f 100644
--- a/src/goabackend/goakerberosprovider.c
+++ b/src/goabackend/goakerberosprovider.c
@@ -27,6 +27,7 @@
 #include "goaidentitymanagererror.h"
 
 #include <gcr/gcr.h>
+#include <libsecret/secret.h>
 
 #include "org.gnome.Identity.h"
 
@@ -272,6 +273,7 @@ on_account_signed_in (GoaProvider   *provider,
 static gboolean
 get_ticket_sync (GoaKerberosProvider *self,
                  GoaObject           *object,
+                 SecretService       *secret_service,
                  gboolean             is_interactive,
                  GCancellable        *cancellable,
                  GError             **error)
@@ -1368,6 +1370,7 @@ dbus_proxy_reload_properties_sync (GDBusProxy    *proxy,
 static gboolean
 ensure_credentials_sync (GoaProvider    *provider,
                          GoaObject      *object,
+                         SecretService  *secret_service,
                          gint           *out_expires_in,
                          GCancellable   *cancellable,
                          GError        **error)
@@ -1405,6 +1408,7 @@ ensure_credentials_sync (GoaProvider    *provider,
       g_mutex_unlock (&identity_manager_mutex);
       ticket_synced = get_ticket_sync (GOA_KERBEROS_PROVIDER (provider),
                                        object,
+                                       secret_service,
                                        FALSE /* Don't allow interaction */,
                                        cancellable,
                                        &lookup_error);
diff --git a/src/goabackend/goalastfmprovider.c b/src/goabackend/goalastfmprovider.c
index ac07e66..a66418e 100644
--- a/src/goabackend/goalastfmprovider.c
+++ b/src/goabackend/goalastfmprovider.c
@@ -250,6 +250,7 @@ lastfm_login_sync (GoaProvider                  *provider,
 static gboolean
 ensure_credentials_sync (GoaProvider         *provider,
                          GoaObject           *object,
+                         SecretService       *secret_service,
                          gint                *out_expires_in,
                          GCancellable        *cancellable,
                          GError             **error)
diff --git a/src/goabackend/goamediaserverprovider.c b/src/goabackend/goamediaserverprovider.c
index 030ad46..8661beb 100644
--- a/src/goabackend/goamediaserverprovider.c
+++ b/src/goabackend/goamediaserverprovider.c
@@ -156,6 +156,7 @@ out:
 static gboolean
 ensure_credentials_sync (GoaProvider         *provider,
                          GoaObject           *object,
+                         SecretService       *secret_service,
                          gint                *out_expires_in,
                          GCancellable        *cancellable,
                          GError             **error)
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 564ba64..7583d91 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -1376,6 +1376,7 @@ free_mutex (GMutex *mutex)
  * goa_oauth2_provider_get_access_token_sync:
  * @self: A #GoaOAuth2Provider.
  * @object: A #GoaObject.
+ * @secret_service: A #SecretService.
  * @force_refresh: If set to %TRUE, forces a refresh of the access token, if possible.
  * @out_access_token_expires_in: (out): Return location for how many seconds the returned token is valid for 
(0 if unknown) or %NULL.
  * @cancellable: (allow-none): A #GCancellable or %NULL.
@@ -1406,6 +1407,7 @@ free_mutex (GMutex *mutex)
 gchar *
 goa_oauth2_provider_get_access_token_sync (GoaOAuth2Provider  *self,
                                            GoaObject          *object,
+                                           SecretService      *secret_service,
                                            gboolean            force_refresh,
                                            gint               *out_access_token_expires_in,
                                            GCancellable       *cancellable,
@@ -1642,6 +1644,7 @@ goa_oauth2_provider_build_object (GoaProvider         *provider,
 static gboolean
 goa_oauth2_provider_ensure_credentials_sync (GoaProvider   *provider,
                                              GoaObject     *object,
+                                             SecretService *secret_service,
                                              gint          *out_expires_in,
                                              GCancellable  *cancellable,
                                              GError       **error)
@@ -1661,6 +1664,7 @@ goa_oauth2_provider_ensure_credentials_sync (GoaProvider   *provider,
  again:
   access_token = goa_oauth2_provider_get_access_token_sync (self,
                                                             object,
+                                                            secret_service,
                                                             force_refresh,
                                                             &access_token_expires_in,
                                                             cancellable,
diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
index 08b998e..c8cf688 100644
--- a/src/goabackend/goaoauthprovider.c
+++ b/src/goabackend/goaoauthprovider.c
@@ -1242,6 +1242,7 @@ free_mutex (GMutex *mutex)
  * goa_oauth_provider_get_access_token_sync:
  * @provider: A #GoaOAuthProvider.
  * @object: A #GoaObject.
+ * @secret_service: A #SecretService.
  * @force_refresh: If set to %TRUE, forces a refresh of the access token, if possible.
  * @out_access_token_secret: (out): The secret for the return access token.
  * @out_access_token_expires_in: (out): Return location for how many seconds the returned token is valid for 
(0 if unknown) or %NULL.
@@ -1273,6 +1274,7 @@ free_mutex (GMutex *mutex)
 gchar *
 goa_oauth_provider_get_access_token_sync (GoaOAuthProvider   *provider,
                                           GoaObject          *object,
+                                          SecretService      *secret_service,
                                           gboolean            force_refresh,
                                           gchar             **out_access_token_secret,
                                           gint               *out_access_token_expires_in,
@@ -1528,6 +1530,7 @@ goa_oauth_provider_build_object (GoaProvider         *provider,
 static gboolean
 goa_oauth_provider_ensure_credentials_sync (GoaProvider    *_provider,
                                             GoaObject      *object,
+                                            SecretService  *secret_service,
                                             gint           *out_expires_in,
                                             GCancellable   *cancellable,
                                             GError        **error)
@@ -1549,6 +1552,7 @@ goa_oauth_provider_ensure_credentials_sync (GoaProvider    *_provider,
  again:
   access_token = goa_oauth_provider_get_access_token_sync (provider,
                                                                    object,
+                                                           secret_service,
                                                                    force_refresh,
                                                                    &access_token_secret,
                                                                    &access_token_expires_in,
diff --git a/src/goabackend/goaowncloudprovider.c b/src/goabackend/goaowncloudprovider.c
index 95c38f8..37abaaf 100644
--- a/src/goabackend/goaowncloudprovider.c
+++ b/src/goabackend/goaowncloudprovider.c
@@ -253,6 +253,7 @@ build_object (GoaProvider         *provider,
 static gboolean
 ensure_credentials_sync (GoaProvider         *provider,
                          GoaObject           *object,
+                         SecretService       *secret_service,
                          gint                *out_expires_in,
                          GCancellable        *cancellable,
                          GError             **error)
diff --git a/src/goabackend/goaprovider-priv.h b/src/goabackend/goaprovider-priv.h
index ca93aee..712b15d 100644
--- a/src/goabackend/goaprovider-priv.h
+++ b/src/goabackend/goaprovider-priv.h
@@ -28,6 +28,7 @@
 #include <goabackend/goaprovider.h>
 #include <goabackend/goabackendenums.h>
 #include <gtk/gtk.h>
+#include <libsecret/secret.h>
 
 G_BEGIN_DECLS
 
@@ -87,6 +88,7 @@ struct _GoaProviderClass
                                                            GError                **error);
   gboolean                (*ensure_credentials_sync)      (GoaProvider            *self,
                                                            GoaObject              *object,
+                                                           SecretService          *secret_service,
                                                            gint                   *out_expires_in,
                                                            GCancellable           *cancellable,
                                                            GError                **error);
@@ -130,6 +132,7 @@ void        goa_provider_ensure_extension_points_registered    (void);
 
 void        goa_provider_ensure_credentials                    (GoaProvider             *self,
                                                                 GoaObject               *object,
+                                                                SecretService           *secret_service,
                                                                 GCancellable            *cancellable,
                                                                 GAsyncReadyCallback      callback,
                                                                 gpointer                 user_data);
@@ -141,6 +144,7 @@ gboolean    goa_provider_ensure_credentials_finish             (GoaProvider
 
 gboolean    goa_provider_ensure_credentials_sync               (GoaProvider             *self,
                                                                 GoaObject               *object,
+                                                                SecretService           *secret_service,
                                                                 gint                    *out_expires_in,
                                                                 GCancellable            *cancellable,
                                                                 GError                 **error);
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index c59122a..f08c913 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -66,6 +66,7 @@ static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
 
 static gboolean goa_provider_ensure_credentials_sync_real (GoaProvider   *self,
                                                            GoaObject     *object,
+                                                           SecretService *secret_service,
                                                            gint          *out_expires_in,
                                                            GCancellable  *cancellable,
                                                            GError       **error);
@@ -682,15 +683,17 @@ goa_provider_build_object (GoaProvider         *self,
 typedef struct
 {
   GoaObject *object;
+  SecretService *secret_service;
   gint expires_in;
 } EnsureCredentialsData;
 
 static EnsureCredentialsData *
-ensure_credentials_data_new (GoaObject *object)
+ensure_credentials_data_new (GoaObject *object, SecretService *secret_service)
 {
   EnsureCredentialsData *data;
   data = g_new0 (EnsureCredentialsData, 1);
   data->object = g_object_ref (object);
+  data->secret_service = g_object_ref (secret_service);
   return data;
 }
 
@@ -698,6 +701,7 @@ static void
 ensure_credentials_data_free (EnsureCredentialsData *data)
 {
   g_object_unref (data->object);
+  g_object_unref (data->secret_service);
   g_free (data);
 }
 
@@ -715,6 +719,7 @@ ensure_credentials_in_thread_func (GTask              *task,
   error = NULL;
   if (!goa_provider_ensure_credentials_sync (GOA_PROVIDER (object),
                                              data->object,
+                                             data->secret_service,
                                              &data->expires_in,
                                              cancellable,
                                              &error))
@@ -728,6 +733,7 @@ ensure_credentials_in_thread_func (GTask              *task,
  * goa_provider_ensure_credentials:
  * @self: A #GoaProvider.
  * @object: A #GoaObject with a #GoaAccount interface.
+ * @secret_service: A #SecretService.
  * @cancellable: (allow-none): A #GCancellable or %NULL.
  * @callback: The function to call when the request is satisfied.
  * @user_data: Pointer to pass to @callback.
@@ -747,6 +753,7 @@ ensure_credentials_in_thread_func (GTask              *task,
 void
 goa_provider_ensure_credentials (GoaProvider          *self,
                                  GoaObject            *object,
+                                 SecretService        *secret_service,
                                  GCancellable         *cancellable,
                                  GAsyncReadyCallback   callback,
                                  gpointer              user_data)
@@ -758,7 +765,9 @@ goa_provider_ensure_credentials (GoaProvider          *self,
   g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
 
   task = g_task_new (self, cancellable, callback, user_data);
-  g_task_set_task_data (task, ensure_credentials_data_new (object), (GDestroyNotify) 
ensure_credentials_data_free);
+  g_task_set_task_data (task,
+                        ensure_credentials_data_new (object, secret_service),
+                        (GDestroyNotify) ensure_credentials_data_free);
   g_task_set_source_tag (task, goa_provider_ensure_credentials);
   g_task_run_in_thread (task, ensure_credentials_in_thread_func);
 
@@ -818,6 +827,7 @@ goa_provider_ensure_credentials_finish (GoaProvider         *self,
  * goa_provider_ensure_credentials_sync:
  * @self: A #GoaProvider.
  * @object: A #GoaObject with a #GoaAccount interface.
+ * @secret_service: A #SecretService.
  * @out_expires_in: (out): Return location for how long the expired credentials are good for (0 if unknown) 
or %NULL.
  * @cancellable: (allow-none): A #GCancellable or %NULL.
  * @error: Return location for error or %NULL.
@@ -830,6 +840,7 @@ goa_provider_ensure_credentials_finish (GoaProvider         *self,
 gboolean
 goa_provider_ensure_credentials_sync (GoaProvider     *self,
                                       GoaObject       *object,
+                                      SecretService   *secret_service,
                                       gint            *out_expires_in,
                                       GCancellable    *cancellable,
                                       GError         **error)
@@ -869,7 +880,12 @@ goa_provider_ensure_credentials_sync (GoaProvider     *self,
       goto out;
     }
 
-  ret = GOA_PROVIDER_GET_CLASS (self)->ensure_credentials_sync (self, object, out_expires_in, cancellable, 
error);
+  ret = GOA_PROVIDER_GET_CLASS (self)->ensure_credentials_sync (self,
+                                                                object,
+                                                                secret_service,
+                                                                out_expires_in,
+                                                                cancellable,
+                                                                error);
 
  out:
   if (!ret && error != NULL && *error == NULL)
@@ -890,6 +906,7 @@ goa_provider_ensure_credentials_sync (GoaProvider     *self,
 static gboolean
 goa_provider_ensure_credentials_sync_real (GoaProvider   *self,
                                            GoaObject     *object,
+                                           SecretService *secret_service,
                                            gint          *out_expires_in,
                                            GCancellable  *cancellable,
                                            GError       **error)
diff --git a/src/goabackend/goautils.c b/src/goabackend/goautils.c
index f384d0c..97fc677 100644
--- a/src/goabackend/goautils.c
+++ b/src/goabackend/goautils.c
@@ -19,7 +19,6 @@
 #include "config.h"
 
 #include <glib/gi18n-lib.h>
-#include <libsecret/secret.h>
 
 #ifdef GOA_TELEPATHY_ENABLED
 #include <telepathy-glib/telepathy-glib.h>
@@ -337,24 +336,27 @@ goa_utils_set_dialog_title (GoaProvider *provider, GtkDialog *dialog, gboolean a
 }
 
 gboolean
-goa_utils_delete_credentials_for_account_sync (GoaProvider   *provider,
+goa_utils_delete_credentials_for_account_sync (SecretService *secret_service,
+                                               GoaProvider   *provider,
                                                GoaAccount    *object,
                                                GCancellable  *cancellable,
                                                GError       **error)
 {
   const gchar *id;
 
+  g_return_val_if_fail (SECRET_IS_SERVICE (secret_service), FALSE);
   g_return_val_if_fail (GOA_IS_PROVIDER (provider), FALSE);
   g_return_val_if_fail (GOA_IS_ACCOUNT (object), FALSE);
   g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
   id = goa_account_get_id (object);
-  return goa_utils_delete_credentials_for_id_sync (provider, id, cancellable, error);
+  return goa_utils_delete_credentials_for_id_sync (secret_service, provider, id, cancellable, error);
 }
 
 gboolean
-goa_utils_delete_credentials_for_id_sync (GoaProvider   *provider,
+goa_utils_delete_credentials_for_id_sync (SecretService *secret_service,
+                                          GoaProvider   *provider,
                                           const gchar   *id,
                                           GCancellable  *cancellable,
                                           GError       **error)
@@ -362,7 +364,9 @@ goa_utils_delete_credentials_for_id_sync (GoaProvider   *provider,
   gboolean ret = FALSE;
   gchar *password_key = NULL;
   GError *sec_error = NULL;
+  GHashTable *attributes = NULL;
 
+  g_return_val_if_fail (SECRET_IS_SERVICE (secret_service), FALSE);
   g_return_val_if_fail (GOA_IS_PROVIDER (provider), FALSE);
   g_return_val_if_fail (id != NULL && id[0] != '\0', FALSE);
   g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
@@ -373,11 +377,11 @@ goa_utils_delete_credentials_for_id_sync (GoaProvider   *provider,
                                   goa_provider_get_credentials_generation (provider),
                                   id);
 
-  secret_password_clear_sync (&secret_password_schema,
-                              cancellable,
-                              &sec_error,
-                              "goa-identity", password_key,
-                              NULL);
+  attributes = secret_attributes_build (&secret_password_schema, "goa-identity", password_key, NULL);
+  if (attributes == NULL)
+    goto out;
+
+  secret_service_clear_sync (secret_service, &secret_password_schema, attributes, cancellable, &sec_error);
   if (sec_error != NULL)
     {
       g_warning ("secret_password_clear_sync() failed: %s", sec_error->message);
@@ -393,6 +397,7 @@ goa_utils_delete_credentials_for_id_sync (GoaProvider   *provider,
   ret = TRUE;
 
  out:
+  g_clear_pointer (&attributes, (GDestroyNotify) g_hash_table_unref);
   g_free (password_key);
   return ret;
 }
diff --git a/src/goabackend/goautils.h b/src/goabackend/goautils.h
index 757318d..080e751 100644
--- a/src/goabackend/goautils.h
+++ b/src/goabackend/goautils.h
@@ -26,6 +26,7 @@
 #include <gio/gio.h>
 #include <glib.h>
 #include <gtk/gtk.h>
+#include <libsecret/secret.h>
 #include <libsoup/soup.h>
 
 #include "goaprovider.h"
@@ -62,12 +63,14 @@ gchar           *goa_utils_data_input_stream_read_line (GDataInputStream  *strea
 
 void             goa_utils_set_dialog_title (GoaProvider *provider, GtkDialog *dialog, gboolean add_account);
 
-gboolean         goa_utils_delete_credentials_for_account_sync (GoaProvider    *provider,
+gboolean         goa_utils_delete_credentials_for_account_sync (SecretService  *secret_service,
+                                                                GoaProvider    *provider,
                                                                 GoaAccount     *account,
                                                                 GCancellable   *cancellable,
                                                                 GError        **error);
 
-gboolean         goa_utils_delete_credentials_for_id_sync (GoaProvider    *provider,
+gboolean         goa_utils_delete_credentials_for_id_sync (SecretService  *secret_service,
+                                                           GoaProvider    *provider,
                                                            const gchar    *id,
                                                            GCancellable   *cancellable,
                                                            GError        **error);


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