2015-12-21 Antti Koivisto <antti@apple.com>
+ Factor NetworkResourceLoader code for storing a cache entry into a function
+ https://bugs.webkit.org/show_bug.cgi?id=152467
+
+ Reviewed by Andreas Kling.
+
+ * NetworkProcess/NetworkResourceLoader.cpp:
+ (WebKit::NetworkResourceLoader::didFinishLoading):
+
+ Having m_cacheEntryForValidation already implies canUseCache() so remove the test from this path.
+ Move storing to the end of the function so we don't delay DidFinishResourceLoad message on it.
+
+ (WebKit::NetworkResourceLoader::sendBufferMaybeAborting):
+ (WebKit::NetworkResourceLoader::tryStoreAsCacheEntry):
+
+ Factor to a function.
+ Remove m_response.isHTTP() test as it is covered by NetworkCache::store().
+ Remove !isPrivateSession test as it is covered by NetworkResourceLoader::canUseCache().
+
+ (WebKit::NetworkResourceLoader::didRetrieveCacheEntry):
+ * NetworkProcess/NetworkResourceLoader.h:
+
+2015-12-21 Antti Koivisto <antti@apple.com>
+
Limit cached redirect chain length
https://bugs.webkit.org/show_bug.cgi?id=152477
void NetworkResourceLoader::didFinishLoading(double finishTime)
{
#if ENABLE(NETWORK_CACHE)
- if (canUseCache(m_networkLoad->currentRequest())) {
- if (m_cacheEntryForValidation) {
- // 304 Not Modified
- ASSERT(m_response.httpStatusCode() == 304);
- LOG(NetworkCache, "(NetworkProcess) revalidated");
- didRetrieveCacheEntry(WTF::move(m_cacheEntryForValidation));
- return;
- }
-
- bool isPrivateSession = sessionID().isEphemeral();
- if (m_bufferedDataForCache && m_response.isHTTP() && !isPrivateSession) {
- // Keep the connection alive.
- RefPtr<NetworkConnectionToWebProcess> connection(&connectionToWebProcess());
- RefPtr<NetworkResourceLoader> loader(this);
- NetworkCache::singleton().store(m_networkLoad->currentRequest(), m_response, WTF::move(m_bufferedDataForCache), [loader, connection](NetworkCache::MappedBody& mappedBody) {
-#if ENABLE(SHAREABLE_RESOURCE)
- if (mappedBody.shareableResourceHandle.isNull())
- return;
- LOG(NetworkCache, "(NetworkProcess) sending DidCacheResource");
- loader->send(Messages::NetworkProcessConnection::DidCacheResource(loader->originalRequest(), mappedBody.shareableResourceHandle, loader->sessionID()));
-#endif
- });
- }
+ if (m_cacheEntryForValidation) {
+ // 304 Not Modified
+ ASSERT(m_response.httpStatusCode() == 304);
+ LOG(NetworkCache, "(NetworkProcess) revalidated");
+ didRetrieveCacheEntry(WTF::move(m_cacheEntryForValidation));
+ return;
}
#endif
send(Messages::WebResourceLoader::DidFinishResourceLoad(finishTime));
}
+#if ENABLE(NETWORK_CACHE)
+ tryStoreAsCacheEntry();
+#endif
+
cleanup();
}
}
#if ENABLE(NETWORK_CACHE)
+void NetworkResourceLoader::tryStoreAsCacheEntry()
+{
+ if (!canUseCache(m_networkLoad->currentRequest()))
+ return;
+ if (!m_bufferedDataForCache)
+ return;
+
+ // Keep the connection alive.
+ RefPtr<NetworkConnectionToWebProcess> connection(&connectionToWebProcess());
+ RefPtr<NetworkResourceLoader> loader(this);
+ NetworkCache::singleton().store(m_networkLoad->currentRequest(), m_response, WTF::move(m_bufferedDataForCache), [loader, connection](NetworkCache::MappedBody& mappedBody) {
+#if ENABLE(SHAREABLE_RESOURCE)
+ if (mappedBody.shareableResourceHandle.isNull())
+ return;
+ LOG(NetworkCache, "(NetworkProcess) sending DidCacheResource");
+ loader->send(Messages::NetworkProcessConnection::DidCacheResource(loader->originalRequest(), mappedBody.shareableResourceHandle, loader->sessionID()));
+#endif
+ });
+}
+
void NetworkResourceLoader::didRetrieveCacheEntry(std::unique_ptr<NetworkCache::Entry> entry)
{
if (isSynchronous()) {