[gnome-software] Only set up the SoupSession in fedora-tagger when required
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Only set up the SoupSession in fedora-tagger when required
- Date: Tue, 15 Oct 2013 15:10:14 +0000 (UTC)
commit 8f028636b7dbc55c26292cb94a79a28844f01e65
Author: Richard Hughes <richard hughsie com>
Date: Tue Oct 15 15:06:26 2013 +0100
Only set up the SoupSession in fedora-tagger when required
This does not need to be done before showing the UI.
src/plugins/gs-plugin-fedora-tagger.c | 56 ++++++++++++++++++++++++++------
1 files changed, 45 insertions(+), 11 deletions(-)
---
diff --git a/src/plugins/gs-plugin-fedora-tagger.c b/src/plugins/gs-plugin-fedora-tagger.c
index 0944674..5fff14e 100644
--- a/src/plugins/gs-plugin-fedora-tagger.c
+++ b/src/plugins/gs-plugin-fedora-tagger.c
@@ -87,16 +87,6 @@ gs_plugin_initialize (GsPlugin *plugin)
plugin->name, GS_PLUGIN_FEDORA_TAGGER_OS_RELEASE_FN);
goto out;
}
-
- /* setup networking */
- plugin->priv->session = soup_session_sync_new_with_options (SOUP_SESSION_USER_AGENT,
- "gnome-software",
- SOUP_SESSION_TIMEOUT, 5000,
- NULL);
- if (plugin->priv->session != NULL) {
- soup_session_add_feature_by_type (plugin->priv->session,
- SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
- }
out:
g_free (data);
}
@@ -174,6 +164,39 @@ 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)
+{
+ gboolean ret = TRUE;
+
+ /* already set up */
+ if (plugin->priv->session != NULL)
+ goto out;
+
+ /* set up a session */
+ plugin->priv->session = soup_session_sync_new_with_options (SOUP_SESSION_USER_AGENT,
+ "gnome-software",
+ SOUP_SESSION_TIMEOUT, 5000,
+ NULL);
+ if (plugin->priv->session == NULL) {
+ ret = FALSE;
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_FAILED,
+ "%s: failed to setup networking",
+ plugin->name);
+ goto out;
+ }
+ soup_session_add_feature_by_type (plugin->priv->session,
+ SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
+out:
+ return ret;
+}
+
/**
* gs_plugin_app_set_rating:
*/
@@ -185,6 +208,7 @@ gs_plugin_app_set_rating (GsPlugin *plugin,
{
SoupMessage *msg = NULL;
const gchar *pkgname;
+ gboolean ret;
gchar *data = NULL;
gchar *error_msg = NULL;
gchar *uri = NULL;
@@ -197,6 +221,11 @@ gs_plugin_app_set_rating (GsPlugin *plugin,
goto out;
}
+ /* ensure networking is set up */
+ ret = gs_plugin_setup_networking (plugin, error);
+ if (!ret)
+ goto out;
+
/* create the PUT data */
uri = g_strdup_printf ("%s/api/v1/rating/%s/",
GS_PLUGIN_FEDORA_TAGGER_SERVER,
@@ -228,7 +257,7 @@ out:
g_free (uri);
if (msg != NULL)
g_object_unref (msg);
- return TRUE;
+ return ret;
}
/**
@@ -331,6 +360,11 @@ 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 */
+ ret = gs_plugin_setup_networking (plugin, error);
+ if (!ret)
+ goto out;
+
/* 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]