ResourceLoadStatistics grandfathering happens much too often.
<rdar://problem/
32655834> and https://bugs.webkit.org/show_bug.cgi?id=174825
Reviewed by Chris Dumez.
Source/WebKit:
The ResourceLoadStatistics grandfathering procedure happens too often.
- With an empty memory store, even though an empty memory store is a perfectly valid state.
- On each launch, even if grandfathering happened on the last launch - because grandfathering
data would not automatically be saved to disk.
- After clearing all website data, at which point no grandfathering can possibly be relevant
because there is no data to grandfather.
This patch fixes those cases and adds API tests to verify they remain fixed.
* Shared/WebsiteData/WebsiteDataType.h:
* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(+[WKWebsiteDataStore _allWebsiteDataTypesIncludingPrivate]): allWebsiteDataTypes, but even with the private ones.
(-[WKWebsiteDataStore _resourceLoadStatisticsClearInMemoryAndPersistentStore]): If the types being cleared cover all of
the types that ResourceLoadStatistics care about, don't grandfather afterwards.
(-[WKWebsiteDataStore _resourceLoadStatisticsClearInMemoryAndPersistentStoreModifiedSinceHours:]): Ditto.
(-[WKWebsiteDataStore _setResourceLoadStatisticsTestingCallback:]):
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
* UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.cpp:
(WebKit::ResourceLoadStatisticsPersistentStorage::populateMemoryStoreFromDisk): Don't grandfather if the store read from
disk is empty (as being empty is perfectly fine), and also log the event of "populated without grandfathering".
* UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::topPrivatelyControlledDomainsWithWebsiteData):
* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::monitoredDataTypes):
(WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
(WebKit::WebResourceLoadStatisticsStore::~WebResourceLoadStatisticsStore):
(WebKit::WebResourceLoadStatisticsStore::removeDataRecords):
(WebKit::WebResourceLoadStatisticsStore::grandfatherExistingWebsiteData): Schedule a write right away so we don't re-grandfather
on next launch, and also log the grandfathering event.
(WebKit::WebResourceLoadStatisticsStore::scheduleClearInMemoryAndPersistent): Takes a ShouldGrandfather flag
to tell whether or not data should be re-grandfathered after the store is cleared.
(WebKit::WebResourceLoadStatisticsStore::logTestingEvent): Log the event to the testing client.
(WebKit::dataTypesToRemove): Deleted.
* UIProcess/WebResourceLoadStatisticsStore.h:
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::removeData):
(WebKit::WebsiteDataStore::setResourceLoadStatisticsEnabled):
(WebKit::WebsiteDataStore::enableResourceLoadStatisticsAndSetTestingCallback): Handles enabling ResourceLoadStatistics both
with and without a testing callback.
* UIProcess/WebsiteData/WebsiteDataStore.h:
Tools:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/EmptyGrandfatheredResourceLoadStatistics.plist: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/ResourceLoadStatistics.mm: Added.
(TEST):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219904
268f45cc-cd09-0410-ab3c-
d52691b4dbfc