[gnome-software] Make all the plugins more threadsafe



commit 8852d38910b823721ec537cc0239a56b332cbec2
Author: Richard Hughes <richard hughsie com>
Date:   Mon Apr 11 21:29:19 2016 +0100

    Make all the plugins more threadsafe
    
    Writelock the GRWLock during setup() and refresh(), and readlock during all
    other operations. Also unconditionally call refresh() when loading the plugin
    rather than leaving the plugin to do the GOnce or GMutex locking correctly.

 src/gs-plugin-loader.c                     |   62 +++++++++++++++++++++++++++-
 src/gs-plugin.h                            |    9 ++++-
 src/plugins/gs-plugin-appstream.c          |   60 +-------------------------
 src/plugins/gs-plugin-fwupd.c              |   24 +---------
 src/plugins/gs-plugin-ostree.c             |   12 ++----
 src/plugins/gs-plugin-packagekit-history.c |   15 +-----
 src/plugins/gs-plugin-shell-extensions.c   |   22 +---------
 src/plugins/gs-plugin-systemd-updates.c    |   16 +------
 8 files changed, 86 insertions(+), 134 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index c8dac94..373c31e 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -188,8 +188,10 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
                        for (l = *list; l != NULL; l = l->next) {
                                g_autoptr(GError) error_local = NULL;
                                app = GS_APP (l->data);
+                               g_rw_lock_reader_lock (&plugin->rwlock);
                                ret = plugin_app_func (plugin, app, flags,
-                                                   cancellable, &error_local);
+                                                      cancellable, &error_local);
+                               g_rw_lock_reader_unlock (&plugin->rwlock);
                                if (!ret) {
                                        g_warning ("failed to call %s on %s: %s",
                                                   function_name_app, plugin->name,
@@ -314,7 +316,9 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
                ptask2 = as_profile_start (priv->profile,
                                           "GsPlugin::%s(%s)",
                                           plugin->name, function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, &list, cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -612,7 +616,9 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, app, cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -1513,8 +1519,10 @@ gs_plugin_loader_search_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, values, &state->list,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -1672,8 +1680,10 @@ gs_plugin_loader_search_files_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, values, &state->list,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -1832,8 +1842,10 @@ gs_plugin_loader_search_what_provides_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, values, &state->list,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -1998,8 +2010,10 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, &state->list,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -2136,8 +2150,10 @@ gs_plugin_loader_get_category_apps_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, state->category, &state->list,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -2460,8 +2476,10 @@ gs_plugin_loader_review_action_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          state->function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, state->app, state->review,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   state->function_name, plugin->name,
@@ -2864,7 +2882,9 @@ gs_plugin_loader_run (GsPluginLoader *plugin_loader, const gchar *function_name)
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                plugin_func (plugin);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 }
@@ -3017,6 +3037,9 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        plugin->scale = gs_plugin_loader_get_scale (plugin_loader);
        g_debug ("opened plugin %s: %s", filename, plugin->name);
 
+       /* rwlock */
+       g_rw_lock_init (&plugin->rwlock);
+
        /* add to array */
        g_ptr_array_add (priv->plugins, plugin);
        return plugin;
@@ -3238,6 +3261,34 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
                }
        }
 
+       /* run setup */
+       for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginSetupFunc plugin_func = NULL;
+               const gchar *function_name = "gs_plugin_setup";
+               gboolean ret;
+               g_autoptr(AsProfileTask) ptask2 = NULL;
+               g_autoptr(GError) error_local = NULL;
+
+               /* run setup() if it exists */
+               plugin = g_ptr_array_index (priv->plugins, i);
+               ret = g_module_symbol (plugin->module,
+                                      function_name,
+                                      (gpointer *) &plugin_func);
+               if (!ret)
+                       continue;
+               ptask2 = as_profile_start (priv->profile,
+                                          "GsPlugin::%s(%s)",
+                                          plugin->name,
+                                          function_name);
+               g_rw_lock_writer_lock (&plugin->rwlock);
+               ret = plugin_func (plugin, NULL, &error_local);
+               g_rw_lock_writer_unlock (&plugin->rwlock);
+               if (!ret) {
+                       g_debug ("disabling %s as setup failed: %s",
+                                plugin->name, error_local->message);
+               }
+       }
+
        /* now we can load the install-queue */
        if (!load_install_queue (plugin_loader, error))
                return FALSE;
@@ -3272,6 +3323,7 @@ gs_plugin_loader_plugin_free (GsPlugin *plugin)
 {
        g_free (plugin->priv);
        g_free (plugin->name);
+       g_rw_lock_clear (&plugin->rwlock);
        g_object_unref (plugin->profile);
        g_object_unref (plugin->soup_session);
        g_module_close (plugin->module);
@@ -3522,7 +3574,9 @@ gs_plugin_loader_run_refresh (GsPluginLoader *plugin_loader,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_writer_lock (&plugin->rwlock);
                ret = plugin_func (plugin, cache_age, flags, cancellable, &error_local);
+               g_rw_lock_writer_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -3662,8 +3716,10 @@ gs_plugin_loader_filename_to_app_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, &state->list, state->filename,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -3803,7 +3859,9 @@ gs_plugin_loader_update_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, state->list, cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -3850,9 +3908,11 @@ gs_plugin_loader_update_thread_cb (GTask *task,
                                                  plugin->name,
                                                  function_name,
                                                  gs_app_get_id (app));
+                       g_rw_lock_reader_lock (&plugin->rwlock);
                        ret = plugin_app_func (plugin, app,
                                               cancellable,
                                               &error_local);
+                       g_rw_lock_reader_unlock (&plugin->rwlock);
                        if (!ret) {
                                g_warning ("failed to call %s on %s: %s",
                                           function_name, plugin->name,
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 2ff6eb0..814cd43 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2012-2014 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2012-2016 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -79,6 +79,7 @@ struct GsPlugin {
        gpointer                 updates_changed_user_data;
        AsProfile               *profile;
        SoupSession             *soup_session;
+       GRWLock                  rwlock;
 };
 
 typedef enum {
@@ -148,6 +149,9 @@ typedef enum {
 typedef const gchar    *(*GsPluginGetNameFunc)         (void);
 typedef const gchar    **(*GsPluginGetDepsFunc)        (GsPlugin       *plugin);
 typedef void            (*GsPluginFunc)                (GsPlugin       *plugin);
+typedef gboolean        (*GsPluginSetupFunc)           (GsPlugin       *plugin,
+                                                        GCancellable   *cancellable,
+                                                        GError         **error);
 typedef gboolean        (*GsPluginSearchFunc)          (GsPlugin       *plugin,
                                                         gchar          **value,
                                                         GList          **list,
@@ -242,6 +246,9 @@ gboolean     gs_plugin_add_search_what_provides     (GsPlugin       *plugin,
 const gchar    **gs_plugin_order_after                 (GsPlugin       *plugin);
 const gchar    **gs_plugin_order_before                (GsPlugin       *plugin);
 const gchar    **gs_plugin_get_conflicts               (GsPlugin       *plugin);
+gboolean        gs_plugin_setup                        (GsPlugin       *plugin,
+                                                        GCancellable   *cancellable,
+                                                        GError         **error);
 gboolean        gs_plugin_add_installed                (GsPlugin       *plugin,
                                                         GList          **list,
                                                         GCancellable   *cancellable,
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index ced6cbc..9a526dc 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -42,8 +42,6 @@
 
 struct GsPluginPrivate {
        AsStore                 *store;
-       GMutex                   store_mutex;
-       gboolean                 done_init;
 };
 
 /**
@@ -75,7 +73,6 @@ void
 gs_plugin_initialize (GsPlugin *plugin)
 {
        plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
-       g_mutex_init (&plugin->priv->store_mutex);
        plugin->priv->store = as_store_new ();
        as_store_set_watch_flags (plugin->priv->store,
                                  AS_STORE_WATCH_FLAG_ADDED |
@@ -102,7 +99,6 @@ void
 gs_plugin_destroy (GsPlugin *plugin)
 {
        g_object_unref (plugin->priv->store);
-       g_mutex_clear (&plugin->priv->store_mutex);
 }
 
 /**
@@ -153,12 +149,10 @@ gs_plugin_appstream_get_origins_hash (GPtrArray *array)
 }
 
 /**
- * gs_plugin_appstream_startup:
- *
- * This must be called with plugin->priv->store_mutex held.
+ * gs_plugin_setup:
  */
-static gboolean
-gs_plugin_appstream_startup (GsPlugin *plugin, GError **error)
+gboolean
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        AsApp *app;
        GPtrArray *items;
@@ -167,13 +161,6 @@ gs_plugin_appstream_startup (GsPlugin *plugin, GError **error)
        guint *perc;
        guint i;
        g_autoptr(GHashTable) origins = NULL;
-       g_autoptr(AsProfileTask) ptask = NULL;
-
-       /* already done */
-       if (plugin->priv->done_init)
-               return TRUE;
-
-       ptask = as_profile_start_literal (plugin->profile, "appstream::startup");
 
        /* Parse the XML */
        if (g_getenv ("GNOME_SOFTWARE_PREFER_LOCAL") != NULL) {
@@ -242,7 +229,6 @@ gs_plugin_appstream_startup (GsPlugin *plugin, GError **error)
        }
 
        /* rely on the store keeping itself updated */
-       plugin->priv->done_init = TRUE;
        return TRUE;
 }
 
@@ -326,11 +312,6 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
        AsApp *item;
        GPtrArray *array;
        guint i;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* find any upgrades */
        array = as_store_get_apps (plugin->priv->store);
@@ -362,11 +343,6 @@ gs_plugin_refine_app (GsPlugin *plugin,
                      GError **error)
 {
        gboolean found = FALSE;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* find by ID then package name */
        if (!gs_plugin_refine_from_id (plugin, app, &found, error))
@@ -397,11 +373,6 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
        GPtrArray *array;
        guint i;
        g_autoptr(AsProfileTask) ptask = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* get the two search terms */
        ptask = as_profile_start_literal (plugin->profile, "appstream::add-category-apps");
@@ -491,11 +462,6 @@ gs_plugin_add_search (GsPlugin *plugin,
        gboolean ret = TRUE;
        guint i;
        g_autoptr(AsProfileTask) ptask = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* search categories for the search term */
        ptask = as_profile_start_literal (plugin->profile, "appstream::search");
@@ -525,11 +491,6 @@ gs_plugin_add_installed (GsPlugin *plugin,
        GPtrArray *array;
        guint i;
        g_autoptr(AsProfileTask) ptask = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* search categories for the search term */
        ptask = as_profile_start_literal (plugin->profile, "appstream::add_installed");
@@ -606,11 +567,6 @@ gs_plugin_add_categories (GsPlugin *plugin,
        GPtrArray *array;
        guint i;
        g_autoptr(AsProfileTask) ptask = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* find out how many packages are in each category */
        ptask = as_profile_start_literal (plugin->profile, "appstream::add-categories");
@@ -639,11 +595,6 @@ gs_plugin_add_popular (GsPlugin *plugin,
        GPtrArray *array;
        guint i;
        g_autoptr(AsProfileTask) ptask = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* find out how many packages are in each category */
        ptask = as_profile_start_literal (plugin->profile, "appstream::add-popular");
@@ -675,11 +626,6 @@ gs_plugin_add_featured (GsPlugin *plugin,
        GPtrArray *array;
        guint i;
        g_autoptr(AsProfileTask) ptask = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* find out how many packages are in each category */
        ptask = as_profile_start_literal (plugin->profile, "appstream::add-featured");
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index 7fedddf..1a137c0 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -41,7 +41,6 @@
  */
 
 struct GsPluginPrivate {
-       GMutex                   mutex;
        FwupdClient             *client;
        GPtrArray               *to_download;
        GPtrArray               *to_ignore;
@@ -106,14 +105,13 @@ gs_plugin_fwupd_changed_cb (FwupdClient *client, GsPlugin *plugin)
 }
 
 /**
- * gs_plugin_startup:
+ * gs_plugin_setup:
  */
-static gboolean
-gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
+gboolean
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        gsize len;
        g_autofree gchar *data = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->mutex);
 
        /* already done */
        if (plugin->priv->cachedir != NULL)
@@ -382,10 +380,6 @@ gs_plugin_add_updates_historical (GsPlugin *plugin,
        g_autoptr(GsApp) app = NULL;
        g_autoptr(FwupdResult) res = NULL;
 
-       /* set up plugin */
-       if (!gs_plugin_startup (plugin, cancellable, error))
-               return FALSE;
-
        /* get historical updates */
        res = fwupd_client_get_results (plugin->priv->client,
                                        FWUPD_DEVICE_ID_ANY,
@@ -426,10 +420,6 @@ gs_plugin_add_updates (GsPlugin *plugin,
        g_autoptr(GError) error_local = NULL;
        g_autoptr(GPtrArray) results = NULL;
 
-       /* set up plugin */
-       if (!gs_plugin_startup (plugin, cancellable, error))
-               return FALSE;
-
        /* get current list of updates */
        results = fwupd_client_get_updates (plugin->priv->client,
                                            cancellable, &error_local);
@@ -585,10 +575,6 @@ gs_plugin_refresh (GsPlugin *plugin,
        const gchar *tmp;
        guint i;
 
-       /* set up plugin */
-       if (!gs_plugin_startup (plugin, cancellable, error))
-               return FALSE;
-
        /* get the metadata and signature file */
        if (flags & GS_PLUGIN_REFRESH_FLAGS_METADATA) {
                if (!gs_plugin_fwupd_check_lvfs_metadata (plugin,
@@ -709,10 +695,6 @@ gs_plugin_update_app (GsPlugin *plugin,
                      GCancellable *cancellable,
                      GError **error)
 {
-       /* set up plugin */
-       if (!gs_plugin_startup (plugin, cancellable, error))
-               return FALSE;
-
        /* locked devices need unlocking, rather than installing */
        if (gs_app_get_metadata_item (app, "fwupd::IsLocked") != NULL) {
                const gchar *device_id;
diff --git a/src/plugins/gs-plugin-ostree.c b/src/plugins/gs-plugin-ostree.c
index b923733..1a7b2e4 100644
--- a/src/plugins/gs-plugin-ostree.c
+++ b/src/plugins/gs-plugin-ostree.c
@@ -87,10 +87,10 @@ gs_plugin_destroy (GsPlugin *plugin)
 }
 
 /**
- * gs_plugin_startup:
+ * gs_plugin_setup:
  */
-static gboolean
-gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
+gboolean
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        /* already started */
        if (plugin->priv->ostree_repo != NULL)
@@ -116,7 +116,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
        g_auto(GStrv) names = NULL;
 
        /* set up plugin */
-       if (!gs_plugin_startup (plugin, cancellable, error))
+       if (!gs_plugin_setup (plugin, cancellable, error))
                return FALSE;
 
        /* get all remotes */
@@ -154,9 +154,5 @@ gs_plugin_refresh (GsPlugin *plugin,
                   GCancellable *cancellable,
                   GError **error)
 {
-       /* set up plugin */
-       if (!gs_plugin_startup (plugin, cancellable, error))
-               return FALSE;
-
        return TRUE;
 }
diff --git a/src/plugins/gs-plugin-packagekit-history.c b/src/plugins/gs-plugin-packagekit-history.c
index fc545ac..2e37c9e 100644
--- a/src/plugins/gs-plugin-packagekit-history.c
+++ b/src/plugins/gs-plugin-packagekit-history.c
@@ -34,7 +34,6 @@
  */
 
 struct GsPluginPrivate {
-       gsize                    loaded;
        GDBusConnection         *connection;
 };
 
@@ -133,10 +132,10 @@ gs_plugin_packagekit_refine_add_history (GsApp *app, GVariant *dict)
 }
 
 /**
- * gs_plugin_load:
+ * gs_plugin_setup:
  */
-static gboolean
-gs_plugin_load (GsPlugin *plugin, GCancellable *cancellable, GError **error)
+gboolean
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        plugin->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
                                                   cancellable,
@@ -161,14 +160,6 @@ gs_plugin_packagekit_refine (GsPlugin *plugin,
        g_autoptr(GVariant) result = NULL;
        g_autoptr(GVariant) tuple = NULL;
 
-       /* already loaded */
-       if (g_once_init_enter (&plugin->priv->loaded)) {
-               ret = gs_plugin_load (plugin, cancellable, error);
-               g_once_init_leave (&plugin->priv->loaded, TRUE);
-               if (!ret)
-                       return FALSE;
-       }
-
        /* get an array of package names */
        package_names = g_new0 (const gchar *, g_list_length (list) + 1);
        for (l = list; l != NULL; l = l->next) {
diff --git a/src/plugins/gs-plugin-shell-extensions.c b/src/plugins/gs-plugin-shell-extensions.c
index c9a7649..924af4e 100644
--- a/src/plugins/gs-plugin-shell-extensions.c
+++ b/src/plugins/gs-plugin-shell-extensions.c
@@ -225,7 +225,7 @@ gs_plugin_shell_extensions_add_app (const gchar *uuid,
 /**
  * gs_plugin_setup:
  */
-static gboolean
+gboolean
 gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        g_autoptr(GVariant) version = NULL;
@@ -263,10 +263,6 @@ gs_plugin_add_installed (GsPlugin *plugin,
        g_autoptr(GVariantIter) iter = NULL;
        g_autoptr(GVariant) retval = NULL;
 
-       /* connect to gnome-shell */
-       if (!gs_plugin_setup (plugin, cancellable, error))
-               return FALSE;
-
        /* installed */
        retval = g_dbus_proxy_call_sync (plugin->priv->proxy,
                                         "ListExtensions",
@@ -683,10 +679,6 @@ gs_plugin_refresh (GsPlugin *plugin,
                }
        }
 
-       /* connect to gnome-shell */
-       if (!gs_plugin_setup (plugin, cancellable, error))
-               return FALSE;
-
        /* get data */
        apps = gs_plugin_shell_extensions_get_apps (plugin, cache_age, error);
        if (apps == NULL)
@@ -726,10 +718,6 @@ gs_plugin_app_remove (GsPlugin *plugin,
        gboolean ret;
        g_autoptr(GVariant) retval = NULL;
 
-       /* connect to gnome-shell */
-       if (!gs_plugin_setup (plugin, cancellable, error))
-               return FALSE;
-
        /* install */
        uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
        retval = g_dbus_proxy_call_sync (plugin->priv->proxy,
@@ -769,10 +757,6 @@ gs_plugin_app_install (GsPlugin *plugin,
        const gchar *retstr;
        g_autoptr(GVariant) retval = NULL;
 
-       /* connect to gnome-shell */
-       if (!gs_plugin_setup (plugin, cancellable, error))
-               return FALSE;
-
        /* install */
        uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
        gs_app_set_state (app, AS_APP_STATE_INSTALLING);
@@ -816,10 +800,6 @@ gs_plugin_launch (GsPlugin *plugin,
        if (gs_app_get_kind (app) != AS_APP_KIND_SHELL_EXTENSION)
                return TRUE;
 
-       /* connect to gnome-shell */
-       if (!gs_plugin_setup (plugin, cancellable, error))
-               return FALSE;
-
        /* install */
        uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
        if (uuid == NULL) {
diff --git a/src/plugins/gs-plugin-systemd-updates.c b/src/plugins/gs-plugin-systemd-updates.c
index 8dd2e84..9b44413 100644
--- a/src/plugins/gs-plugin-systemd-updates.c
+++ b/src/plugins/gs-plugin-systemd-updates.c
@@ -35,7 +35,6 @@
 
 struct GsPluginPrivate {
        GFileMonitor            *monitor;
-       gsize                    done_init;
 };
 
 /**
@@ -80,10 +79,10 @@ gs_plugin_systemd_updates_changed_cb (GFileMonitor *monitor,
 }
 
 /**
- * gs_plugin_startup:
+ * gs_plugin_setup:
  */
-static gboolean
-gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
+gboolean
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        plugin->priv->monitor = pk_offline_get_prepared_monitor (cancellable, error);
        if (plugin->priv->monitor == NULL)
@@ -103,19 +102,10 @@ gs_plugin_add_updates (GsPlugin *plugin,
                       GCancellable *cancellable,
                       GError **error)
 {
-       gboolean ret;
        guint i;
        g_autoptr(GError) error_local = NULL;
        g_auto(GStrv) package_ids = NULL;
 
-       /* watch the file in case it comes or goes */
-       if (g_once_init_enter (&plugin->priv->done_init)) {
-               ret = gs_plugin_startup (plugin, cancellable, error);
-               g_once_init_leave (&plugin->priv->done_init, TRUE);
-               if (!ret)
-                       return FALSE;
-       }
-
        /* get the id's if the file exists */
        package_ids = pk_offline_get_prepared_ids (&error_local);
        if (package_ids == NULL) {


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