ResourceLoadStatistics grandfathering happens much too often.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jul 2017 05:44:05 +0000 (05:44 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jul 2017 05:44:05 +0000 (05:44 +0000)
commit9f4c6a3180ec803aac01989f1e1e41bd7c100a89
treeb564745735199a887ab0b449538a58362aa09ac6
parent3d71b84c36b3ec5ff672c405fbed3168049534aa
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
15 files changed:
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebsiteData/WebsiteDataType.h
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h
Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.cpp
Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.h
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/EmptyGrandfatheredResourceLoadStatistics.plist [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ResourceLoadStatistics.mm [new file with mode: 0644]