[gnome-software: 15/38] gs-plugin-job: Add helper function for REFRESH jobs
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 15/38] gs-plugin-job: Add helper function for REFRESH jobs
- Date: Thu, 3 Mar 2022 16:39:53 +0000 (UTC)
commit efb101e5941f034385b55b9ac2f49c27039ab6d7
Author: Philip Withnall <pwithnall endlessos org>
Date: Thu Jan 27 19:16:13 2022 +0000
gs-plugin-job: Add helper function for REFRESH jobs
This creates a `GsPluginJob` for a `REFRESH` action. In subsequent
commits it will be turned into a full `GsPluginJob` subclass; this
commit is factored out first so the call sites don’t have to change
again later.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1472
lib/gnome-software.h | 1 +
lib/gs-cmd.c | 10 ++++------
lib/gs-plugin-job-refresh-metadata.c | 38 ++++++++++++++++++++++++++++++++++++
lib/gs-plugin-job-refresh-metadata.h | 24 +++++++++++++++++++++++
lib/meson.build | 2 ++
plugins/flatpak/gs-self-test.c | 35 +++++++++++++--------------------
src/gs-loading-page.c | 5 ++---
src/gs-overview-page.c | 6 ++----
src/gs-update-monitor.c | 5 ++---
src/gs-updates-page.c | 6 ++----
10 files changed, 91 insertions(+), 41 deletions(-)
---
diff --git a/lib/gnome-software.h b/lib/gnome-software.h
index 7cf850203..1e27e23d0 100644
--- a/lib/gnome-software.h
+++ b/lib/gnome-software.h
@@ -29,6 +29,7 @@
#include <gs-plugin-job.h>
#include <gs-plugin-job-list-installed-apps.h>
#include <gs-plugin-job-refine.h>
+#include <gs-plugin-job-refresh-metadata.h>
#include <gs-plugin-vfuncs.h>
#include <gs-remote-icon.h>
#include <gs-utils.h>
diff --git a/lib/gs-cmd.c b/lib/gs-cmd.c
index 5df895e1c..5fdb2fe82 100644
--- a/lib/gs-cmd.c
+++ b/lib/gs-cmd.c
@@ -377,9 +377,8 @@ main (int argc, char **argv)
* spin up the plugins enough as to prime caches */
if (g_getenv ("GS_CMD_NO_INITIAL_REFRESH") == NULL) {
g_autoptr(GsPluginJob) plugin_job = NULL;
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "age", (guint64) G_MAXUINT,
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (G_MAXUINT64,
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
ret = gs_plugin_loader_job_action (self->plugin_loader, plugin_job,
NULL, &error);
if (!ret) {
@@ -662,9 +661,8 @@ main (int argc, char **argv)
}
} else if (argc >= 2 && g_strcmp0 (argv[1], "refresh") == 0) {
g_autoptr(GsPluginJob) plugin_job = NULL;
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "age", cache_age_secs,
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (cache_age_secs,
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
ret = gs_plugin_loader_job_action (self->plugin_loader, plugin_job,
NULL, &error);
} else if (argc >= 1 && g_strcmp0 (argv[1], "user-hash") == 0) {
diff --git a/lib/gs-plugin-job-refresh-metadata.c b/lib/gs-plugin-job-refresh-metadata.c
new file mode 100644
index 000000000..4cb1a3221
--- /dev/null
+++ b/lib/gs-plugin-job-refresh-metadata.c
@@ -0,0 +1,38 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2022 Endless OS Foundation LLC
+ *
+ * Author: Philip Withnall <pwithnall endlessos org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <glib.h>
+
+#include "gs-plugin-job.h"
+#include "gs-plugin-job-refresh-metadata.h"
+#include "gs-plugin-types.h"
+
+/**
+ * gs_plugin_job_refresh_metadata_new:
+ * @cache_age_secs: maximum allowed cache age, in seconds
+ * @flags: flags to affect the refresh
+ *
+ * Create a new #GsPluginJob for refreshing metadata about available
+ * applications.
+ *
+ * Caches will be refreshed if they are older than @cache_age_secs.
+ *
+ * Returns: (transfer full): a new #GsPluginJob
+ * Since: 42
+ */
+GsPluginJob *
+gs_plugin_job_refresh_metadata_new (guint64 cache_age_secs,
+ GsPluginRefreshMetadataFlags flags)
+{
+ return gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
+ "age", cache_age_secs,
+ "interactive", (flags & GS_PLUGIN_REFRESH_METADATA_FLAGS_INTERACTIVE) ?
TRUE : FALSE,
+ NULL);
+}
diff --git a/lib/gs-plugin-job-refresh-metadata.h b/lib/gs-plugin-job-refresh-metadata.h
new file mode 100644
index 000000000..ae0b6b8a5
--- /dev/null
+++ b/lib/gs-plugin-job-refresh-metadata.h
@@ -0,0 +1,24 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2022 Endless OS Foundation LLC
+ *
+ * Author: Philip Withnall <pwithnall endlessos org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#pragma once
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include "gs-plugin-job.h"
+
+G_BEGIN_DECLS
+
+GsPluginJob *gs_plugin_job_refresh_metadata_new (guint64 cache_age_secs,
+ GsPluginRefreshMetadataFlags flags);
+
+G_END_DECLS
diff --git a/lib/meson.build b/lib/meson.build
index 23490d942..7e1645770 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -24,6 +24,7 @@ libgnomesoftware_public_headers = [
'gs-plugin-job.h',
'gs-plugin-job-list-installed-apps.h',
'gs-plugin-job-refine.h',
+ 'gs-plugin-job-refresh-metadata.h',
'gs-plugin-loader.h',
'gs-plugin-loader-sync.h',
'gs-plugin-types.h',
@@ -102,6 +103,7 @@ libgnomesoftware = library(
'gs-plugin-job.c',
'gs-plugin-job-list-installed-apps.c',
'gs-plugin-job-refine.c',
+ 'gs-plugin-job-refresh-metadata.c',
'gs-plugin-loader.c',
'gs-plugin-loader-sync.c',
'gs-remote-icon.c',
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index 493ab0f05..5b4a1faf8 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -350,9 +350,8 @@ gs_plugins_flatpak_app_with_runtime_func (GsPluginLoader *plugin_loader)
/* refresh the appstream metadata */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "age", (guint64) G_MAXUINT,
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (G_MAXUINT64,
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
g_assert_no_error (error);
g_assert_true (ret);
@@ -597,9 +596,8 @@ gs_plugins_flatpak_app_missing_runtime_func (GsPluginLoader *plugin_loader)
/* refresh the appstream metadata */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "age", (guint64) G_MAXUINT,
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (G_MAXUINT64,
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
g_assert_no_error (error);
g_assert_true (ret);
@@ -1124,9 +1122,8 @@ flatpak_bundle_or_ref_helper (GsPluginLoader *plugin_loader,
/* refresh the appstream metadata */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "age", (guint64) 0,
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (0,
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
g_assert_no_error (error);
g_assert_true (ret);
@@ -1441,9 +1438,8 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
/* refresh the appstream metadata */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "age", (guint64) G_MAXUINT,
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (G_MAXUINT64,
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
gs_test_flush_main_context ();
g_assert_no_error (error);
@@ -1487,9 +1483,8 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
/* refresh the appstream metadata */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "age", (guint64) 0, /* force now */
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (0, /* force now */
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
g_assert_no_error (error);
g_assert_true (ret);
@@ -1694,9 +1689,8 @@ gs_plugins_flatpak_runtime_extension_func (GsPluginLoader *plugin_loader)
/* refresh the appstream metadata */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "age", (guint64) G_MAXUINT,
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (G_MAXUINT64,
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
gs_test_flush_main_context ();
g_assert_no_error (error);
@@ -1747,9 +1741,8 @@ gs_plugins_flatpak_runtime_extension_func (GsPluginLoader *plugin_loader)
/* refresh the appstream metadata */
g_object_unref (plugin_job);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "age", (guint64) 0, /* force now */
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (0, /* force now */
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
g_assert_no_error (error);
g_assert_true (ret);
diff --git a/src/gs-loading-page.c b/src/gs-loading-page.c
index a35418cc9..170c1e98d 100644
--- a/src/gs-loading-page.c
+++ b/src/gs-loading-page.c
@@ -132,9 +132,8 @@ gs_loading_page_load (GsLoadingPage *self)
} else
cache_age_secs = G_MAXUINT64;
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "age", cache_age_secs,
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (cache_age_secs,
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
gs_plugin_loader_job_process_async (priv->plugin_loader, plugin_job,
priv->cancellable,
gs_loading_page_refresh_cb,
diff --git a/src/gs-overview-page.c b/src/gs-overview-page.c
index 50e2e2cfb..0fabc0aae 100644
--- a/src/gs-overview-page.c
+++ b/src/gs-overview-page.c
@@ -602,10 +602,8 @@ third_party_response_cb (GtkInfoBar *info_bar,
self->third_party_needs_question = FALSE;
refresh_third_party_repo (self);
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "interactive", FALSE,
- "age", (guint64) 1,
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (1,
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
gs_plugin_loader_job_process_async (self->plugin_loader, plugin_job,
self->cancellable,
(GAsyncReadyCallback) gs_overview_page_refresh_cb,
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index c58a1da8f..aef361a48 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -984,9 +984,8 @@ check_updates (GsUpdateMonitor *monitor)
}
g_debug ("Daily update check due");
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "age", (guint64) (60 * 60 * 24),
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (60 * 60 * 24,
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
gs_plugin_loader_job_process_async (monitor->plugin_loader, plugin_job,
monitor->refresh_cancellable,
refresh_cache_finished_cb,
diff --git a/src/gs-updates-page.c b/src/gs-updates-page.c
index 686ec740c..217f8e9f3 100644
--- a/src/gs-updates-page.c
+++ b/src/gs-updates-page.c
@@ -773,10 +773,8 @@ gs_updates_page_get_new_updates (GsUpdatesPage *self)
g_clear_object (&self->cancellable_refresh);
self->cancellable_refresh = g_cancellable_new ();
- plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
- "interactive", TRUE,
- "age", (guint64) 1,
- NULL);
+ plugin_job = gs_plugin_job_refresh_metadata_new (1,
+ GS_PLUGIN_REFRESH_METADATA_FLAGS_INTERACTIVE);
gs_plugin_loader_job_process_async (self->plugin_loader, plugin_job,
self->cancellable_refresh,
(GAsyncReadyCallback) gs_updates_page_refresh_cb,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]