Title: [219277] trunk
Revision
219277
Author
[email protected]
Date
2017-07-08 16:11:16 -0700 (Sat, 08 Jul 2017)

Log Message

Simplify WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore
https://bugs.webkit.org/show_bug.cgi?id=174290

Reviewed by Brent Fulgham.

Source/WebKit2:

* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _resourceLoadStatisticsProcessStatisticsAndDataRecords]):
(-[WKWebsiteDataStore _resourceLoadStatisticsSubmitTelemetry]):
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
Rename a couple of functions in the Cocoa SPI for clarity and to match the name
of their internal implementation.

* UIProcess/Storage/ResourceLoadStatisticsStore.cpp:
(WebKit::ResourceLoadStatisticsStore::create):
(WebKit::ResourceLoadStatisticsStore::ensureResourceStatisticsForPrimaryDomain):
Stylistic changes.

(WebKit::ResourceLoadStatisticsStore::createEncoderFromData):
Make const.

(WebKit::ResourceLoadStatisticsStore::readDataFromDecoder):
Use HashMap::add() instead of HashMap::set(). There is not supposed to have any duplicate
keys so add() is sufficient and more efficient.

(WebKit::ResourceLoadStatisticsStore::clearInMemoryAndPersistent): Removed.
clearInMemoryAndPersistent() was only called from WebResourceLoadStatisticsStore and
the m_deletePersistentStoreHandler / m_grandfatherExistingWebsiteDataHandler were both
set by the WebResourceLoadStatisticsStore as well. Therefore, we don't really need this
function, WebResourceLoadStatisticsStore now calls ResourceLoadStatisticsStore::clearInMemory()
instead and takes care of doing what the m_deletePersistentStoreHandler /
m_grandfatherExistingWebsiteDataHandler handlers were doing on its side.

(WebKit::ResourceLoadStatisticsStore::mergeStatistics):
Pass Vector as rvalue reference, as a preparation for a future optimization. Added FIXME
comment about the optimization.

(WebKit::ResourceLoadStatisticsStore::setNotificationCallback): Removed.
(WebKit::ResourceLoadStatisticsStore::setGrandfatherExistingWebsiteDataCallback): Removed.
(WebKit::ResourceLoadStatisticsStore::setDeletePersistentStoreCallback): Removed.
(WebKit::ResourceLoadStatisticsStore::setFireTelemetryCallback): Removed.
Drop those callback setters. WebResourceLoadStatisticsStore is the only client of
ResourceLoadStatisticsStore and those callbacks were always called as a result of
an operation requested by the WebResourceLoadStatisticsStore. Therefore, those are
not needed. WebResourceLoadStatisticsStore can take care of doing what those
callbacks were doing on its side.

(WebKit::ResourceLoadStatisticsStore::processStatistics):
Pass parameter by const reference since we clearly do not intend to transfer ownership of it.

(WebKit::ResourceLoadStatisticsStore::topPrivatelyControlledDomainsToRemoveWebsiteDataFor):
(WebKit::ResourceLoadStatisticsStore::updateStatisticsForRemovedDataRecords):
(WebKit::ResourceLoadStatisticsStore::handleFreshStartWithEmptyOrNoStore):
Stylistic changes.

(WebKit::ResourceLoadStatisticsStore::shouldRemoveDataRecords): Removed.
(WebKit::ResourceLoadStatisticsStore::dataRecordsBeingRemoved): Removed.
(WebKit::ResourceLoadStatisticsStore::dataRecordsWereRemoved): Removed.
Those were moved to WebResourceLoadStatisticsStore since they do not require
any access to the statistics, and are only used by WebResourceLoadStatisticsStore.

* UIProcess/Storage/ResourceLoadStatisticsStore.h:

* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
Store registering most callbacks on the coreStore. Instead, the logic of those
callbacks is now inlined in the few methods in WebResourceLoadStatisticsStore
that were causing these callbacks to be called.

(WebKit::WebResourceLoadStatisticsStore::removeDataRecords):
Access some methods on WebResourceLoadStatisticsStore instead of the coreStore
since those were moved.

(WebKit::WebResourceLoadStatisticsStore::processStatisticsAndDataRecords):
Drop unnecessary mutable for lambda.

(WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
Pass parameter as rvalue reference as a preparation for a future optimization.

(WebKit::WebResourceLoadStatisticsStore::hasStatisticsFileChangedSinceLastSync):
Make const.

(WebKit::WebResourceLoadStatisticsStore::submitTelemetry):
Add assertion to make sure this is called on the main thread.

(WebKit::WebResourceLoadStatisticsStore::fireDataModificationHandler): Removed.
This was dispatching to a background queue to call fireDataModificationHandler()
on the ResourceLoadStatisticsStore. The coreStore would then dispatch back on the
main thread to call the WebResourceLoadStatisticsStore's modification handler.
This modification handler was merely calling processStatisticsAndDataRecords().
Therefore, callers of WebResourceLoadStatisticsStore::fireDataModificationHandler()
can call WebResourceLoadStatisticsStore::processStatisticsAndDataRecords() directly
instead.

(WebKit::WebResourceLoadStatisticsStore::fireTelemetryHandler): Removed.
This was calling ResourceLoadStatisticsStore::fireTelemetryHandler(), which was
calling back WebResourceLoadStatisticsStore's fireTelemetryHandler. The handler
in question was merely calling submitTelemetry(). Therefore, callers of
WebResourceLoadStatisticsStore::fireTelemetryHandler() can call
WebResourceLoadStatisticsStore::submitTelemetry() directly instead.

(WebKit::WebResourceLoadStatisticsStore::clearInMemoryAndPersistent):
Call ResourceLoadStatisticsStore::clearInMemory() instead of clearInMemoryAndPersistent(),
which was removed. ResourceLoadStatisticsStore::clearInMemoryAndPersistent() was calling
clearInMemory() and then 2 of WebResourceLoadStatisticsStore's handlers. Instead, we now
call the functions that those handlers were calling directly, thus eliminating the need
for those handlers.

(WebKit::WebResourceLoadStatisticsStore::setMinimumTimeBetweenDataRecordsRemoval):
Set m_minimumTimeBetweenDataRecordsRemoval directly as it is now store on this class
instead of the coreStore.

(WebKit::WebResourceLoadStatisticsStore::shouldRemoveDataRecords):
(WebKit::WebResourceLoadStatisticsStore::dataRecordsBeingRemoved):
(WebKit::WebResourceLoadStatisticsStore::dataRecordsWereRemoved):
Those were merely moved from the ResourceLoadStatisticsStore.

* UIProcess/WebResourceLoadStatisticsStore.h:

* UIProcess/WebResourceLoadStatisticsTelemetry.cpp:
(WebKit::WebResourceLoadStatisticsTelemetry::calculateAndSubmit):
Check for sortedPrevalentResources.isEmpty() instead of checking if the size
if less than minimumPrevalentResourcesForTelemetry.
ResourceLoadStatisticsStore::sortedPrevalentResourceTelemetry() either returns
an empty vector or a vector with more than minimumPrevalentResourcesForTelemetry
items. Therefore, there is no need to expose minimumPrevalentResourcesForTelemetry.

Tools:

Rename testRunner API to match the new internal API names.

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

LayoutTests:

Update layout tests to reflect changes to the testRunner API naming.

* http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html:
* http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html:
* http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html:
* http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html:
* http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html:
* http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html:
* http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html:
* http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html:
* http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html:
* http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store.html:
* http/tests/loading/resourceLoadStatistics/grandfathering.html:
* http/tests/loading/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html:
* http/tests/loading/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html:
* 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:
* http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html:
* http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction.html:
* http/tests/loading/resourceLoadStatistics/prevalent-resource-without-user-interaction.html:
* http/tests/loading/resourceLoadStatistics/telemetry-generation.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (219276 => 219277)


--- trunk/LayoutTests/ChangeLog	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/ChangeLog	2017-07-08 23:11:16 UTC (rev 219277)
@@ -1,3 +1,33 @@
+2017-07-08  Chris Dumez  <[email protected]>
+
+        Simplify WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore
+        https://bugs.webkit.org/show_bug.cgi?id=174290
+
+        Reviewed by Brent Fulgham.
+
+        Update layout tests to reflect changes to the testRunner API naming.
+
+        * http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html:
+        * http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html:
+        * http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html:
+        * http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html:
+        * http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html:
+        * http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html:
+        * http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html:
+        * http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html:
+        * http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html:
+        * http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store.html:
+        * http/tests/loading/resourceLoadStatistics/grandfathering.html:
+        * http/tests/loading/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html:
+        * http/tests/loading/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html:
+        * 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:
+        * http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html:
+        * http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction.html:
+        * http/tests/loading/resourceLoadStatistics/prevalent-resource-without-user-interaction.html:
+        * http/tests/loading/resourceLoadStatistics/telemetry-generation.html:
+
 2017-07-07  Daniel Bates  <[email protected]>
 
         [AppCache] Ignore fallback entries whose namespace is not prefixed with manifest path

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -36,7 +36,7 @@
 
         testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
 
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
@@ -46,4 +46,4 @@
     }
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -37,7 +37,7 @@
         testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
         testRunner.installStatisticsDidModifyDataRecordsCallback(completeTest);
 
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
@@ -47,4 +47,4 @@
     }
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -34,7 +34,7 @@
 
         testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
 
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
@@ -44,4 +44,4 @@
     }
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -35,7 +35,7 @@
 
         testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
 
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
@@ -45,4 +45,4 @@
     }
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -44,7 +44,7 @@
 
         testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
 
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
@@ -54,4 +54,4 @@
     }
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -39,7 +39,7 @@
 
         testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
 
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
@@ -49,4 +49,4 @@
     }
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -39,7 +39,7 @@
 
         testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
 
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
@@ -49,4 +49,4 @@
     }
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -39,7 +39,7 @@
 
         testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
 
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -55,7 +55,7 @@
         testRunner.installStatisticsDidScanDataRecordsCallback(testStep2);
         testRunner.installStatisticsDidModifyDataRecordsCallback(testStep2);
 
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
@@ -65,4 +65,4 @@
     }
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -55,7 +55,7 @@
         testRunner.installStatisticsDidScanDataRecordsCallback(testStep2);
         testRunner.installStatisticsDidModifyDataRecordsCallback(testStep2);
 
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
@@ -65,4 +65,4 @@
     }
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/grandfathering.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/grandfathering.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/grandfathering.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -36,7 +36,7 @@
         testRunner.installStatisticsDidModifyDataRecordsCallback(function() {
             runTest();
         });
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     function clearInMemoryAndPersistentStoreAndContinue() {

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -43,7 +43,7 @@
         });
         testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
         testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -43,7 +43,7 @@
         });
         testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
         testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {

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


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -45,7 +45,7 @@
         testRunner.installStatisticsDidModifyDataRecordsCallback(function() {
             runTest();
         });
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     function setUserInteractionAndContinue() {

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


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -125,4 +125,4 @@
     runTest();
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

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


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -83,4 +83,4 @@
     runTest();
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -37,7 +37,7 @@
         testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
         testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
         testRunner.setStatisticsTimeToLiveUserInteraction(0);
-        setTimeout("testRunner.statisticsFireDataModificationHandler()", 1000);
+        setTimeout("testRunner.statisticsProcessStatisticsAndDataRecords()", 1000);
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -43,7 +43,7 @@
         });
         testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
         testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-without-user-interaction.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-without-user-interaction.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-without-user-interaction.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -36,7 +36,7 @@
         });
         testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
         testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {

Modified: trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/telemetry-generation.html (219276 => 219277)


--- trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/telemetry-generation.html	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/telemetry-generation.html	2017-07-08 23:11:16 UTC (rev 219277)
@@ -74,7 +74,7 @@
 
         testRunner.installStatisticsDidScanDataRecordsCallback(checkInsufficientClassificationAndContinue);
         testRunner.installStatisticsDidRunTelemetryCallback(checkInsufficientTelemetry);
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     function setUpSufficientStatisticsAndContinue() {
@@ -85,11 +85,11 @@
 
         testRunner.installStatisticsDidScanDataRecordsCallback(checkSufficientClassificationAndContinue);
         testRunner.installStatisticsDidRunTelemetryCallback(checkSufficientTelemetry);
-        testRunner.statisticsFireDataModificationHandler();
+        testRunner.statisticsProcessStatisticsAndDataRecords();
     }
 
     function runTelemetryAndContinue() {
-        testRunner.statisticsFireTelemetryHandler();
+        testRunner.statisticsSubmitTelemetry();
     }
 
     var testResult;
@@ -116,4 +116,4 @@
     }
 </script>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/Source/WebKit2/ChangeLog (219276 => 219277)


--- trunk/Source/WebKit2/ChangeLog	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Source/WebKit2/ChangeLog	2017-07-08 23:11:16 UTC (rev 219277)
@@ -1,3 +1,131 @@
+2017-07-08  Chris Dumez  <[email protected]>
+
+        Simplify WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore
+        https://bugs.webkit.org/show_bug.cgi?id=174290
+
+        Reviewed by Brent Fulgham.
+
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore _resourceLoadStatisticsProcessStatisticsAndDataRecords]):
+        (-[WKWebsiteDataStore _resourceLoadStatisticsSubmitTelemetry]):
+        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+        Rename a couple of functions in the Cocoa SPI for clarity and to match the name
+        of their internal implementation.
+
+        * UIProcess/Storage/ResourceLoadStatisticsStore.cpp:
+        (WebKit::ResourceLoadStatisticsStore::create):
+        (WebKit::ResourceLoadStatisticsStore::ensureResourceStatisticsForPrimaryDomain):
+        Stylistic changes.
+
+        (WebKit::ResourceLoadStatisticsStore::createEncoderFromData):
+        Make const.
+
+        (WebKit::ResourceLoadStatisticsStore::readDataFromDecoder):
+        Use HashMap::add() instead of HashMap::set(). There is not supposed to have any duplicate
+        keys so add() is sufficient and more efficient.
+
+        (WebKit::ResourceLoadStatisticsStore::clearInMemoryAndPersistent): Removed.
+        clearInMemoryAndPersistent() was only called from WebResourceLoadStatisticsStore and
+        the m_deletePersistentStoreHandler / m_grandfatherExistingWebsiteDataHandler were both
+        set by the WebResourceLoadStatisticsStore as well. Therefore, we don't really need this
+        function, WebResourceLoadStatisticsStore now calls ResourceLoadStatisticsStore::clearInMemory()
+        instead and takes care of doing what the m_deletePersistentStoreHandler /
+        m_grandfatherExistingWebsiteDataHandler handlers were doing on its side.
+
+        (WebKit::ResourceLoadStatisticsStore::mergeStatistics):
+        Pass Vector as rvalue reference, as a preparation for a future optimization. Added FIXME
+        comment about the optimization.
+
+        (WebKit::ResourceLoadStatisticsStore::setNotificationCallback): Removed.
+        (WebKit::ResourceLoadStatisticsStore::setGrandfatherExistingWebsiteDataCallback): Removed.
+        (WebKit::ResourceLoadStatisticsStore::setDeletePersistentStoreCallback): Removed.
+        (WebKit::ResourceLoadStatisticsStore::setFireTelemetryCallback): Removed.
+        Drop those callback setters. WebResourceLoadStatisticsStore is the only client of
+        ResourceLoadStatisticsStore and those callbacks were always called as a result of
+        an operation requested by the WebResourceLoadStatisticsStore. Therefore, those are
+        not needed. WebResourceLoadStatisticsStore can take care of doing what those
+        callbacks were doing on its side.
+
+        (WebKit::ResourceLoadStatisticsStore::processStatistics):
+        Pass parameter by const reference since we clearly do not intend to transfer ownership of it.
+
+        (WebKit::ResourceLoadStatisticsStore::topPrivatelyControlledDomainsToRemoveWebsiteDataFor):
+        (WebKit::ResourceLoadStatisticsStore::updateStatisticsForRemovedDataRecords):
+        (WebKit::ResourceLoadStatisticsStore::handleFreshStartWithEmptyOrNoStore):
+        Stylistic changes.
+
+        (WebKit::ResourceLoadStatisticsStore::shouldRemoveDataRecords): Removed.
+        (WebKit::ResourceLoadStatisticsStore::dataRecordsBeingRemoved): Removed.
+        (WebKit::ResourceLoadStatisticsStore::dataRecordsWereRemoved): Removed.
+        Those were moved to WebResourceLoadStatisticsStore since they do not require
+        any access to the statistics, and are only used by WebResourceLoadStatisticsStore.
+
+        * UIProcess/Storage/ResourceLoadStatisticsStore.h:
+
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
+        Store registering most callbacks on the coreStore. Instead, the logic of those
+        callbacks is now inlined in the few methods in WebResourceLoadStatisticsStore
+        that were causing these callbacks to be called.
+
+        (WebKit::WebResourceLoadStatisticsStore::removeDataRecords):
+        Access some methods on WebResourceLoadStatisticsStore instead of the coreStore
+        since those were moved.
+
+        (WebKit::WebResourceLoadStatisticsStore::processStatisticsAndDataRecords):
+        Drop unnecessary mutable for lambda.
+
+        (WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
+        Pass parameter as rvalue reference as a preparation for a future optimization.
+
+        (WebKit::WebResourceLoadStatisticsStore::hasStatisticsFileChangedSinceLastSync):
+        Make const.
+
+        (WebKit::WebResourceLoadStatisticsStore::submitTelemetry):
+        Add assertion to make sure this is called on the main thread.
+
+        (WebKit::WebResourceLoadStatisticsStore::fireDataModificationHandler): Removed.
+        This was dispatching to a background queue to call fireDataModificationHandler()
+        on the ResourceLoadStatisticsStore. The coreStore would then dispatch back on the
+        main thread to call the WebResourceLoadStatisticsStore's modification handler.
+        This modification handler was merely calling processStatisticsAndDataRecords().
+        Therefore, callers of WebResourceLoadStatisticsStore::fireDataModificationHandler()
+        can call WebResourceLoadStatisticsStore::processStatisticsAndDataRecords() directly
+        instead.
+
+        (WebKit::WebResourceLoadStatisticsStore::fireTelemetryHandler): Removed.
+        This was calling ResourceLoadStatisticsStore::fireTelemetryHandler(), which was
+        calling back WebResourceLoadStatisticsStore's fireTelemetryHandler. The handler
+        in question was merely calling submitTelemetry(). Therefore, callers of
+        WebResourceLoadStatisticsStore::fireTelemetryHandler() can call
+        WebResourceLoadStatisticsStore::submitTelemetry() directly instead.
+
+        (WebKit::WebResourceLoadStatisticsStore::clearInMemoryAndPersistent):
+        Call ResourceLoadStatisticsStore::clearInMemory() instead of clearInMemoryAndPersistent(),
+        which was removed. ResourceLoadStatisticsStore::clearInMemoryAndPersistent() was calling
+        clearInMemory() and then 2 of WebResourceLoadStatisticsStore's handlers. Instead, we now
+        call the functions that those handlers were calling directly, thus eliminating the need
+        for those handlers.
+
+        (WebKit::WebResourceLoadStatisticsStore::setMinimumTimeBetweenDataRecordsRemoval):
+        Set m_minimumTimeBetweenDataRecordsRemoval directly as it is now store on this class
+        instead of the coreStore.
+
+        (WebKit::WebResourceLoadStatisticsStore::shouldRemoveDataRecords):
+        (WebKit::WebResourceLoadStatisticsStore::dataRecordsBeingRemoved):
+        (WebKit::WebResourceLoadStatisticsStore::dataRecordsWereRemoved):
+        Those were merely moved from the ResourceLoadStatisticsStore.
+
+        * UIProcess/WebResourceLoadStatisticsStore.h:
+
+        * UIProcess/WebResourceLoadStatisticsTelemetry.cpp:
+        (WebKit::WebResourceLoadStatisticsTelemetry::calculateAndSubmit):
+        Check for sortedPrevalentResources.isEmpty() instead of checking if the size
+        if less than minimumPrevalentResourcesForTelemetry.
+        ResourceLoadStatisticsStore::sortedPrevalentResourceTelemetry() either returns
+        an empty vector or a vector with more than minimumPrevalentResourcesForTelemetry
+        items. Therefore, there is no need to expose minimumPrevalentResourcesForTelemetry.
+
 2017-07-08  Yusuke Suzuki  <[email protected]>
 
         Drop NOSNIFF compile flag

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


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2017-07-08 23:11:16 UTC (rev 219277)
@@ -345,13 +345,13 @@
     store->setGrandfatheringTime(Seconds {seconds });
 }
 
-- (void)_resourceLoadStatisticsFireDataModificationHandler
+- (void)_resourceLoadStatisticsProcessStatisticsAndDataRecords
 {
     auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
     if (!store)
         return;
 
-    store->fireDataModificationHandler();
+    store->processStatisticsAndDataRecords();
 }
 
 - (void)_resourceLoadStatisticsFireShouldPartitionCookiesHandler
@@ -375,13 +375,13 @@
         store->fireShouldPartitionCookiesHandler({ host }, { }, false);
 }
 
-- (void)_resourceLoadStatisticsFireTelemetryHandler
+- (void)_resourceLoadStatisticsSubmitTelemetry
 {
     auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
     if (!store)
         return;
 
-    store->fireTelemetryHandler();
+    store->submitTelemetry();
 }
 
 - (void)_resourceLoadStatisticsSetNotifyPagesWhenDataRecordsWereScanned:(BOOL)value

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


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2017-07-08 23:11:16 UTC (rev 219277)
@@ -57,10 +57,10 @@
 - (void)_resourceLoadStatisticsSetTimeToLiveCookiePartitionFree:(double)seconds WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (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)_resourceLoadStatisticsFireDataModificationHandler 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)_resourceLoadStatisticsFireTelemetryHandler 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));
 - (void)_resourceLoadStatisticsSetNotifyPagesWhenTelemetryWasCaptured:(BOOL)value WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));

Modified: trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.cpp (219276 => 219277)


--- trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.cpp	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.cpp	2017-07-08 23:11:16 UTC (rev 219277)
@@ -26,13 +26,9 @@
 #include "config.h"
 #include "ResourceLoadStatisticsStore.h"
 
-#include "Logging.h"
 #include <WebCore/KeyedCoding.h>
 #include <WebCore/ResourceLoadStatistics.h>
-#include <WebCore/SharedBuffer.h>
-#include <WebCore/URL.h>
 #include <wtf/CrossThreadCopier.h>
-#include <wtf/NeverDestroyed.h>
 #include <wtf/RunLoop.h>
 
 namespace WebKit {
@@ -39,14 +35,15 @@
 
 using namespace WebCore;
 
+const unsigned minimumPrevalentResourcesForTelemetry = 3;
+const unsigned operatingDatesWindow { 30 };
 const unsigned statisticsModelVersion { 6 };
-const unsigned operatingDatesWindow { 30 };
-    
+
 Ref<ResourceLoadStatisticsStore> ResourceLoadStatisticsStore::create()
 {
-    return adoptRef(*new ResourceLoadStatisticsStore());
+    return adoptRef(*new ResourceLoadStatisticsStore);
 }
-    
+
 bool ResourceLoadStatisticsStore::isPrevalentResource(const String& primaryDomain) const
 {
     ASSERT(!RunLoop::isMain());
@@ -70,16 +67,14 @@
 ResourceLoadStatistics& ResourceLoadStatisticsStore::ensureResourceStatisticsForPrimaryDomain(const String& primaryDomain)
 {
     ASSERT(!RunLoop::isMain());
-    auto addResult = m_resourceStatisticsMap.ensure(primaryDomain, [&primaryDomain] {
+    return m_resourceStatisticsMap.ensure(primaryDomain, [&primaryDomain] {
         return ResourceLoadStatistics(primaryDomain);
-    });
-
-    return addResult.iterator->value;
+    }).iterator->value;
 }
 
 typedef HashMap<String, ResourceLoadStatistics>::KeyValuePairType StatisticsValue;
 
-std::unique_ptr<KeyedEncoder> ResourceLoadStatisticsStore::createEncoderFromData()
+std::unique_ptr<KeyedEncoder> ResourceLoadStatisticsStore::createEncoderFromData() const
 {
     ASSERT(!RunLoop::isMain());
     auto encoder = KeyedEncoder::encoder();
@@ -100,7 +95,7 @@
 void ResourceLoadStatisticsStore::readDataFromDecoder(KeyedDecoder& decoder)
 {
     ASSERT(!RunLoop::isMain());
-    if (m_resourceStatisticsMap.size())
+    if (!m_resourceStatisticsMap.isEmpty())
         return;
 
     unsigned versionOnDisk;
@@ -131,7 +126,7 @@
             prevalentResourceDomainsWithoutUserInteraction.uncheckedAppend(statistics.highLevelDomain);
             statistics.isMarkedForCookiePartitioning = true;
         }
-        m_resourceStatisticsMap.set(statistics.highLevelDomain, WTFMove(statistics));
+        m_resourceStatisticsMap.add(statistics.highLevelDomain, WTFMove(statistics));
     }
 
     succeeded = decoder.decodeObjects("operatingDates", m_operatingDates, [](KeyedDecoder& decoder, WallTime& wallTime) {
@@ -158,20 +153,12 @@
     fireShouldPartitionCookiesHandler({ }, { }, true);
 }
 
-void ResourceLoadStatisticsStore::clearInMemoryAndPersistent()
+void ResourceLoadStatisticsStore::mergeStatistics(Vector<ResourceLoadStatistics>&& statistics)
 {
     ASSERT(!RunLoop::isMain());
-    clearInMemory();
-    if (m_deletePersistentStoreHandler)
-        m_deletePersistentStoreHandler();
-    if (m_grandfatherExistingWebsiteDataHandler)
-        m_grandfatherExistingWebsiteDataHandler();
-}
-
-void ResourceLoadStatisticsStore::mergeStatistics(const Vector<ResourceLoadStatistics>& statistics)
-{
-    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);
         });
@@ -180,47 +167,11 @@
     }
 }
 
-void ResourceLoadStatisticsStore::setNotificationCallback(WTF::Function<void()>&& handler)
-{
-    m_dataAddedHandler = WTFMove(handler);
-}
-
 void ResourceLoadStatisticsStore::setShouldPartitionCookiesCallback(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&& handler)
 {
     m_shouldPartitionCookiesForDomainsHandler = WTFMove(handler);
 }
-    
-void ResourceLoadStatisticsStore::setGrandfatherExistingWebsiteDataCallback(WTF::Function<void()>&& handler)
-{
-    m_grandfatherExistingWebsiteDataHandler = WTFMove(handler);
-}
 
-void ResourceLoadStatisticsStore::setDeletePersistentStoreCallback(WTF::Function<void()>&& handler)
-{
-    m_deletePersistentStoreHandler = WTFMove(handler);
-}
-
-void ResourceLoadStatisticsStore::setFireTelemetryCallback(WTF::Function<void()>&& handler)
-{
-    m_fireTelemetryHandler = WTFMove(handler);
-}
-    
-void ResourceLoadStatisticsStore::fireDataModificationHandler()
-{
-    ASSERT(!RunLoop::isMain());
-    RunLoop::main().dispatch([this, protectedThis = makeRef(*this)] () {
-        if (m_dataAddedHandler)
-            m_dataAddedHandler();
-    });
-}
-
-void ResourceLoadStatisticsStore::fireTelemetryHandler()
-{
-    ASSERT(RunLoop::isMain());
-    if (m_fireTelemetryHandler)
-        m_fireTelemetryHandler();
-}
-    
 inline bool ResourceLoadStatisticsStore::shouldPartitionCookies(const ResourceLoadStatistics& statistic) const
 {
     return statistic.isPrevalentResource && (!statistic.hadUserInteraction || WallTime::now() > statistic.mostRecentUserInteractionTime + m_timeToLiveCookiePartitionFree);
@@ -287,12 +238,6 @@
     m_timeToLiveCookiePartitionFree = seconds;
 }
 
-void ResourceLoadStatisticsStore::setMinimumTimeBetweenDataRecordsRemoval(Seconds seconds)
-{
-    ASSERT(seconds >= 0_s);
-    m_minimumTimeBetweenDataRecordsRemoval = seconds;
-}
-
 void ResourceLoadStatisticsStore::setGrandfatheringTime(Seconds seconds)
 {
     ASSERT(seconds >= 0_s);
@@ -299,7 +244,7 @@
     m_grandfatheringTime = seconds;
 }
 
-void ResourceLoadStatisticsStore::processStatistics(WTF::Function<void(ResourceLoadStatistics&)>&& processFunction)
+void ResourceLoadStatisticsStore::processStatistics(const WTF::Function<void(ResourceLoadStatistics&)>& processFunction)
 {
     ASSERT(!RunLoop::isMain());
     for (auto& resourceStatistic : m_resourceStatisticsMap.values())
@@ -336,9 +281,7 @@
 
     Vector<String> prevalentResources;
     for (auto& statistic : m_resourceStatisticsMap.values()) {
-        if (statistic.isPrevalentResource
-            && !hasHadRecentUserInteraction(statistic)
-            && (!shouldCheckForGrandfathering || !statistic.grandfathered))
+        if (statistic.isPrevalentResource && !hasHadRecentUserInteraction(statistic) && (!shouldCheckForGrandfathering || !statistic.grandfathered))
             prevalentResources.append(statistic.highLevelDomain);
 
         if (shouldClearGrandfathering && statistic.grandfathered)
@@ -382,7 +325,7 @@
 {
     ASSERT(!RunLoop::isMain());
     for (auto& prevalentResourceDomain : prevalentResourceDomains) {
-        ResourceLoadStatistics& statistic = ensureResourceStatisticsForPrimaryDomain(prevalentResourceDomain);
+        auto& statistic = ensureResourceStatisticsForPrimaryDomain(prevalentResourceDomain);
         ++statistic.dataRecordsRemoved;
     }
 }
@@ -391,37 +334,12 @@
 {
     ASSERT(!RunLoop::isMain());
     for (auto& topPrivatelyControlledDomain : topPrivatelyControlledDomainsToGrandfather) {
-        ResourceLoadStatistics& statistic = ensureResourceStatisticsForPrimaryDomain(topPrivatelyControlledDomain);
+        auto& statistic = ensureResourceStatisticsForPrimaryDomain(topPrivatelyControlledDomain);
         statistic.grandfathered = true;
     }
     m_endOfGrandfatheringTimestamp = WallTime::now() + m_grandfatheringTime;
 }
 
-bool ResourceLoadStatisticsStore::shouldRemoveDataRecords() const
-{
-    ASSERT(!RunLoop::isMain());
-    if (m_dataRecordsRemovalPending)
-        return false;
-
-    if (m_lastTimeDataRecordsWereRemoved && MonotonicTime::now() < (m_lastTimeDataRecordsWereRemoved + m_minimumTimeBetweenDataRecordsRemoval))
-        return false;
-
-    return true;
-}
-
-void ResourceLoadStatisticsStore::dataRecordsBeingRemoved()
-{
-    ASSERT(!RunLoop::isMain());
-    m_lastTimeDataRecordsWereRemoved = MonotonicTime::now();
-    m_dataRecordsRemovalPending = true;
-}
-
-void ResourceLoadStatisticsStore::dataRecordsWereRemoved()
-{
-    ASSERT(!RunLoop::isMain());
-    m_dataRecordsRemovalPending = false;
-}
-
 void ResourceLoadStatisticsStore::includeTodayAsOperatingDateIfNecessary()
 {
     if (!m_operatingDates.isEmpty() && (WallTime::now() - m_operatingDates.last() < 24_h))

Modified: trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.h (219276 => 219277)


--- trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.h	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.h	2017-07-08 23:11:16 UTC (rev 219277)
@@ -41,8 +41,6 @@
 
 namespace WebKit {
 
-static const auto minimumPrevalentResourcesForTelemetry = 3;
-
 struct PrevalentResourceTelemetry {
     unsigned numberOfTimesDataRecordsRemoved;
     bool hasHadUserInteraction;
@@ -57,38 +55,29 @@
 public:
     static Ref<ResourceLoadStatisticsStore> create();
 
-    std::unique_ptr<WebCore::KeyedEncoder> createEncoderFromData();
+    std::unique_ptr<WebCore::KeyedEncoder> createEncoderFromData() const;
     void readDataFromDecoder(WebCore::KeyedDecoder&);
 
     bool isEmpty() const { return m_resourceStatisticsMap.isEmpty(); }
-    size_t size() const { return m_resourceStatisticsMap.size(); }
     void clearInMemory();
-    void clearInMemoryAndPersistent();
 
     WebCore::ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
-    void setResourceStatisticsForPrimaryDomain(const String&, WebCore::ResourceLoadStatistics&&);
 
     bool isPrevalentResource(const String&) const;
     bool isGrandFathered(const String&) const;
     
-    void mergeStatistics(const Vector<WebCore::ResourceLoadStatistics>&);
+    void mergeStatistics(Vector<WebCore::ResourceLoadStatistics>&&);
 
-    void setNotificationCallback(WTF::Function<void()>&&);
     void setShouldPartitionCookiesCallback(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&&);
-    void setDeletePersistentStoreCallback(WTF::Function<void()>&&);
-    void setGrandfatherExistingWebsiteDataCallback(WTF::Function<void()>&&);
-    void setFireTelemetryCallback(WTF::Function<void()>&& handler);
 
-    void fireDataModificationHandler();
-    void fireTelemetryHandler();
     void setTimeToLiveUserInteraction(std::optional<Seconds>);
     void setTimeToLiveCookiePartitionFree(Seconds);
-    void setMinimumTimeBetweenDataRecordsRemoval(Seconds);
     void setGrandfatheringTime(Seconds);
+
     void fireShouldPartitionCookiesHandler();
     void fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst);
 
-    void processStatistics(WTF::Function<void (WebCore::ResourceLoadStatistics&)>&&);
+    void processStatistics(const WTF::Function<void (WebCore::ResourceLoadStatistics&)>&);
 
     bool hasHadRecentUserInteraction(WebCore::ResourceLoadStatistics&) const;
     Vector<String> topPrivatelyControlledDomainsToRemoveWebsiteDataFor();
@@ -96,10 +85,6 @@
     void updateStatisticsForRemovedDataRecords(const HashSet<String>& prevalentResourceDomains);
 
     void handleFreshStartWithEmptyOrNoStore(HashSet<String>&& topPrivatelyControlledDomainsToGrandfather);
-    bool shouldRemoveDataRecords() const;
-    void dataRecordsBeingRemoved();
-    void dataRecordsWereRemoved();
-
     void includeTodayAsOperatingDateIfNecessary();
 
 private:
@@ -111,20 +96,13 @@
     HashMap<String, WebCore::ResourceLoadStatistics> m_resourceStatisticsMap;
     Deque<WTF::WallTime> m_operatingDates;
 
-    WTF::Function<void()> m_dataAddedHandler;
     WTF::Function<void(const Vector<String>&, const Vector<String>&, bool clearFirst)> m_shouldPartitionCookiesForDomainsHandler;
-    WTF::Function<void()> m_grandfatherExistingWebsiteDataHandler;
-    WTF::Function<void()> m_deletePersistentStoreHandler;
-    WTF::Function<void()> m_fireTelemetryHandler;
 
     std::optional<Seconds> m_timeToLiveUserInteraction;
     Seconds m_timeToLiveCookiePartitionFree { 24_h };
     Seconds m_grandfatheringTime { 1_h };
-    Seconds m_minimumTimeBetweenDataRecordsRemoval { 1_h };
 
     WallTime m_endOfGrandfatheringTimestamp;
-    MonotonicTime m_lastTimeDataRecordsWereRemoved;
-    bool m_dataRecordsRemovalPending { false };
 };
     
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp (219276 => 219277)


--- trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp	2017-07-08 23:11:16 UTC (rev 219277)
@@ -27,10 +27,11 @@
 #include "WebResourceLoadStatisticsStore.h"
 
 #include "Logging.h"
+#include "ResourceLoadStatisticsStore.h"
 #include "WebProcessMessages.h"
-#include "WebProcessPool.h"
 #include "WebProcessProxy.h"
 #include "WebResourceLoadStatisticsStoreMessages.h"
+#include "WebResourceLoadStatisticsTelemetry.h"
 #include "WebsiteDataFetchOption.h"
 #include "WebsiteDataType.h"
 #include <WebCore/FileMonitor.h>
@@ -37,14 +38,10 @@
 #include <WebCore/FileSystem.h>
 #include <WebCore/KeyedCoding.h>
 #include <WebCore/ResourceLoadStatistics.h>
+#include <WebCore/SharedBuffer.h>
 #include <wtf/CrossThreadCopier.h>
-#include <wtf/MainThread.h>
 #include <wtf/MathExtras.h>
-#include <wtf/MonotonicTime.h>
 #include <wtf/NeverDestroyed.h>
-#include <wtf/RunLoop.h>
-#include <wtf/Seconds.h>
-#include <wtf/WallTime.h>
 #include <wtf/threads/BinarySemaphore.h>
 
 #if PLATFORM(COCOA)
@@ -103,23 +100,6 @@
     registerUserDefaultsIfNeeded();
 #endif
 
-    m_resourceLoadStatisticsStore->setNotificationCallback([this, protectedThis = makeRef(*this)] {
-        if (m_resourceLoadStatisticsStore->isEmpty())
-            return;
-        processStatisticsAndDataRecords();
-    });
-    m_resourceLoadStatisticsStore->setGrandfatherExistingWebsiteDataCallback([this, protectedThis = makeRef(*this)] {
-        grandfatherExistingWebsiteData();
-    });
-    m_resourceLoadStatisticsStore->setDeletePersistentStoreCallback([this, protectedThis = makeRef(*this)] {
-        m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] {
-            deleteStoreFromDisk();
-        });
-    });
-    m_resourceLoadStatisticsStore->setFireTelemetryCallback([this, protectedThis = makeRef(*this)] {
-        submitTelemetry();
-    });
-
     if (updatePartitionCookiesForDomainsHandler) {
         m_resourceLoadStatisticsStore->setShouldPartitionCookiesCallback([updatePartitionCookiesForDomainsHandler = WTFMove(updatePartitionCookiesForDomainsHandler)] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst) {
             updatePartitionCookiesForDomainsHandler(domainsToRemove, domainsToAdd, shouldClearFirst);
@@ -164,7 +144,7 @@
 {
     ASSERT(!RunLoop::isMain());
     
-    if (!coreStore().shouldRemoveDataRecords())
+    if (!shouldRemoveDataRecords())
         return;
 
     auto prevalentResourceDomains = coreStore().topPrivatelyControlledDomainsToRemoveWebsiteDataFor();
@@ -171,15 +151,15 @@
     if (prevalentResourceDomains.isEmpty())
         return;
     
-    coreStore().dataRecordsBeingRemoved();
+    dataRecordsBeingRemoved();
 
     // 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.
-            m_statisticsQueue->dispatch([protectedThis = WTFMove(protectedThis), topDomains = CrossThreadCopier<HashSet<String>>::copy(domainsWithDeletedWebsiteData)] () mutable {
-                protectedThis->coreStore().updateStatisticsForRemovedDataRecords(topDomains);
-                protectedThis->coreStore().dataRecordsWereRemoved();
+            m_statisticsQueue->dispatch([this, protectedThis = WTFMove(protectedThis), topDomains = CrossThreadCopier<HashSet<String>>::copy(domainsWithDeletedWebsiteData)] () mutable {
+                coreStore().updateStatisticsForRemovedDataRecords(topDomains);
+                dataRecordsWereRemoved();
             });
         });
     });
@@ -196,7 +176,7 @@
         removeDataRecords();
         
         if (notifyPagesWhenDataRecordsWereScanned) {
-            RunLoop::main().dispatch([] () mutable {
+            RunLoop::main().dispatch([] {
                 WebProcessProxy::notifyPageStatisticsAndDataRecordsProcessed();
             });
         }
@@ -205,9 +185,11 @@
     });
 }
 
-void WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated(const Vector<WebCore::ResourceLoadStatistics>& origins)
+void WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated(Vector<WebCore::ResourceLoadStatistics>&& origins)
 {
-    coreStore().mergeStatistics(origins);
+    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();
@@ -237,7 +219,7 @@
     return WallTime::fromRawSeconds(modificationTime);
 }
 
-bool WebResourceLoadStatisticsStore::hasStatisticsFileChangedSinceLastSync(const String& path)
+bool WebResourceLoadStatisticsStore::hasStatisticsFileChangedSinceLastSync(const String& path) const
 {
     return statisticsFileModificationTime(path) > m_lastStatisticsFileSyncTime;
 }
@@ -549,6 +531,7 @@
 
 void WebResourceLoadStatisticsStore::submitTelemetry()
 {
+    ASSERT(RunLoop::isMain());
     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
         WebResourceLoadStatisticsTelemetry::calculateAndSubmit(coreStore());
     });
@@ -692,19 +675,11 @@
     });
 }
 
-void WebResourceLoadStatisticsStore::fireDataModificationHandler()
+void WebResourceLoadStatisticsStore::fireShouldPartitionCookiesHandler()
 {
     // 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().fireDataModificationHandler();
-    });
-}
 
-void WebResourceLoadStatisticsStore::fireShouldPartitionCookiesHandler()
-{
-    // 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();
     });
@@ -719,13 +694,6 @@
     });
 }
 
-void WebResourceLoadStatisticsStore::fireTelemetryHandler()
-{
-    // Helper function used by testing system. Should only be called from the main thread.
-    ASSERT(RunLoop::isMain());
-    coreStore().fireTelemetryHandler();
-}
-
 void WebResourceLoadStatisticsStore::clearInMemory()
 {
     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
@@ -736,7 +704,9 @@
 void WebResourceLoadStatisticsStore::clearInMemoryAndPersistent()
 {
     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
-        coreStore().clearInMemoryAndPersistent();
+        coreStore().clearInMemory();
+        deleteStoreFromDisk();
+        grandfatherExistingWebsiteData();
     });
 }
 
@@ -759,7 +729,8 @@
 
 void WebResourceLoadStatisticsStore::setMinimumTimeBetweenDataRecordsRemoval(Seconds seconds)
 {
-    coreStore().setMinimumTimeBetweenDataRecordsRemoval(seconds);
+    ASSERT(seconds >= 0_s);
+    m_minimumTimeBetweenDataRecordsRemoval = seconds;
 }
 
 void WebResourceLoadStatisticsStore::setGrandfatheringTime(Seconds seconds)
@@ -766,5 +737,30 @@
 {
     coreStore().setGrandfatheringTime(seconds);
 }
+
+bool WebResourceLoadStatisticsStore::shouldRemoveDataRecords() const
+{
+    ASSERT(!RunLoop::isMain());
+    if (m_dataRecordsRemovalPending)
+        return false;
+
+    if (m_lastTimeDataRecordsWereRemoved && MonotonicTime::now() < (m_lastTimeDataRecordsWereRemoved + m_minimumTimeBetweenDataRecordsRemoval))
+        return false;
+
+    return true;
+}
+
+void WebResourceLoadStatisticsStore::dataRecordsBeingRemoved()
+{
+    ASSERT(!RunLoop::isMain());
+    m_lastTimeDataRecordsWereRemoved = MonotonicTime::now();
+    m_dataRecordsRemovalPending = true;
+}
+
+void WebResourceLoadStatisticsStore::dataRecordsWereRemoved()
+{
+    ASSERT(!RunLoop::isMain());
+    m_dataRecordsRemovalPending = false;
+}
     
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h (219276 => 219277)


--- trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h	2017-07-08 23:11:16 UTC (rev 219277)
@@ -25,14 +25,12 @@
 
 #pragma once
 
-#include "APIObject.h"
 #include "Connection.h"
 #include "ResourceLoadStatisticsClassifier.h"
-#include "ResourceLoadStatisticsStore.h"
-#include "WebResourceLoadStatisticsTelemetry.h"
-#include "WebsiteDataRecord.h"
+#include <wtf/MonotonicTime.h>
 #include <wtf/RunLoop.h>
 #include <wtf/Vector.h>
+#include <wtf/WallTime.h>
 #include <wtf/text/WTFString.h>
 
 #if HAVE(CORE_PREDICTION)
@@ -40,8 +38,6 @@
 #endif
 
 namespace WTF {
-class MonotonicTime;
-class WallTime;
 class WorkQueue;
 }
 
@@ -49,11 +45,13 @@
 class FileMonitor;
 class KeyedDecoder;
 class KeyedEncoder;
+class URL;
 struct ResourceLoadStatistics;
 }
 
 namespace WebKit {
 
+class ResourceLoadStatisticsStore;
 class WebProcessProxy;
 
 class WebResourceLoadStatisticsStore final : public IPC::Connection::WorkQueueMessageReceiver {
@@ -64,12 +62,13 @@
         return adoptRef(*new WebResourceLoadStatisticsStore(resourceLoadStatisticsDirectory, WTFMove(updatePartitionCookiesForDomainsHandler)));
     }
 
+    ~WebResourceLoadStatisticsStore();
+
     static void setNotifyPagesWhenDataRecordsWereScanned(bool);
     static void setShouldClassifyResourcesBeforeDataRecordsRemoval(bool);
     static void setShouldSubmitTelemetry(bool);
-    virtual ~WebResourceLoadStatisticsStore();
 
-    void resourceLoadStatisticsUpdated(const Vector<WebCore::ResourceLoadStatistics>& origins);
+    void resourceLoadStatisticsUpdated(Vector<WebCore::ResourceLoadStatistics>&& origins);
 
     void processWillOpenConnection(WebProcessProxy&, IPC::Connection&);
     void processDidCloseConnection(WebProcessProxy&, IPC::Connection&);
@@ -86,11 +85,11 @@
     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 fireDataModificationHandler();
     void fireShouldPartitionCookiesHandler();
     void fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst);
+    void processStatisticsAndDataRecords();
+    void submitTelemetry();
 
-    void fireTelemetryHandler();
     void clearInMemory();
     void clearInMemoryAndPersistent();
     void clearInMemoryAndPersistent(std::chrono::system_clock::time_point modifiedSince);
@@ -106,7 +105,6 @@
     ResourceLoadStatisticsStore& coreStore() { return m_resourceLoadStatisticsStore.get(); }
     const ResourceLoadStatisticsStore& coreStore() const { return m_resourceLoadStatisticsStore.get(); }
 
-    void processStatisticsAndDataRecords();
     void readDataFromDiskIfNeeded();
 
     void classifyResource(WebCore::ResourceLoadStatistics&);
@@ -133,9 +131,11 @@
     void syncWithExistingStatisticsStorageIfNeeded();
     void refreshFromDisk();
     void submitTelemetryIfNecessary();
-    void submitTelemetry();
-    bool hasStatisticsFileChangedSinceLastSync(const String& path);
+    bool hasStatisticsFileChangedSinceLastSync(const String& path) const;
     void performDailyTasks();
+    bool shouldRemoveDataRecords() const;
+    void dataRecordsBeingRemoved();
+    void dataRecordsWereRemoved();
 
 #if PLATFORM(COCOA)
     void registerUserDefaultsIfNeeded();
@@ -150,10 +150,13 @@
     Ref<WTF::WorkQueue> m_statisticsQueue;
     std::unique_ptr<WebCore::FileMonitor> m_statisticsStorageMonitor;
     const String m_statisticsStoragePath;
-    WTF::WallTime m_lastStatisticsFileSyncTime;
-    WTF::MonotonicTime m_lastStatisticsWriteTime;
+    WallTime m_lastStatisticsFileSyncTime;
+    MonotonicTime m_lastStatisticsWriteTime;
     RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryOneShotTimer;
     RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryRepeatedTimer;
+    MonotonicTime m_lastTimeDataRecordsWereRemoved;
+    Seconds m_minimumTimeBetweenDataRecordsRemoval { 1_h };
+    bool m_dataRecordsRemovalPending { false };
     bool m_didScheduleWrite { false };
 };
 

Modified: trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsTelemetry.cpp (219276 => 219277)


--- trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsTelemetry.cpp	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsTelemetry.cpp	2017-07-08 23:11:16 UTC (rev 219277)
@@ -189,7 +189,7 @@
     ASSERT(!RunLoop::isMain());
     
     auto sortedPrevalentResources = resourceLoadStatisticsStore.sortedPrevalentResourceTelemetry();
-    if (notifyPagesWhenTelemetryWasCaptured && sortedPrevalentResources.size() < minimumPrevalentResourcesForTelemetry) {
+    if (notifyPagesWhenTelemetryWasCaptured && sortedPrevalentResources.isEmpty()) {
         notifyPages(0, 0, 0);
         return;
     }

Modified: trunk/Tools/ChangeLog (219276 => 219277)


--- trunk/Tools/ChangeLog	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Tools/ChangeLog	2017-07-08 23:11:16 UTC (rev 219277)
@@ -1,3 +1,27 @@
+2017-07-08  Chris Dumez  <[email protected]>
+
+        Simplify WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore
+        https://bugs.webkit.org/show_bug.cgi?id=174290
+
+        Reviewed by Brent Fulgham.
+
+        Rename testRunner API to match the new internal API names.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::statisticsProcessStatisticsAndDataRecords):
+        (WTR::TestRunner::statisticsSubmitTelemetry):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::statisticsProcessStatisticsAndDataRecords):
+        (WTR::TestController::statisticsSubmitTelemetry):
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
+        (WTR::TestController::statisticsProcessStatisticsAndDataRecords):
+        (WTR::TestController::statisticsSubmitTelemetry):
+
 2017-07-08  Yusuke Suzuki  <[email protected]>
 
         Drop NOSNIFF compile flag

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (219276 => 219277)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2017-07-08 23:11:16 UTC (rev 219277)
@@ -265,10 +265,10 @@
     void setStatisticsSubresourceUniqueRedirectTo(DOMString hostName, DOMString hostNameRedirectedTo);
     void setStatisticsTimeToLiveUserInteraction(double seconds);
     void setStatisticsTimeToLiveCookiePartitionFree(double seconds);
-    void statisticsFireDataModificationHandler();
+    void statisticsProcessStatisticsAndDataRecords();
     void statisticsFireShouldPartitionCookiesHandler();
     void statisticsFireShouldPartitionCookiesHandlerForOneDomain(DOMString hostName, boolean value);
-    void statisticsFireTelemetryHandler();
+    void statisticsSubmitTelemetry();
     void setStatisticsNotifyPagesWhenDataRecordsWereScanned(boolean value);
     void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(boolean value);
     void setStatisticsNotifyPagesWhenTelemetryWasCaptured(boolean value);

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (219276 => 219277)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2017-07-08 23:11:16 UTC (rev 219277)
@@ -1413,9 +1413,9 @@
     callTestRunnerCallback(StatisticsDidRunTelemetryCallbackID, 1, &result);
 }
     
-void TestRunner::statisticsFireDataModificationHandler()
+void TestRunner::statisticsProcessStatisticsAndDataRecords()
 {
-    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsFireDataModificationHandler"));
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsProcessStatisticsAndDataRecords"));
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr);
 }
 
@@ -1450,9 +1450,9 @@
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
 }
 
-void TestRunner::statisticsFireTelemetryHandler()
+void TestRunner::statisticsSubmitTelemetry()
 {
-    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsFireTelemetryHandler"));
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsSubmitTelemetry"));
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr);
 }
 

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (219276 => 219277)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2017-07-08 23:11:16 UTC (rev 219277)
@@ -353,10 +353,10 @@
     void statisticsDidModifyDataRecordsCallback();
     void statisticsDidScanDataRecordsCallback();
     void statisticsDidRunTelemetryCallback(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins);
-    void statisticsFireDataModificationHandler();
+    void statisticsProcessStatisticsAndDataRecords();
     void statisticsFireShouldPartitionCookiesHandler();
     void statisticsFireShouldPartitionCookiesHandlerForOneDomain(JSStringRef hostName, bool value);
-    void statisticsFireTelemetryHandler();
+    void statisticsSubmitTelemetry();
     void setStatisticsPrevalentResource(JSStringRef hostName, bool value);
     bool isStatisticsPrevalentResource(JSStringRef hostName);
     void setStatisticsHasHadUserInteraction(JSStringRef hostName, bool value);

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (219276 => 219277)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2017-07-08 23:11:16 UTC (rev 219277)
@@ -2296,7 +2296,7 @@
 {
 }
 
-void TestController::statisticsFireDataModificationHandler()
+void TestController::statisticsProcessStatisticsAndDataRecords()
 {
 }
 
@@ -2308,7 +2308,7 @@
 {
 }
 
-void TestController::statisticsFireTelemetryHandler()
+void TestController::statisticsSubmitTelemetry()
 {
 }
 

Modified: trunk/Tools/WebKitTestRunner/TestController.h (219276 => 219277)


--- trunk/Tools/WebKitTestRunner/TestController.h	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2017-07-08 23:11:16 UTC (rev 219277)
@@ -161,10 +161,10 @@
     void setStatisticsSubresourceUniqueRedirectTo(WKStringRef hostName, WKStringRef hostNameRedirectedTo);
     void setStatisticsTimeToLiveUserInteraction(double seconds);
     void setStatisticsTimeToLiveCookiePartitionFree(double seconds);
-    void statisticsFireDataModificationHandler();
+    void statisticsProcessStatisticsAndDataRecords();
     void statisticsFireShouldPartitionCookiesHandler();
     void statisticsFireShouldPartitionCookiesHandlerForOneDomain(WKStringRef hostName, bool value);
-    void statisticsFireTelemetryHandler();
+    void statisticsSubmitTelemetry();
     void setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool);
     void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool);
     void setStatisticsNotifyPagesWhenTelemetryWasCaptured(bool value);

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (219276 => 219277)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2017-07-08 23:11:16 UTC (rev 219277)
@@ -1037,8 +1037,8 @@
         return nullptr;
     }
 
-    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsFireDataModificationHandler")) {
-        TestController::singleton().statisticsFireDataModificationHandler();
+    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsProcessStatisticsAndDataRecords")) {
+        TestController::singleton().statisticsProcessStatisticsAndDataRecords();
         return nullptr;
     }
     
@@ -1061,8 +1061,8 @@
         return nullptr;
     }
     
-    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsFireTelemetryHandler")) {
-        TestController::singleton().statisticsFireTelemetryHandler();
+    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsSubmitTelemetry")) {
+        TestController::singleton().statisticsSubmitTelemetry();
         return nullptr;
     }
     

Modified: trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm (219276 => 219277)


--- trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2017-07-08 15:58:16 UTC (rev 219276)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2017-07-08 23:11:16 UTC (rev 219277)
@@ -301,9 +301,9 @@
     [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSetTimeToLiveCookiePartitionFree:seconds];
 }
 
-void TestController::statisticsFireDataModificationHandler()
+void TestController::statisticsProcessStatisticsAndDataRecords()
 {
-    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsFireDataModificationHandler];
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsProcessStatisticsAndDataRecords];
 }
 
 void TestController::statisticsFireShouldPartitionCookiesHandler()
@@ -316,9 +316,9 @@
     [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsFireShouldPartitionCookiesHandlerForOneDomain:value forHost:toNSString(hostName)];
 }
 
-void TestController::statisticsFireTelemetryHandler()
+void TestController::statisticsSubmitTelemetry()
 {
-    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsFireTelemetryHandler];
+    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSubmitTelemetry];
 }
 
 void TestController::setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool value)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to