[gnome-software] Do not set up a new SoupSession for each screenshot
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Do not set up a new SoupSession for each screenshot
- Date: Wed, 9 Oct 2013 08:28:54 +0000 (UTC)
commit d36af996e6e9e101f49ac7b7466af8ef05157c82
Author: Richard Hughes <richard hughsie com>
Date: Wed Oct 9 09:28:41 2013 +0100
Do not set up a new SoupSession for each screenshot
This allows us to pipeline the requests and speed up the loading.
src/gs-screenshot-image.c | 53 +++++++++++++++++---------------------------
src/gs-screenshot-image.h | 3 +-
src/gs-shell-details.c | 29 +++++++++++++++++++-----
3 files changed, 46 insertions(+), 39 deletions(-)
---
diff --git a/src/gs-screenshot-image.c b/src/gs-screenshot-image.c
index 685f96e..0c6e88a 100644
--- a/src/gs-screenshot-image.c
+++ b/src/gs-screenshot-image.c
@@ -24,7 +24,6 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <libsoup/soup.h>
#include "gs-screenshot-image.h"
@@ -311,24 +310,12 @@ gs_screenshot_image_destroy (GtkWidget *widget)
static void
gs_screenshot_image_init (GsScreenshotImage *ssimg)
{
- GsScreenshotImagePrivate *priv;
AtkObject *accessible;
+ ssimg->priv = gs_screenshot_image_get_instance_private (ssimg);
+
gtk_widget_set_has_window (GTK_WIDGET (ssimg), FALSE);
gtk_widget_init_template (GTK_WIDGET (ssimg));
- priv = gs_screenshot_image_get_instance_private (ssimg);
-
- /* setup networking */
- priv->session = soup_session_sync_new_with_options (SOUP_SESSION_USER_AGENT,
- "gnome-software",
- SOUP_SESSION_TIMEOUT, 5000,
- NULL);
- if (priv->session == NULL) {
- g_warning ("Failed to setup networking");
- return;
- }
- soup_session_add_feature_by_type (priv->session,
- SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
accessible = gtk_widget_get_accessible (GTK_WIDGET (ssimg));
if (accessible != 0) {
@@ -337,24 +324,25 @@ gs_screenshot_image_init (GsScreenshotImage *ssimg)
}
}
+/**
+ * gs_screenshot_image_draw:
+ **/
static gboolean
-gs_screenshot_image_draw (GtkWidget *widget,
- cairo_t *cr)
+gs_screenshot_image_draw (GtkWidget *widget, cairo_t *cr)
{
- GtkStyleContext *context;
-
- context = gtk_widget_get_style_context (widget);
-
- gtk_render_background (context, cr,
- 0, 0,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
- gtk_render_frame (context, cr,
- 0, 0,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
-
- return GTK_WIDGET_CLASS (gs_screenshot_image_parent_class)->draw (widget, cr);
+ GtkStyleContext *context;
+
+ context = gtk_widget_get_style_context (widget);
+ gtk_render_background (context, cr,
+ 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+ gtk_render_frame (context, cr,
+ 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+
+ return GTK_WIDGET_CLASS (gs_screenshot_image_parent_class)->draw (widget, cr);
}
/**
@@ -383,10 +371,11 @@ gs_screenshot_image_class_init (GsScreenshotImageClass *klass)
* gs_screenshot_image_new:
**/
GtkWidget *
-gs_screenshot_image_new (void)
+gs_screenshot_image_new (SoupSession *session)
{
GsScreenshotImage *ssimg;
ssimg = g_object_new (GS_TYPE_SCREENSHOT_IMAGE, NULL);
+ ssimg->priv->session = g_object_ref (session);
return GTK_WIDGET (ssimg);
}
diff --git a/src/gs-screenshot-image.h b/src/gs-screenshot-image.h
index 221a180..bd90a5c 100644
--- a/src/gs-screenshot-image.h
+++ b/src/gs-screenshot-image.h
@@ -24,6 +24,7 @@
#define GS_SCREENSHOT_IMAGE_H
#include <gtk/gtk.h>
+#include <libsoup/soup.h>
#include "gs-screenshot.h"
@@ -52,7 +53,7 @@ struct _GsScreenshotImageClass
};
GType gs_screenshot_image_get_type (void);
-GtkWidget *gs_screenshot_image_new (void);
+GtkWidget *gs_screenshot_image_new (SoupSession *session);
GsScreenshot *gs_screenshot_image_get_screenshot (GsScreenshotImage *ssimg);
void gs_screenshot_image_set_screenshot (GsScreenshotImage *ssimg,
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 1fa84ab..4028544 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -45,6 +45,7 @@ struct GsShellDetailsPrivate
GtkSizeGroup *history_sizegroup_state;
GtkSizeGroup *history_sizegroup_timestamp;
GtkSizeGroup *history_sizegroup_version;
+ SoupSession *session;
};
G_DEFINE_TYPE (GsShellDetails, gs_shell_details, G_TYPE_OBJECT)
@@ -295,7 +296,7 @@ gs_shell_details_set_app (GsShellDetails *shell_details, GsApp *app)
screenshots = gs_app_get_screenshots (app);
if (screenshots->len > 0) {
ss = g_ptr_array_index (screenshots, 0);
- ssimg = gs_screenshot_image_new ();
+ ssimg = gs_screenshot_image_new (priv->session);
gtk_widget_set_can_focus (gtk_bin_get_child (GTK_BIN (ssimg)), FALSE);
gs_screenshot_image_set_cachedir (GS_SCREENSHOT_IMAGE (ssimg), g_get_user_cache_dir ());
gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg),
@@ -315,7 +316,7 @@ gs_shell_details_set_app (GsShellDetails *shell_details, GsApp *app)
gtk_box_pack_start (GTK_BOX (widget), list, FALSE, FALSE, 0);
for (i = 0; i < screenshots->len; i++) {
ss = g_ptr_array_index (screenshots, i);
- ssimg = gs_screenshot_image_new ();
+ ssimg = gs_screenshot_image_new (priv->session);
gs_screenshot_image_set_cachedir (GS_SCREENSHOT_IMAGE (ssimg), g_get_user_cache_dir
());
gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg),
ss,
@@ -705,10 +706,24 @@ gs_shell_details_class_init (GsShellDetailsClass *klass)
static void
gs_shell_details_init (GsShellDetails *shell_details)
{
+ GsShellDetailsPrivate *priv;
+
shell_details->priv = GS_SHELL_DETAILS_GET_PRIVATE (shell_details);
- shell_details->priv->history_sizegroup_state = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
- shell_details->priv->history_sizegroup_timestamp = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
- shell_details->priv->history_sizegroup_version = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+ priv = shell_details->priv;
+
+ priv->history_sizegroup_state = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+ priv->history_sizegroup_timestamp = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+ priv->history_sizegroup_version = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+
+ /* setup networking */
+ priv->session = soup_session_sync_new_with_options (SOUP_SESSION_USER_AGENT,
+ "gnome-software",
+ SOUP_SESSION_TIMEOUT, 5000,
+ NULL);
+ if (priv->session != NULL) {
+ soup_session_add_feature_by_type (priv->session,
+ SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
+ }
}
/**
@@ -727,8 +742,10 @@ gs_shell_details_finalize (GObject *object)
g_object_unref (priv->builder);
g_object_unref (priv->plugin_loader);
g_object_unref (priv->cancellable);
- if (priv->app)
+ if (priv->app != NULL)
g_object_unref (priv->app);
+ if (priv->session != NULL)
+ g_object_unref (priv->session);
G_OBJECT_CLASS (gs_shell_details_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]