[libsoup/carlosgc/remove-request-started: 6/9] Stop connecting to SoupSession::request-queued from SoupSessionFeature




commit 5f318feb27f3ea1968d3f1dba80510864758f036
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Thu Oct 22 15:22:24 2020 +0200

    Stop connecting to SoupSession::request-queued from SoupSessionFeature
    
    SoupSession now notifies all the features about message being queued and
    unqueued. This way features implementing attach don't need to chain up,
    since there's no longer a default implementation for attach and detach.

 docs/reference/libsoup-3.0-sections.txt |   2 +
 libsoup/auth/soup-auth-manager.c        |   6 --
 libsoup/cache/soup-cache.c              |   6 --
 libsoup/cookies/soup-cookie-jar.c       |   2 +-
 libsoup/hsts/soup-hsts-enforcer.c       |  16 +----
 libsoup/soup-logger.c                   |   6 --
 libsoup/soup-session-feature.c          | 111 ++++++++++++--------------------
 libsoup/soup-session-feature.h          |  12 +++-
 libsoup/soup-session.c                  |  15 +++++
 9 files changed, 69 insertions(+), 107 deletions(-)
---
diff --git a/docs/reference/libsoup-3.0-sections.txt b/docs/reference/libsoup-3.0-sections.txt
index 70b545b7..05acf88a 100644
--- a/docs/reference/libsoup-3.0-sections.txt
+++ b/docs/reference/libsoup-3.0-sections.txt
@@ -488,6 +488,8 @@ SOUP_TYPE_SESSION_FEATURE
 <SUBSECTION Private>
 soup_session_feature_attach
 soup_session_feature_detach
+soup_session_feature_request_queued
+soup_session_feature_request_unqueued
 soup_session_feature_add_feature
 soup_session_feature_has_feature
 soup_session_feature_remove_feature
diff --git a/libsoup/auth/soup-auth-manager.c b/libsoup/auth/soup-auth-manager.c
index 34780b05..c05fa844 100644
--- a/libsoup/auth/soup-auth-manager.c
+++ b/libsoup/auth/soup-auth-manager.c
@@ -50,7 +50,6 @@
  * Since: 2.42
  */
 static void soup_auth_manager_session_feature_init (SoupSessionFeatureInterface *feature_interface, gpointer 
interface_data);
-static SoupSessionFeatureInterface *soup_session_feature_default_interface;
 
 enum {
        AUTHENTICATE,
@@ -232,8 +231,6 @@ soup_auth_manager_attach (SoupSessionFeature *feature, SoupSession *session)
 
        /* FIXME: should support multiple sessions */
        priv->session = session;
-
-       soup_session_feature_default_interface->attach (feature, session);
 }
 
 static inline const char *
@@ -836,9 +833,6 @@ static void
 soup_auth_manager_session_feature_init (SoupSessionFeatureInterface *feature_interface,
                                        gpointer interface_data)
 {
-       soup_session_feature_default_interface =
-               g_type_default_interface_peek (SOUP_TYPE_SESSION_FEATURE);
-
        feature_interface->attach = soup_auth_manager_attach;
        feature_interface->request_queued = soup_auth_manager_request_queued;
        feature_interface->request_unqueued = soup_auth_manager_request_unqueued;
diff --git a/libsoup/cache/soup-cache.c b/libsoup/cache/soup-cache.c
index 5a00467c..1144b5b0 100644
--- a/libsoup/cache/soup-cache.c
+++ b/libsoup/cache/soup-cache.c
@@ -50,7 +50,6 @@
  * #SoupCache implements a file-based cache for HTTP resources.
  */
 
-static SoupSessionFeatureInterface *soup_cache_default_feature_interface;
 static void soup_cache_session_feature_init (SoupSessionFeatureInterface *feature_interface, gpointer 
interface_data);
 
 static SoupContentProcessorInterface *soup_cache_default_content_processor_interface;
@@ -755,17 +754,12 @@ attach (SoupSessionFeature *feature, SoupSession *session)
        SoupCache *cache = SOUP_CACHE (feature);
        SoupCachePrivate *priv = soup_cache_get_instance_private (cache);
        priv->session = session;
-
-       soup_cache_default_feature_interface->attach (feature, session);
 }
 
 static void
 soup_cache_session_feature_init (SoupSessionFeatureInterface *feature_interface,
                                        gpointer interface_data)
 {
-       soup_cache_default_feature_interface =
-               g_type_default_interface_peek (SOUP_TYPE_SESSION_FEATURE);
-
        feature_interface->attach = attach;
        feature_interface->request_queued = request_queued;
 }
diff --git a/libsoup/cookies/soup-cookie-jar.c b/libsoup/cookies/soup-cookie-jar.c
index 1cf24f3a..1cd736e9 100644
--- a/libsoup/cookies/soup-cookie-jar.c
+++ b/libsoup/cookies/soup-cookie-jar.c
@@ -847,7 +847,7 @@ soup_cookie_jar_request_unqueued (SoupSessionFeature *feature,
                                  SoupSession *session,
                                  SoupMessage *msg)
 {
-       g_signal_handlers_disconnect_by_func (msg, process_set_cookie_header, feature);
+       g_signal_handlers_disconnect_by_data (msg, feature);
 }
 
 static void
diff --git a/libsoup/hsts/soup-hsts-enforcer.c b/libsoup/hsts/soup-hsts-enforcer.c
index 9201f3c6..63c96f3b 100644
--- a/libsoup/hsts/soup-hsts-enforcer.c
+++ b/libsoup/hsts/soup-hsts-enforcer.c
@@ -42,7 +42,6 @@
  *
  **/
 
-static SoupSessionFeatureInterface *soup_hsts_enforcer_default_feature_interface;
 static void soup_hsts_enforcer_session_feature_init (SoupSessionFeatureInterface *feature_interface, 
gpointer interface_data);
 
 enum {
@@ -566,9 +565,6 @@ soup_hsts_enforcer_attach (SoupSessionFeature *feature, SoupSession *session)
 {
         SoupHSTSEnforcerPrivate *priv = soup_hsts_enforcer_get_instance_private (SOUP_HSTS_ENFORCER 
(feature));
        priv->session = session;
-
-       if (soup_hsts_enforcer_default_feature_interface->attach)
-               soup_hsts_enforcer_default_feature_interface->attach (feature, session);
 }
 
 static void
@@ -578,9 +574,6 @@ soup_hsts_enforcer_request_queued (SoupSessionFeature *feature,
 {
        g_signal_connect (msg, "restarted", G_CALLBACK (message_restarted_cb), feature);
        preprocess_request (SOUP_HSTS_ENFORCER (feature), msg);
-
-       if (soup_hsts_enforcer_default_feature_interface->request_queued)
-               soup_hsts_enforcer_default_feature_interface->request_queued (feature, session, msg);
 }
 
 static void
@@ -588,20 +581,13 @@ soup_hsts_enforcer_request_unqueued (SoupSessionFeature *feature,
                                     SoupSession *session,
                                     SoupMessage *msg)
 {
-       g_signal_handlers_disconnect_by_func (msg, message_restarted_cb, feature);
-       g_signal_handlers_disconnect_by_func (msg, got_sts_header_cb, feature);
-
-       if (soup_hsts_enforcer_default_feature_interface->request_unqueued)
-               soup_hsts_enforcer_default_feature_interface->request_unqueued (feature, session, msg);
+       g_signal_handlers_disconnect_by_data (msg, feature);
 }
 
 static void
 soup_hsts_enforcer_session_feature_init (SoupSessionFeatureInterface *feature_interface,
                                         gpointer interface_data)
 {
-       soup_hsts_enforcer_default_feature_interface =
-               g_type_default_interface_peek (SOUP_TYPE_SESSION_FEATURE);
-
        feature_interface->attach = soup_hsts_enforcer_attach;
        feature_interface->request_queued = soup_hsts_enforcer_request_queued;
        feature_interface->request_unqueued = soup_hsts_enforcer_request_unqueued;
diff --git a/libsoup/soup-logger.c b/libsoup/soup-logger.c
index 402f4f57..41bfcdc0 100644
--- a/libsoup/soup-logger.c
+++ b/libsoup/soup-logger.c
@@ -130,7 +130,6 @@ enum {
        LAST_PROP
 };
 
-static SoupSessionFeatureInterface *soup_logger_default_feature_interface;
 static void soup_logger_session_feature_init (SoupSessionFeatureInterface *feature_interface, gpointer 
interface_data);
 
 G_DEFINE_TYPE_WITH_CODE (SoupLogger, soup_logger, G_TYPE_OBJECT,
@@ -760,17 +759,12 @@ soup_logger_feature_attach (SoupSessionFeature *feature,
        SoupLoggerPrivate *priv = soup_logger_get_instance_private (SOUP_LOGGER (feature));
 
        priv->session = session;
-
-       soup_logger_default_feature_interface->attach (feature, session);
 }
 
 static void
 soup_logger_session_feature_init (SoupSessionFeatureInterface *feature_interface,
                                  gpointer interface_data)
 {
-       soup_logger_default_feature_interface =
-               g_type_default_interface_peek (SOUP_TYPE_SESSION_FEATURE);
-
        feature_interface->attach = soup_logger_feature_attach;
        feature_interface->request_queued = soup_logger_request_queued;
        feature_interface->request_unqueued = soup_logger_request_unqueued;
diff --git a/libsoup/soup-session-feature.c b/libsoup/soup-session-feature.c
index a25313b7..26f10348 100644
--- a/libsoup/soup-session-feature.c
+++ b/libsoup/soup-session-feature.c
@@ -41,7 +41,6 @@
  * @attach: Perform setup when a feature is added to a session
  * @detach: Perform cleanup when a feature is removed from a session
  * @request_queued: Proxies the session's #SoupSession::request_queued signal
- * @request_started: Proxies the session's #SoupSession::request_started signal. Deprecated 2.50. Use 
#SoupMessage::starting instead.
  * @request_unqueued: Proxies the session's #SoupSession::request_unqueued signal
  * @add_feature: adds a sub-feature to the main feature
  * @remove_feature: removes a sub-feature from the main feature
@@ -54,103 +53,75 @@
 
 G_DEFINE_INTERFACE (SoupSessionFeature, soup_session_feature, G_TYPE_OBJECT)
 
-static void
-weak_notify_unref (gpointer feature, GObject *ex_object)
+void
+soup_session_feature_attach (SoupSessionFeature *feature,
+                            SoupSession        *session)
 {
-       g_object_unref (feature);
-}
+       SoupSessionFeatureInterface *iface;
 
-static void
-request_queued (SoupSession *session, SoupMessage *msg, gpointer feature)
-{
-       if (soup_message_disables_feature (msg, feature))
-               return;
+       g_return_if_fail (SOUP_IS_SESSION_FEATURE (feature));
+       g_return_if_fail (SOUP_IS_SESSION (session));
 
-       g_object_ref (feature);
-       if (SOUP_SESSION_FEATURE_GET_IFACE (feature)->request_queued) {
-               SOUP_SESSION_FEATURE_GET_IFACE (feature)->
-                       request_queued (feature, session, msg);
-       }
+       iface = SOUP_SESSION_FEATURE_GET_IFACE (feature);
+       if (iface->attach)
+               iface->attach (feature, session);
 }
 
-static void
-request_started (SoupSession *session, SoupMessage *msg, gpointer feature)
+void
+soup_session_feature_detach (SoupSessionFeature *feature,
+                            SoupSession        *session)
 {
-       if (soup_message_disables_feature (msg, feature))
-               return;
-
-       SOUP_SESSION_FEATURE_GET_IFACE (feature)->
-               request_started (feature, session, msg);
-}
+       SoupSessionFeatureInterface *iface;
 
-static void
-request_unqueued (SoupSession *session, SoupMessage *msg, gpointer feature)
-{
-       if (soup_message_disables_feature (msg, feature))
-               return;
+       g_return_if_fail (SOUP_IS_SESSION_FEATURE (feature));
+       g_return_if_fail (SOUP_IS_SESSION (session));
 
-       if (SOUP_SESSION_FEATURE_GET_IFACE (feature)->request_unqueued) {
-               SOUP_SESSION_FEATURE_GET_IFACE (feature)->
-                       request_unqueued (feature, session, msg);
-       }
-       g_object_unref (feature);
+       iface = SOUP_SESSION_FEATURE_GET_IFACE (feature);
+       if (iface->detach)
+               iface->detach (feature, session);
 }
 
 static void
-soup_session_feature_real_attach (SoupSessionFeature *feature, SoupSession *session)
+soup_session_feature_default_init (SoupSessionFeatureInterface *iface)
 {
-       g_object_weak_ref (G_OBJECT (session),
-                          weak_notify_unref, g_object_ref (feature));
-
-       g_signal_connect (session, "request_queued",
-                         G_CALLBACK (request_queued), feature);
-
-       if (SOUP_SESSION_FEATURE_GET_IFACE (feature)->request_started) {
-               g_signal_connect (session, "request_started",
-                                 G_CALLBACK (request_started), feature);
-       }
-
-       g_signal_connect (session, "request_unqueued",
-                         G_CALLBACK (request_unqueued), feature);
 }
 
 void
-soup_session_feature_attach (SoupSessionFeature *feature,
-                            SoupSession        *session)
+soup_session_feature_request_queued (SoupSessionFeature *feature,
+                                    SoupSession        *session,
+                                    SoupMessage        *msg)
 {
+       SoupSessionFeatureInterface *iface;
+
        g_return_if_fail (SOUP_IS_SESSION_FEATURE (feature));
        g_return_if_fail (SOUP_IS_SESSION (session));
+       g_return_if_fail (SOUP_IS_MESSAGE (msg));
 
-       SOUP_SESSION_FEATURE_GET_IFACE (feature)->attach (feature, session);
-}
-
-static void
-soup_session_feature_real_detach (SoupSessionFeature *feature, SoupSession *session)
-{
-       g_object_weak_unref (G_OBJECT (session), weak_notify_unref, feature);
-
-       g_signal_handlers_disconnect_by_func (session, request_queued, feature);
-       g_signal_handlers_disconnect_by_func (session, request_started, feature);
-       g_signal_handlers_disconnect_by_func (session, request_unqueued, feature);
+       if (soup_message_disables_feature (msg, feature))
+                return;
 
-       g_object_unref (feature);
+       iface = SOUP_SESSION_FEATURE_GET_IFACE (feature);
+       if (iface->request_queued)
+               iface->request_queued (feature, session, msg);
 }
 
 void
-soup_session_feature_detach (SoupSessionFeature *feature,
-                            SoupSession        *session)
+soup_session_feature_request_unqueued (SoupSessionFeature *feature,
+                                      SoupSession        *session,
+                                      SoupMessage        *msg)
 {
+       SoupSessionFeatureInterface *iface;
+
        g_return_if_fail (SOUP_IS_SESSION_FEATURE (feature));
        g_return_if_fail (SOUP_IS_SESSION (session));
+       g_return_if_fail (SOUP_IS_MESSAGE (msg));
 
-       SOUP_SESSION_FEATURE_GET_IFACE (feature)->detach (feature, session);
-}
+       if (soup_message_disables_feature (msg, feature))
+                return;
 
-static void
-soup_session_feature_default_init (SoupSessionFeatureInterface *iface)
-{
-       iface->attach = soup_session_feature_real_attach;
-       iface->detach = soup_session_feature_real_detach;
+       iface = SOUP_SESSION_FEATURE_GET_IFACE (feature);
+        if (iface->request_unqueued)
+                iface->request_unqueued (feature, session, msg);
 }
 
 /**
diff --git a/libsoup/soup-session-feature.h b/libsoup/soup-session-feature.h
index 929f93a1..ee46a8d7 100644
--- a/libsoup/soup-session-feature.h
+++ b/libsoup/soup-session-feature.h
@@ -25,9 +25,6 @@ struct _SoupSessionFeatureInterface {
        void     (*request_queued)   (SoupSessionFeature *feature,
                                      SoupSession        *session,
                                      SoupMessage        *msg);
-       void     (*request_started)  (SoupSessionFeature *feature,
-                                     SoupSession        *session,
-                                     SoupMessage        *msg);
        void     (*request_unqueued) (SoupSessionFeature *feature,
                                      SoupSession        *session,
                                      SoupMessage        *msg);
@@ -48,6 +45,15 @@ SOUP_AVAILABLE_IN_2_24
 void     soup_session_feature_detach         (SoupSessionFeature *feature,
                                              SoupSession        *session);
 
+SOUP_AVAILABLE_IN_ALL
+void     soup_session_feature_request_queued (SoupSessionFeature *feature,
+                                             SoupSession        *session,
+                                             SoupMessage        *msg);
+SOUP_AVAILABLE_IN_ALL
+void     soup_session_feature_request_unqueued (SoupSessionFeature *feature,
+                                               SoupSession        *session,
+                                               SoupMessage        *msg);
+
 SOUP_AVAILABLE_IN_2_34
 gboolean soup_session_feature_add_feature    (SoupSessionFeature *feature,
                                              GType               type);
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index dd83420a..557835bc 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -976,6 +976,7 @@ soup_session_append_queue_item (SoupSession        *session,
        SoupSessionPrivate *priv = soup_session_get_instance_private (session);
        SoupMessageQueueItem *item;
        SoupSessionHost *host;
+       GSList *f;
 
        soup_message_cleanup_response (msg);
 
@@ -995,6 +996,12 @@ soup_session_append_queue_item (SoupSession        *session,
        g_signal_connect (msg, "restarted",
                          G_CALLBACK (message_restarted), item);
 
+       for (f = priv->features; f; f = g_slist_next (f)) {
+               SoupSessionFeature *feature = SOUP_SESSION_FEATURE (f->data);
+
+               g_object_ref (feature);
+               soup_session_feature_request_queued (feature, session, msg);
+       }
        g_signal_emit (session, signals[REQUEST_QUEUED], 0, msg);
 
        soup_message_queue_item_ref (item);
@@ -1176,6 +1183,7 @@ soup_session_unqueue_item (SoupSession          *session,
        SoupSessionPrivate *priv = soup_session_get_instance_private (session);
        SoupSessionHost *host;
        SoupConnection *dedicated_conn = NULL;
+       GSList *f;
 
        if (item->conn) {
                if (item->conn_is_dedicated)
@@ -1217,6 +1225,13 @@ soup_session_unqueue_item (SoupSession          *session,
         */
        g_signal_handlers_disconnect_matched (item->msg, G_SIGNAL_MATCH_DATA,
                                              0, 0, NULL, NULL, item);
+
+       for (f = priv->features; f; f = g_slist_next (f)) {
+               SoupSessionFeature *feature = SOUP_SESSION_FEATURE (f->data);
+
+               soup_session_feature_request_unqueued (feature, session, item->msg);
+               g_object_unref (feature);
+       }
        g_signal_emit (session, signals[REQUEST_UNQUEUED], 0, item->msg);
        soup_message_queue_item_unref (item);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]