[gnome-software] Register/unregister the search provider in the DBus related methods



commit bca6f3ad933f828d0c7a8cefe5c9080dd80aa9b7
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Mon May 8 23:43:03 2017 +0200

    Register/unregister the search provider in the DBus related methods
    
    Instead of just registering the search provider on startup, we instead
    do it in the implementation of dbus_register and dbus_unregister of the
    application, this way the object is registerd before the name is owned
    which avoids e.g.: sending a message after the name is owned but before
    the object is registered.

 src/gs-application.c           |   36 ++++++++++++++++++++++++++----------
 src/gs-shell-search-provider.c |    6 ++++++
 src/gs-shell-search-provider.h |    1 +
 3 files changed, 33 insertions(+), 10 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 89569f1..1a0d885 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -166,6 +166,30 @@ 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);
+       app->search_provider = gs_shell_search_provider_new ();
+       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)
 {
@@ -739,17 +763,8 @@ 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
@@ -822,7 +837,6 @@ 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
@@ -954,6 +968,8 @@ 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 47c1686..0d4ac26 100644
--- a/src/gs-shell-search-provider.c
+++ b/src/gs-shell-search-provider.c
@@ -316,6 +316,12 @@ 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 4c3cd11..817d600 100644
--- a/src/gs-shell-search-provider.h
+++ b/src/gs-shell-search-provider.h
@@ -33,6 +33,7 @@ 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]