[gnome-software/wip/kalev/soup-session: 1/2] Set up soup session in _initialize
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/kalev/soup-session: 1/2] Set up soup session in _initialize
- Date: Thu, 14 Jan 2016 14:05:04 +0000 (UTC)
commit 439488af59a81d05dec2d28f8cd2039e84de438f
Author: Kalev Lember <klember redhat com>
Date: Fri Nov 27 15:42:00 2015 +0100
Set up soup session in _initialize
We used to try to init a soup session at the beginning of each network
accessing function, and carefully check if the init succeeded before
doing further work with the session object.
However, soup_session_new() can never fail and always returns a valid
object. Knowing that, we can simplify the code a bit.
This commit moves soup_session_new() calls to _initialize and removes
needless return value checks.
src/plugins/gs-plugin-fedora-tagger-ratings.c | 37 ++-------------------
src/plugins/gs-plugin-fedora-tagger-usage.c | 32 ++----------------
src/plugins/gs-plugin-fwupd.c | 45 +++++-------------------
src/plugins/gs-plugin-icons.c | 32 ++----------------
4 files changed, 19 insertions(+), 127 deletions(-)
---
diff --git a/src/plugins/gs-plugin-fedora-tagger-ratings.c b/src/plugins/gs-plugin-fedora-tagger-ratings.c
index 9a35240..4051746 100644
--- a/src/plugins/gs-plugin-fedora-tagger-ratings.c
+++ b/src/plugins/gs-plugin-fedora-tagger-ratings.c
@@ -61,6 +61,9 @@ gs_plugin_initialize (GsPlugin *plugin)
"gnome-software",
"fedora-tagger.db",
NULL);
+ plugin->priv->session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
+ "gnome-software",
+ NULL);
/* check that we are running on Fedora */
if (!gs_plugin_check_distro_id (plugin, "fedora")) {
@@ -145,32 +148,6 @@ gs_plugin_parse_json (const gchar *data, gsize data_len, const gchar *key)
return value;
}
-
-/**
- * gs_plugin_setup_networking:
- */
-static gboolean
-gs_plugin_setup_networking (GsPlugin *plugin, GError **error)
-{
- /* already set up */
- if (plugin->priv->session != NULL)
- return TRUE;
-
- /* set up a session */
- plugin->priv->session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
- "gnome-software",
- NULL);
- if (plugin->priv->session == NULL) {
- g_set_error (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_FAILED,
- "%s: failed to setup networking",
- plugin->name);
- return FALSE;
- }
- return TRUE;
-}
-
/**
* gs_plugin_app_set_rating_pkg:
*/
@@ -233,10 +210,6 @@ gs_plugin_app_set_rating (GsPlugin *plugin,
return TRUE;
}
- /* ensure networking is set up */
- if (!gs_plugin_setup_networking (plugin, error))
- return FALSE;
-
/* set rating for each package */
for (i = 0; i < sources->len; i++) {
pkgname = g_ptr_array_index (sources, i);
@@ -361,10 +334,6 @@ gs_plugin_fedora_tagger_download (GsPlugin *plugin, GError **error)
GS_PLUGIN_FEDORA_TAGGER_SERVER);
msg = soup_message_new (SOUP_METHOD_GET, uri);
- /* ensure networking is set up */
- if (!gs_plugin_setup_networking (plugin, error))
- return FALSE;
-
/* set sync request */
status_code = soup_session_send_message (plugin->priv->session, msg);
if (status_code != SOUP_STATUS_OK) {
diff --git a/src/plugins/gs-plugin-fedora-tagger-usage.c b/src/plugins/gs-plugin-fedora-tagger-usage.c
index ddad2bd..53697ca 100644
--- a/src/plugins/gs-plugin-fedora-tagger-usage.c
+++ b/src/plugins/gs-plugin-fedora-tagger-usage.c
@@ -53,6 +53,9 @@ gs_plugin_initialize (GsPlugin *plugin)
g_autoptr(GSettings) settings = NULL;
plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ plugin->priv->session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
+ "gnome-software",
+ NULL);
/* this is opt-in, and turned off by default */
settings = g_settings_new ("org.gnome.desktop.privacy");
@@ -94,31 +97,6 @@ gs_plugin_destroy (GsPlugin *plugin)
}
/**
- * gs_plugin_setup_networking:
- */
-static gboolean
-gs_plugin_setup_networking (GsPlugin *plugin, GError **error)
-{
- /* already set up */
- if (plugin->priv->session != NULL)
- return TRUE;
-
- /* set up a session */
- plugin->priv->session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
- "gnome-software",
- NULL);
- if (plugin->priv->session == NULL) {
- g_set_error (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_FAILED,
- "%s: failed to setup networking",
- plugin->name);
- return FALSE;
- }
- return TRUE;
-}
-
-/**
* gs_plugin_app_set_usage_pkg:
*/
static gboolean
@@ -177,10 +155,6 @@ gs_plugin_app_set_usage_app (GsPlugin *plugin,
if (sources->len == 0)
return TRUE;
- /* ensure networking is set up */
- if (!gs_plugin_setup_networking (plugin, error))
- return FALSE;
-
/* tell fedora-tagger about this package */
for (i = 0; i < sources->len; i++) {
pkgname = g_ptr_array_index (sources, i);
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index d5e5f66..4626628 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -45,37 +45,6 @@ struct GsPluginPrivate {
};
/**
- * gs_plugin_fwupd_setup_networking:
- */
-static gboolean
-gs_plugin_fwupd_setup_networking (GsPlugin *plugin, GError **error)
-{
- g_autofree gchar *user_agent = NULL;
-
- /* already set up */
- if (plugin->priv->session != NULL)
- return TRUE;
-
- /* set up a session */
- user_agent = g_strdup_printf ("%s/%s", PACKAGE_NAME, PACKAGE_VERSION);
- plugin->priv->session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
- user_agent,
- NULL);
- if (plugin->priv->session == NULL) {
- g_set_error (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_FAILED,
- "%s: failed to setup networking",
- plugin->name);
- return FALSE;
- }
- /* this disables the double-compression of the firmware.xml.gz file */
- soup_session_remove_feature_by_type (plugin->priv->session,
- SOUP_TYPE_CONTENT_DECODER);
- return TRUE;
-}
-
-/**
* gs_plugin_get_name:
*/
const gchar *
@@ -90,9 +59,19 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
+ g_autofree gchar *user_agent = NULL;
+
plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
plugin->priv->to_download = g_ptr_array_new_with_free_func (g_free);
plugin->priv->to_ignore = g_ptr_array_new_with_free_func (g_free);
+
+ user_agent = g_strdup_printf ("%s/%s", PACKAGE_NAME, PACKAGE_VERSION);
+ plugin->priv->session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
+ user_agent,
+ NULL);
+ /* this disables the double-compression of the firmware.xml.gz file */
+ soup_session_remove_feature_by_type (plugin->priv->session,
+ SOUP_TYPE_CONTENT_DECODER);
}
/**
@@ -737,10 +716,6 @@ gs_plugin_refresh (GsPlugin *plugin,
if (plugin->priv->proxy == NULL)
return TRUE;
- /* ensure networking is set up */
- if (!gs_plugin_fwupd_setup_networking (plugin, error))
- return FALSE;
-
/* get the metadata and signature file */
if (!gs_plugin_fwupd_check_lvfs_metadata (plugin, cache_age, cancellable, error))
return FALSE;
diff --git a/src/plugins/gs-plugin-icons.c b/src/plugins/gs-plugin-icons.c
index 8055b82..aee873f 100644
--- a/src/plugins/gs-plugin-icons.c
+++ b/src/plugins/gs-plugin-icons.c
@@ -50,6 +50,9 @@ void
gs_plugin_initialize (GsPlugin *plugin)
{
plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ plugin->priv->session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
+ "gnome-software",
+ NULL);
}
/**
@@ -76,31 +79,6 @@ gs_plugin_destroy (GsPlugin *plugin)
}
/**
- * gs_plugin_setup_networking:
- */
-static gboolean
-gs_plugin_setup_networking (GsPlugin *plugin, GError **error)
-{
- /* already set up */
- if (plugin->priv->session != NULL)
- return TRUE;
-
- /* set up a session */
- plugin->priv->session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
- "gnome-software",
- NULL);
- if (plugin->priv->session == NULL) {
- g_set_error (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_FAILED,
- "%s: failed to setup networking",
- plugin->name);
- return FALSE;
- }
- return TRUE;
-}
-
-/**
* gs_plugin_icons_download:
*/
static gboolean
@@ -122,10 +100,6 @@ gs_plugin_icons_download (GsPlugin *plugin, const gchar *uri, const gchar *filen
return FALSE;
}
- /* ensure networking is set up */
- if (!gs_plugin_setup_networking (plugin, error))
- return FALSE;
-
/* set sync request */
status_code = soup_session_send_message (plugin->priv->session, msg);
if (status_code != SOUP_STATUS_OK) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]