[gnome-software: 28/72] provenance-license: Make refine asynchronous




commit c0b433a2f88edda4d6166fe81d0a63f5077b232b
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Nov 24 17:12:13 2021 +0000

    provenance-license: Make refine asynchronous
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 plugins/core/gs-plugin-provenance-license.c | 53 ++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 13 deletions(-)
---
diff --git a/plugins/core/gs-plugin-provenance-license.c b/plugins/core/gs-plugin-provenance-license.c
index 4a83acd92..8ddd0717f 100644
--- a/plugins/core/gs-plugin-provenance-license.c
+++ b/plugins/core/gs-plugin-provenance-license.c
@@ -18,6 +18,8 @@
  * SECTION:
  * Marks the application as Free Software if it comes from an origin
  * that is recognized as being DFSGish-free.
+ *
+ * This plugin executes entirely in the main thread.
  */
 
 struct _GsPluginProvenanceLicense {
@@ -132,37 +134,62 @@ refine_app (GsPluginProvenanceLicense  *self,
        return TRUE;
 }
 
-gboolean
-gs_plugin_refine (GsPlugin             *plugin,
-                 GsAppList            *list,
-                 GsPluginRefineFlags   flags,
-                 GCancellable         *cancellable,
-                 GError              **error)
+static void
+gs_plugin_provenance_license_refine_async (GsPlugin            *plugin,
+                                           GsAppList           *list,
+                                           GsPluginRefineFlags  flags,
+                                           GCancellable        *cancellable,
+                                           GAsyncReadyCallback  callback,
+                                           gpointer             user_data)
 {
        GsPluginProvenanceLicense *self = GS_PLUGIN_PROVENANCE_LICENSE (plugin);
+       g_autoptr(GTask) task = NULL;
+       g_autoptr(GError) local_error = NULL;
+
+       task = g_task_new (plugin, cancellable, callback, user_data);
+       g_task_set_source_tag (task, gs_plugin_provenance_license_refine_async);
 
        /* nothing to do here */
-       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE) == 0)
-               return TRUE;
+       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE) == 0) {
+               g_task_return_boolean (task, TRUE);
+               return;
+       }
+
        /* nothing to search */
-       if (self->sources == NULL || self->sources[0] == NULL)
-               return TRUE;
+       if (self->sources == NULL || self->sources[0] == NULL) {
+               g_task_return_boolean (task, TRUE);
+               return;
+       }
 
        for (guint i = 0; i < gs_app_list_length (list); i++) {
                GsApp *app = gs_app_list_index (list, i);
-               if (!refine_app (self, app, flags, cancellable, error))
-                       return FALSE;
+               if (!refine_app (self, app, flags, cancellable, &local_error)) {
+                       g_task_return_error (task, g_steal_pointer (&local_error));
+                       return;
+               }
        }
 
-       return TRUE;
+       g_task_return_boolean (task, TRUE);
+}
+
+static gboolean
+gs_plugin_provenance_license_refine_finish (GsPlugin      *plugin,
+                                            GAsyncResult  *result,
+                                            GError       **error)
+{
+       return g_task_propagate_boolean (G_TASK (result), error);
 }
 
 static void
 gs_plugin_provenance_license_class_init (GsPluginProvenanceLicenseClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GsPluginClass *plugin_class = GS_PLUGIN_CLASS (klass);
 
        object_class->dispose = gs_plugin_provenance_license_dispose;
+
+       plugin_class->refine_async = gs_plugin_provenance_license_refine_async;
+       plugin_class->refine_finish = gs_plugin_provenance_license_refine_finish;
 }
 
 GType


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