Title: [134623] trunk/Source/WebKit2
Revision
134623
Author
[email protected]
Date
2012-11-14 10:20:52 -0800 (Wed, 14 Nov 2012)

Log Message

Deliver data from NetworkProcess to resources progressively.
https://bugs.webkit.org/show_bug.cgi?id=102171

Reviewed by Alexey Proskuryakov.

Instead of buffering up the data for an entire resource and delivering it in one chunk, we need
to deliver data progressively.

This allows progressive parsing of textual resources and progressive rendering of images,
as well as allows endless multipart resources (e.g., multipart jpegs) to work at all.

* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::didReceiveData): Don't buffer data locally (for now) but rather
  pass it straight through to the WebProcess.
(WebKit::NetworkResourceLoader::didFinishLoading): Only notify didFinishLoading instead of
  delivering a chunk of buffered data.
(WebKit::NetworkResourceLoader::didFail):
* NetworkProcess/NetworkResourceLoader.h:

* WebProcess/Network/NetworkProcessConnection.cpp:
(WebKit::NetworkProcessConnection::didReceiveData): Pass through towards ResourceLoader.
(WebKit::NetworkProcessConnection::didFinishResourceLoad):
(WebKit::NetworkProcessConnection::didFailResourceLoad):
* WebProcess/Network/NetworkProcessConnection.h:
* WebProcess/Network/NetworkProcessConnection.messages.in:

* WebProcess/Network/WebResourceLoadScheduler.cpp:
(WebKit::WebResourceLoadScheduler::didReceiveData): Hand this chunk of data to the ResourceLoader directly.
(WebKit::WebResourceLoadScheduler::didFinishResourceLoad):
* WebProcess/Network/WebResourceLoadScheduler.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (134622 => 134623)


--- trunk/Source/WebKit2/ChangeLog	2012-11-14 18:07:01 UTC (rev 134622)
+++ trunk/Source/WebKit2/ChangeLog	2012-11-14 18:20:52 UTC (rev 134623)
@@ -1,3 +1,36 @@
+2012-11-14  Brady Eidson  <[email protected]>
+
+        Deliver data from NetworkProcess to resources progressively.
+        https://bugs.webkit.org/show_bug.cgi?id=102171
+
+        Reviewed by Alexey Proskuryakov.
+
+        Instead of buffering up the data for an entire resource and delivering it in one chunk, we need
+        to deliver data progressively.
+
+        This allows progressive parsing of textual resources and progressive rendering of images,
+        as well as allows endless multipart resources (e.g., multipart jpegs) to work at all.
+
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::didReceiveData): Don't buffer data locally (for now) but rather
+          pass it straight through to the WebProcess.
+        (WebKit::NetworkResourceLoader::didFinishLoading): Only notify didFinishLoading instead of
+          delivering a chunk of buffered data.
+        (WebKit::NetworkResourceLoader::didFail):
+        * NetworkProcess/NetworkResourceLoader.h:
+
+        * WebProcess/Network/NetworkProcessConnection.cpp:
+        (WebKit::NetworkProcessConnection::didReceiveData): Pass through towards ResourceLoader.
+        (WebKit::NetworkProcessConnection::didFinishResourceLoad):
+        (WebKit::NetworkProcessConnection::didFailResourceLoad):
+        * WebProcess/Network/NetworkProcessConnection.h:
+        * WebProcess/Network/NetworkProcessConnection.messages.in:
+
+        * WebProcess/Network/WebResourceLoadScheduler.cpp:
+        (WebKit::WebResourceLoadScheduler::didReceiveData): Hand this chunk of data to the ResourceLoader directly.
+        (WebKit::WebResourceLoadScheduler::didFinishResourceLoad):
+        * WebProcess/Network/WebResourceLoadScheduler.h:
+
 2012-11-14  Anton Obzhirov  <[email protected]>
 
         Add platform implementation of remote web inspector server for GTK port.

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (134622 => 134623)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2012-11-14 18:07:01 UTC (rev 134622)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2012-11-14 18:20:52 UTC (rev 134623)
@@ -29,6 +29,7 @@
 #if ENABLE(NETWORK_PROCESS)
 
 #include "BlockingResponseMap.h"
+#include "DataReference.h"
 #include "Logging.h"
 #include "NetworkConnectionToWebProcess.h"
 #include "NetworkProcess.h"
@@ -148,50 +149,31 @@
     connectionToWebProcess()->connection()->send(Messages::NetworkProcessConnection::DidReceiveResponse(m_identifier, response), 0);
 }
 
-void NetworkResourceLoader::didReceiveData(ResourceHandle*, const char* data, int length, int /*encodedDataLength*/)
+void NetworkResourceLoader::didReceiveData(ResourceHandle*, const char* data, int length, int encodedDataLength)
 {
-    // FIXME (NetworkProcess): We have to progressively notify the WebProcess as data is received.
-    if (!m_buffer)
-        m_buffer = ResourceBuffer::create();
-    m_buffer->append(data, length);
+    // FIXME (NetworkProcess): For the memory cache we'll also need to cache the response data here.
+    // Such buffering will need to be thread safe, as this callback is happening on a background thread.
+    
+    CoreIPC::DataReference dataReference(reinterpret_cast<const uint8_t*>(data), length);
+    connectionToWebProcess()->connection()->send(Messages::NetworkProcessConnection::DidReceiveData(m_identifier, dataReference, encodedDataLength, false), 0);
 }
 
 void NetworkResourceLoader::didFinishLoading(ResourceHandle*, double finishTime)
 {
-    // FIXME (NetworkProcess): Currently this callback can come in on a non-main thread.
-    // This is okay for now since resource buffers are per-NetworkResourceLoader.
-    // Once we manage memory in an actual memory cache that also includes SharedMemory blocks this will get complicated.
-    // Maybe we should marshall it to the main thread?
-
-    ShareableResource::Handle handle;
-
-    if (m_buffer && m_buffer->size()) {
-        // FIXME (NetworkProcess): We shouldn't be creating this SharedMemory on demand here.
-        // SharedMemory blocks need to be managed as part of the cache backing store.
-        RefPtr<SharedMemory> sharedBuffer = SharedMemory::create(m_buffer->size());
-        memcpy(sharedBuffer->data(), m_buffer->data(), m_buffer->size());
-
-        RefPtr<ShareableResource> shareableResource = ShareableResource::create(sharedBuffer.release(), 0, m_buffer->size());
-
-        // FIXME (NetworkProcess): Handle errors from createHandle();
-        if (!shareableResource->createHandle(handle))
-            LOG_ERROR("Failed to create handle to shareable resource memory\n");
-    }
-
-    connectionToWebProcess()->connection()->send(Messages::NetworkProcessConnection::DidReceiveResource(m_identifier, handle, finishTime), 0);
+    // FIXME (NetworkProcess): For the memory cache we'll need to update the finished status of the cached resource here.
+    // Such bookkeeping will need to be thread safe, as this callback is happening on a background thread.
+    connectionToWebProcess()->connection()->send(Messages::NetworkProcessConnection::DidFinishResourceLoad(m_identifier, finishTime), 0);
     scheduleStopOnMainThread();
 }
 
 void NetworkResourceLoader::didFail(ResourceHandle*, const ResourceError& error)
 {
+    // FIXME (NetworkProcess): For the memory cache we'll need to update the finished status of the cached resource here.
+    // Such bookkeeping will need to be thread safe, as this callback is happening on a background thread.
     connectionToWebProcess()->connection()->send(Messages::NetworkProcessConnection::DidFailResourceLoad(m_identifier, error), 0);
     scheduleStopOnMainThread();
 }
 
-// FIXME (NetworkProcess): Many of the following ResourceHandleClient methods definitely need implementations. A few will not.
-// Once we know what they are they can be removed.
-
-
 static BlockingResponseMap<ResourceRequest*>& responseMap()
 {
     AtomicallyInitializedStatic(BlockingResponseMap<ResourceRequest*>&, responseMap = *new BlockingResponseMap<ResourceRequest*>);
@@ -227,6 +209,9 @@
     RunLoop::main()->dispatch(WTF::bind(&NetworkResourceLoadScheduler::receivedRedirect, &NetworkProcess::shared().networkResourceLoadScheduler(), m_identifier, request.url()));
 }
 
+// FIXME (NetworkProcess): Many of the following ResourceHandleClient methods definitely need implementations. A few will not.
+// Once we know what they are they can be removed.
+
 void NetworkResourceLoader::didSendData(WebCore::ResourceHandle*, unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/)
 {
     notImplemented();

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h (134622 => 134623)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h	2012-11-14 18:07:01 UTC (rev 134622)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h	2012-11-14 18:20:52 UTC (rev 134623)
@@ -114,9 +114,6 @@
     RefPtr<RemoteNetworkingContext> m_networkingContext;
     RefPtr<WebCore::ResourceHandle> m_handle;    
     RefPtr<NetworkConnectionToWebProcess> m_connection;
-
-    // FIXME (NetworkProcess): Response data lifetime should be managed outside NetworkRequest.
-    RefPtr<WebCore::ResourceBuffer> m_buffer;
 };
 
 void didReceiveWillSendRequestHandled(uint64_t requestID, const WebCore::ResourceRequest&);

Modified: trunk/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp (134622 => 134623)


--- trunk/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp	2012-11-14 18:07:01 UTC (rev 134622)
+++ trunk/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp	2012-11-14 18:20:52 UTC (rev 134623)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "NetworkProcessConnection.h"
 
+#include "DataReference.h"
 #include "NetworkConnectionToWebProcessMessages.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebProcess.h"
@@ -85,6 +86,21 @@
     WebProcess::shared().webResourceLoadScheduler().didReceiveResponse(resourceLoadIdentifier, response);
 }
 
+void NetworkProcessConnection::didReceiveData(ResourceLoadIdentifier resourceLoadIdentifier, const CoreIPC::DataReference& data, int64_t encodedDataLength, bool allAtOnce)
+{
+    WebProcess::shared().webResourceLoadScheduler().didReceiveData(resourceLoadIdentifier, reinterpret_cast<const char*>(data.data()), data.size(), encodedDataLength, allAtOnce);
+}
+
+void NetworkProcessConnection::didFinishResourceLoad(ResourceLoadIdentifier resourceLoadIdentifier, double finishTime)
+{
+    WebProcess::shared().webResourceLoadScheduler().didFinishResourceLoad(resourceLoadIdentifier, finishTime);
+}
+
+void NetworkProcessConnection::didFailResourceLoad(ResourceLoadIdentifier resourceLoadIdentifier, const ResourceError& error)
+{
+    WebProcess::shared().webResourceLoadScheduler().didFailResourceLoad(resourceLoadIdentifier, error);
+}
+
 void NetworkProcessConnection::didReceiveResource(ResourceLoadIdentifier resourceLoadIdentifier, const ShareableResource::Handle& handle, double finishTime)
 {
     RefPtr<ResourceBuffer> resourceBuffer;
@@ -98,11 +114,6 @@
     WebProcess::shared().webResourceLoadScheduler().didReceiveResource(resourceLoadIdentifier, *resourceBuffer, finishTime);
 }
 
-void NetworkProcessConnection::didFailResourceLoad(ResourceLoadIdentifier resourceLoadIdentifier, const ResourceError& error)
-{
-    WebProcess::shared().webResourceLoadScheduler().didFailResourceLoad(resourceLoadIdentifier, error);
-}
-
 } // namespace WebKit
 
 #endif // ENABLE(NETWORK_PROCESS)

Modified: trunk/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h (134622 => 134623)


--- trunk/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h	2012-11-14 18:07:01 UTC (rev 134622)
+++ trunk/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h	2012-11-14 18:20:52 UTC (rev 134623)
@@ -33,6 +33,10 @@
 
 #if ENABLE(NETWORK_PROCESS)
 
+namespace CoreIPC {
+class DataReference;
+}
+
 namespace WebCore {
 class ResourceError;
 class ResourceRequest;
@@ -67,9 +71,12 @@
 
     void willSendRequest(uint64_t requestID, ResourceLoadIdentifier, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
     void didReceiveResponse(ResourceLoadIdentifier, const WebCore::ResourceResponse&);
-    void didReceiveResource(ResourceLoadIdentifier, const ShareableResource::Handle&, double finishTime);
+    void didReceiveData(ResourceLoadIdentifier, const CoreIPC::DataReference&, int64_t encodedDataLength, bool allAtOnce);
+    void didFinishResourceLoad(ResourceLoadIdentifier, double finishTime);
     void didFailResourceLoad(ResourceLoadIdentifier, const WebCore::ResourceError&);
 
+    void didReceiveResource(ResourceLoadIdentifier, const ShareableResource::Handle&, double finishTime);
+
     // The connection from the web process to the network process.
     RefPtr<CoreIPC::Connection> m_connection;
 };

Modified: trunk/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.messages.in (134622 => 134623)


--- trunk/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.messages.in	2012-11-14 18:07:01 UTC (rev 134622)
+++ trunk/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.messages.in	2012-11-14 18:20:52 UTC (rev 134623)
@@ -27,8 +27,12 @@
     // FIXME (NetworkProcess): We'll need much more granularity for response messages.
     WillSendRequest(uint64_t requestID, uint64_t resourceLoadIdentifier, WebCore::ResourceRequest request, WebCore::ResourceResponse redirectResponse)
     DidReceiveResponse(uint64_t resourceLoadIdentifier, WebCore::ResourceResponse response)
+    DidReceiveData(uint64_t resourceLoadIdentifier, CoreIPC::DataReference data, int64_t encodedDataLength, bool allAtOnce)
+    DidFinishResourceLoad(uint64_t resourceLoadIdentifier, double finishTime)
+    DidFailResourceLoad(uint64_t resourceLoadIdentifier, WebCore::ResourceError error)
+
+    // DidReceiveResource is for when we have the entire resource data available at once, such as when the resource is cached in memory
     DidReceiveResource(uint64_t resourceLoadIdentifier, WebKit::ShareableResource::Handle resource, double finishTime)
-    DidFailResourceLoad(uint64_t resourceLoadIdentifier, WebCore::ResourceError error)
 }
 
 #endif // ENABLE(NETWORK_PROCESS)

Modified: trunk/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp (134622 => 134623)


--- trunk/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp	2012-11-14 18:07:01 UTC (rev 134622)
+++ trunk/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp	2012-11-14 18:20:52 UTC (rev 134623)
@@ -205,6 +205,24 @@
     loader->didReceiveResponse(response);
 }
 
+void WebResourceLoadScheduler::didReceiveData(ResourceLoadIdentifier identifier, const char* data, int size, int64_t encodedDataLength, bool allAtOnce)
+{
+    RefPtr<ResourceLoader> loader = m_pendingResourceLoaders.get(identifier);
+    ASSERT(loader);
+
+    LOG(Network, "(WebProcess) WebResourceLoadScheduler::didReceiveData of size %i for '%s'", size, loader->url().string().utf8().data());
+    loader->didReceiveData(data, size, encodedDataLength, allAtOnce);
+}
+
+void WebResourceLoadScheduler::didFinishResourceLoad(ResourceLoadIdentifier identifier, double finishTime)
+{
+    RefPtr<ResourceLoader> loader = m_pendingResourceLoaders.get(identifier);
+    ASSERT(loader);
+
+    LOG(Network, "(WebProcess) WebResourceLoadScheduler::didFinishResourceLoad for '%s'", loader->url().string().utf8().data());
+    loader->didFinishLoading(finishTime);
+}
+
 void WebResourceLoadScheduler::didReceiveResource(ResourceLoadIdentifier identifier, const ResourceBuffer& buffer, double finishTime)
 {    
     RefPtr<ResourceLoader> loader = m_pendingResourceLoaders.get(identifier);

Modified: trunk/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.h (134622 => 134623)


--- trunk/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.h	2012-11-14 18:07:01 UTC (rev 134622)
+++ trunk/Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.h	2012-11-14 18:20:52 UTC (rev 134623)
@@ -57,10 +57,14 @@
 
     virtual void setSerialLoadingEnabled(bool) OVERRIDE;
 
+    // FIXME (NetworkProcess): Get the ResourceLoadScheduler out of the business of vending this data directly to ResourceLoaders.
+    // The Messages should be sent to an object that proxies the ResourceLoader directly.
     void willSendRequest(ResourceLoadIdentifier, WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse);
     void didReceiveResponse(ResourceLoadIdentifier, const WebCore::ResourceResponse&);
+    void didReceiveData(ResourceLoadIdentifier, const char*, int, int64_t encodedDataLength, bool allAtOnce);
+    void didFinishResourceLoad(ResourceLoadIdentifier, double finishTime);
+    void didFailResourceLoad(ResourceLoadIdentifier, const WebCore::ResourceError&);
     void didReceiveResource(ResourceLoadIdentifier, const WebCore::ResourceBuffer&, double finishTime);
-    void didFailResourceLoad(ResourceLoadIdentifier, const WebCore::ResourceError&);
 
 private:
     void scheduleLoad(WebCore::ResourceLoader*, WebCore::ResourceLoadPriority);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to