WebKit Bugzilla
Attachment 350137 Details for
Bug 189711
: Resource Load Statistics: Add optional cap on partitioned cache max age
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for landing
bug-189711-20180919114121.patch (text/plain), 52.47 KB, created by
John Wilander
on 2018-09-19 11:41:21 PDT
(
hide
)
Description:
Patch for landing
Filename:
MIME Type:
Creator:
John Wilander
Created:
2018-09-19 11:41:21 PDT
Size:
52.47 KB
patch
obsolete
>Subversion Revision: 236151 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index bd769ff935f045de971085efc3d1c18675cbf132..8cce2f9e55b2cf49d052188976a34b01e854969c 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,22 @@ >+2018-09-18 John Wilander <wilander@apple.com> >+ >+ Resource Load Statistics: Add optional cap on partitioned cache max age >+ https://bugs.webkit.org/show_bug.cgi?id=189711 >+ <rdar://problem/39246837> >+ >+ Reviewed by Antti Koivisto and Chris Dumez. >+ >+ Test: http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource.html >+ >+ * platform/network/NetworkStorageSession.h: >+ * platform/network/cf/NetworkStorageSessionCFNet.cpp: >+ (WebCore::NetworkStorageSession::maxAgeCacheCap): >+ Checks if a max age cap is set and returns it if the request >+ represents a prevalent resource. >+ (WebCore::NetworkStorageSession::setCacheMaxAgeCapForPrevalentResources): >+ (WebCore::NetworkStorageSession::resetCacheMaxAgeCapForPrevalentResources): >+ New functionality to receive a max age cap setting in the session. >+ > 2018-09-18 Simon Fraser <simon.fraser@apple.com> > > Remove the unused RenderLayerCompositor::enclosingCompositorFlushingLayers() >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index cef685b4b835acfa051b162ada2d8a3ec3d2aa7f..4920e6e122f46fcc1d1ae4e7a689d823e20c6ece 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,72 @@ >+2018-09-18 John Wilander <wilander@apple.com> >+ >+ Resource Load Statistics: Add optional cap on partitioned cache max age >+ https://bugs.webkit.org/show_bug.cgi?id=189711 >+ <rdar://problem/39246837> >+ >+ Reviewed by Antti Koivisto and Chris Dumez. >+ >+ These changes add the capability to set a max age cap for prevalent resources >+ and consults it when retrieving cache entries. If an entry is capped and found >+ to be too old, it will not be used but instead removed from the cache. >+ >+ This functionality is off by default because no cap is set by default. >+ >+ * NetworkProcess/NetworkProcess.cpp: >+ (WebKit::NetworkProcess::setCacheMaxAgeCapForPrevalentResources): >+ (WebKit::NetworkProcess::resetCacheMaxAgeCapForPrevalentResources): >+ Infrastructure for testing. >+ * NetworkProcess/NetworkProcess.h: >+ * NetworkProcess/NetworkProcess.messages.in: >+ * NetworkProcess/NetworkResourceLoader.cpp: >+ (WebKit::NetworkResourceLoader::retrieveCacheEntry): >+ Now sends in the session ID in the retrieve call. >+ * NetworkProcess/cache/NetworkCache.cpp: >+ (WebKit::NetworkCache::hasReachedPrevalentResourceAgeCap): >+ Static convenience function. >+ (WebKit::NetworkCache::makeUseDecision): >+ Now receives an optional maxAge parameter and checks >+ hasReachedPrevalentResourceAgeCap() first. >+ (WebKit::NetworkCache::Cache::retrieve): >+ Now takes a session ID. >+ * NetworkProcess/cache/NetworkCache.h: >+ * NetworkProcess/cache/NetworkCacheStatistics.cpp: >+ (WebKit::NetworkCache::cachedEntryReuseFailureToDiagnosticKey): >+ Added UseDecision::NoDueToPrevalentResourceAgeCap which causes a >+ return of WebCore::DiagnosticLoggingKeys::otherKey(). >+ * UIProcess/API/C/WKWebsiteDataStoreRef.cpp: >+ (WKWebsiteDataStoreSetStatisticsCacheMaxAgeCap): >+ (WKWebsiteDataStoreStatisticsResetToConsistentState): >+ Infrastructure for testing. >+ * UIProcess/API/C/WKWebsiteDataStoreRef.h: >+ * UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm: >+ (WebKit::ResourceLoadStatisticsMemoryStore::registerUserDefaultsIfNeeded): >+ Now supports a user default ResourceLoadStatisticsCacheMaxAgeCap. >+ * UIProcess/Network/NetworkProcessProxy.cpp: >+ (WebKit::NetworkProcessProxy::hasStorageAccessForFrame): >+ (WebKit::NetworkProcessProxy::grantStorageAccess): >+ (WebKit::NetworkProcessProxy::removeAllStorageAccess): >+ (WebKit::NetworkProcessProxy::getAllStorageAccessEntries): >+ (WebKit::NetworkProcessProxy::setCacheMaxAgeCapForPrevalentResources): >+ (WebKit::NetworkProcessProxy::didSetCacheMaxAgeCapForPrevalentResources): >+ (WebKit::NetworkProcessProxy::resetCacheMaxAgeCapForPrevalentResources): >+ (WebKit::NetworkProcessProxy::didResetCacheMaxAgeCapForPrevalentResources): >+ (WebKit::nextRequestStorageAccessContextId): Deleted. >+ Deleted this to make all code use the generic generateCallbackID(). >+ * UIProcess/Network/NetworkProcessProxy.h: >+ * UIProcess/Network/NetworkProcessProxy.messages.in: >+ Used to transfer the setting from the UI process to the network process. >+ * UIProcess/ResourceLoadStatisticsMemoryStore.cpp: >+ (WebKit::ResourceLoadStatisticsMemoryStore::setCacheMaxAgeCap): >+ * UIProcess/ResourceLoadStatisticsMemoryStore.h: >+ * UIProcess/WebResourceLoadStatisticsStore.cpp: >+ (WebKit::WebResourceLoadStatisticsStore::setCacheMaxAgeCap): >+ * UIProcess/WebResourceLoadStatisticsStore.h: >+ * UIProcess/WebsiteData/WebsiteDataStore.cpp: >+ (WebKit::WebsiteDataStore::setCacheMaxAgeCapForPrevalentResources): >+ (WebKit::WebsiteDataStore::resetCacheMaxAgeCapForPrevalentResources): >+ * UIProcess/WebsiteData/WebsiteDataStore.h: >+ > 2018-09-18 Ryan Haddad <ryanhaddad@apple.com> > > Unreviewed, rolling out r236138. >diff --git a/Source/WebCore/platform/network/NetworkStorageSession.h b/Source/WebCore/platform/network/NetworkStorageSession.h >index 986f7e439279911a9654761c756c4c22bef0ef26..81dacff97d901feec55bdc82f8a180673a483c42 100644 >--- a/Source/WebCore/platform/network/NetworkStorageSession.h >+++ b/Source/WebCore/platform/network/NetworkStorageSession.h >@@ -110,6 +110,9 @@ public: > WEBCORE_EXPORT void removeStorageAccessForFrame(uint64_t frameID, uint64_t pageID); > WEBCORE_EXPORT void removeStorageAccessForAllFramesOnPage(uint64_t pageID); > WEBCORE_EXPORT void removeAllStorageAccess(); >+ WEBCORE_EXPORT void setCacheMaxAgeCapForPrevalentResources(Seconds); >+ WEBCORE_EXPORT void resetCacheMaxAgeCapForPrevalentResources(); >+ WEBCORE_EXPORT std::optional<Seconds> maxAgeCacheCap(const ResourceRequest&); > #endif > #elif USE(SOUP) > NetworkStorageSession(PAL::SessionID, std::unique_ptr<SoupNetworkSession>&&); >@@ -187,6 +190,7 @@ private: > HashSet<String> m_topPrivatelyControlledDomainsToBlock; > HashMap<uint64_t, HashMap<uint64_t, String, DefaultHash<uint64_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>>, DefaultHash<uint64_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>> m_framesGrantedStorageAccess; > HashMap<uint64_t, HashMap<String, String>, DefaultHash<uint64_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>> m_pagesGrantedStorageAccess; >+ std::optional<Seconds> m_cacheMaxAgeCapForPrevalentResources { }; > #endif > > #if PLATFORM(COCOA) >diff --git a/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp b/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp >index c9d2964421ebdd8b4674046dcc4c503c7afb4995..33d23bc9b8987df1ef0a5a9bd7d287908c7b51da 100644 >--- a/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp >+++ b/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp >@@ -266,6 +266,13 @@ bool NetworkStorageSession::shouldBlockCookies(const URL& firstPartyForCookies, > return shouldBlockThirdPartyCookies(resourceDomain); > } > >+std::optional<Seconds> NetworkStorageSession::maxAgeCacheCap(const ResourceRequest& request) >+{ >+ if (m_cacheMaxAgeCapForPrevalentResources && shouldBlockCookies(request, std::nullopt, std::nullopt)) >+ return m_cacheMaxAgeCapForPrevalentResources; >+ return std::nullopt; >+} >+ > void NetworkStorageSession::setPrevalentDomainsToBlockCookiesFor(const Vector<String>& domains, bool clearFirst) > { > if (clearFirst) { >@@ -370,6 +377,15 @@ void NetworkStorageSession::removeAllStorageAccess() > m_framesGrantedStorageAccess.clear(); > } > >+void NetworkStorageSession::setCacheMaxAgeCapForPrevalentResources(Seconds seconds) >+{ >+ m_cacheMaxAgeCapForPrevalentResources = seconds; >+} >+ >+void NetworkStorageSession::resetCacheMaxAgeCapForPrevalentResources() >+{ >+ m_cacheMaxAgeCapForPrevalentResources = std::nullopt; >+} > #endif // HAVE(CFNETWORK_STORAGE_PARTITIONING) > > #if !PLATFORM(COCOA) >diff --git a/Source/WebKit/NetworkProcess/NetworkProcess.cpp b/Source/WebKit/NetworkProcess/NetworkProcess.cpp >index deaed323308e28053d709fc24483fe275495d04f..b450a886f2a160d8802b395d90a35ce0f94a1f74 100644 >--- a/Source/WebKit/NetworkProcess/NetworkProcess.cpp >+++ b/Source/WebKit/NetworkProcess/NetworkProcess.cpp >@@ -473,6 +473,24 @@ void NetworkProcess::removePrevalentDomains(PAL::SessionID sessionID, const Vect > if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID)) > networkStorageSession->removePrevalentDomains(domains); > } >+ >+void NetworkProcess::setCacheMaxAgeCapForPrevalentResources(PAL::SessionID sessionID, Seconds seconds, uint64_t contextId) >+{ >+ if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID)) >+ networkStorageSession->setCacheMaxAgeCapForPrevalentResources(Seconds { seconds }); >+ else >+ ASSERT_NOT_REACHED(); >+ parentProcessConnection()->send(Messages::NetworkProcessProxy::DidSetCacheMaxAgeCapForPrevalentResources(contextId), 0); >+} >+ >+void NetworkProcess::resetCacheMaxAgeCapForPrevalentResources(PAL::SessionID sessionID, uint64_t contextId) >+{ >+ if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID)) >+ networkStorageSession->resetCacheMaxAgeCapForPrevalentResources(); >+ else >+ ASSERT_NOT_REACHED(); >+ parentProcessConnection()->send(Messages::NetworkProcessProxy::DidResetCacheMaxAgeCapForPrevalentResources(contextId), 0); >+} > #endif > > bool NetworkProcess::sessionIsControlledByAutomation(PAL::SessionID sessionID) const >diff --git a/Source/WebKit/NetworkProcess/NetworkProcess.h b/Source/WebKit/NetworkProcess/NetworkProcess.h >index 7db3971277726a2ea377cf40ef683a59bc8c89e3..92d6d0344b620f9dfeed620b845a5c04733c322c 100644 >--- a/Source/WebKit/NetworkProcess/NetworkProcess.h >+++ b/Source/WebKit/NetworkProcess/NetworkProcess.h >@@ -146,6 +146,8 @@ public: > void grantStorageAccess(PAL::SessionID, const String& resourceDomain, const String& firstPartyDomain, std::optional<uint64_t> frameID, uint64_t pageID, uint64_t contextId); > void removeAllStorageAccess(PAL::SessionID, uint64_t contextId); > void removePrevalentDomains(PAL::SessionID, const Vector<String>& domains); >+ void setCacheMaxAgeCapForPrevalentResources(PAL::SessionID, Seconds, uint64_t contextId); >+ void resetCacheMaxAgeCapForPrevalentResources(PAL::SessionID, uint64_t contextId); > #endif > > Seconds loadThrottleLatency() const { return m_loadThrottleLatency; } >diff --git a/Source/WebKit/NetworkProcess/NetworkProcess.messages.in b/Source/WebKit/NetworkProcess/NetworkProcess.messages.in >index b96976602ab8d94e670796de3e5b8b078a46b322..4d0c8b1e60b63bd7d4233a8f8fa9611cb63845f6 100644 >--- a/Source/WebKit/NetworkProcess/NetworkProcess.messages.in >+++ b/Source/WebKit/NetworkProcess/NetworkProcess.messages.in >@@ -87,7 +87,9 @@ messages -> NetworkProcess LegacyReceiver { > GetAllStorageAccessEntries(PAL::SessionID sessionID, uint64_t contextId) > GrantStorageAccess(PAL::SessionID sessionID, String resourceDomain, String firstPartyDomain, std::optional<uint64_t> frameID, uint64_t pageID, uint64_t contextId) > RemoveAllStorageAccess(PAL::SessionID sessionID, uint64_t contextId) >- RemovePrevalentDomains(PAL::SessionID sessionID, Vector<String> domainsWithInteraction); >+ RemovePrevalentDomains(PAL::SessionID sessionID, Vector<String> domainsWithInteraction) >+ SetCacheMaxAgeCapForPrevalentResources(PAL::SessionID sessionID, Seconds seconds, uint64_t contextId) >+ ResetCacheMaxAgeCapForPrevalentResources(PAL::SessionID sessionID, uint64_t contextId) > #endif > > SetSessionIsControlledByAutomation(PAL::SessionID sessionID, bool controlled); >diff --git a/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp b/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp >index 5c11bab201e92ac6968be681137852eb502843f4..f1095f4282806d03feb29b3c445f91f1aeecedab 100644 >--- a/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp >+++ b/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp >@@ -214,7 +214,7 @@ void NetworkResourceLoader::retrieveCacheEntry(const ResourceRequest& request) > ASSERT(canUseCache(request)); > > RefPtr<NetworkResourceLoader> loader(this); >- m_cache->retrieve(request, { m_parameters.webPageID, m_parameters.webFrameID }, [this, loader = WTFMove(loader), request = ResourceRequest { request }](auto entry, auto info) mutable { >+ m_cache->retrieve(request, { m_parameters.webPageID, m_parameters.webFrameID }, sessionID(), [this, loader = WTFMove(loader), request = ResourceRequest { request }](auto entry, auto info) mutable { > if (loader->hasOneRef()) { > // The loader has been aborted and is only held alive by this lambda. > return; >diff --git a/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp b/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp >index da07e8287ac9ceaca400efcd2b06f0b23e81fbdc..0d80bf7c8c2570fb80da5648b91ecddf8b565540 100644 >--- a/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp >+++ b/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp >@@ -152,6 +152,11 @@ static bool cachePolicyAllowsExpired(WebCore::ResourceRequestCachePolicy policy) > return false; > } > >+static bool hasReachedPrevalentResourceAgeCap(const WebCore::ResourceResponse& response, WallTime timestamp, const Seconds maxAge) >+{ >+ return WebCore::computeCurrentAge(response, timestamp) > maxAge; >+} >+ > static bool responseHasExpired(const WebCore::ResourceResponse& response, WallTime timestamp, std::optional<Seconds> maxStale) > { > if (response.cacheControlContainsNoCache()) >@@ -183,8 +188,11 @@ static bool responseNeedsRevalidation(const WebCore::ResourceResponse& response, > return responseHasExpired(response, timestamp, requestDirectives.maxStale); > } > >-static UseDecision makeUseDecision(const Entry& entry, const WebCore::ResourceRequest& request) >+static UseDecision makeUseDecision(const Entry& entry, const WebCore::ResourceRequest& request, std::optional<Seconds> maxAge) > { >+ if (maxAge && hasReachedPrevalentResourceAgeCap(entry.response(), entry.timeStamp(), maxAge.value())) >+ return UseDecision::NoDueToPrevalentResourceAgeCap; >+ > // The request is conditional so we force revalidation from the network. We merely check the disk cache > // so we can update the cache entry. > if (request.isConditional() && !entry.redirectRequest()) >@@ -271,7 +279,7 @@ static StoreDecision makeStoreDecision(const WebCore::ResourceRequest& originalR > return StoreDecision::Yes; > } > >-void Cache::retrieve(const WebCore::ResourceRequest& request, const GlobalFrameID& frameID, RetrieveCompletionHandler&& completionHandler) >+void Cache::retrieve(const WebCore::ResourceRequest& request, const GlobalFrameID& frameID, PAL::SessionID sessionID, RetrieveCompletionHandler&& completionHandler) > { > ASSERT(request.url().protocolIsInHTTPFamily()); > >@@ -315,7 +323,7 @@ void Cache::retrieve(const WebCore::ResourceRequest& request, const GlobalFrameI > } > #endif > >- m_storage->retrieve(storageKey, priority, [this, protectedThis = makeRef(*this), request, completionHandler = WTFMove(completionHandler), info = WTFMove(info), storageKey, frameID](auto record, auto timings) mutable { >+ m_storage->retrieve(storageKey, priority, [this, protectedThis = makeRef(*this), request, completionHandler = WTFMove(completionHandler), info = WTFMove(info), storageKey, frameID, sessionID](auto record, auto timings) mutable { > info.storageTimings = timings; > > if (!record) { >@@ -332,13 +340,22 @@ void Cache::retrieve(const WebCore::ResourceRequest& request, const GlobalFrameI > > auto entry = Entry::decodeStorageRecord(*record); > >- auto useDecision = entry ? makeUseDecision(*entry, request) : UseDecision::NoDueToDecodeFailure; >+ std::optional<Seconds> maxAgeCap; >+#if HAVE(CFNETWORK_STORAGE_PARTITIONING) >+ if (auto networkStorageSession = WebCore::NetworkStorageSession::storageSession(sessionID)) >+ maxAgeCap = networkStorageSession->maxAgeCacheCap(request); >+#endif >+ auto useDecision = entry ? makeUseDecision(*entry, request, maxAgeCap) : UseDecision::NoDueToDecodeFailure; > switch (useDecision) { > case UseDecision::Use: > break; > case UseDecision::Validate: > entry->setNeedsValidation(true); > break; >+ case UseDecision::NoDueToPrevalentResourceAgeCap: >+ entry = nullptr; >+ m_storage->remove(storageKey); >+ break; > default: > entry = nullptr; > }; >diff --git a/Source/WebKit/NetworkProcess/cache/NetworkCache.h b/Source/WebKit/NetworkProcess/cache/NetworkCache.h >index cf5b7bbf2a4b3ca45a15a5b368858684992943c2..f15ad6bd0adc8c7358c1a949980d8409e62833a4 100644 >--- a/Source/WebKit/NetworkProcess/cache/NetworkCache.h >+++ b/Source/WebKit/NetworkProcess/cache/NetworkCache.h >@@ -82,6 +82,7 @@ enum class UseDecision { > NoDueToMissingValidatorFields, > NoDueToDecodeFailure, > NoDueToExpiredRedirect, >+ NoDueToPrevalentResourceAgeCap > }; > > using GlobalFrameID = std::pair<uint64_t /*webPageID*/, uint64_t /*webFrameID*/>; >@@ -112,7 +113,7 @@ public: > WTF_MAKE_FAST_ALLOCATED; > }; > using RetrieveCompletionHandler = Function<void (std::unique_ptr<Entry>, const RetrieveInfo&)>; >- void retrieve(const WebCore::ResourceRequest&, const GlobalFrameID&, RetrieveCompletionHandler&&); >+ void retrieve(const WebCore::ResourceRequest&, const GlobalFrameID&, PAL::SessionID, RetrieveCompletionHandler&&); > std::unique_ptr<Entry> store(const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, RefPtr<WebCore::SharedBuffer>&&, Function<void (MappedBody&)>&&); > std::unique_ptr<Entry> storeRedirect(const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, const WebCore::ResourceRequest& redirectRequest); > std::unique_ptr<Entry> update(const WebCore::ResourceRequest&, const GlobalFrameID&, const Entry&, const WebCore::ResourceResponse& validatingResponse); >diff --git a/Source/WebKit/NetworkProcess/cache/NetworkCacheStatistics.cpp b/Source/WebKit/NetworkProcess/cache/NetworkCacheStatistics.cpp >index 8ee745357bc988cb1eb19e0992f126458eba7027..a155e9f2e3ae1381443a4a0ce0b240757e4a69eb 100644 >--- a/Source/WebKit/NetworkProcess/cache/NetworkCacheStatistics.cpp >+++ b/Source/WebKit/NetworkProcess/cache/NetworkCacheStatistics.cpp >@@ -282,6 +282,7 @@ static String cachedEntryReuseFailureToDiagnosticKey(UseDecision decision) > return WebCore::DiagnosticLoggingKeys::missingValidatorFieldsKey(); > case UseDecision::NoDueToDecodeFailure: > case UseDecision::NoDueToExpiredRedirect: >+ case UseDecision::NoDueToPrevalentResourceAgeCap: > return WebCore::DiagnosticLoggingKeys::otherKey(); > case UseDecision::Use: > case UseDecision::Validate: >diff --git a/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp b/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp >index 7f23e90ff7c6e2ce4d54792c64a0b9623f2efe83..2464b0bda456da5b9fde29be01b9aeee5db6e066 100644 >--- a/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp >+++ b/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp >@@ -462,6 +462,13 @@ void WKWebsiteDataStoreStatisticsClearThroughWebsiteDataRemoval(WKWebsiteDataSto > }); > } > >+void WKWebsiteDataStoreSetStatisticsCacheMaxAgeCap(WKWebsiteDataStoreRef dataStoreRef, double seconds, void* context, WKWebsiteDataStoreSetStatisticsCacheMaxAgeCapFunction callback) >+{ >+ WebKit::toImpl(dataStoreRef)->websiteDataStore().setCacheMaxAgeCapForPrevalentResources(Seconds { seconds }, [context, callback] { >+ callback(context); >+ }); >+} >+ > void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreStatisticsResetToConsistentStateFunction completionHandler) > { > auto callbackAggregator = CallbackAggregator::create([context, completionHandler]() { >@@ -470,6 +477,7 @@ void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef da > > auto& store = WebKit::toImpl(dataStoreRef)->websiteDataStore(); > store.clearResourceLoadStatisticsInWebProcesses([callbackAggregator = callbackAggregator.copyRef()] { }); >+ store.resetCacheMaxAgeCapForPrevalentResources([callbackAggregator = callbackAggregator.copyRef()] { }); > > auto* statisticsStore = store.resourceLoadStatistics(); > if (!statisticsStore) >diff --git a/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h b/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h >index 02e7bce612ed153744daf96981f9835ed892d3c0..d7d899e43f75ac0d47b2cc8ed0075db89ada5765 100644 >--- a/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h >+++ b/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h >@@ -91,6 +91,8 @@ typedef void (*WKWebsiteDataStoreStatisticsClearInMemoryAndPersistentStoreModifi > WK_EXPORT void WKWebsiteDataStoreStatisticsClearInMemoryAndPersistentStoreModifiedSinceHours(WKWebsiteDataStoreRef dataStoreRef, unsigned hours, void* context, WKWebsiteDataStoreStatisticsClearInMemoryAndPersistentStoreModifiedSinceHoursFunction callback); > typedef void (*WKWebsiteDataStoreStatisticsClearThroughWebsiteDataRemovalFunction)(void* functionContext); > WK_EXPORT void WKWebsiteDataStoreStatisticsClearThroughWebsiteDataRemoval(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreStatisticsClearThroughWebsiteDataRemovalFunction callback); >+typedef void (*WKWebsiteDataStoreSetStatisticsCacheMaxAgeCapFunction)(void* functionContext); >+WK_EXPORT void WKWebsiteDataStoreSetStatisticsCacheMaxAgeCap(WKWebsiteDataStoreRef dataStoreRef, double seconds, void* context, WKWebsiteDataStoreSetStatisticsCacheMaxAgeCapFunction); > typedef void (*WKWebsiteDataStoreStatisticsResetToConsistentStateFunction)(void* functionContext); > WK_EXPORT void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreStatisticsResetToConsistentStateFunction completionHandler); > >diff --git a/Source/WebKit/UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm b/Source/WebKit/UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm >index bfeedf94caaf3da6fdbd2aa631fb8fc5e456719f..8d9d1bb2628962bf5c5a0fe9fb2bfc55976820a1 100644 >--- a/Source/WebKit/UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm >+++ b/Source/WebKit/UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm >@@ -52,6 +52,10 @@ void ResourceLoadStatisticsMemoryStore::registerUserDefaultsIfNeeded() > if (debugManualPrevalentResource) > setPrevalentResourceForDebugMode(debugManualPrevalentResource); > setStorageAccessPromptsEnabled([[NSUserDefaults standardUserDefaults] boolForKey:@"ExperimentalStorageAccessPromptsEnabled"]); >+ >+ Seconds cacheMaxAgeCapForPrevalentResources([[NSUserDefaults standardUserDefaults] doubleForKey:@"ResourceLoadStatisticsCacheMaxAgeCap"]); >+ if (cacheMaxAgeCapForPrevalentResources > 0_s && cacheMaxAgeCapForPrevalentResources <= 24_h * 365) >+ setCacheMaxAgeCap(cacheMaxAgeCapForPrevalentResources); > }); > } > >diff --git a/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp b/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp >index 56bfcac38d1d842c78d2968a70f9f321f2eb0582..f89c41c07b0143a7f4bd0006d420f72c1c9d8ce0 100644 >--- a/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp >+++ b/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp >@@ -404,15 +404,9 @@ void NetworkProcessProxy::didUpdateBlockCookies(uint64_t callbackId) > m_updateBlockCookiesCallbackMap.take(callbackId)(); > } > >-static uint64_t nextRequestStorageAccessContextId() >-{ >- static uint64_t nextContextId = 0; >- return ++nextContextId; >-} >- > void NetworkProcessProxy::hasStorageAccessForFrame(PAL::SessionID sessionID, const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID, WTF::CompletionHandler<void(bool)>&& callback) > { >- auto contextId = nextRequestStorageAccessContextId(); >+ auto contextId = generateCallbackID(); > auto addResult = m_storageAccessResponseCallbackMap.add(contextId, WTFMove(callback)); > ASSERT_UNUSED(addResult, addResult.isNewEntry); > send(Messages::NetworkProcess::HasStorageAccessForFrame(sessionID, resourceDomain, firstPartyDomain, frameID, pageID, contextId), 0); >@@ -420,7 +414,7 @@ void NetworkProcessProxy::hasStorageAccessForFrame(PAL::SessionID sessionID, con > > void NetworkProcessProxy::grantStorageAccess(PAL::SessionID sessionID, const String& resourceDomain, const String& firstPartyDomain, std::optional<uint64_t> frameID, uint64_t pageID, WTF::CompletionHandler<void(bool)>&& callback) > { >- auto contextId = nextRequestStorageAccessContextId(); >+ auto contextId = generateCallbackID(); > auto addResult = m_storageAccessResponseCallbackMap.add(contextId, WTFMove(callback)); > ASSERT_UNUSED(addResult, addResult.isNewEntry); > send(Messages::NetworkProcess::GrantStorageAccess(sessionID, resourceDomain, firstPartyDomain, frameID, pageID, contextId), 0); >@@ -439,7 +433,7 @@ void NetworkProcessProxy::removeAllStorageAccess(PAL::SessionID sessionID, Compl > return; > } > >- auto contextId = nextRequestStorageAccessContextId(); >+ auto contextId = generateCallbackID(); > auto addResult = m_removeAllStorageAccessCallbackMap.add(contextId, WTFMove(completionHandler)); > ASSERT_UNUSED(addResult, addResult.isNewEntry); > send(Messages::NetworkProcess::RemoveAllStorageAccess(sessionID, contextId), 0); >@@ -453,7 +447,7 @@ void NetworkProcessProxy::didRemoveAllStorageAccess(uint64_t contextId) > > void NetworkProcessProxy::getAllStorageAccessEntries(PAL::SessionID sessionID, CompletionHandler<void(Vector<String>&& domains)>&& callback) > { >- auto contextId = nextRequestStorageAccessContextId(); >+ auto contextId = generateCallbackID(); > auto addResult = m_allStorageAccessEntriesCallbackMap.add(contextId, WTFMove(callback)); > ASSERT_UNUSED(addResult, addResult.isNewEntry); > send(Messages::NetworkProcess::GetAllStorageAccessEntries(sessionID, contextId), 0); >@@ -464,6 +458,44 @@ void NetworkProcessProxy::allStorageAccessEntriesResult(Vector<String>&& domains > auto callback = m_allStorageAccessEntriesCallbackMap.take(contextId); > callback(WTFMove(domains)); > } >+ >+void NetworkProcessProxy::setCacheMaxAgeCapForPrevalentResources(PAL::SessionID sessionID, Seconds seconds, CompletionHandler<void()>&& completionHandler) >+{ >+ if (!canSendMessage()) { >+ completionHandler(); >+ return; >+ } >+ >+ auto contextId = generateCallbackID(); >+ auto addResult = m_updateRuntimeSettingsCallbackMap.add(contextId, WTFMove(completionHandler)); >+ ASSERT_UNUSED(addResult, addResult.isNewEntry); >+ send(Messages::NetworkProcess::SetCacheMaxAgeCapForPrevalentResources(sessionID, seconds, contextId), 0); >+} >+ >+void NetworkProcessProxy::didSetCacheMaxAgeCapForPrevalentResources(uint64_t contextId) >+{ >+ auto completionHandler = m_updateRuntimeSettingsCallbackMap.take(contextId); >+ completionHandler(); >+} >+ >+void NetworkProcessProxy::resetCacheMaxAgeCapForPrevalentResources(PAL::SessionID sessionID, CompletionHandler<void()>&& completionHandler) >+{ >+ if (!canSendMessage()) { >+ completionHandler(); >+ return; >+ } >+ >+ auto contextId = generateCallbackID(); >+ auto addResult = m_updateRuntimeSettingsCallbackMap.add(contextId, WTFMove(completionHandler)); >+ ASSERT_UNUSED(addResult, addResult.isNewEntry); >+ send(Messages::NetworkProcess::ResetCacheMaxAgeCapForPrevalentResources(sessionID, contextId), 0); >+} >+ >+void NetworkProcessProxy::didResetCacheMaxAgeCapForPrevalentResources(uint64_t contextId) >+{ >+ auto completionHandler = m_updateRuntimeSettingsCallbackMap.take(contextId); >+ completionHandler(); >+} > #endif > > void NetworkProcessProxy::sendProcessWillSuspendImminently() >diff --git a/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h b/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h >index 8354026d520600ff1d36dee4a3fc1f22891e4d1a..6f9648db8a0e707c0734d330234057ad1fa8e3a0 100644 >--- a/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h >+++ b/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h >@@ -83,6 +83,8 @@ public: > void getAllStorageAccessEntries(PAL::SessionID, CompletionHandler<void(Vector<String>&& domains)>&&); > void grantStorageAccess(PAL::SessionID, const String& resourceDomain, const String& firstPartyDomain, std::optional<uint64_t> frameID, uint64_t pageID, CompletionHandler<void(bool)>&& callback); > void removeAllStorageAccess(PAL::SessionID, CompletionHandler<void()>&&); >+ void setCacheMaxAgeCapForPrevalentResources(PAL::SessionID, Seconds, CompletionHandler<void()>&&); >+ void resetCacheMaxAgeCapForPrevalentResources(PAL::SessionID, CompletionHandler<void()>&&); > #endif > > void writeBlobToFilePath(const WebCore::URL&, const String& path, CompletionHandler<void(bool)>&& callback); >@@ -147,6 +149,8 @@ private: > void storageAccessRequestResult(bool wasGranted, uint64_t contextId); > void allStorageAccessEntriesResult(Vector<String>&& domains, uint64_t contextId); > void didRemoveAllStorageAccess(uint64_t contextId); >+ void didSetCacheMaxAgeCapForPrevalentResources(uint64_t contextId); >+ void didResetCacheMaxAgeCapForPrevalentResources(uint64_t contextId); > #endif > void retrieveCacheStorageParameters(PAL::SessionID); > >@@ -186,6 +190,8 @@ private: > HashMap<uint64_t, CompletionHandler<void()>> m_removeAllStorageAccessCallbackMap; > HashMap<uint64_t, CompletionHandler<void(Vector<String>&& domains)>> m_allStorageAccessEntriesCallbackMap; > >+ HashMap<uint64_t, CompletionHandler<void()>> m_updateRuntimeSettingsCallbackMap; >+ > #if ENABLE(CONTENT_EXTENSIONS) > HashSet<WebUserContentControllerProxy*> m_webUserContentControllerProxies; > #endif >diff --git a/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in b/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in >index 512dff20da3732f1b9bea711d73a347405abffbd..ae7f56e4d368fa8f59da8686f2fbc321a49cfe22 100644 >--- a/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in >+++ b/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in >@@ -46,6 +46,8 @@ messages -> NetworkProcessProxy LegacyReceiver { > StorageAccessRequestResult(bool wasGranted, uint64_t contextId) > AllStorageAccessEntriesResult(Vector<String> domains, uint64_t contextId) > DidRemoveAllStorageAccess(uint64_t contextId) >+ DidSetCacheMaxAgeCapForPrevalentResources(uint64_t contextId) >+ DidResetCacheMaxAgeCapForPrevalentResources(uint64_t contextId) > #endif > #if ENABLE(CONTENT_EXTENSIONS) > ContentExtensionRules(WebKit::UserContentControllerIdentifier identifier) >diff --git a/Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.cpp b/Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.cpp >index 14c837ad59d5d7e393726597320b56ae451985fe..4774eb1991b0efea6d8ef916978212f5d320023e 100644 >--- a/Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.cpp >+++ b/Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.cpp >@@ -832,6 +832,16 @@ void ResourceLoadStatisticsMemoryStore::setGrandfatheringTime(Seconds seconds) > m_parameters.grandfatheringTime = seconds; > } > >+void ResourceLoadStatisticsMemoryStore::setCacheMaxAgeCap(Seconds seconds) >+{ >+ ASSERT(!RunLoop::isMain()); >+ ASSERT(seconds >= 0_s); >+ >+ RunLoop::main().dispatch([store = makeRef(m_store), seconds] () { >+ store->setCacheMaxAgeCap(seconds, [] { }); >+ }); >+} >+ > bool ResourceLoadStatisticsMemoryStore::shouldRemoveDataRecords() const > { > ASSERT(!RunLoop::isMain()); >diff --git a/Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.h b/Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.h >index 634b82d1fe848e4175b4011d96c0531383dda5a4..b7082074ef0d099c57f417700a1577adf9ce4c99 100644 >--- a/Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.h >+++ b/Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.h >@@ -113,6 +113,7 @@ public: > void setTimeToLiveUserInteraction(Seconds); > void setMinimumTimeBetweenDataRecordsRemoval(Seconds); > void setGrandfatheringTime(Seconds); >+ void setCacheMaxAgeCap(Seconds); > void setResourceLoadStatisticsDebugMode(bool); > bool isDebugModeEnabled() const { return m_debugModeEnabled; }; > void setPrevalentResourceForDebugMode(const String& domain); >diff --git a/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp b/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp >index c7db69b15d1d48d7a4da378f986c445c02e32b37..11be04572f2e5b15e323049bd5deb20306822dd4 100644 >--- a/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp >+++ b/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp >@@ -833,6 +833,20 @@ void WebResourceLoadStatisticsStore::setGrandfatheringTime(Seconds seconds) > }); > } > >+void WebResourceLoadStatisticsStore::setCacheMaxAgeCap(Seconds seconds, CompletionHandler<void()>&& completionHandler) >+{ >+ ASSERT(RunLoop::isMain()); >+ ASSERT(seconds >= 0_s); >+ >+#if HAVE(CFNETWORK_STORAGE_PARTITIONING) >+ if (m_websiteDataStore) { >+ m_websiteDataStore->setCacheMaxAgeCapForPrevalentResources(seconds, WTFMove(completionHandler)); >+ return; >+ } >+#endif >+ completionHandler(); >+} >+ > void WebResourceLoadStatisticsStore::callUpdatePrevalentDomainsToBlockCookiesForHandler(const Vector<String>& domainsToBlock, ShouldClearFirst shouldClearFirst, CompletionHandler<void()>&& completionHandler) > { > ASSERT(RunLoop::isMain()); >diff --git a/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h b/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h >index f0f50a8cb5bcb1b87b512b24b29d9c17a19e4467..8bd1685c57f111366e63b3e60627f7a16f8200b2 100644 >--- a/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h >+++ b/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h >@@ -125,6 +125,7 @@ public: > void setTimeToLiveUserInteraction(Seconds); > void setMinimumTimeBetweenDataRecordsRemoval(Seconds); > void setGrandfatheringTime(Seconds); >+ void setCacheMaxAgeCap(Seconds, CompletionHandler<void()>&&); > void setMaxStatisticsEntries(size_t); > void setPruneEntriesDownTo(size_t); > >diff --git a/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp b/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp >index df21776daaf588072e75f511c671b94f9df70c8c..308718aa4aa35a0b2f7212ed01b7371fd2bf7435 100644 >--- a/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp >+++ b/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp >@@ -1342,6 +1342,35 @@ void WebsiteDataStore::grantStorageAccess(String&& subFrameHost, String&& topFra > } > #endif > >+void WebsiteDataStore::setCacheMaxAgeCapForPrevalentResources(Seconds seconds, CompletionHandler<void()>&& completionHandler) >+{ >+#if HAVE(CFNETWORK_STORAGE_PARTITIONING) >+ auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler)); >+ >+ for (auto& processPool : processPools()) { >+ if (auto* networkProcess = processPool->networkProcess()) >+ networkProcess->setCacheMaxAgeCapForPrevalentResources(m_sessionID, seconds, [callbackAggregator = callbackAggregator.copyRef()] { }); >+ } >+#else >+ UNUSED_PARAM(seconds); >+ completionHandler(); >+#endif >+} >+ >+void WebsiteDataStore::resetCacheMaxAgeCapForPrevalentResources(CompletionHandler<void()>&& completionHandler) >+{ >+#if HAVE(CFNETWORK_STORAGE_PARTITIONING) >+ auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler)); >+ >+ for (auto& processPool : processPools()) { >+ if (auto* networkProcess = processPool->networkProcess()) >+ networkProcess->resetCacheMaxAgeCapForPrevalentResources(m_sessionID, [callbackAggregator = callbackAggregator.copyRef()] { }); >+ } >+#else >+ completionHandler(); >+#endif >+} >+ > void WebsiteDataStore::networkProcessDidCrash() > { > #if HAVE(CFNETWORK_STORAGE_PARTITIONING) >diff --git a/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h b/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h >index a80ef16cebc97c479f3706bd07056a477278cda2..5569c9c5de480ad090630b1b279cf38b05958492 100644 >--- a/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h >+++ b/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h >@@ -143,6 +143,8 @@ public: > void requestStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool promptEnabled, CompletionHandler<void(StorageAccessStatus)>&&); > void grantStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool userWasPrompted, CompletionHandler<void(bool)>&&); > #endif >+ void setCacheMaxAgeCapForPrevalentResources(Seconds, CompletionHandler<void()>&&); >+ void resetCacheMaxAgeCapForPrevalentResources(CompletionHandler<void()>&&); > void networkProcessDidCrash(); > void resolveDirectoriesIfNecessary(); > const String& resolvedApplicationCacheDirectory() const { return m_resolvedConfiguration.applicationCacheDirectory; } >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 2767dbf827b6eb6488b3239c2403372b2b8f6b4a..7fc38343f4e88bda916e39d0b9565f4898c413e5 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,23 @@ >+2018-09-18 John Wilander <wilander@apple.com> >+ >+ Resource Load Statistics: Add optional cap on partitioned cache max age >+ https://bugs.webkit.org/show_bug.cgi?id=189711 >+ <rdar://problem/39246837> >+ >+ Reviewed by Antti Koivisto and Chris Dumez. >+ >+ This change adds infrastructure for layout tests of capped cache max age. >+ >+ * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: >+ * WebKitTestRunner/InjectedBundle/TestRunner.cpp: >+ (WTR::TestRunner::setStatisticsCacheMaxAgeCap): >+ * WebKitTestRunner/InjectedBundle/TestRunner.h: >+ * WebKitTestRunner/TestController.cpp: >+ (WTR::TestController::setStatisticsCacheMaxAgeCap): >+ * WebKitTestRunner/TestController.h: >+ * WebKitTestRunner/TestInvocation.cpp: >+ (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle): >+ > 2018-09-18 Jonathan Bedard <jbedard@apple.com> > > webkitpy: Clobbering and building occurs multiple times for iOS Simulator ports >diff --git a/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl b/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl >index 227bf1092dccc5bf890e5fcf1e4684b84b59cd8b..13de72065e6eac09bd107679da026d958e833557 100644 >--- a/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl >+++ b/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl >@@ -307,6 +307,7 @@ interface TestRunner { > void statisticsClearInMemoryAndPersistentStore(object callback); > void statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned long hours, object callback); > void statisticsClearThroughWebsiteDataRemoval(object callback); >+ void setStatisticsCacheMaxAgeCap(double seconds); > void statisticsResetToConsistentState(object completionHandler); > > // Injected bundle form client. >diff --git a/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp b/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp >index f70ee1311514194e65578da968d5d7c258cfd1aa..2c6168b2db05c8802161b30d5b7eed16e59fecc4 100644 >--- a/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp >+++ b/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp >@@ -1945,6 +1945,13 @@ void TestRunner::statisticsClearThroughWebsiteDataRemoval(JSValueRef callback) > WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr); > } > >+void TestRunner::setStatisticsCacheMaxAgeCap(double seconds) >+{ >+ WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetStatisticsCacheMaxAgeCap")); >+ WKRetainPtr<WKDoubleRef> messageBody(AdoptWK, WKDoubleCreate(seconds)); >+ WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); >+} >+ > void TestRunner::statisticsCallClearThroughWebsiteDataRemovalCallback() > { > callTestRunnerCallback(StatisticsDidClearThroughWebsiteDataRemovalCallbackID); >diff --git a/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h b/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h >index 95d596aa8e821283e60ed0cfd6e1796049eeb358..110ee85c176df0a4990c4e29de044de1a5c62d46 100644 >--- a/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h >+++ b/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h >@@ -421,6 +421,7 @@ public: > void statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned hours, JSValueRef callback); > void statisticsClearThroughWebsiteDataRemoval(JSValueRef callback); > void statisticsCallClearThroughWebsiteDataRemovalCallback(); >+ void setStatisticsCacheMaxAgeCap(double seconds); > void statisticsResetToConsistentState(JSValueRef completionHandler); > void statisticsCallDidResetToConsistentStateCallback(); > >diff --git a/Tools/WebKitTestRunner/TestController.cpp b/Tools/WebKitTestRunner/TestController.cpp >index 3f3ba2a5123f3fea0e55741de1c4039aaf1b61e0..4764ec8184e8a68caa6f3788e9fb5c40ba1fdd73 100644 >--- a/Tools/WebKitTestRunner/TestController.cpp >+++ b/Tools/WebKitTestRunner/TestController.cpp >@@ -3122,6 +3122,14 @@ void TestController::statisticsClearThroughWebsiteDataRemoval() > m_currentInvocation->didClearStatisticsThroughWebsiteDataRemoval(); > } > >+void TestController::setStatisticsCacheMaxAgeCap(double seconds) >+{ >+ auto* dataStore = WKContextGetWebsiteDataStore(platformContext()); >+ ResourceStatisticsCallbackContext context(*this); >+ WKWebsiteDataStoreSetStatisticsCacheMaxAgeCap(dataStore, seconds, &context, resourceStatisticsVoidResultCallback); >+ runUntil(context.done, noTimeout); >+} >+ > void TestController::statisticsResetToConsistentState() > { > auto* dataStore = WKContextGetWebsiteDataStore(platformContext()); >diff --git a/Tools/WebKitTestRunner/TestController.h b/Tools/WebKitTestRunner/TestController.h >index a1fe510f18edbba9e9964e9e671429a100d18fd6..7661f5e5904e466af5002f711f99283badea4f94 100644 >--- a/Tools/WebKitTestRunner/TestController.h >+++ b/Tools/WebKitTestRunner/TestController.h >@@ -221,6 +221,7 @@ public: > void statisticsClearInMemoryAndPersistentStore(); > void statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned); > void statisticsClearThroughWebsiteDataRemoval(); >+ void setStatisticsCacheMaxAgeCap(double seconds); > void statisticsResetToConsistentState(); > > void getAllStorageAccessEntries(); >diff --git a/Tools/WebKitTestRunner/TestInvocation.cpp b/Tools/WebKitTestRunner/TestInvocation.cpp >index 550f9d3398c7fcdb388fdd82281553b8ef84873c..ecfd6cc62c0523b46f35555b02405db64f85ba68 100644 >--- a/Tools/WebKitTestRunner/TestInvocation.cpp >+++ b/Tools/WebKitTestRunner/TestInvocation.cpp >@@ -1358,6 +1358,13 @@ WKRetainPtr<WKTypeRef> TestInvocation::didReceiveSynchronousMessageFromInjectedB > return nullptr; > } > >+ if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsCacheMaxAgeCap")) { >+ ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID()); >+ WKDoubleRef seconds = static_cast<WKDoubleRef>(messageBody); >+ TestController::singleton().setStatisticsCacheMaxAgeCap(WKDoubleGetValue(seconds)); >+ return nullptr; >+ } >+ > if (WKStringIsEqualToUTF8CString(messageName, "StatisticsResetToConsistentState")) { > if (m_shouldDumpResourceLoadStatistics) > m_savedResourceLoadStatistics = TestController::singleton().dumpResourceLoadStatistics(); >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 4b81bc1389b11ccccc9f461969266fa1514153c8..7cd545469af3d333bb7b5d90ac72b5b15ea1ba4f 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,22 @@ >+2018-09-18 John Wilander <wilander@apple.com> >+ >+ Resource Load Statistics: Add optional cap on partitioned cache max age >+ https://bugs.webkit.org/show_bug.cgi?id=189711 >+ <rdar://problem/39246837> >+ >+ Reviewed by Antti Koivisto and Chris Dumez. >+ >+ * http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-expected.txt: Added. >+ * http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource.html: Added. >+ * http/tests/resourceLoadStatistics/resources/cached-permanent-redirect.php: Added. >+ * http/tests/resourceLoadStatistics/resources/echo-query.php: Added. >+ * platform/ios/TestExpectations: >+ New test marked as [ Pass ]. >+ * platform/mac-wk2/TestExpectations: >+ New test marked as [ Pass ]. >+ * platform/wk2/TestExpectations: >+ New test marked as [ Skip ] because it's not supported on non-Cocoa platforms. >+ > 2018-09-18 Youenn Fablet <youenn@apple.com> > > Enable Unified Plan by default >diff --git a/LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..63c6069f643675d201dd61186873cad51006e7cb >--- /dev/null >+++ b/LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-expected.txt >@@ -0,0 +1,11 @@ >+Tests that cache max-age is capped for prevalent resources. >+ >+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". >+ >+ >+PASS loadedUrl is "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value=1234" >+PASS loadedUrl is "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value=" >+PASS successfullyParsed is true >+ >+TEST COMPLETE >+ >diff --git a/LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource.html b/LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource.html >new file mode 100644 >index 0000000000000000000000000000000000000000..08b82bbfb5475005721df83daf7dd832afdc8955 >--- /dev/null >+++ b/LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource.html >@@ -0,0 +1,60 @@ >+<!DOCTYPE html> >+<html> >+<head> >+ <script src="/js-test-resources/js-test.js"></script> >+ <script src="resources/util.js"></script> >+ <title>Tests for Capped Cache Max-Age</title> >+</head> >+<body> >+<script> >+ description("Tests that cache max-age is capped for prevalent resources."); >+ jsTestIsAsync = true; >+ >+ var loadedUrl; >+ function firstFetch() { >+ // This should create a capped cache entry. >+ fetch("http://localhost:8000/resourceLoadStatistics/resources/cached-permanent-redirect.php", >+ { >+ cache: "reload", >+ headers: { >+ "X-WebKit": "1234", >+ } >+ } >+ ).then(function(response) { >+ loadedUrl = response.url; >+ shouldBeEqualToString("loadedUrl", "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value=1234"); >+ secondFetch(); >+ }).catch(function(error) { >+ testFailed(error.message); >+ setEnableFeature(false, finishJSTest); >+ }); >+ } >+ >+ function secondFetch() { >+ // This should not trigger a successful cache hit. >+ fetch("http://localhost:8000/resourceLoadStatistics/resources/cached-permanent-redirect.php", >+ { >+ cache: "force-cache", >+ } >+ ).then(function(response) { >+ loadedUrl = response.url; >+ shouldBeEqualToString("loadedUrl", "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value="); >+ setEnableFeature(false, finishJSTest); >+ }).catch(function(error) { >+ testFailed(error.message); >+ setEnableFeature(false, finishJSTest); >+ }); >+ } >+ >+ setEnableFeature(true, function() { >+ if (testRunner.isStatisticsPrevalentResource("http://localhost")) >+ testFailed("Localhost was classified as prevalent resource before the test started."); >+ >+ testRunner.setStatisticsCacheMaxAgeCap(0); >+ testRunner.setStatisticsPrevalentResource("http://localhost", true, function() { >+ testRunner.statisticsUpdateCookieBlocking(firstFetch); >+ }); >+ }); >+</script> >+</body> >+</html> >diff --git a/LayoutTests/http/tests/resourceLoadStatistics/resources/cached-permanent-redirect.php b/LayoutTests/http/tests/resourceLoadStatistics/resources/cached-permanent-redirect.php >new file mode 100644 >index 0000000000000000000000000000000000000000..947ed3b9f84b09f99b6068bdfe5425031f03fb7d >--- /dev/null >+++ b/LayoutTests/http/tests/resourceLoadStatistics/resources/cached-permanent-redirect.php >@@ -0,0 +1,12 @@ >+<?php >+header("Access-Control-Allow-Origin: http://127.0.0.1:8000"); >+header("Access-Control-Allow-Headers: X-WebKit"); >+if ($_SERVER["REQUEST_METHOD"] == "OPTIONS" && isset($_SERVER["HTTP_ACCESS_CONTROL_REQUEST_METHOD"]) && $_SERVER["HTTP_ACCESS_CONTROL_REQUEST_METHOD"] == "GET") { >+ exit; >+} >+$headerStringValue = $_SERVER["HTTP_X_WEBKIT"]; >+header("HTTP/1.1 301 Moved Permanently"); >+header("Cache-Control: private, max-age=31536000", true); >+header('ETag: "WebKitTest"', true); >+header("Location: http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value=" . $headerStringValue); >+?> >\ No newline at end of file >diff --git a/LayoutTests/http/tests/resourceLoadStatistics/resources/echo-query.php b/LayoutTests/http/tests/resourceLoadStatistics/resources/echo-query.php >new file mode 100644 >index 0000000000000000000000000000000000000000..6f0a5735254bce404dd247a5aa00fb991bc46e0a >--- /dev/null >+++ b/LayoutTests/http/tests/resourceLoadStatistics/resources/echo-query.php >@@ -0,0 +1,9 @@ >+<?php >+header("Access-Control-Allow-Origin: http://127.0.0.1:8000"); >+header("Access-Control-Allow-Headers: X-WebKit"); >+if(isset($_GET["value"])) { >+ echo $_GET["value"]; >+} else { >+ echo "No query parameter named 'value.'"; >+} >+?> >\ No newline at end of file >diff --git a/LayoutTests/platform/ios/TestExpectations b/LayoutTests/platform/ios/TestExpectations >index 58d68b1fddd439f4365c800edeec85c463de318a..1eb66f1a268a57df08e7b393b1092ed277465bea 100644 >--- a/LayoutTests/platform/ios/TestExpectations >+++ b/LayoutTests/platform/ios/TestExpectations >@@ -2830,6 +2830,7 @@ http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subreso > http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html [ Pass ] > http/tests/storageAccess/deny-storage-access-under-opener.html [ Pass ] > http/tests/storageAccess/grant-storage-access-under-opener.html [ Pass ] >+http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource.html [ Pass ] > > # Skipped in general expectations since they only work on iOS and Mac, WK2. > http/tests/security/strip-referrer-to-origin-for-third-party-redirects-in-private-mode.html [ Pass ] >diff --git a/LayoutTests/platform/mac-wk2/TestExpectations b/LayoutTests/platform/mac-wk2/TestExpectations >index a74d475d684988fc748a8a88e22d9cd8d0f10c03..6ba64c898ebe624a69adb73e12cc3e991264f501 100644 >--- a/LayoutTests/platform/mac-wk2/TestExpectations >+++ b/LayoutTests/platform/mac-wk2/TestExpectations >@@ -763,6 +763,7 @@ webkit.org/b/185994 [ Debug ] fast/text/user-installed-fonts/shadow-postscript-f > [ HighSierra+ ] http/tests/resourceLoadStatistics/grandfathering.html [ Pass ] > [ HighSierra+ ] http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html [ Pass ] > [ HighSierra+ ] http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html [ Pass ] >+[ HighSierra+ ] http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource.html [ Pass ] > > # Skipped in general expectations since they only work on iOS and Mac, WK2. > http/tests/security/strip-referrer-to-origin-for-third-party-redirects-in-private-mode.html [ Pass ] >diff --git a/LayoutTests/platform/wk2/TestExpectations b/LayoutTests/platform/wk2/TestExpectations >index 89270a157efc770a877833e48cf632d8f2c61f3f..40bf53714cd5e221a6f9afa5e4447a4c07414730 100644 >--- a/LayoutTests/platform/wk2/TestExpectations >+++ b/LayoutTests/platform/wk2/TestExpectations >@@ -730,6 +730,7 @@ http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subreso > http/tests/resourceLoadStatistics/add-blocking-to-redirect.html [ Skip ] > http/tests/resourceLoadStatistics/remove-blocking-in-redirect.html [ Skip ] > http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html [ Skip ] >+http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource.html [ Skip ] > > # Process swapping is only implemented on WebKit2. > http/tests/navigation/process-swap-window-open.html [ Pass ]
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189711
:
350075
|
350077
|
350079
|
350080
| 350137