[gnome-software] Do not initialize plugins in every instance



commit 70ca78393e3ec8441a9dae11570713a4017f2b36
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Fri May 5 20:56:04 2017 +0200

    Do not initialize plugins in every instance
    
    The plugins are being initialized for the search provider service from
    the "dbus-register" implementation which gets called in every new
    instance of GNOME Software and not only in the primary one.
    As a result, instead of readily opening GNOME Software when a secondary
    instance is launched, there will be a delay until all the plugins are
    initialized.
    
    This patch moves the search provider setup to the gs_application_setup
    call, ensuring that this code is only run in the primary instance.

 src/gs-application.c           |   50 +++++++++++++++------------------------
 src/gs-shell-search-provider.c |    6 ----
 src/gs-shell-search-provider.h |    1 -
 3 files changed, 19 insertions(+), 38 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 3e46783..89569f1 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -166,35 +166,6 @@ gs_application_initialize_plugins (GsApplication *app)
 
 }
 
-static gboolean
-gs_application_dbus_register (GApplication    *application,
-                              GDBusConnection *connection,
-                              const gchar     *object_path,
-                              GError         **error)
-{
-       GsApplication *app = GS_APPLICATION (application);
-
-       gs_application_initialize_plugins (app);
-       app->search_provider = gs_shell_search_provider_new ();
-       gs_shell_search_provider_setup (app->search_provider,
-                                       app->plugin_loader);
-
-       return gs_shell_search_provider_register (app->search_provider, connection, error);
-}
-
-static void
-gs_application_dbus_unregister (GApplication    *application,
-                                GDBusConnection *connection,
-                                const gchar     *object_path)
-{
-       GsApplication *app = GS_APPLICATION (application);
-
-       if (app->search_provider != NULL) {
-               gs_shell_search_provider_unregister (app->search_provider);
-               g_clear_object (&app->search_provider);
-       }
-}
-
 static void
 gs_application_show_first_run_dialog (GsApplication *app)
 {
@@ -766,6 +737,22 @@ gs_application_settings_changed_cb (GApplication *self,
 }
 
 static void
+gs_application_setup_search_provider (GsApplication *app)
+{
+       GDBusConnection *connection;
+       g_autoptr(GError) error = NULL;
+
+       gs_application_initialize_plugins (app);
+       app->search_provider = gs_shell_search_provider_new ();
+       gs_shell_search_provider_setup (app->search_provider, app->plugin_loader);
+
+       connection = g_application_get_dbus_connection (G_APPLICATION (app));
+       if (!gs_shell_search_provider_register (app->search_provider, connection,
+                                               &error))
+               g_warning ("Could not register search provider: %s", error->message);
+}
+
+static void
 gs_application_startup (GApplication *application)
 {
        GSettings *settings;
@@ -775,6 +762,8 @@ gs_application_startup (GApplication *application)
                                         actions, G_N_ELEMENTS (actions),
                                         application);
 
+       gs_application_setup_search_provider (GS_APPLICATION (application));
+
 #ifdef HAVE_PACKAGEKIT
        GS_APPLICATION (application)->dbus_helper = gs_dbus_helper_new ();
 #endif
@@ -833,6 +822,7 @@ gs_application_dispose (GObject *object)
        g_clear_object (&app->shell);
        g_clear_object (&app->provider);
        g_clear_object (&app->update_monitor);
+       g_clear_object (&app->search_provider);
 #ifdef HAVE_PACKAGEKIT
        g_clear_object (&app->dbus_helper);
 #endif
@@ -964,8 +954,6 @@ gs_application_class_init (GsApplicationClass *class)
        G_APPLICATION_CLASS (class)->activate = gs_application_activate;
        G_APPLICATION_CLASS (class)->handle_local_options = gs_application_handle_local_options;
        G_APPLICATION_CLASS (class)->open = gs_application_open;
-       G_APPLICATION_CLASS (class)->dbus_register = gs_application_dbus_register;
-       G_APPLICATION_CLASS (class)->dbus_unregister = gs_application_dbus_unregister;
 }
 
 GsApplication *
diff --git a/src/gs-shell-search-provider.c b/src/gs-shell-search-provider.c
index 0d4ac26..47c1686 100644
--- a/src/gs-shell-search-provider.c
+++ b/src/gs-shell-search-provider.c
@@ -316,12 +316,6 @@ gs_shell_search_provider_register (GsShellSearchProvider *self,
                                                 "/org/gnome/Software/SearchProvider", error);
 }
 
-void
-gs_shell_search_provider_unregister (GsShellSearchProvider *self)
-{
-       g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->skeleton));
-}
-
 static void
 search_provider_dispose (GObject *obj)
 {
diff --git a/src/gs-shell-search-provider.h b/src/gs-shell-search-provider.h
index 817d600..4c3cd11 100644
--- a/src/gs-shell-search-provider.h
+++ b/src/gs-shell-search-provider.h
@@ -33,7 +33,6 @@ G_DECLARE_FINAL_TYPE (GsShellSearchProvider, gs_shell_search_provider, GS, SHELL
 gboolean                gs_shell_search_provider_register      (GsShellSearchProvider   *self,
                                                                 GDBusConnection         *connection,
                                                                 GError                 **error);
-void                    gs_shell_search_provider_unregister    (GsShellSearchProvider   *self);
 GsShellSearchProvider  *gs_shell_search_provider_new           (void);
 void                    gs_shell_search_provider_setup         (GsShellSearchProvider   *provider,
                                                                 GsPluginLoader          *loader);


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