Add didChangePriority() to ResourceHandle
authorsimonjam@chromium.org <simonjam@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Feb 2013 07:40:08 +0000 (07:40 +0000)
committersimonjam@chromium.org <simonjam@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Feb 2013 07:40:08 +0000 (07:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=107995

Reviewed by Darin Fisher.

Source/Platform:

* chromium/public/WebURLLoader.h:
(WebKit):
(WebURLLoader):
(WebKit::WebURLLoader::didChangePriority): Added.

Source/WebCore:

For PLT, it's important that preloads remain a lower priority than parser requested resources.
This can lead to a 5% improvement.

The plan is to use this plumbing to expose the desired behavior. This patch simply allows a
resource's priority to change and have it propagate to the network layer. An upcoming patch will
lower the priority of preloads and then increase the priority when the parser officially requests
it.

No new tests. No visible change, because priority doesn't change yet.

* loader/cache/CachedResource.cpp:
(WebCore):
(WebCore::CachedResource::setLoadPriority):
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource): Allow loads to modify priority.
* loader/cache/CachedResourceRequest.h:
(WebCore::CachedResourceRequest::setPriority): Notify when priority changes.
* platform/network/ResourceHandle.cpp:
(WebCore::ResourceHandle::didChangePriority): Added.
(WebCore):
* platform/network/ResourceHandle.h:
(ResourceHandle):
* platform/network/chromium/ResourceHandle.cpp:
(WebCore::ResourceHandleInternal::didChangePriority):
(WebCore):
(WebCore::ResourceHandle::didChangePriority):
* platform/network/chromium/ResourceHandleInternal.h:
(ResourceHandleInternal):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@141684 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/Platform/ChangeLog
Source/Platform/chromium/public/WebURLLoader.h
Source/WebCore/ChangeLog
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceRequest.h
Source/WebCore/platform/network/ResourceHandle.cpp
Source/WebCore/platform/network/ResourceHandle.h
Source/WebCore/platform/network/chromium/ResourceHandle.cpp
Source/WebCore/platform/network/chromium/ResourceHandleInternal.h

index 2c4a893..7ecd9ac 100644 (file)
@@ -1,3 +1,15 @@
+2013-02-01  James Simonsen  <simonjam@chromium.org>
+
+        Add didChangePriority() to ResourceHandle
+        https://bugs.webkit.org/show_bug.cgi?id=107995
+
+        Reviewed by Darin Fisher.
+
+        * chromium/public/WebURLLoader.h:
+        (WebKit):
+        (WebURLLoader):
+        (WebKit::WebURLLoader::didChangePriority): Added.
+
 2013-02-01  Kevin Ellis  <kevers@chromium.org>
 
         [chromium] Fat scrollbars on Windows in high-DPI mode.
index a47b986..9337bb0 100644 (file)
 #define WebURLLoader_h
 
 #include "WebCommon.h"
+#include "WebURLRequest.h"
 
 namespace WebKit {
 
 class WebData;
 class WebURLLoaderClient;
-class WebURLRequest;
 class WebURLResponse;
 struct WebURLError;
 
@@ -64,6 +64,11 @@ public:
 
     // Suspends/resumes an asynchronous load.
     virtual void setDefersLoading(bool) = 0;
+
+    // Notifies the loader that the priority of a WebURLRequest has changed from
+    // its previous value. For example, a preload request starts with low
+    // priority, but may increase when the resource is needed for rendering.
+    virtual void didChangePriority(WebURLRequest::Priority newPriority) { }
 };
 
 } // namespace WebKit
index b91d3cf..88ff1f6 100644 (file)
@@ -1,3 +1,39 @@
+2013-02-01  James Simonsen  <simonjam@chromium.org>
+
+        Add didChangePriority() to ResourceHandle
+        https://bugs.webkit.org/show_bug.cgi?id=107995
+
+        Reviewed by Darin Fisher.
+
+        For PLT, it's important that preloads remain a lower priority than parser requested resources.
+        This can lead to a 5% improvement.
+
+        The plan is to use this plumbing to expose the desired behavior. This patch simply allows a
+        resource's priority to change and have it propagate to the network layer. An upcoming patch will
+        lower the priority of preloads and then increase the priority when the parser officially requests
+        it.
+
+        No new tests. No visible change, because priority doesn't change yet.
+
+        * loader/cache/CachedResource.cpp:
+        (WebCore):
+        (WebCore::CachedResource::setLoadPriority):
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::requestResource): Allow loads to modify priority.
+        * loader/cache/CachedResourceRequest.h:
+        (WebCore::CachedResourceRequest::setPriority): Notify when priority changes.
+        * platform/network/ResourceHandle.cpp:
+        (WebCore::ResourceHandle::didChangePriority): Added.
+        (WebCore):
+        * platform/network/ResourceHandle.h:
+        (ResourceHandle):
+        * platform/network/chromium/ResourceHandle.cpp:
+        (WebCore::ResourceHandleInternal::didChangePriority):
+        (WebCore):
+        (WebCore::ResourceHandle::didChangePriority):
+        * platform/network/chromium/ResourceHandleInternal.h:
+        (ResourceHandleInternal):
+
 2013-02-01  Roger Fong  <roger_fong@apple.com>
 
         Unreviewed. Clean up WebCore VS2010 project.
index 6d5c2b3..f0314e7 100644 (file)
@@ -863,12 +863,16 @@ unsigned CachedResource::overheadSize() const
     static const int kAverageClientsHashMapSize = 384;
     return sizeof(CachedResource) + m_response.memoryUsage() + kAverageClientsHashMapSize + m_resourceRequest.url().string().length() * 2;
 }
-    
-void CachedResource::setLoadPriority(ResourceLoadPriority loadPriority) 
-{ 
+
+void CachedResource::setLoadPriority(ResourceLoadPriority loadPriority)
+{
     if (loadPriority == ResourceLoadPriorityUnresolved)
+        loadPriority = defaultPriorityForResourceType(type());
+    if (loadPriority == m_loadPriority)
         return;
     m_loadPriority = loadPriority;
+    if (m_loader && m_loader->handle())
+        m_loader->handle()->didChangePriority(loadPriority);
 }
 
 
index 583729d..2e4f657 100644 (file)
@@ -465,7 +465,9 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(Cache
     if (!resource)
         return 0;
 
-    resource->setLoadPriority(request.priority());
+    if (!request.forPreload() || policy != Use)
+        resource->setLoadPriority(request.priority());
+
     if ((policy != Use || resource->stillNeedsLoad()) && CachedResourceRequest::NoDefer == request.defer()) {
         resource->load(this, request.options());
 
index 9d408e6..3759b28 100644 (file)
@@ -51,6 +51,7 @@ public:
     void setCharset(const String& charset) { m_charset = charset; }
     const ResourceLoaderOptions& options() const { return m_options; }
     void setOptions(const ResourceLoaderOptions& options) { m_options = options; }
+    void setPriority(ResourceLoadPriority priority) { m_priority = priority; }
     ResourceLoadPriority priority() const { return m_priority; }
     bool forPreload() const { return m_forPreload; }
     void setForPreload(bool forPreload) { m_forPreload = forPreload; }
index 57eefed..4bc94e7 100644 (file)
@@ -185,6 +185,11 @@ void ResourceHandle::setDefersLoading(bool defers)
     platformSetDefersLoading(defers);
 }
 
+void ResourceHandle::didChangePriority(ResourceLoadPriority)
+{
+    // Optionally implemented by platform.
+}
+
 void ResourceHandle::cacheMetadata(const ResourceResponse&, const Vector<char>&)
 {
     // Optionally implemented by platform.
index 7b9e30e..fa30589 100644 (file)
@@ -29,6 +29,7 @@
 #include "AuthenticationClient.h"
 #include "HTTPHeaderMap.h"
 #include "ResourceHandleTypes.h"
+#include "ResourceLoadPriority.h"
 #include <wtf/OwnPtr.h>
 #include <wtf/RefCounted.h>
 
@@ -190,7 +191,9 @@ public:
 #if PLATFORM(BLACKBERRY)
     void pauseLoad(bool);
 #endif
-      
+
+    void didChangePriority(ResourceLoadPriority);
+
     ResourceRequest& firstRequest();
     const String& lastHTTPMethod() const;
 
index f5e7cbe..ac14921 100644 (file)
@@ -88,6 +88,11 @@ void ResourceHandleInternal::setDefersLoading(bool value)
     m_loader->setDefersLoading(value);
 }
 
+void ResourceHandleInternal::didChangePriority(WebURLRequest::Priority newPriority)
+{
+    m_loader->didChangePriority(newPriority);
+}
+
 bool ResourceHandleInternal::allowStoredCredentials() const
 {
     return m_client && m_client->shouldUseCredentialStorage(m_owner);
@@ -276,6 +281,11 @@ void ResourceHandle::loadResourceSynchronously(NetworkingContext* context,
     data.append(dataOut.data(), dataOut.size());
 }
 
+void ResourceHandle::didChangePriority(ResourceLoadPriority newPriority)
+{
+    d->didChangePriority(static_cast<WebURLRequest::Priority>(newPriority));
+}
+
 // static
 void ResourceHandle::cacheMetadata(const ResourceResponse& response, const Vector<char>& data)
 {
index 9eefee8..d38d93e 100644 (file)
@@ -35,6 +35,7 @@
 #include <public/WebCommon.h>
 #include <public/WebURLLoader.h>
 #include <public/WebURLLoaderClient.h>
+#include <public/WebURLRequest.h>
 
 namespace WebCore {
 
@@ -51,6 +52,7 @@ public:
     void cancel();
     void setDefersLoading(bool);
     bool allowStoredCredentials() const;
+    void didChangePriority(WebKit::WebURLRequest::Priority);
 
     // WebURLLoaderClient methods:
     virtual void willSendRequest(WebKit::WebURLLoader*, WebKit::WebURLRequest&, const WebKit::WebURLResponse&);