Simplify WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Jul 2017 23:11:16 +0000 (23:11 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Jul 2017 23:11:16 +0000 (23:11 +0000)
commit348023f101a2c5b781e2ffd5a93c2633d630eea7
tree01210522e1c7b37fc287178700e0154d10085481
parent87e15f399a7798dbcd9e0289db121adaf07b2e13
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219277 268f45cc-cd09-0410-ab3c-d52691b4dbfc
37 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html
LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html
LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html
LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html
LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html
LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html
LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html
LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html
LayoutTests/http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html
LayoutTests/http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store.html
LayoutTests/http/tests/loading/resourceLoadStatistics/grandfathering.html
LayoutTests/http/tests/loading/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html
LayoutTests/http/tests/loading/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html
LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html
LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html
LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html
LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html
LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction.html
LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-without-user-interaction.html
LayoutTests/http/tests/loading/resourceLoadStatistics/telemetry-generation.html
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h
Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.cpp
Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.h
Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp
Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h
Source/WebKit2/UIProcess/WebResourceLoadStatisticsTelemetry.cpp
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestController.h
Tools/WebKitTestRunner/TestInvocation.cpp
Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm