Add soup_session_prepare_for_uri
authorDan Winship <danw@gnome.org>
Sat, 7 Nov 2009 19:15:08 +0000 (14:15 -0500)
committerDan Winship <danw@gnome.org>
Sun, 22 Nov 2009 01:01:44 +0000 (20:01 -0500)
Lets the session prepare for a possible upcoming request. (Eg,
WebKitGTK will call this when the user hovers over a link.) Currently
just does DNS resolution. Will eventually do proxy resolution as well.

Based on a patch from José Millán Soto
https://bugzilla.gnome.org/show_bug.cgi?id=598948

libsoup/soup-session.c
libsoup/soup-session.h

index fc6f524..9c3efdb 100644 (file)
@@ -809,16 +809,12 @@ soup_session_host_new (SoupSession *session, SoupURI *uri)
        return host;
 }
 
-/* Note: get_host_for_message doesn't lock the host_lock. The caller
- * must do it itself if there's a chance the host doesn't already
- * exist.
- */
+/* Requires host_lock to be locked */
 static SoupSessionHost *
-get_host_for_message (SoupSession *session, SoupMessage *msg)
+get_host_for_uri (SoupSession *session, SoupURI *uri)
 {
        SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
        SoupSessionHost *host;
-       SoupURI *uri = soup_message_get_uri (msg);
 
        host = g_hash_table_lookup (priv->hosts, uri);
        if (host)
@@ -830,6 +826,16 @@ get_host_for_message (SoupSession *session, SoupMessage *msg)
        return host;
 }
 
+/* Note: get_host_for_message doesn't lock the host_lock. The caller
+ * must do it itself if there's a chance the host doesn't already
+ * exist.
+ */
+static SoupSessionHost *
+get_host_for_message (SoupSession *session, SoupMessage *msg)
+{
+       return get_host_for_uri (session, soup_message_get_uri (msg));
+}
+
 static void
 free_host (SoupSessionHost *host)
 {
@@ -1522,6 +1528,38 @@ soup_session_abort (SoupSession *session)
 }
 
 /**
+* soup_session_prepare_for_uri:
+* @session: a #SoupSession
+* @uri: a #SoupURI which may be required
+*
+* Tells @session that @uri may be requested shortly, and so the
+* session can try to prepare (resolving the domain name, obtaining
+* proxy address, etc.) in order to work more quickly once the URI is
+* actually requested.
+*
+* This method acts asynchronously, in @session's %async_context.
+* If you are using #SoupSessionSync and do not have a main loop running,
+* then you can't use this method.
+*
+* Since: 2.30
+**/
+void
+soup_session_prepare_for_uri (SoupSession *session, SoupURI *uri)
+{
+       SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
+       SoupSessionHost *host;
+       SoupAddress *addr;
+
+       g_mutex_lock (priv->host_lock);
+       host = get_host_for_uri (session, uri);
+       addr = g_object_ref (host->addr);
+       g_mutex_unlock (priv->host_lock);
+
+       soup_address_resolve_async (addr, priv->async_context,
+                                   NULL, NULL, NULL);
+}
+
+/**
  * soup_session_add_feature:
  * @session: a #SoupSession
  * @feature: an object that implements #SoupSessionFeature
index 598ee45..6080008 100644 (file)
@@ -93,6 +93,8 @@ void            soup_session_cancel_message   (SoupSession           *session,
                                               guint                  status_code);
 void            soup_session_abort            (SoupSession           *session);
 
+void            soup_session_prepare_for_uri  (SoupSession           *session,
+                                              SoupURI               *uri);
 
 void                soup_session_add_feature            (SoupSession        *session,
                                                         SoupSessionFeature *feature);