Skip to content

Commit

Permalink
Merge ResourceLoadStatisticsStore and ResourceLoadStatisticsDatabaseS…
Browse files Browse the repository at this point in the history
…tore

https://bugs.webkit.org/show_bug.cgi?id=259715
<rdar://113236158>

Reviewed by Chris Dumez.

Now that we only have a SQLite-based ITP database, we should remove the needless layering
created by a separate ResourceLoadStatisticsStore and ResourceLoadStatisticsDatabaseStore
child class.

This will allow us to reduce complexity by removing a needless child class, but will also
remove numerous virtual method calls, type checks, and downcast operations needed to dispatch
methods to the child class.

* Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp: Removed.
* Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp: Many methods moved here
from ResourceLoadStatisticsDatabaseStore.cpp.
(WebKit::ResourceLoadStatisticsStore::computeImportance): Deleted.
* Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h:
(WebKit::ResourceLoadStatisticsStore::isDebugModeEnabled const): Deleted.
(WebKit::ResourceLoadStatisticsStore::setThirdPartyCookieBlockingMode): Deleted.
(WebKit::ResourceLoadStatisticsStore::thirdPartyCookieBlockingMode const): Deleted.
(WebKit::ResourceLoadStatisticsStore::setSameSiteStrictEnforcementEnabled): Deleted.
(WebKit::ResourceLoadStatisticsStore::isSameSiteStrictEnforcementEnabled const): Deleted.
(WebKit::ResourceLoadStatisticsStore::setFirstPartyWebsiteDataRemovalMode): Deleted.
(WebKit::ResourceLoadStatisticsStore::setStandaloneApplicationDomain): Deleted.
(WebKit::ResourceLoadStatisticsStore::store const): Deleted.
(WebKit::ResourceLoadStatisticsStore::isMemoryStore const): Deleted.
(WebKit::ResourceLoadStatisticsStore::isDatabaseStore const): Deleted.
(WebKit::ResourceLoadStatisticsStore::dataRecordsBeingRemoved const): Deleted.
(WebKit::ResourceLoadStatisticsStore::store): Deleted.
(WebKit::ResourceLoadStatisticsStore::workQueue): Deleted.
(WebKit::ResourceLoadStatisticsStore::classifier): Deleted.
(WebKit::ResourceLoadStatisticsStore::parameters const): Deleted.
(WebKit::ResourceLoadStatisticsStore::endOfGrandfatheringTimestamp): Deleted.
(WebKit::ResourceLoadStatisticsStore::endOfGrandfatheringTimestamp const): Deleted.
(WebKit::ResourceLoadStatisticsStore::clearEndOfGrandfatheringTimeStamp): Deleted.
(WebKit::ResourceLoadStatisticsStore::debugManualPrevalentResource const): Deleted.
(WebKit::ResourceLoadStatisticsStore::debugStaticPrevalentResource const): Deleted.
(WebKit::ResourceLoadStatisticsStore::debugLoggingEnabled const): Deleted.
(WebKit::ResourceLoadStatisticsStore::debugModeEnabled const): Deleted.
(WebKit::ResourceLoadStatisticsStore::firstPartyWebsiteDataRemovalMode const): Deleted.
(WebKit::ResourceLoadStatisticsStore::setDebugLogggingEnabled): Deleted.
* Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore): Update to call method directly,
rather than using is<> and downcast<>.
(WebKit::WebResourceLoadStatisticsStore::populateMemoryStoreFromDisk): Ditto.
(WebKit::WebResourceLoadStatisticsStore::statisticsDatabaseHasAllTables): Ditto.
(WebKit::WebResourceLoadStatisticsStore::performDailyTasks): Ditto.
(WebKit::WebResourceLoadStatisticsStore::isRelationshipOnlyInDatabaseOnce): Ditto.
(WebKit::WebResourceLoadStatisticsStore::scheduleClearInMemoryAndPersistent): Ditto.
(WebKit::WebResourceLoadStatisticsStore::domainIDExistsInDatabase): Ditto.
(WebKit::WebResourceLoadStatisticsStore::suspend): Ditto.
* Source/WebKit/Sources.txt:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/266741@main
  • Loading branch information
brentfulgham authored and Brent Fulgham committed Aug 9, 2023
1 parent a652661 commit f0bb878
Show file tree
Hide file tree
Showing 8 changed files with 3,041 additions and 2,999 deletions.
2,866 changes: 0 additions & 2,866 deletions Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp

This file was deleted.

2,817 changes: 2,807 additions & 10 deletions Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp

Large diffs are not rendered by default.

309 changes: 211 additions & 98 deletions Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.h

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "NetworkProcessProxyMessages.h"
#include "NetworkSession.h"
#include "PrivateClickMeasurementManager.h"
#include "ResourceLoadStatisticsDatabaseStore.h"
#include "ResourceLoadStatisticsStore.h"
#include "ShouldGrandfatherStatistics.h"
#include "StorageAccessStatus.h"
#include "WebFrameProxy.h"
Expand Down Expand Up @@ -161,7 +161,7 @@ WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore(NetworkSession& n

if (!resourceLoadStatisticsDirectory.isEmpty()) {
postTask([this, resourceLoadStatisticsDirectory = resourceLoadStatisticsDirectory.isolatedCopy(), shouldIncludeLocalhost, sessionID = networkSession.sessionID()] {
m_statisticsStore = makeUnique<ResourceLoadStatisticsDatabaseStore>(*this, m_statisticsQueue, shouldIncludeLocalhost, resourceLoadStatisticsDirectory, sessionID);
m_statisticsStore = makeUnique<ResourceLoadStatisticsStore>(*this, m_statisticsQueue, shouldIncludeLocalhost, resourceLoadStatisticsDirectory, sessionID);

auto legacyPlistFilePath = FileSystem::pathByAppendingComponent(resourceLoadStatisticsDirectory, "full_browsing_session_resourceLog.plist"_s);
if (FileSystem::fileExists(legacyPlistFilePath))
Expand Down Expand Up @@ -234,13 +234,12 @@ void WebResourceLoadStatisticsStore::populateMemoryStoreFromDisk(CompletionHandl
ASSERT(RunLoop::isMain());

postTask([this, protectedThis = Ref { *this }, completionHandler = WTFMove(completionHandler)]() mutable {
if (m_statisticsStore && is<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore)) {
auto& databaseStore = downcast<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore);
if (databaseStore.isNewResourceLoadStatisticsDatabaseFile()) {
if (m_statisticsStore) {
if (m_statisticsStore->isNewResourceLoadStatisticsDatabaseFile()) {
m_statisticsStore->grandfatherExistingWebsiteData([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)]() mutable {
postTaskReply(WTFMove(completionHandler));
});
databaseStore.setIsNewResourceLoadStatisticsDatabaseFile(false);
m_statisticsStore->setIsNewResourceLoadStatisticsDatabaseFile(false);
} else
postTaskReply([this, protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)]() mutable {
logTestingEvent("PopulatedWithoutGrandfathering"_s);
Expand Down Expand Up @@ -304,12 +303,12 @@ void WebResourceLoadStatisticsStore::statisticsDatabaseHasAllTables(CompletionHa
ASSERT(RunLoop::isMain());

postTask([this, completionHandler = WTFMove(completionHandler)]() mutable {
if (!m_statisticsStore || !is<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore)) {
if (!m_statisticsStore) {
completionHandler(false);
ASSERT_NOT_REACHED();
return;
}
auto missingTables = downcast<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore).checkForMissingTablesInSchema();
auto missingTables = m_statisticsStore->checkForMissingTablesInSchema();
postTaskReply([hasAllTables = missingTables ? false : true, completionHandler = WTFMove(completionHandler)] () mutable {
completionHandler(hasAllTables);
});
Expand Down Expand Up @@ -741,8 +740,7 @@ void WebResourceLoadStatisticsStore::performDailyTasks()
postTask([this] {
if (m_statisticsStore) {
m_statisticsStore->includeTodayAsOperatingDateIfNecessary();
if (is<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore))
downcast<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore).runIncrementalVacuumCommand();
m_statisticsStore->runIncrementalVacuumCommand();
}
});
}
Expand Down Expand Up @@ -903,12 +901,12 @@ void WebResourceLoadStatisticsStore::isRelationshipOnlyInDatabaseOnce(Registrabl
ASSERT(RunLoop::isMain());

postTask([this, subDomain = WTFMove(subDomain).isolatedCopy(), topDomain = WTFMove(topDomain).isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
if (!m_statisticsStore || !is<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore)) {
if (!m_statisticsStore) {
completionHandler(false);
return;
}

bool isRelationshipOnlyInDatabaseOnce = downcast<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore).isCorrectSubStatisticsCount(subDomain, topDomain);
bool isRelationshipOnlyInDatabaseOnce = m_statisticsStore->isCorrectSubStatisticsCount(subDomain, topDomain);

postTaskReply([isRelationshipOnlyInDatabaseOnce, completionHandler = WTFMove(completionHandler)]() mutable {
completionHandler(isRelationshipOnlyInDatabaseOnce);
Expand Down Expand Up @@ -1176,8 +1174,7 @@ void WebResourceLoadStatisticsStore::scheduleClearInMemoryAndPersistent(ShouldGr
if (shouldGrandfather == ShouldGrandfatherStatistics::Yes) {
if (m_statisticsStore) {
m_statisticsStore->grandfatherExistingWebsiteData([callbackAggregator = WTFMove(callbackAggregator)]() mutable { });
if (is<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore))
downcast<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore).setIsNewResourceLoadStatisticsDatabaseFile(true);
m_statisticsStore->setIsNewResourceLoadStatisticsDatabaseFile(true);
} else
RELEASE_LOG(ResourceLoadStatistics, "WebResourceLoadStatisticsStore::scheduleClearInMemoryAndPersistent After being cleared, m_statisticsStore is null when trying to grandfather data.");
}
Expand Down Expand Up @@ -1210,12 +1207,11 @@ void WebResourceLoadStatisticsStore::domainIDExistsInDatabase(int domainID, Comp
ASSERT(RunLoop::isMain());

postTask([this, domainID, completionHandler = WTFMove(completionHandler)]() mutable {
if (!m_statisticsStore || !is<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore)) {
if (!m_statisticsStore) {
completionHandler(false);
return;
}
auto& databaseStore = downcast<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore);
bool domainIDExists = databaseStore.domainIDExistsInDatabase(domainID);
bool domainIDExists = m_statisticsStore->domainIDExistsInDatabase(domainID);
postTaskReply([domainIDExists, completionHandler = WTFMove(completionHandler)]() mutable {
completionHandler(domainIDExists);
});
Expand Down Expand Up @@ -1522,7 +1518,7 @@ void WebResourceLoadStatisticsStore::aggregatedThirdPartyData(CompletionHandler<
void WebResourceLoadStatisticsStore::suspend(CompletionHandler<void()>&& completionHandler)
{
ASSERT(RunLoop::isMain());
sharedStatisticsQueue()->suspend(ResourceLoadStatisticsDatabaseStore::interruptAllDatabases, WTFMove(completionHandler));
sharedStatisticsQueue()->suspend(ResourceLoadStatisticsStore::interruptAllDatabases, WTFMove(completionHandler));
}

void WebResourceLoadStatisticsStore::resume()
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/NetworkProcess/storage/SQLiteStorageArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
#include "SQLiteStorageArea.h"

#include "Logging.h"
#include <WebCore/SQLiteDatabase.h>
#include <WebCore/SQLiteFileSystem.h>
#include <WebCore/SQLiteStatement.h>
#include <WebCore/SQLiteStatementAutoResetScope.h>
#include <WebCore/SQLiteTransaction.h>
#include <WebCore/StorageMap.h>
#include <wtf/FileSystem.h>
Expand Down
9 changes: 7 additions & 2 deletions Source/WebKit/NetworkProcess/storage/SQLiteStorageArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
#pragma once

#include "StorageAreaBase.h"
#include <WebCore/SQLiteDatabase.h>
#include <WebCore/SQLiteStatementAutoResetScope.h>

namespace WebCore {
class SQLiteDatabase;
class SQLiteStatement;
class SQLiteStatementAutoResetScope;
class SQLiteTransaction;
}

namespace WebKit {

Expand Down
1 change: 0 additions & 1 deletion Source/WebKit/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ NetworkProcess/NetworkSocketChannel.cpp
NetworkProcess/PingLoad.cpp
NetworkProcess/PreconnectTask.cpp

NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp
NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp

NetworkProcess/Cookies/WebCookieManager.cpp
Expand Down
4 changes: 0 additions & 4 deletions Source/WebKit/WebKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5610,8 +5610,6 @@
75A8D2C5187CCF9F00C39C9E /* WKWebsiteDataStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebsiteDataStore.mm; sourceTree = "<group>"; };
75A8D2D4187D1C0100C39C9E /* WKWebsiteDataStoreInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebsiteDataStoreInternal.h; sourceTree = "<group>"; };
762B7484120BBA2D00819339 /* WKPreferencesRefPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKPreferencesRefPrivate.h; sourceTree = "<group>"; };
7A0D7861220791EC00EBCF54 /* ResourceLoadStatisticsDatabaseStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ResourceLoadStatisticsDatabaseStore.h; path = Classifier/ResourceLoadStatisticsDatabaseStore.h; sourceTree = "<group>"; };
7A0D7862220791ED00EBCF54 /* ResourceLoadStatisticsDatabaseStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ResourceLoadStatisticsDatabaseStore.cpp; path = Classifier/ResourceLoadStatisticsDatabaseStore.cpp; sourceTree = "<group>"; };
7A10937629BF8B71006BDB7B /* WebPageInlines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebPageInlines.h; sourceTree = "<group>"; };
7A1E2A841EEFE88A0037A0E0 /* APINotificationProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APINotificationProvider.h; sourceTree = "<group>"; };
7A3ACE1A1EEEF78C00A864A4 /* APIInjectedBundlePageLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIInjectedBundlePageLoaderClient.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -11408,8 +11406,6 @@
7A843A1D21E41FD900DEF663 /* Classifier */ = {
isa = PBXGroup;
children = (
7A0D7862220791ED00EBCF54 /* ResourceLoadStatisticsDatabaseStore.cpp */,
7A0D7861220791EC00EBCF54 /* ResourceLoadStatisticsDatabaseStore.h */,
7ACE82E8221CAE07000DA94C /* ResourceLoadStatisticsStore.cpp */,
7ACE82E7221CAE06000DA94C /* ResourceLoadStatisticsStore.h */,
7A41E9FA21F81DAC00B88CDB /* ShouldGrandfatherStatistics.h */,
Expand Down

0 comments on commit f0bb878

Please sign in to comment.