Title: [219297] trunk
Revision
219297
Author
cdu...@apple.com
Date
2017-07-10 10:09:38 -0700 (Mon, 10 Jul 2017)

Log Message

Further WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore clean up
https://bugs.webkit.org/show_bug.cgi?id=174301

Reviewed by Brent Fulgham.

Source/WebCore:

Moved some generic file system utility functions down to platform's FileSystem.h.

* platform/FileSystem.cpp:
(WebCore::openAndLockFile):
(WebCore::unlockAndCloseFile):
* platform/FileSystem.h:

Source/WebKit2:

General clean up and various simplifications / optimizations to WebResourceLoadStatisticsStore
and ResourceLoadStatisticsStore classes.

* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _resourceLoadStatisticsUpdateCookiePartitioning]):
(-[WKWebsiteDataStore _resourceLoadStatisticsSetShouldPartitionCookies:forHost:]):
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
* UIProcess/Storage/ResourceLoadStatisticsStore.cpp:
(WebKit::ResourceLoadStatisticsStore::create):
(WebKit::ResourceLoadStatisticsStore::ResourceLoadStatisticsStore):
(WebKit::ResourceLoadStatisticsStore::hasHadRecentUserInteraction):
(WebKit::ResourceLoadStatisticsStore::createEncoderFromData):
(WebKit::ResourceLoadStatisticsStore::populateFromDecoder):
(WebKit::ResourceLoadStatisticsStore::clearInMemory):
(WebKit::ResourceLoadStatisticsStore::mergeStatistics):
(WebKit::ResourceLoadStatisticsStore::updateCookiePartitioning):
(WebKit::ResourceLoadStatisticsStore::updateCookiePartitioningForDomains):
(WebKit::ResourceLoadStatisticsStore::processStatistics):
(WebKit::ResourceLoadStatisticsStore::hasHadUnexpiredRecentUserInteraction):
(WebKit::ResourceLoadStatisticsStore::topPrivatelyControlledDomainsToRemoveWebsiteDataFor):
* UIProcess/Storage/ResourceLoadStatisticsStore.h:
* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
(WebKit::WebResourceLoadStatisticsStore::~WebResourceLoadStatisticsStore):
(WebKit::WebResourceLoadStatisticsStore::removeDataRecords):
(WebKit::WebResourceLoadStatisticsStore::processStatisticsAndDataRecords):
(WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
(WebKit::WebResourceLoadStatisticsStore::grandfatherExistingWebsiteData):
(WebKit::WebResourceLoadStatisticsStore::readDataFromDiskIfNeeded):
(WebKit::WebResourceLoadStatisticsStore::refreshFromDisk):
(WebKit::WebResourceLoadStatisticsStore::applicationWillTerminate):
(WebKit::WebResourceLoadStatisticsStore::resourceLogFilePath):
(WebKit::WebResourceLoadStatisticsStore::writeStoreToDisk):
(WebKit::WebResourceLoadStatisticsStore::scheduleOrWriteStoreToDisk):
(WebKit::WebResourceLoadStatisticsStore::writeEncoderToDisk):
(WebKit::WebResourceLoadStatisticsStore::startMonitoringStatisticsStorage):
(WebKit::WebResourceLoadStatisticsStore::platformExcludeFromBackup):
(WebKit::WebResourceLoadStatisticsStore::createDecoderFromDisk):
(WebKit::WebResourceLoadStatisticsStore::performDailyTasks):
(WebKit::WebResourceLoadStatisticsStore::logUserInteraction):
(WebKit::WebResourceLoadStatisticsStore::hasHadUserInteraction):
(WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioning):
(WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioningForDomains):
(WebKit::WebResourceLoadStatisticsStore::clearInMemory):
(WebKit::WebResourceLoadStatisticsStore::clearInMemoryAndPersistent):
(WebKit::WebResourceLoadStatisticsStore::shouldRemoveDataRecords):
(WebKit::WebResourceLoadStatisticsStore::setDataRecordsBeingRemoved):
* UIProcess/WebResourceLoadStatisticsStore.h:
* UIProcess/WebResourceLoadStatisticsTelemetry.cpp:
(WebKit::sortedPrevalentResourceTelemetry):
(WebKit::WebResourceLoadStatisticsTelemetry::calculateAndSubmit):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::updateCookiePartitioningForTopPrivatelyOwnedDomains):
(WebKit::WebsiteDataStore::setResourceLoadStatisticsEnabled):
* UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

Rename some of the testRunner API for clarity and to better match what it calls
internally.

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::statisticsUpdateCookiePartitioning):
(WTR::TestRunner::statisticsSetShouldPartitionCookiesForHost):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::statisticsUpdateCookiePartitioning):
(WTR::TestController::statisticsSetShouldPartitionCookiesForHost):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
* WebKitTestRunner/cocoa/TestControllerCocoa.mm:
(WTR::TestController::statisticsUpdateCookiePartitioning):
(WTR::TestController::statisticsSetShouldPartitionCookiesForHost):

LayoutTests:

Update existing layout tests to reflect testRunner API changes.

* http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html:
* http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html:
* http/tests/loading/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (219296 => 219297)


--- trunk/LayoutTests/ChangeLog	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/LayoutTests/ChangeLog	2017-07-10 17:09:38 UTC (rev 219297)
@@ -1,3 +1,16 @@
+2017-07-10  Chris Dumez  <cdu...@apple.com>
+
+        Further WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore clean up
+        https://bugs.webkit.org/show_bug.cgi?id=174301
+
+        Reviewed by Brent Fulgham.
+
+        Update existing layout tests to reflect testRunner API changes.
+
+        * http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html:
+        * http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html:
+        * http/tests/loading/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html:
+
 2017-07-10  Andreas Kling  <akl...@apple.com>
 
         REGRESSION(r210226): Keyboard-focused element not preserved when navigating back through page cache, causing multiple elements to have focus

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html (219296 => 219297)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html	2017-07-10 17:09:38 UTC (rev 219297)
@@ -93,7 +93,7 @@
         testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
         testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
 
-        testRunner.statisticsFireShouldPartitionCookiesHandlerForOneDomain("localhost", true);
+        testRunner.statisticsUpdateCookiePartitioningForOneDomain("localhost", true);
         testRunner.setStatisticsPrevalentResource("http://localhost", true);
         if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
             testFailed("Host did not get set as prevalent resource.");

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html (219296 => 219297)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html	2017-07-10 17:09:38 UTC (rev 219297)
@@ -40,7 +40,7 @@
     }
 
     function fireShouldPartitionCookiesHandlerAndContinue() {
-        testRunner.statisticsFireShouldPartitionCookiesHandler();
+        testRunner.statisticsUpdateCookiePartitioning();
         runTest();
     }
 
@@ -115,7 +115,7 @@
         if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
             testFailed("Host did not get set as prevalent resource.");
 
-        testRunner.statisticsFireShouldPartitionCookiesHandler();
+        testRunner.statisticsUpdateCookiePartitioning();
 
         testRunner.waitUntilDone();
         testRunner.dumpChildFramesAsText();

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html (219296 => 219297)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html	2017-07-10 17:09:38 UTC (rev 219297)
@@ -73,7 +73,7 @@
     if (document.location.host === partitionHost && document.location.hash == "" && window.testRunner && window.internals) {
         setEnableFeature(true);
 
-        testRunner.statisticsFireShouldPartitionCookiesHandlerForOneDomain("localhost", true);
+        testRunner.statisticsUpdateCookiePartitioningForOneDomain("localhost", true);
 
         testRunner.waitUntilDone();
         testRunner.dumpChildFramesAsText();

Modified: trunk/Source/WebCore/ChangeLog (219296 => 219297)


--- trunk/Source/WebCore/ChangeLog	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebCore/ChangeLog	2017-07-10 17:09:38 UTC (rev 219297)
@@ -1,3 +1,17 @@
+2017-07-10  Chris Dumez  <cdu...@apple.com>
+
+        Further WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore clean up
+        https://bugs.webkit.org/show_bug.cgi?id=174301
+
+        Reviewed by Brent Fulgham.
+
+        Moved some generic file system utility functions down to platform's FileSystem.h.
+
+        * platform/FileSystem.cpp:
+        (WebCore::openAndLockFile):
+        (WebCore::unlockAndCloseFile):
+        * platform/FileSystem.h:
+
 2017-07-10  Andreas Kling  <akl...@apple.com>
 
         REGRESSION(r210226): Keyboard-focused element not preserved when navigating back through page cache, causing multiple elements to have focus

Modified: trunk/Source/WebCore/Modules/webdatabase/OriginLock.cpp (219296 => 219297)


--- trunk/Source/WebCore/Modules/webdatabase/OriginLock.cpp	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebCore/Modules/webdatabase/OriginLock.cpp	2017-07-10 17:09:38 UTC (rev 219297)
@@ -52,7 +52,7 @@
     m_mutex.lock();
 
 #if USE(FILE_LOCK)
-    m_lockHandle = openFile(m_lockFileName, OpenForWrite);
+    m_lockHandle = openAndLockFile(m_lockFileName, OpenForWrite);
     if (m_lockHandle == invalidPlatformFileHandle) {
         // The only way we can get here is if the directory containing the lock
         // has been deleted or we were given a path to a non-existant directory.
@@ -60,8 +60,6 @@
         m_mutex.unlock();
         return;
     }
-
-    lockFile(m_lockHandle, LockExclusive);
 #endif
 }
 
@@ -75,9 +73,7 @@
     if (m_lockHandle == invalidPlatformFileHandle) 
         return;
 
-    unlockFile(m_lockHandle);
-
-    closeFile(m_lockHandle);
+    unlockAndCloseFile(m_lockHandle);
     m_lockHandle = invalidPlatformFileHandle;
 #endif
 

Modified: trunk/Source/WebCore/platform/FileSystem.cpp (219296 => 219297)


--- trunk/Source/WebCore/platform/FileSystem.cpp	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebCore/platform/FileSystem.cpp	2017-07-10 17:09:38 UTC (rev 219297)
@@ -327,4 +327,27 @@
 #endif
 }
 
+PlatformFileHandle openAndLockFile(const String& path, FileOpenMode openMode, FileLockMode lockMode)
+{
+    auto handle = openFile(path, openMode);
+    if (handle == invalidPlatformFileHandle)
+        return invalidPlatformFileHandle;
+
+#if USE(FILE_LOCK)
+    bool locked = lockFile(handle, lockMode);
+    ASSERT_UNUSED(locked, locked);
+#endif
+
+    return handle;
+}
+
+void unlockAndCloseFile(PlatformFileHandle handle)
+{
+#if USE(FILE_LOCK)
+    bool unlocked = unlockFile(handle);
+    ASSERT_UNUSED(unlocked, unlocked);
+#endif
+    closeFile(handle);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/FileSystem.h (219296 => 219297)


--- trunk/Source/WebCore/platform/FileSystem.h	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebCore/platform/FileSystem.h	2017-07-10 17:09:38 UTC (rev 219297)
@@ -135,6 +135,9 @@
 // Returns number of bytes actually written if successful, -1 otherwise.
 WEBCORE_EXPORT int readFromFile(PlatformFileHandle, char* data, int length);
 
+WEBCORE_EXPORT PlatformFileHandle openAndLockFile(const String&, FileOpenMode, FileLockMode = LockExclusive);
+WEBCORE_EXPORT void unlockAndCloseFile(PlatformFileHandle);
+
 // Appends the contents of the file found at 'path' to the open PlatformFileHandle.
 // Returns true if the write was successful, false if it was not.
 bool appendFileContentsToFileHandle(const String& path, PlatformFileHandle&);

Modified: trunk/Source/WebKit2/ChangeLog (219296 => 219297)


--- trunk/Source/WebKit2/ChangeLog	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebKit2/ChangeLog	2017-07-10 17:09:38 UTC (rev 219297)
@@ -1,3 +1,66 @@
+2017-07-10  Chris Dumez  <cdu...@apple.com>
+
+        Further WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore clean up
+        https://bugs.webkit.org/show_bug.cgi?id=174301
+
+        Reviewed by Brent Fulgham.
+
+        General clean up and various simplifications / optimizations to WebResourceLoadStatisticsStore
+        and ResourceLoadStatisticsStore classes.
+
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore _resourceLoadStatisticsUpdateCookiePartitioning]):
+        (-[WKWebsiteDataStore _resourceLoadStatisticsSetShouldPartitionCookies:forHost:]):
+        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+        * UIProcess/Storage/ResourceLoadStatisticsStore.cpp:
+        (WebKit::ResourceLoadStatisticsStore::create):
+        (WebKit::ResourceLoadStatisticsStore::ResourceLoadStatisticsStore):
+        (WebKit::ResourceLoadStatisticsStore::hasHadRecentUserInteraction):
+        (WebKit::ResourceLoadStatisticsStore::createEncoderFromData):
+        (WebKit::ResourceLoadStatisticsStore::populateFromDecoder):
+        (WebKit::ResourceLoadStatisticsStore::clearInMemory):
+        (WebKit::ResourceLoadStatisticsStore::mergeStatistics):
+        (WebKit::ResourceLoadStatisticsStore::updateCookiePartitioning):
+        (WebKit::ResourceLoadStatisticsStore::updateCookiePartitioningForDomains):
+        (WebKit::ResourceLoadStatisticsStore::processStatistics):
+        (WebKit::ResourceLoadStatisticsStore::hasHadUnexpiredRecentUserInteraction):
+        (WebKit::ResourceLoadStatisticsStore::topPrivatelyControlledDomainsToRemoveWebsiteDataFor):
+        * UIProcess/Storage/ResourceLoadStatisticsStore.h:
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
+        (WebKit::WebResourceLoadStatisticsStore::~WebResourceLoadStatisticsStore):
+        (WebKit::WebResourceLoadStatisticsStore::removeDataRecords):
+        (WebKit::WebResourceLoadStatisticsStore::processStatisticsAndDataRecords):
+        (WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
+        (WebKit::WebResourceLoadStatisticsStore::grandfatherExistingWebsiteData):
+        (WebKit::WebResourceLoadStatisticsStore::readDataFromDiskIfNeeded):
+        (WebKit::WebResourceLoadStatisticsStore::refreshFromDisk):
+        (WebKit::WebResourceLoadStatisticsStore::applicationWillTerminate):
+        (WebKit::WebResourceLoadStatisticsStore::resourceLogFilePath):
+        (WebKit::WebResourceLoadStatisticsStore::writeStoreToDisk):
+        (WebKit::WebResourceLoadStatisticsStore::scheduleOrWriteStoreToDisk):
+        (WebKit::WebResourceLoadStatisticsStore::writeEncoderToDisk):
+        (WebKit::WebResourceLoadStatisticsStore::startMonitoringStatisticsStorage):
+        (WebKit::WebResourceLoadStatisticsStore::platformExcludeFromBackup):
+        (WebKit::WebResourceLoadStatisticsStore::createDecoderFromDisk):
+        (WebKit::WebResourceLoadStatisticsStore::performDailyTasks):
+        (WebKit::WebResourceLoadStatisticsStore::logUserInteraction):
+        (WebKit::WebResourceLoadStatisticsStore::hasHadUserInteraction):
+        (WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioning):
+        (WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioningForDomains):
+        (WebKit::WebResourceLoadStatisticsStore::clearInMemory):
+        (WebKit::WebResourceLoadStatisticsStore::clearInMemoryAndPersistent):
+        (WebKit::WebResourceLoadStatisticsStore::shouldRemoveDataRecords):
+        (WebKit::WebResourceLoadStatisticsStore::setDataRecordsBeingRemoved):
+        * UIProcess/WebResourceLoadStatisticsStore.h:
+        * UIProcess/WebResourceLoadStatisticsTelemetry.cpp:
+        (WebKit::sortedPrevalentResourceTelemetry):
+        (WebKit::WebResourceLoadStatisticsTelemetry::calculateAndSubmit):
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::updateCookiePartitioningForTopPrivatelyOwnedDomains):
+        (WebKit::WebsiteDataStore::setResourceLoadStatisticsEnabled):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
 2017-07-10  Michael Catanzaro  <mcatanz...@igalia.com>
 
         [SOUP] Remove WebKitSoupCookieJarSqlite

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (219296 => 219297)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2017-07-10 17:09:38 UTC (rev 219297)
@@ -354,16 +354,16 @@
     store->processStatisticsAndDataRecords();
 }
 
-- (void)_resourceLoadStatisticsFireShouldPartitionCookiesHandler
+- (void)_resourceLoadStatisticsUpdateCookiePartitioning
 {
     auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
     if (!store)
         return;
 
-    store->fireShouldPartitionCookiesHandler();
+    store->updateCookiePartitioning();
 }
 
-- (void)_resourceLoadStatisticsFireShouldPartitionCookiesHandlerForOneDomain:(BOOL)value forHost:(NSString *)host
+- (void)_resourceLoadStatisticsSetShouldPartitionCookies:(BOOL)value forHost:(NSString *)host
 {
     auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
     if (!store)
@@ -370,9 +370,9 @@
         return;
 
     if (value)
-        store->fireShouldPartitionCookiesHandler({ }, { host }, false);
+        store->updateCookiePartitioningForDomains({ }, { host }, WebKit::ShouldClearFirst::No);
     else
-        store->fireShouldPartitionCookiesHandler({ host }, { }, false);
+        store->updateCookiePartitioningForDomains({ host }, { }, WebKit::ShouldClearFirst::No);
 }
 
 - (void)_resourceLoadStatisticsSubmitTelemetry

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h (219296 => 219297)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2017-07-10 17:09:38 UTC (rev 219297)
@@ -58,8 +58,8 @@
 - (void)_resourceLoadStatisticsSetMinimumTimeBetweenDataRecordsRemoval:(double)seconds WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_resourceLoadStatisticsSetGrandfatheringTime:(double)seconds WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_resourceLoadStatisticsProcessStatisticsAndDataRecords WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
-- (void)_resourceLoadStatisticsFireShouldPartitionCookiesHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
-- (void)_resourceLoadStatisticsFireShouldPartitionCookiesHandlerForOneDomain:(BOOL)value forHost:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsUpdateCookiePartitioning WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_resourceLoadStatisticsSetShouldPartitionCookies:(BOOL)value forHost:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_resourceLoadStatisticsSubmitTelemetry WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_resourceLoadStatisticsSetNotifyPagesWhenDataRecordsWereScanned:(BOOL)value WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_resourceLoadStatisticsSetShouldClassifyResourcesBeforeDataRecordsRemoval:(BOOL)value WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));

Modified: trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.cpp (219296 => 219297)


--- trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.cpp	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.cpp	2017-07-10 17:09:38 UTC (rev 219297)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "ResourceLoadStatisticsStore.h"
 
+#include "WebsiteDataStore.h"
 #include <WebCore/KeyedCoding.h>
 #include <WebCore/ResourceLoadStatistics.h>
 #include <wtf/CrossThreadCopier.h>
@@ -35,15 +36,19 @@
 
 using namespace WebCore;
 
-const unsigned minimumPrevalentResourcesForTelemetry = 3;
 const unsigned operatingDatesWindow { 30 };
 const unsigned statisticsModelVersion { 6 };
 
-Ref<ResourceLoadStatisticsStore> ResourceLoadStatisticsStore::create()
+Ref<ResourceLoadStatisticsStore> ResourceLoadStatisticsStore::create(UpdateCookiePartitioningForDomainsHandler&& updateCookiePartitioningForDomainsHandler)
 {
-    return adoptRef(*new ResourceLoadStatisticsStore);
+    return adoptRef(*new ResourceLoadStatisticsStore(WTFMove(updateCookiePartitioningForDomainsHandler)));
 }
 
+ResourceLoadStatisticsStore::ResourceLoadStatisticsStore(UpdateCookiePartitioningForDomainsHandler&& updateCookiePartitioningForDomainsHandler)
+    : m_updateCookiePartitioningForDomainsHandler(WTFMove(updateCookiePartitioningForDomainsHandler))
+{
+}
+
 bool ResourceLoadStatisticsStore::isPrevalentResource(const String& primaryDomain) const
 {
     ASSERT(!RunLoop::isMain());
@@ -63,6 +68,15 @@
 
     return mapEntry->value.grandfathered;
 }
+
+bool ResourceLoadStatisticsStore::hasHadRecentUserInteraction(const String& primaryDomain)
+{
+    auto mapEntry = m_resourceStatisticsMap.find(primaryDomain);
+    if (mapEntry == m_resourceStatisticsMap.end())
+        return false;
+
+    return hasHadUnexpiredRecentUserInteraction(mapEntry->value);
+}
     
 ResourceLoadStatistics& ResourceLoadStatisticsStore::ensureResourceStatisticsForPrimaryDomain(const String& primaryDomain)
 {
@@ -72,8 +86,6 @@
     }).iterator->value;
 }
 
-typedef HashMap<String, ResourceLoadStatistics>::KeyValuePairType StatisticsValue;
-
 std::unique_ptr<KeyedEncoder> ResourceLoadStatisticsStore::createEncoderFromData() const
 {
     ASSERT(!RunLoop::isMain());
@@ -81,7 +93,7 @@
     encoder->encodeUInt32("version", statisticsModelVersion);
     encoder->encodeDouble("endOfGrandfatheringTimestamp", m_endOfGrandfatheringTimestamp.secondsSinceEpoch().value());
     
-    encoder->encodeObjects("browsingStatistics", m_resourceStatisticsMap.begin(), m_resourceStatisticsMap.end(), [](KeyedEncoder& encoderInner, const StatisticsValue& origin) {
+    encoder->encodeObjects("browsingStatistics", m_resourceStatisticsMap.begin(), m_resourceStatisticsMap.end(), [](KeyedEncoder& encoderInner, const auto& origin) {
         origin.value.encode(encoderInner);
     });
 
@@ -92,7 +104,7 @@
     return encoder;
 }
 
-void ResourceLoadStatisticsStore::readDataFromDecoder(KeyedDecoder& decoder)
+void ResourceLoadStatisticsStore::populateFromDecoder(KeyedDecoder& decoder)
 {
     ASSERT(!RunLoop::isMain());
     if (!m_resourceStatisticsMap.isEmpty())
@@ -141,7 +153,7 @@
     if (!succeeded)
         return;
     
-    fireShouldPartitionCookiesHandler({ }, prevalentResourceDomainsWithoutUserInteraction, true);
+    updateCookiePartitioningForDomains({ }, prevalentResourceDomainsWithoutUserInteraction, ShouldClearFirst::Yes);
 }
 
 void ResourceLoadStatisticsStore::clearInMemory()
@@ -150,7 +162,7 @@
     m_resourceStatisticsMap.clear();
     m_operatingDates.clear();
 
-    fireShouldPartitionCookiesHandler({ }, { }, true);
+    updateCookiePartitioningForDomains({ }, { }, ShouldClearFirst::Yes);
 }
 
 void ResourceLoadStatisticsStore::mergeStatistics(Vector<ResourceLoadStatistics>&& statistics)
@@ -157,32 +169,25 @@
 {
     ASSERT(!RunLoop::isMain());
     for (auto& statistic : statistics) {
-        // FIXME: In the case where the statistics does not already exist, it seems inefficient to create
-        // an empty one just to merge the new one into it.
         auto result = m_resourceStatisticsMap.ensure(statistic.highLevelDomain, [&statistic] {
-            return ResourceLoadStatistics(statistic.highLevelDomain);
+            return WTFMove(statistic);
         });
-        
-        result.iterator->value.merge(statistic);
+        if (!result.isNewEntry)
+            result.iterator->value.merge(statistic);
     }
 }
 
-void ResourceLoadStatisticsStore::setShouldPartitionCookiesCallback(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&& handler)
-{
-    m_shouldPartitionCookiesForDomainsHandler = WTFMove(handler);
-}
-
 inline bool ResourceLoadStatisticsStore::shouldPartitionCookies(const ResourceLoadStatistics& statistic) const
 {
     return statistic.isPrevalentResource && (!statistic.hadUserInteraction || WallTime::now() > statistic.mostRecentUserInteractionTime + m_timeToLiveCookiePartitionFree);
 }
 
-void ResourceLoadStatisticsStore::fireShouldPartitionCookiesHandler()
+void ResourceLoadStatisticsStore::updateCookiePartitioning()
 {
     ASSERT(!RunLoop::isMain());
+
     Vector<String> domainsToRemove;
     Vector<String> domainsToAdd;
-    
     for (auto& resourceStatistic : m_resourceStatisticsMap.values()) {
         bool shouldPartition = shouldPartitionCookies(resourceStatistic);
         if (resourceStatistic.isMarkedForCookiePartitioning && !shouldPartition) {
@@ -198,23 +203,21 @@
         return;
 
     RunLoop::main().dispatch([this, protectedThis = makeRef(*this), domainsToRemove = CrossThreadCopier<Vector<String>>::copy(domainsToRemove), domainsToAdd = CrossThreadCopier<Vector<String>>::copy(domainsToAdd)] () {
-        if (m_shouldPartitionCookiesForDomainsHandler)
-            m_shouldPartitionCookiesForDomainsHandler(domainsToRemove, domainsToAdd, false);
+        m_updateCookiePartitioningForDomainsHandler(domainsToRemove, domainsToAdd, ShouldClearFirst::No);
     });
 }
 
-void ResourceLoadStatisticsStore::fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)
+void ResourceLoadStatisticsStore::updateCookiePartitioningForDomains(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, ShouldClearFirst shouldClearFirst)
 {
     ASSERT(!RunLoop::isMain());
     if (domainsToRemove.isEmpty() && domainsToAdd.isEmpty())
         return;
     
-    RunLoop::main().dispatch([this, clearFirst, protectedThis = makeRef(*this), domainsToRemove = CrossThreadCopier<Vector<String>>::copy(domainsToRemove), domainsToAdd = CrossThreadCopier<Vector<String>>::copy(domainsToAdd)] () {
-        if (m_shouldPartitionCookiesForDomainsHandler)
-            m_shouldPartitionCookiesForDomainsHandler(domainsToRemove, domainsToAdd, clearFirst);
+    RunLoop::main().dispatch([this, shouldClearFirst, protectedThis = makeRef(*this), domainsToRemove = CrossThreadCopier<Vector<String>>::copy(domainsToRemove), domainsToAdd = CrossThreadCopier<Vector<String>>::copy(domainsToAdd)] () {
+        m_updateCookiePartitioningForDomainsHandler(domainsToRemove, domainsToAdd, shouldClearFirst);
     });
     
-    if (clearFirst) {
+    if (shouldClearFirst == ShouldClearFirst::Yes) {
         for (auto& resourceStatistic : m_resourceStatisticsMap.values())
             resourceStatistic.isMarkedForCookiePartitioning = false;
     } else {
@@ -251,8 +254,15 @@
         processFunction(resourceStatistic);
 }
 
-bool ResourceLoadStatisticsStore::hasHadRecentUserInteraction(ResourceLoadStatistics& resourceStatistic) const
+void ResourceLoadStatisticsStore::processStatistics(const WTF::Function<void (const ResourceLoadStatistics&)>& processFunction) const
 {
+    ASSERT(!RunLoop::isMain());
+    for (auto& resourceStatistic : m_resourceStatisticsMap.values())
+        processFunction(resourceStatistic);
+}
+
+bool ResourceLoadStatisticsStore::hasHadUnexpiredRecentUserInteraction(ResourceLoadStatistics& resourceStatistic) const
+{
     if (!resourceStatistic.hadUserInteraction)
         return false;
 
@@ -281,7 +291,7 @@
 
     Vector<String> prevalentResources;
     for (auto& statistic : m_resourceStatisticsMap.values()) {
-        if (statistic.isPrevalentResource && !hasHadRecentUserInteraction(statistic) && (!shouldCheckForGrandfathering || !statistic.grandfathered))
+        if (statistic.isPrevalentResource && !hasHadUnexpiredRecentUserInteraction(statistic) && (!shouldCheckForGrandfathering || !statistic.grandfathered))
             prevalentResources.append(statistic.highLevelDomain);
 
         if (shouldClearGrandfathering && statistic.grandfathered)
@@ -290,37 +300,7 @@
 
     return prevalentResources;
 }
-    
-Vector<PrevalentResourceTelemetry> ResourceLoadStatisticsStore::sortedPrevalentResourceTelemetry() const
-{
-    ASSERT(!RunLoop::isMain());
-    Vector<PrevalentResourceTelemetry> sorted;
-    for (auto& statistic : m_resourceStatisticsMap.values()) {
-        if (!statistic.isPrevalentResource)
-            continue;
 
-        unsigned daysSinceUserInteraction = statistic.mostRecentUserInteractionTime <= WallTime() ? 0 : std::floor((WallTime::now() - statistic.mostRecentUserInteractionTime) / 24_h);
-        sorted.append(PrevalentResourceTelemetry {
-            statistic.dataRecordsRemoved,
-            statistic.hadUserInteraction,
-            daysSinceUserInteraction,
-            statistic.subframeUnderTopFrameOrigins.size(),
-            statistic.subresourceUnderTopFrameOrigins.size(),
-            statistic.subresourceUniqueRedirectsTo.size()
-        });
-    }
-    
-    if (sorted.size() < minimumPrevalentResourcesForTelemetry)
-        return { };
-
-    std::sort(sorted.begin(), sorted.end(), [](const PrevalentResourceTelemetry& a, const PrevalentResourceTelemetry& b) {
-        return a.subframeUnderTopFrameOrigins + a.subresourceUnderTopFrameOrigins + a.subresourceUniqueRedirectsTo >
-        b.subframeUnderTopFrameOrigins + b.subresourceUnderTopFrameOrigins + b.subresourceUniqueRedirectsTo;
-    });
-    
-    return sorted;
-}
-
 void ResourceLoadStatisticsStore::updateStatisticsForRemovedDataRecords(const HashSet<String>& prevalentResourceDomains)
 {
     ASSERT(!RunLoop::isMain());

Modified: trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.h (219296 => 219297)


--- trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.h	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.h	2017-07-10 17:09:38 UTC (rev 219297)
@@ -41,22 +41,16 @@
 
 namespace WebKit {
 
-struct PrevalentResourceTelemetry {
-    unsigned numberOfTimesDataRecordsRemoved;
-    bool hasHadUserInteraction;
-    unsigned daysSinceUserInteraction;
-    unsigned subframeUnderTopFrameOrigins;
-    unsigned subresourceUnderTopFrameOrigins;
-    unsigned subresourceUniqueRedirectsTo;
-};
+enum class ShouldClearFirst;
 
 // FIXME: We should probably consider merging this with WebResourceLoadStatisticsStore.
 class ResourceLoadStatisticsStore : public ThreadSafeRefCounted<ResourceLoadStatisticsStore> {
 public:
-    static Ref<ResourceLoadStatisticsStore> create();
+    using UpdateCookiePartitioningForDomainsHandler = WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, ShouldClearFirst)>;
+    static Ref<ResourceLoadStatisticsStore> create(UpdateCookiePartitioningForDomainsHandler&&);
 
     std::unique_ptr<WebCore::KeyedEncoder> createEncoderFromData() const;
-    void readDataFromDecoder(WebCore::KeyedDecoder&);
+    void populateFromDecoder(WebCore::KeyedDecoder&);
 
     bool isEmpty() const { return m_resourceStatisticsMap.isEmpty(); }
     void clearInMemory();
@@ -65,23 +59,21 @@
 
     bool isPrevalentResource(const String&) const;
     bool isGrandFathered(const String&) const;
+    bool hasHadRecentUserInteraction(const String&);
     
     void mergeStatistics(Vector<WebCore::ResourceLoadStatistics>&&);
 
-    void setShouldPartitionCookiesCallback(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&&);
-
     void setTimeToLiveUserInteraction(std::optional<Seconds>);
     void setTimeToLiveCookiePartitionFree(Seconds);
     void setGrandfatheringTime(Seconds);
 
-    void fireShouldPartitionCookiesHandler();
-    void fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst);
+    void updateCookiePartitioning();
+    void updateCookiePartitioningForDomains(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, ShouldClearFirst);
 
     void processStatistics(const WTF::Function<void (WebCore::ResourceLoadStatistics&)>&);
+    void processStatistics(const WTF::Function<void (const WebCore::ResourceLoadStatistics&)>&) const;
 
-    bool hasHadRecentUserInteraction(WebCore::ResourceLoadStatistics&) const;
     Vector<String> topPrivatelyControlledDomainsToRemoveWebsiteDataFor();
-    Vector<PrevalentResourceTelemetry> sortedPrevalentResourceTelemetry() const;
     void updateStatisticsForRemovedDataRecords(const HashSet<String>& prevalentResourceDomains);
 
     void handleFreshStartWithEmptyOrNoStore(HashSet<String>&& topPrivatelyControlledDomainsToGrandfather);
@@ -88,15 +80,16 @@
     void includeTodayAsOperatingDateIfNecessary();
 
 private:
-    ResourceLoadStatisticsStore() = default;
+    explicit ResourceLoadStatisticsStore(UpdateCookiePartitioningForDomainsHandler&&);
 
     bool shouldPartitionCookies(const WebCore::ResourceLoadStatistics&) const;
     bool hasStatisticsExpired(const WebCore::ResourceLoadStatistics&) const;
+    bool hasHadUnexpiredRecentUserInteraction(WebCore::ResourceLoadStatistics&) const;
 
     HashMap<String, WebCore::ResourceLoadStatistics> m_resourceStatisticsMap;
     Deque<WTF::WallTime> m_operatingDates;
 
-    WTF::Function<void(const Vector<String>&, const Vector<String>&, bool clearFirst)> m_shouldPartitionCookiesForDomainsHandler;
+    UpdateCookiePartitioningForDomainsHandler m_updateCookiePartitioningForDomainsHandler;
 
     std::optional<Seconds> m_timeToLiveUserInteraction;
     Seconds m_timeToLiveCookiePartitionFree { 24_h };

Modified: trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp (219296 => 219297)


--- trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp	2017-07-10 17:09:38 UTC (rev 219297)
@@ -33,6 +33,7 @@
 #include "WebResourceLoadStatisticsStoreMessages.h"
 #include "WebResourceLoadStatisticsTelemetry.h"
 #include "WebsiteDataFetchOption.h"
+#include "WebsiteDataStore.h"
 #include "WebsiteDataType.h"
 #include <WebCore/FileMonitor.h>
 #include <WebCore/FileSystem.h>
@@ -44,25 +45,17 @@
 #include <wtf/NeverDestroyed.h>
 #include <wtf/threads/BinarySemaphore.h>
 
-#if PLATFORM(COCOA)
-#define ENABLE_MULTIPROCESS_ACCESS_TO_STATISTICS_STORE 1
-#endif
-
 using namespace WebCore;
 
 namespace WebKit {
 
+constexpr Seconds minimumStatisticsFileWriteInterval { 5_min };
+
 template<typename T> static inline String primaryDomain(const T& value)
 {
     return ResourceLoadStatistics::primaryDomain(value);
 }
 
-constexpr Seconds minimumStatisticsFileWriteInterval { 5_min };
-
-static bool notifyPagesWhenDataRecordsWereScanned = false;
-static bool shouldClassifyResourcesBeforeDataRecordsRemoval = true;
-static auto shouldSubmitTelemetry = true;
-
 static const OptionSet<WebsiteDataType>& dataTypesToRemove()
 {
     static NeverDestroyed<OptionSet<WebsiteDataType>> dataTypes(std::initializer_list<WebsiteDataType>({
@@ -87,12 +80,11 @@
     return dataTypes;
 }
 
-WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore(const String& resourceLoadStatisticsDirectory, UpdatePartitionCookiesForDomainsHandler&& updatePartitionCookiesForDomainsHandler)
-    : m_resourceLoadStatisticsStore(ResourceLoadStatisticsStore::create())
+WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore(const String& resourceLoadStatisticsDirectory, UpdateCookiePartitioningForDomainsHandler&& updateCookiePartitioningForDomainsHandler)
+    : m_resourceLoadStatisticsStore(ResourceLoadStatisticsStore::create(WTFMove(updateCookiePartitioningForDomainsHandler)))
     , m_statisticsQueue(WorkQueue::create("WebResourceLoadStatisticsStore Process Data Queue", WorkQueue::Type::Serial, WorkQueue::QOS::Utility))
     , m_statisticsStoragePath(resourceLoadStatisticsDirectory)
-    , m_telemetryOneShotTimer(RunLoop::main(), this, &WebResourceLoadStatisticsStore::submitTelemetryIfNecessary)
-    , m_telemetryRepeatedTimer(RunLoop::main(), this, &WebResourceLoadStatisticsStore::performDailyTasks)
+    , m_dailyTasksTimer(RunLoop::main(), this, &WebResourceLoadStatisticsStore::performDailyTasks)
 {
     ASSERT(RunLoop::isMain());
 
@@ -100,39 +92,21 @@
     registerUserDefaultsIfNeeded();
 #endif
 
-    if (updatePartitionCookiesForDomainsHandler) {
-        m_resourceLoadStatisticsStore->setShouldPartitionCookiesCallback([updatePartitionCookiesForDomainsHandler = WTFMove(updatePartitionCookiesForDomainsHandler)] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst) {
-            updatePartitionCookiesForDomainsHandler(domainsToRemove, domainsToAdd, shouldClearFirst);
-        });
-    }
-
     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
         readDataFromDiskIfNeeded();
         startMonitoringStatisticsStorage();
     });
+    m_statisticsQueue->dispatchAfter(5_s, [this, protectedThis = makeRef(*this)] {
+        if (m_shouldSubmitTelemetry)
+            WebResourceLoadStatisticsTelemetry::calculateAndSubmit(coreStore());
+    });
 
-    m_telemetryOneShotTimer.startOneShot(5_s);
-    m_telemetryRepeatedTimer.startRepeating(24_h);
+    m_dailyTasksTimer.startRepeating(24_h);
 }
 
 WebResourceLoadStatisticsStore::~WebResourceLoadStatisticsStore()
 {
 }
-
-void WebResourceLoadStatisticsStore::setNotifyPagesWhenDataRecordsWereScanned(bool always)
-{
-    notifyPagesWhenDataRecordsWereScanned = always;
-}
-
-void WebResourceLoadStatisticsStore::setShouldClassifyResourcesBeforeDataRecordsRemoval(bool value)
-{
-    shouldClassifyResourcesBeforeDataRecordsRemoval = value;
-}
-
-void WebResourceLoadStatisticsStore::setShouldSubmitTelemetry(bool value)
-{
-    shouldSubmitTelemetry = value;
-}
     
 void WebResourceLoadStatisticsStore::classifyResource(ResourceLoadStatistics& resourceStatistic)
 {
@@ -151,15 +125,13 @@
     if (prevalentResourceDomains.isEmpty())
         return;
     
-    dataRecordsBeingRemoved();
+    setDataRecordsBeingRemoved(true);
 
-    // Switch to the main thread to get the default website data store
     RunLoop::main().dispatch([prevalentResourceDomains = CrossThreadCopier<Vector<String>>::copy(prevalentResourceDomains), this, protectedThis = makeRef(*this)] () mutable {
-        WebProcessProxy::deleteWebsiteDataForTopPrivatelyControlledDomainsInAllPersistentDataStores(dataTypesToRemove(), WTFMove(prevalentResourceDomains), notifyPagesWhenDataRecordsWereScanned, [this, protectedThis = WTFMove(protectedThis)](const HashSet<String>& domainsWithDeletedWebsiteData) mutable {
-            // But always touch the ResourceLoadStatistics store on the worker queue.
+        WebProcessProxy::deleteWebsiteDataForTopPrivatelyControlledDomainsInAllPersistentDataStores(dataTypesToRemove(), WTFMove(prevalentResourceDomains), m_shouldNotifyPagesWhenDataRecordsWereScanned, [this, protectedThis = WTFMove(protectedThis)](const HashSet<String>& domainsWithDeletedWebsiteData) mutable {
             m_statisticsQueue->dispatch([this, protectedThis = WTFMove(protectedThis), topDomains = CrossThreadCopier<HashSet<String>>::copy(domainsWithDeletedWebsiteData)] () mutable {
                 coreStore().updateStatisticsForRemovedDataRecords(topDomains);
-                dataRecordsWereRemoved();
+                setDataRecordsBeingRemoved(false);
             });
         });
     });
@@ -168,7 +140,7 @@
 void WebResourceLoadStatisticsStore::processStatisticsAndDataRecords()
 {
     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] () {
-        if (shouldClassifyResourcesBeforeDataRecordsRemoval) {
+        if (m_shouldClassifyResourcesBeforeDataRecordsRemoval) {
             coreStore().processStatistics([this] (ResourceLoadStatistics& resourceStatistic) {
                 classifyResource(resourceStatistic);
             });
@@ -175,7 +147,7 @@
         }
         removeDataRecords();
         
-        if (notifyPagesWhenDataRecordsWereScanned) {
+        if (m_shouldNotifyPagesWhenDataRecordsWereScanned) {
             RunLoop::main().dispatch([] {
                 WebProcessProxy::notifyPageStatisticsAndDataRecordsProcessed();
             });
@@ -190,20 +162,19 @@
     ASSERT(!RunLoop::isMain());
 
     coreStore().mergeStatistics(WTFMove(origins));
-    // Fire before processing statistics to propagate user
-    // interaction as fast as possible to the network process.
-    coreStore().fireShouldPartitionCookiesHandler();
+    // Fire before processing statistics to propagate user interaction as fast as possible to the network process.
+    coreStore().updateCookiePartitioning();
     processStatisticsAndDataRecords();
 }
 
 void WebResourceLoadStatisticsStore::grandfatherExistingWebsiteData()
 {
-    // Switch to the main thread to get the default website data store
+    ASSERT(!RunLoop::isMain());
+
     RunLoop::main().dispatch([this, protectedThis = makeRef(*this)] () mutable {
-        WebProcessProxy::topPrivatelyControlledDomainsWithWebsiteData(dataTypesToRemove(), notifyPagesWhenDataRecordsWereScanned, [this, protectedThis = WTFMove(protectedThis)] (HashSet<String>&& topPrivatelyControlledDomainsWithWebsiteData) mutable {
-            // But always touch the ResourceLoadStatistics store on the worker queue
-            m_statisticsQueue->dispatch([protectedThis = WTFMove(protectedThis), topDomains = CrossThreadCopier<HashSet<String>>::copy(topPrivatelyControlledDomainsWithWebsiteData)] () mutable {
-                protectedThis->coreStore().handleFreshStartWithEmptyOrNoStore(WTFMove(topDomains));
+        WebProcessProxy::topPrivatelyControlledDomainsWithWebsiteData(dataTypesToRemove(), m_shouldNotifyPagesWhenDataRecordsWereScanned, [this, protectedThis = WTFMove(protectedThis)] (HashSet<String>&& topPrivatelyControlledDomainsWithWebsiteData) mutable {
+            m_statisticsQueue->dispatch([this, protectedThis = WTFMove(protectedThis), topDomains = CrossThreadCopier<HashSet<String>>::copy(topPrivatelyControlledDomainsWithWebsiteData)] () mutable {
+                coreStore().handleFreshStartWithEmptyOrNoStore(WTFMove(topDomains));
             });
         });
     });
@@ -248,7 +219,7 @@
     }
 
     coreStore().clearInMemory();
-    coreStore().readDataFromDecoder(*decoder);
+    coreStore().populateFromDecoder(*decoder);
 
     m_lastStatisticsFileSyncTime = readTime;
 
@@ -278,7 +249,7 @@
     if (!decoder)
         return;
 
-    coreStore().readDataFromDecoder(*decoder);
+    coreStore().populateFromDecoder(*decoder);
     m_lastStatisticsFileSyncTime = readTime;
 }
     
@@ -295,12 +266,12 @@
 void WebResourceLoadStatisticsStore::applicationWillTerminate()
 {
     BinarySemaphore semaphore;
+    // Make sure any pending work in our queue is finished before we terminate.
     m_statisticsQueue->dispatch([&semaphore, this, protectedThis = makeRef(*this)] {
         // Write final file state to disk.
         if (m_didScheduleWrite)
             writeStoreToDisk();
 
-        // Make sure any ongoing work in our queue is finished before we terminate.
         semaphore.signal();
     });
     semaphore.wait(WallTime::infinity());
@@ -317,7 +288,6 @@
     if (statisticsStoragePath.isEmpty())
         return emptyString();
 
-    // TODO Decide what to call this file
     return pathByAppendingComponent(statisticsStoragePath, "full_browsing_session_resourceLog.plist");
 }
 
@@ -332,7 +302,7 @@
     auto encoder = coreStore().createEncoderFromData();
 
     String resourceLog = resourceLogFilePath();
-    writeEncoderToDisk(*encoder.get(), resourceLog);
+    writeEncoderToDisk(*encoder, resourceLog);
 
     m_lastStatisticsFileSyncTime = WallTime::now();
     m_lastStatisticsWriteTime = MonotonicTime::now();
@@ -349,8 +319,8 @@
     if (timeSinceLastWrite < minimumStatisticsFileWriteInterval) {
         if (!m_didScheduleWrite) {
             m_didScheduleWrite = true;
-            Seconds delayUntil = minimumStatisticsFileWriteInterval - timeSinceLastWrite + 1_s;
-            m_statisticsQueue->dispatchAfter(delayUntil, [this, protectedThis = makeRef(*this)] {
+            Seconds delay = minimumStatisticsFileWriteInterval - timeSinceLastWrite + 1_s;
+            m_statisticsQueue->dispatchAfter(delay, [this, protectedThis = makeRef(*this)] {
                 writeStoreToDisk();
             });
         }
@@ -360,31 +330,6 @@
     writeStoreToDisk();
 }
 
-static PlatformFileHandle openAndLockFile(const String& path, FileOpenMode mode)
-{
-    ASSERT(!RunLoop::isMain());
-    auto handle = openFile(path, mode);
-    if (handle == invalidPlatformFileHandle)
-        return invalidPlatformFileHandle;
-
-#if ENABLE(MULTIPROCESS_ACCESS_TO_STATISTICS_STORE)
-    bool locked = lockFile(handle, WebCore::LockExclusive);
-    ASSERT_UNUSED(locked, locked);
-#endif
-
-    return handle;
-}
-
-static void closeAndUnlockFile(PlatformFileHandle handle)
-{
-    ASSERT(!RunLoop::isMain());
-#if ENABLE(MULTIPROCESS_ACCESS_TO_STATISTICS_STORE)
-    bool unlocked = unlockFile(handle);
-    ASSERT_UNUSED(unlocked, unlocked);
-#endif
-    closeFile(handle);
-}
-
 void WebResourceLoadStatisticsStore::writeEncoderToDisk(KeyedEncoder& encoder, const String& path) const
 {
     ASSERT(!RunLoop::isMain());
@@ -404,7 +349,7 @@
         return;
     
     int64_t writtenBytes = writeToFile(handle, rawData->data(), rawData->size());
-    closeAndUnlockFile(handle);
+    unlockAndCloseFile(handle);
 
     if (writtenBytes != static_cast<int64_t>(rawData->size()))
         RELEASE_LOG_ERROR(ResourceLoadStatistics, "WebResourceLoadStatisticsStore: We only wrote %d out of %d bytes to disk", static_cast<unsigned>(writtenBytes), rawData->size());
@@ -423,12 +368,6 @@
         RELEASE_LOG_ERROR(ResourceLoadStatistics, "Unable to delete statistics file: %s", resourceLogPath.utf8().data());
 }
 
-void WebResourceLoadStatisticsStore::clearInMemoryData()
-{
-    ASSERT(!RunLoop::isMain());
-    coreStore().clearInMemory();
-}
-
 void WebResourceLoadStatisticsStore::startMonitoringStatisticsStorage()
 {
     ASSERT(!RunLoop::isMain());
@@ -446,7 +385,7 @@
             refreshFromDisk();
             break;
         case FileMonitor::FileChangeType::Removal:
-            clearInMemoryData();
+            coreStore().clearInMemory();
             m_statisticsStorageMonitor = nullptr;
             break;
         }
@@ -471,12 +410,10 @@
 
     refreshFromDisk();
 }
-    
-    
+
 #if !PLATFORM(COCOA)
 void WebResourceLoadStatisticsStore::platformExcludeFromBackup() const
 {
-    // Do nothing
 }
 #endif
 
@@ -489,13 +426,13 @@
     
     long long fileSize = 0;
     if (!getFileSize(handle, fileSize)) {
-        closeAndUnlockFile(handle);
+        unlockAndCloseFile(handle);
         return nullptr;
     }
     
     size_t bytesToRead;
     if (!WTF::convertSafely(fileSize, bytesToRead)) {
-        closeAndUnlockFile(handle);
+        unlockAndCloseFile(handle);
         return nullptr;
     }
 
@@ -502,7 +439,7 @@
     Vector<char> buffer(bytesToRead);
     size_t totalBytesRead = readFromFile(handle, buffer.data(), buffer.size());
 
-    closeAndUnlockFile(handle);
+    unlockAndCloseFile(handle);
 
     if (totalBytesRead != bytesToRead)
         return nullptr;
@@ -515,20 +452,10 @@
     ASSERT(RunLoop::isMain());
 
     coreStore().includeTodayAsOperatingDateIfNecessary();
-
-    submitTelemetryIfNecessary();
+    if (m_shouldSubmitTelemetry)
+        submitTelemetry();
 }
 
-void WebResourceLoadStatisticsStore::submitTelemetryIfNecessary()
-{
-    ASSERT(RunLoop::isMain());
-    
-    if (!shouldSubmitTelemetry)
-        return;
-    
-    submitTelemetry();
-}
-
 void WebResourceLoadStatisticsStore::submitTelemetry()
 {
     ASSERT(RunLoop::isMain());
@@ -547,7 +474,7 @@
         statistics.hadUserInteraction = true;
         statistics.mostRecentUserInteractionTime = WallTime::now();
 
-        coreStore().fireShouldPartitionCookiesHandler({ primaryDomainString }, { }, false);
+        coreStore().updateCookiePartitioningForDomains({ primaryDomainString }, { }, ShouldClearFirst::No);
     });
 }
 
@@ -571,10 +498,9 @@
     }
 
     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), url = "" completionHandler = WTFMove(completionHandler)] () mutable {
-        // FIXME: Why is this potentially creating a store entry just for querying?
-        auto& statistics = coreStore().ensureResourceStatisticsForPrimaryDomain(primaryDomain(url));
-        RunLoop::main().dispatch([hasHadUserInteraction = coreStore().hasHadRecentUserInteraction(statistics), completionHandler = WTFMove(completionHandler)] {
-            completionHandler(hasHadUserInteraction);
+        bool hadUserInteraction = coreStore().hasHadRecentUserInteraction(primaryDomain(url));
+        RunLoop::main().dispatch([hadUserInteraction, completionHandler = WTFMove(completionHandler)] {
+            completionHandler(hadUserInteraction);
         });
     });
 }
@@ -675,27 +601,28 @@
     });
 }
 
-void WebResourceLoadStatisticsStore::fireShouldPartitionCookiesHandler()
+void WebResourceLoadStatisticsStore::updateCookiePartitioning()
 {
     // Helper function used by testing system. Should only be called from the main thread.
     ASSERT(RunLoop::isMain());
 
     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
-        coreStore().fireShouldPartitionCookiesHandler();
+        coreStore().updateCookiePartitioning();
     });
 }
 
-void WebResourceLoadStatisticsStore::fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)
+void WebResourceLoadStatisticsStore::updateCookiePartitioningForDomains(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, ShouldClearFirst shouldClearFirst)
 {
     // Helper function used by testing system. Should only be called from the main thread.
     ASSERT(RunLoop::isMain());
-    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), domainsToRemove = CrossThreadCopier<Vector<String>>::copy(domainsToRemove), domainsToAdd = CrossThreadCopier<Vector<String>>::copy(domainsToAdd), clearFirst] {
-        coreStore().fireShouldPartitionCookiesHandler(domainsToRemove, domainsToAdd, clearFirst);
+    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), domainsToRemove = CrossThreadCopier<Vector<String>>::copy(domainsToRemove), domainsToAdd = CrossThreadCopier<Vector<String>>::copy(domainsToAdd), shouldClearFirst] {
+        coreStore().updateCookiePartitioningForDomains(domainsToRemove, domainsToAdd, shouldClearFirst);
     });
 }
 
 void WebResourceLoadStatisticsStore::clearInMemory()
 {
+    ASSERT(RunLoop::isMain());
     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
         coreStore().clearInMemory();
     });
@@ -703,6 +630,7 @@
 
 void WebResourceLoadStatisticsStore::clearInMemoryAndPersistent()
 {
+    ASSERT(RunLoop::isMain());
     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
         coreStore().clearInMemory();
         deleteStoreFromDisk();
@@ -741,26 +669,18 @@
 bool WebResourceLoadStatisticsStore::shouldRemoveDataRecords() const
 {
     ASSERT(!RunLoop::isMain());
-    if (m_dataRecordsRemovalPending)
+    if (m_dataRecordsBeingRemoved)
         return false;
 
-    if (m_lastTimeDataRecordsWereRemoved && MonotonicTime::now() < (m_lastTimeDataRecordsWereRemoved + m_minimumTimeBetweenDataRecordsRemoval))
-        return false;
-
-    return true;
+    return !m_lastTimeDataRecordsWereRemoved || MonotonicTime::now() >= (m_lastTimeDataRecordsWereRemoved + m_minimumTimeBetweenDataRecordsRemoval);
 }
 
-void WebResourceLoadStatisticsStore::dataRecordsBeingRemoved()
+void WebResourceLoadStatisticsStore::setDataRecordsBeingRemoved(bool value)
 {
     ASSERT(!RunLoop::isMain());
-    m_lastTimeDataRecordsWereRemoved = MonotonicTime::now();
-    m_dataRecordsRemovalPending = true;
+    m_dataRecordsBeingRemoved = value;
+    if (m_dataRecordsBeingRemoved)
+        m_lastTimeDataRecordsWereRemoved = MonotonicTime::now();
 }
-
-void WebResourceLoadStatisticsStore::dataRecordsWereRemoved()
-{
-    ASSERT(!RunLoop::isMain());
-    m_dataRecordsRemovalPending = false;
-}
     
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h (219296 => 219297)


--- trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h	2017-07-10 17:09:38 UTC (rev 219297)
@@ -54,19 +54,22 @@
 class ResourceLoadStatisticsStore;
 class WebProcessProxy;
 
+enum class ShouldClearFirst;
+
+// FIXME: We should consider moving FileSystem I/O to a separate class.
 class WebResourceLoadStatisticsStore final : public IPC::Connection::WorkQueueMessageReceiver {
 public:
-    using UpdatePartitionCookiesForDomainsHandler = WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst)>;
-    static Ref<WebResourceLoadStatisticsStore> create(const String& resourceLoadStatisticsDirectory, UpdatePartitionCookiesForDomainsHandler&& updatePartitionCookiesForDomainsHandler = { })
+    using UpdateCookiePartitioningForDomainsHandler = WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, ShouldClearFirst)>;
+    static Ref<WebResourceLoadStatisticsStore> create(const String& resourceLoadStatisticsDirectory, UpdateCookiePartitioningForDomainsHandler&& updateCookiePartitioningForDomainsHandler = { })
     {
-        return adoptRef(*new WebResourceLoadStatisticsStore(resourceLoadStatisticsDirectory, WTFMove(updatePartitionCookiesForDomainsHandler)));
+        return adoptRef(*new WebResourceLoadStatisticsStore(resourceLoadStatisticsDirectory, WTFMove(updateCookiePartitioningForDomainsHandler)));
     }
 
     ~WebResourceLoadStatisticsStore();
 
-    static void setNotifyPagesWhenDataRecordsWereScanned(bool);
-    static void setShouldClassifyResourcesBeforeDataRecordsRemoval(bool);
-    static void setShouldSubmitTelemetry(bool);
+    void setNotifyPagesWhenDataRecordsWereScanned(bool value) { m_shouldNotifyPagesWhenDataRecordsWereScanned = value; }
+    void setShouldClassifyResourcesBeforeDataRecordsRemoval(bool value) { m_shouldClassifyResourcesBeforeDataRecordsRemoval = value; }
+    void setShouldSubmitTelemetry(bool value) { m_shouldSubmitTelemetry = value; }
 
     void resourceLoadStatisticsUpdated(Vector<WebCore::ResourceLoadStatistics>&& origins);
 
@@ -85,8 +88,8 @@
     void setSubframeUnderTopFrameOrigin(const WebCore::URL& subframe, const WebCore::URL& topFrame);
     void setSubresourceUnderTopFrameOrigin(const WebCore::URL& subresource, const WebCore::URL& topFrame);
     void setSubresourceUniqueRedirectTo(const WebCore::URL& subresource, const WebCore::URL& hostNameRedirectedTo);
-    void fireShouldPartitionCookiesHandler();
-    void fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst);
+    void updateCookiePartitioning();
+    void updateCookiePartitioningForDomains(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, ShouldClearFirst);
     void processStatisticsAndDataRecords();
     void submitTelemetry();
 
@@ -100,7 +103,7 @@
     void setGrandfatheringTime(Seconds);
 
 private:
-    WebResourceLoadStatisticsStore(const String&, UpdatePartitionCookiesForDomainsHandler&&);
+    WebResourceLoadStatisticsStore(const String&, UpdateCookiePartitioningForDomainsHandler&&);
 
     ResourceLoadStatisticsStore& coreStore() { return m_resourceLoadStatisticsStore.get(); }
     const ResourceLoadStatisticsStore& coreStore() const { return m_resourceLoadStatisticsStore.get(); }
@@ -127,15 +130,12 @@
     WallTime statisticsFileModificationTime(const String& label) const;
     void platformExcludeFromBackup() const;
     void deleteStoreFromDisk();
-    void clearInMemoryData();
     void syncWithExistingStatisticsStorageIfNeeded();
     void refreshFromDisk();
-    void submitTelemetryIfNecessary();
     bool hasStatisticsFileChangedSinceLastSync(const String& path) const;
     void performDailyTasks();
     bool shouldRemoveDataRecords() const;
-    void dataRecordsBeingRemoved();
-    void dataRecordsWereRemoved();
+    void setDataRecordsBeingRemoved(bool);
 
 #if PLATFORM(COCOA)
     void registerUserDefaultsIfNeeded();
@@ -152,12 +152,14 @@
     const String m_statisticsStoragePath;
     WallTime m_lastStatisticsFileSyncTime;
     MonotonicTime m_lastStatisticsWriteTime;
-    RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryOneShotTimer;
-    RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryRepeatedTimer;
+    RunLoop::Timer<WebResourceLoadStatisticsStore> m_dailyTasksTimer;
     MonotonicTime m_lastTimeDataRecordsWereRemoved;
     Seconds m_minimumTimeBetweenDataRecordsRemoval { 1_h };
-    bool m_dataRecordsRemovalPending { false };
+    bool m_dataRecordsBeingRemoved { false };
     bool m_didScheduleWrite { false };
+    bool m_shouldNotifyPagesWhenDataRecordsWereScanned { false };
+    bool m_shouldClassifyResourcesBeforeDataRecordsRemoval { true };
+    bool m_shouldSubmitTelemetry { true };
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsTelemetry.cpp (219296 => 219297)


--- trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsTelemetry.cpp	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsTelemetry.cpp	2017-07-10 17:09:38 UTC (rev 219297)
@@ -39,9 +39,49 @@
 using namespace WebCore;
 
 namespace WebKit {
-    
-static auto notifyPagesWhenTelemetryWasCaptured = false;
-    
+
+const unsigned minimumPrevalentResourcesForTelemetry = 3;
+static bool notifyPagesWhenTelemetryWasCaptured = false;
+
+struct PrevalentResourceTelemetry {
+    unsigned numberOfTimesDataRecordsRemoved;
+    bool hasHadUserInteraction;
+    unsigned daysSinceUserInteraction;
+    unsigned subframeUnderTopFrameOrigins;
+    unsigned subresourceUnderTopFrameOrigins;
+    unsigned subresourceUniqueRedirectsTo;
+};
+
+static Vector<PrevalentResourceTelemetry> sortedPrevalentResourceTelemetry(const ResourceLoadStatisticsStore& store)
+{
+    ASSERT(!RunLoop::isMain());
+    Vector<PrevalentResourceTelemetry> sorted;
+    store.processStatistics([&sorted] (auto& statistic) {
+        if (!statistic.isPrevalentResource)
+            return;
+
+        unsigned daysSinceUserInteraction = statistic.mostRecentUserInteractionTime <= WallTime() ? 0 : std::floor((WallTime::now() - statistic.mostRecentUserInteractionTime) / 24_h);
+        sorted.append(PrevalentResourceTelemetry {
+            statistic.dataRecordsRemoved,
+            statistic.hadUserInteraction,
+            daysSinceUserInteraction,
+            statistic.subframeUnderTopFrameOrigins.size(),
+            statistic.subresourceUnderTopFrameOrigins.size(),
+            statistic.subresourceUniqueRedirectsTo.size()
+        });
+    });
+
+    if (sorted.size() < minimumPrevalentResourcesForTelemetry)
+        return { };
+
+    std::sort(sorted.begin(), sorted.end(), [](const PrevalentResourceTelemetry& a, const PrevalentResourceTelemetry& b) {
+        return a.subframeUnderTopFrameOrigins + a.subresourceUnderTopFrameOrigins + a.subresourceUniqueRedirectsTo >
+        b.subframeUnderTopFrameOrigins + b.subresourceUnderTopFrameOrigins + b.subresourceUniqueRedirectsTo;
+    });
+
+    return sorted;
+}
+
 static unsigned numberOfResourcesWithUserInteraction(const Vector<PrevalentResourceTelemetry>& resources, size_t begin, size_t end)
 {
     if (resources.isEmpty() || resources.size() < begin + 1 || resources.size() < end + 1)
@@ -188,7 +228,7 @@
 {
     ASSERT(!RunLoop::isMain());
     
-    auto sortedPrevalentResources = resourceLoadStatisticsStore.sortedPrevalentResourceTelemetry();
+    auto sortedPrevalentResources = sortedPrevalentResourceTelemetry(resourceLoadStatisticsStore);
     if (notifyPagesWhenTelemetryWasCaptured && sortedPrevalentResources.isEmpty()) {
         notifyPages(0, 0, 0);
         return;

Modified: trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp (219296 => 219297)


--- trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp	2017-07-10 17:09:38 UTC (rev 219297)
@@ -1099,10 +1099,10 @@
 }
 
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
-void WebsiteDataStore::updateCookiePartitioningForTopPrivatelyOwnedDomains(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst)
+void WebsiteDataStore::updateCookiePartitioningForTopPrivatelyOwnedDomains(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, ShouldClearFirst shouldClearFirst)
 {
     for (auto& processPool : processPools())
-        processPool->sendToNetworkingProcess(Messages::NetworkProcess::UpdateCookiePartitioningForTopPrivatelyOwnedDomains(domainsToRemove, domainsToAdd, shouldClearFirst));
+        processPool->sendToNetworkingProcess(Messages::NetworkProcess::UpdateCookiePartitioningForTopPrivatelyOwnedDomains(domainsToRemove, domainsToAdd, shouldClearFirst == ShouldClearFirst::Yes));
 }
 #endif
 
@@ -1263,7 +1263,7 @@
 
     if (enabled) {
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
-        m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(m_configuration.resourceLoadStatisticsDirectory, [this] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst) {
+        m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(m_configuration.resourceLoadStatisticsDirectory, [this] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, ShouldClearFirst shouldClearFirst) {
             updateCookiePartitioningForTopPrivatelyOwnedDomains(domainsToRemove, domainsToAdd, shouldClearFirst);
         });
 #else

Modified: trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h (219296 => 219297)


--- trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h	2017-07-10 17:09:38 UTC (rev 219297)
@@ -62,6 +62,8 @@
 struct PluginModuleInfo;
 #endif
 
+enum class ShouldClearFirst { No, Yes };
+
 class WebsiteDataStore : public RefCounted<WebsiteDataStore>, public WebProcessLifetimeObserver {
 public:
     struct Configuration {
@@ -101,7 +103,7 @@
     void removeDataForTopPrivatelyControlledDomains(OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, const Vector<String>& topPrivatelyControlledDomains, Function<void(HashSet<String>&&)>&& completionHandler);
 
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
-    void updateCookiePartitioningForTopPrivatelyOwnedDomains(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst);
+    void updateCookiePartitioningForTopPrivatelyOwnedDomains(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, ShouldClearFirst);
 #endif
     void resolveDirectoriesIfNecessary();
     const String& resolvedApplicationCacheDirectory() const { return m_resolvedConfiguration.applicationCacheDirectory; }

Modified: trunk/Tools/ChangeLog (219296 => 219297)


--- trunk/Tools/ChangeLog	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Tools/ChangeLog	2017-07-10 17:09:38 UTC (rev 219297)
@@ -1,3 +1,28 @@
+2017-07-10  Chris Dumez  <cdu...@apple.com>
+
+        Further WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore clean up
+        https://bugs.webkit.org/show_bug.cgi?id=174301
+
+        Reviewed by Brent Fulgham.
+
+        Rename some of the testRunner API for clarity and to better match what it calls
+        internally.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::statisticsUpdateCookiePartitioning):
+        (WTR::TestRunner::statisticsSetShouldPartitionCookiesForHost):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::statisticsUpdateCookiePartitioning):
+        (WTR::TestController::statisticsSetShouldPartitionCookiesForHost):
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
+        (WTR::TestController::statisticsUpdateCookiePartitioning):
+        (WTR::TestController::statisticsSetShouldPartitionCookiesForHost):
+
 2017-07-10  Charlie Turner  <ctur...@igalia.com>
 
         [GStreamer] Live twitch.tv videos do not play

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (219296 => 219297)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2017-07-10 17:09:38 UTC (rev 219297)
@@ -266,8 +266,8 @@
     void setStatisticsTimeToLiveUserInteraction(double seconds);
     void setStatisticsTimeToLiveCookiePartitionFree(double seconds);
     void statisticsProcessStatisticsAndDataRecords();
-    void statisticsFireShouldPartitionCookiesHandler();
-    void statisticsFireShouldPartitionCookiesHandlerForOneDomain(DOMString hostName, boolean value);
+    void statisticsUpdateCookiePartitioning();
+    void statisticsSetShouldPartitionCookiesForHost(DOMString hostName, boolean value);
     void statisticsSubmitTelemetry();
     void setStatisticsNotifyPagesWhenDataRecordsWereScanned(boolean value);
     void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(boolean value);

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (219296 => 219297)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2017-07-10 17:09:38 UTC (rev 219297)
@@ -1419,13 +1419,13 @@
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr);
 }
 
-void TestRunner::statisticsFireShouldPartitionCookiesHandler()
+void TestRunner::statisticsUpdateCookiePartitioning()
 {
-    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsFireShouldPartitionCookiesHandler"));
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsUpdateCookiePartitioning"));
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr);
 }
 
-void TestRunner::statisticsFireShouldPartitionCookiesHandlerForOneDomain(JSStringRef hostName, bool value)
+void TestRunner::statisticsSetShouldPartitionCookiesForHost(JSStringRef hostName, bool value)
 {
     Vector<WKRetainPtr<WKStringRef>> keys;
     Vector<WKRetainPtr<WKTypeRef>> values;
@@ -1444,7 +1444,7 @@
         rawValues[i] = values[i].get();
     }
     
-    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsFireShouldPartitionCookiesHandlerForOneDomain"));
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsSetShouldPartitionCookiesForHost"));
     WKRetainPtr<WKDictionaryRef> messageBody(AdoptWK, WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size()));
     
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (219296 => 219297)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2017-07-10 17:09:38 UTC (rev 219297)
@@ -354,8 +354,8 @@
     void statisticsDidScanDataRecordsCallback();
     void statisticsDidRunTelemetryCallback(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins);
     void statisticsProcessStatisticsAndDataRecords();
-    void statisticsFireShouldPartitionCookiesHandler();
-    void statisticsFireShouldPartitionCookiesHandlerForOneDomain(JSStringRef hostName, bool value);
+    void statisticsUpdateCookiePartitioning();
+    void statisticsSetShouldPartitionCookiesForHost(JSStringRef hostName, bool value);
     void statisticsSubmitTelemetry();
     void setStatisticsPrevalentResource(JSStringRef hostName, bool value);
     bool isStatisticsPrevalentResource(JSStringRef hostName);

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (219296 => 219297)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2017-07-10 17:09:38 UTC (rev 219297)
@@ -2300,11 +2300,11 @@
 {
 }
 
-void TestController::statisticsFireShouldPartitionCookiesHandler()
+void TestController::statisticsUpdateCookiePartitioning()
 {
 }
 
-void TestController::statisticsFireShouldPartitionCookiesHandlerForOneDomain(WKStringRef, bool)
+void TestController::statisticsSetShouldPartitionCookiesForHost(WKStringRef, bool)
 {
 }
 

Modified: trunk/Tools/WebKitTestRunner/TestController.h (219296 => 219297)


--- trunk/Tools/WebKitTestRunner/TestController.h	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2017-07-10 17:09:38 UTC (rev 219297)
@@ -162,8 +162,8 @@
     void setStatisticsTimeToLiveUserInteraction(double seconds);
     void setStatisticsTimeToLiveCookiePartitionFree(double seconds);
     void statisticsProcessStatisticsAndDataRecords();
-    void statisticsFireShouldPartitionCookiesHandler();
-    void statisticsFireShouldPartitionCookiesHandlerForOneDomain(WKStringRef hostName, bool value);
+    void statisticsUpdateCookiePartitioning();
+    void statisticsSetShouldPartitionCookiesForHost(WKStringRef hostName, bool value);
     void statisticsSubmitTelemetry();
     void setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool);
     void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool);

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (219296 => 219297)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2017-07-10 17:09:38 UTC (rev 219297)
@@ -1042,12 +1042,12 @@
         return nullptr;
     }
     
-    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsFireShouldPartitionCookiesHandler")) {
-        TestController::singleton().statisticsFireShouldPartitionCookiesHandler();
+    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsUpdateCookiePartitioning")) {
+        TestController::singleton().statisticsUpdateCookiePartitioning();
         return nullptr;
     }
 
-    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsFireShouldPartitionCookiesHandlerForOneDomain")) {
+    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsSetShouldPartitionCookiesForHost")) {
         ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
         
         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
@@ -1057,7 +1057,7 @@
         WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get()));
         WKBooleanRef value = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get()));
         
-        TestController::singleton().statisticsFireShouldPartitionCookiesHandlerForOneDomain(hostName, WKBooleanGetValue(value));
+        TestController::singleton().statisticsSetShouldPartitionCookiesForHost(hostName, WKBooleanGetValue(value));
         return nullptr;
     }
     

Modified: trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm (219296 => 219297)


--- trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2017-07-10 17:03:14 UTC (rev 219296)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2017-07-10 17:09:38 UTC (rev 219297)
@@ -306,14 +306,14 @@
     [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsProcessStatisticsAndDataRecords];
 }
 
-void TestController::statisticsFireShouldPartitionCookiesHandler()
+void TestController::statisticsUpdateCookiePartitioning()
 {
-    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsFireShouldPartitionCookiesHandler];
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsUpdateCookiePartitioning];
 }
 
-void TestController::statisticsFireShouldPartitionCookiesHandlerForOneDomain(WKStringRef hostName, bool value)
+void TestController::statisticsSetShouldPartitionCookiesForHost(WKStringRef hostName, bool value)
 {
-    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsFireShouldPartitionCookiesHandlerForOneDomain:value forHost:toNSString(hostName)];
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetShouldPartitionCookies:value forHost:toNSString(hostName)];
 }
 
 void TestController::statisticsSubmitTelemetry()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to