[gnome-software: 2/4] gs-download-utils: Use new SoupSession construction method
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 2/4] gs-download-utils: Use new SoupSession construction method
- Date: Wed, 2 Feb 2022 15:55:36 +0000 (UTC)
commit 655679e911e7bf085afbff47e484ae3ba6cd70a7
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed Feb 2 12:10:29 2022 +0000
gs-download-utils: Use new SoupSession construction method
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1472
lib/gs-external-appstream-utils.c | 9 +++++++--
lib/gs-plugin-loader.c | 4 +---
plugins/core/gs-plugin-icons.c | 11 +++++++----
src/gs-page.c | 7 +++----
src/gs-screenshot-carousel.c | 4 ++--
5 files changed, 20 insertions(+), 15 deletions(-)
---
diff --git a/lib/gs-external-appstream-utils.c b/lib/gs-external-appstream-utils.c
index b8bafee62..7f218e1ea 100644
--- a/lib/gs-external-appstream-utils.c
+++ b/lib/gs-external-appstream-utils.c
@@ -10,6 +10,7 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include <libsoup/soup.h>
#include "gs-external-appstream-utils.h"
@@ -88,12 +89,12 @@ static gboolean
gs_external_appstream_refresh_sys (GsPlugin *plugin,
const gchar *url,
const gchar *basename,
+ SoupSession *soup_session,
guint cache_age,
GCancellable *cancellable,
GError **error)
{
GOutputStream *outstream = NULL;
- SoupSession *soup_session;
guint status_code;
gboolean file_written;
gconstpointer downloaded_data;
@@ -135,7 +136,6 @@ gs_external_appstream_refresh_sys (GsPlugin *plugin,
}
/* get the data */
- soup_session = gs_plugin_get_soup_session (plugin);
#if SOUP_CHECK_VERSION(3, 0, 0)
bytes = soup_session_send_and_read (soup_session, msg, cancellable, error);
if (bytes != NULL) {
@@ -251,6 +251,7 @@ static gboolean
gs_external_appstream_refresh_url (GsPlugin *plugin,
GSettings *settings,
const gchar *url,
+ SoupSession *soup_session,
guint cache_age,
GCancellable *cancellable,
GError **error)
@@ -270,6 +271,7 @@ gs_external_appstream_refresh_url (GsPlugin *plugin,
if (g_settings_get_boolean (settings, "external-appstream-system-wide")) {
return gs_external_appstream_refresh_sys (plugin, url,
basename,
+ soup_session,
cache_age,
cancellable,
error);
@@ -300,8 +302,10 @@ gs_external_appstream_refresh (GsPlugin *plugin,
{
g_autoptr(GSettings) settings = NULL;
g_auto(GStrv) appstream_urls = NULL;
+ g_autoptr(SoupSession) soup_session = NULL;
settings = g_settings_new ("org.gnome.software");
+ soup_session = gs_build_soup_session ();
appstream_urls = g_settings_get_strv (settings,
"external-appstream-urls");
for (guint i = 0; appstream_urls[i] != NULL; ++i) {
@@ -315,6 +319,7 @@ gs_external_appstream_refresh (GsPlugin *plugin,
if (!gs_external_appstream_refresh_url (plugin,
settings,
appstream_urls[i],
+ soup_session,
cache_age,
cancellable,
&error_local)) {
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index c14006a15..856188205 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -2786,9 +2786,7 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
(GDestroyNotify) g_object_unref);
/* share a soup session (also disable the double-compression) */
- plugin_loader->soup_session = soup_session_new_with_options ("user-agent", gs_user_agent (),
- "timeout", 10,
- NULL);
+ plugin_loader->soup_session = gs_build_soup_session ();
/* get the category manager */
plugin_loader->category_manager = gs_category_manager_new ();
diff --git a/plugins/core/gs-plugin-icons.c b/plugins/core/gs-plugin-icons.c
index b28596ed0..567fdfa89 100644
--- a/plugins/core/gs-plugin-icons.c
+++ b/plugins/core/gs-plugin-icons.c
@@ -9,6 +9,7 @@
#include <config.h>
+#include <libsoup/soup.h>
#include <string.h>
#include <gnome-software.h>
@@ -31,6 +32,7 @@ struct _GsPluginIcons
{
GsPlugin parent;
+ SoupSession *soup_session; /* (owned) */
GsWorkerThread *worker; /* (owned) */
};
@@ -51,6 +53,7 @@ gs_plugin_icons_dispose (GObject *object)
{
GsPluginIcons *self = GS_PLUGIN_ICONS (object);
+ g_clear_object (&self->soup_session);
g_clear_object (&self->worker);
G_OBJECT_CLASS (gs_plugin_icons_parent_class)->dispose (object);
@@ -68,6 +71,8 @@ gs_plugin_icons_setup_async (GsPlugin *plugin,
task = g_task_new (plugin, cancellable, callback, user_data);
g_task_set_source_tag (task, gs_plugin_icons_setup_async);
+ self->soup_session = gs_build_soup_session ();
+
/* Start up a worker thread to process all the plugin’s function calls. */
self->worker = gs_worker_thread_new ("gs-plugin-icons");
@@ -112,6 +117,7 @@ shutdown_cb (GObject *source_object,
g_autoptr(GsWorkerThread) worker = NULL;
g_autoptr(GError) local_error = NULL;
+ g_clear_object (&self->soup_session);
worker = g_steal_pointer (&self->worker);
if (!gs_worker_thread_shutdown_finish (worker, result, &local_error)) {
@@ -137,7 +143,6 @@ refine_app (GsPluginIcons *self,
GCancellable *cancellable,
GError **error)
{
- SoupSession *soup_session;
guint maximum_icon_size;
assert_in_worker (self);
@@ -146,12 +151,10 @@ refine_app (GsPluginIcons *self,
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON) == 0)
return TRUE;
- soup_session = gs_plugin_get_soup_session (GS_PLUGIN (self));
-
/* Currently a 160px icon is needed for #GsFeatureTile, at most. */
maximum_icon_size = 160 * gs_plugin_get_scale (GS_PLUGIN (self));
- gs_app_ensure_icons_downloaded (app, soup_session, maximum_icon_size, cancellable);
+ gs_app_ensure_icons_downloaded (app, self->soup_session, maximum_icon_size, cancellable);
return TRUE;
}
diff --git a/src/gs-page.c b/src/gs-page.c
index 1b17023e5..25b4a4160 100644
--- a/src/gs-page.c
+++ b/src/gs-page.c
@@ -13,6 +13,7 @@
#include <glib/gi18n.h>
#include "gs-application.h"
+#include "gs-download-utils.h"
#include "gs-page.h"
#include "gs-common.h"
#include "gs-screenshot-image.h"
@@ -102,8 +103,7 @@ gs_page_show_update_message (GsPageHelper *helper, AsScreenshot *ss)
g_autoptr(SoupSession) soup_session = NULL;
/* load screenshot */
- soup_session = soup_session_new_with_options ("user-agent",
- gs_user_agent (), NULL);
+ soup_session = gs_build_soup_session ();
ssimg = gs_screenshot_image_new (soup_session);
gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg), ss);
gs_screenshot_image_set_size (GS_SCREENSHOT_IMAGE (ssimg), 400, 225);
@@ -373,8 +373,7 @@ gs_page_needs_user_action (GsPageHelper *helper, AsScreenshot *ss)
gtk_widget_set_sensitive (helper->button_install, FALSE);
/* load screenshot */
- soup_session = soup_session_new_with_options ("user-agent",
- gs_user_agent (), NULL);
+ soup_session = gs_build_soup_session ();
ssimg = gs_screenshot_image_new (soup_session);
gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg), ss);
gs_screenshot_image_set_size (GS_SCREENSHOT_IMAGE (ssimg), 400, 225);
diff --git a/src/gs-screenshot-carousel.c b/src/gs-screenshot-carousel.c
index a1720b32b..9a59a2a90 100644
--- a/src/gs-screenshot-carousel.c
+++ b/src/gs-screenshot-carousel.c
@@ -33,6 +33,7 @@
#include <string.h>
#include "gs-common.h"
+#include "gs-download-utils.h"
#include "gs-utils.h"
#include "gs-screenshot-carousel.h"
@@ -333,8 +334,7 @@ gs_screenshot_carousel_init (GsScreenshotCarousel *self)
adw_carousel_set_allow_scroll_wheel (ADW_CAROUSEL (self->carousel), FALSE);
/* setup networking */
- self->session = soup_session_new_with_options ("user-agent", gs_user_agent (),
- NULL);
+ self->session = gs_build_soup_session ();
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]