Title: [176120] trunk/Source/WebCore
Revision
176120
Author
carlo...@webkit.org
Date
2014-11-14 01:21:48 -0800 (Fri, 14 Nov 2014)

Log Message

[SOUP] Use GMainLoopSource for request timeout in ResourceHandle
https://bugs.webkit.org/show_bug.cgi?id=138695

Reviewed by Sergio Villar Senin.

We are currently using soup_timeout_add() that simply creates a
GSource and attaches it to the given context. Using
GMainLoopSource we simplify the code and fix any potential problem
of converting the double value into milliseconds.

* platform/network/ResourceHandleInternal.h:
* platform/network/soup/ResourceHandleSoup.cpp:
(WebCore::cleanupSoupRequestOperation):
(WebCore::ResourceHandle::sendPendingRequest):
(WebCore::ResourceHandle::platformSetDefersLoading):
(WebCore::requestTimeoutCallback): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (176119 => 176120)


--- trunk/Source/WebCore/ChangeLog	2014-11-14 08:49:55 UTC (rev 176119)
+++ trunk/Source/WebCore/ChangeLog	2014-11-14 09:21:48 UTC (rev 176120)
@@ -1,3 +1,22 @@
+2014-11-14  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [SOUP] Use GMainLoopSource for request timeout in ResourceHandle
+        https://bugs.webkit.org/show_bug.cgi?id=138695
+
+        Reviewed by Sergio Villar Senin.
+
+        We are currently using soup_timeout_add() that simply creates a
+        GSource and attaches it to the given context. Using
+        GMainLoopSource we simplify the code and fix any potential problem
+        of converting the double value into milliseconds.
+
+        * platform/network/ResourceHandleInternal.h:
+        * platform/network/soup/ResourceHandleSoup.cpp:
+        (WebCore::cleanupSoupRequestOperation):
+        (WebCore::ResourceHandle::sendPendingRequest):
+        (WebCore::ResourceHandle::platformSetDefersLoading):
+        (WebCore::requestTimeoutCallback): Deleted.
+
 2014-11-13  Tim Horton  <timothy_hor...@apple.com>
 
         [mac] Keep around more decoded image data, since it's purgeable

Modified: trunk/Source/WebCore/platform/network/ResourceHandleInternal.h (176119 => 176120)


--- trunk/Source/WebCore/platform/network/ResourceHandleInternal.h	2014-11-14 08:49:55 UTC (rev 176119)
+++ trunk/Source/WebCore/platform/network/ResourceHandleInternal.h	2014-11-14 09:21:48 UTC (rev 176120)
@@ -51,6 +51,7 @@
 #if USE(SOUP)
 #include "GUniquePtrSoup.h"
 #include <libsoup/soup.h>
+#include <wtf/gobject/GMainLoopSource.h>
 #include <wtf/gobject/GRefPtr.h>
 #endif
 
@@ -196,7 +197,7 @@
         GRefPtr<SoupMultipartInputStream> m_multipartInputStream;
         GRefPtr<GCancellable> m_cancellable;
         GRefPtr<GAsyncResult> m_deferredResult;
-        GRefPtr<GSource> m_timeoutSource;
+        GMainLoopSource m_timeoutSource;
         GUniquePtr<SoupBuffer> m_soupBuffer;
         unsigned long m_bodySize;
         unsigned long m_bodyDataSent;

Modified: trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp (176119 => 176120)


--- trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp	2014-11-14 08:49:55 UTC (rev 176119)
+++ trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp	2014-11-14 09:21:48 UTC (rev 176120)
@@ -231,7 +231,6 @@
 static void cleanupSoupRequestOperation(ResourceHandle*, bool isDestroying = false);
 static void sendRequestCallback(GObject*, GAsyncResult*, gpointer);
 static void readCallback(GObject*, GAsyncResult*, gpointer);
-static gboolean requestTimeoutCallback(void*);
 #if ENABLE(WEB_TIMING)
 static int  milisecondsSinceRequest(double requestTime);
 #endif
@@ -590,10 +589,7 @@
         d->m_soupMessage.clear();
     }
 
-    if (d->m_timeoutSource) {
-        g_source_destroy(d->m_timeoutSource.get());
-        d->m_timeoutSource.clear();
-    }
+    d->m_timeoutSource.cancel();
 
     if (!isDestroying)
         handle->deref();
@@ -1015,10 +1011,11 @@
 #endif
 
     if (d->m_firstRequest.timeoutInterval() > 0) {
-        // soup_add_timeout returns a GSource* whose only reference is owned by
-        // the context. We need to have our own reference to it, hence not using adoptRef.
-        d->m_timeoutSource = soup_add_timeout(g_main_context_get_thread_default(),
-            d->m_firstRequest.timeoutInterval() * 1000, requestTimeoutCallback, this);
+        d->m_timeoutSource.scheduleAfterDelay("[WebKit] ResourceHandle request timeout", [this] {
+            client()->didFail(this, ResourceError::timeoutError(firstRequest().url().string()));
+            cancel();
+        }, std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(d->m_firstRequest.timeoutInterval())),
+        G_PRIORITY_DEFAULT, nullptr, g_main_context_get_thread_default());
     }
 
     // Balanced by a deref() in cleanupSoupRequestOperation, which should always run.
@@ -1223,10 +1220,7 @@
 
     // Except when canceling a possible timeout timer, we only need to take action here to UN-defer loading.
     if (defersLoading) {
-        if (d->m_timeoutSource) {
-            g_source_destroy(d->m_timeoutSource.get());
-            d->m_timeoutSource.clear();
-        }
+        d->m_timeoutSource.cancel();
         return;
     }
 
@@ -1345,15 +1339,6 @@
     continueAfterDidReceiveResponse(this);
 }
 
-static gboolean requestTimeoutCallback(gpointer data)
-{
-    RefPtr<ResourceHandle> handle = static_cast<ResourceHandle*>(data);
-    handle->client()->didFail(handle.get(), ResourceError::timeoutError(handle->getInternal()->m_firstRequest.url().string()));
-    handle->cancel();
-
-    return FALSE;
 }
 
-}
-
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to