Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 9d250b4

Browse files
Create a mechanism to add missing ITP Database tables when the schema is updated
https://bugs.webkit.org/show_bug.cgi?id=211004 <rdar://problem/62261187> Reviewed by John Wilander. Source/WebKit: This patch updates the ITP database to better handle added tables to the schema. Currently the database store deletes and re-creates the database when any schema change is encountered. This is simple but would result in ITP data loss during schema updates, so this patch searches the schema for missing tables and adds any it finds. * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp: (WebKit::createTableQueries): Convert the tables array to a mapping of table names to their respective CREATE TABLE queries so we can add missing tables on the fly. (WebKit::ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore): (WebKit::ResourceLoadStatisticsDatabaseStore::openITPDatabase): Remove call to createSchema() from the constructor. It makes more sense to base this on whether the file is new as opposed to whether one table exists. (WebKit::ResourceLoadStatisticsDatabaseStore::checkForMissingTablesInSchema): (WebKit::ResourceLoadStatisticsDatabaseStore::migrateDataToNewTablesIfNecessary): (WebKit::ResourceLoadStatisticsDatabaseStore::addMissingTablesIfNecessary): Checks for missing tables and adds them using a best-effort approach. Call createUniqueIndices() to call all CREATE UNIQUE INDEX queries, even though we may not need them all. It is much simpler than to associate each query with its table, and it doesn't hurt to call again. (WebKit::ResourceLoadStatisticsDatabaseStore::openAndUpdateSchemaIfNecessary): Add missing tables instead of deleting the old database file. Changed the function name to reflect this. Deleted a FIXME which this patch addresses but added a new FIXME for migrating data when adding new columns, which this patch does not address. (WebKit::ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema): Deleted. (WebKit::ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary): Deleted. * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h: * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp: (WebKit::WebResourceLoadStatisticsStore::statisticsDatabaseHasAllTables): * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h: * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::statisticsDatabaseHasAllTables): * NetworkProcess/NetworkProcess.h: * NetworkProcess/NetworkProcess.messages.in: * UIProcess/API/Cocoa/WKWebsiteDataStore.mm: (-[WKWebsiteDataStore _statisticsDatabaseHasAllTables:]): * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h: * UIProcess/Network/NetworkProcessProxy.cpp: (WebKit::NetworkProcessProxy::statisticsDatabaseHasAllTables): * UIProcess/Network/NetworkProcessProxy.h: * UIProcess/WebsiteData/WebsiteDataStore.cpp: (WebKit::WebsiteDataStore::statisticsDatabaseHasAllTables): * UIProcess/WebsiteData/WebsiteDataStore.h: Added an SPI call to test that the database schema includes all tables. This tests the database is not dropped when a new table is added upon opening the database. Tools: Add test case which copies a database schema with a missing table into the ITP database file, then ensures the pre-seeded data is migrated over and that the schema now has all tables (including the previously missing one). * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm: (TEST): * TestWebKitAPI/Tests/WebKitCocoa/missingTopFrameUniqueRedirectSameSiteStrictTableSchema.db: Added. * TestWebKitAPI/Tests/WebKitCocoa/missingTopFrameUniqueRedirectSameSiteStrictTableSchema.db-shm: Added. * TestWebKitAPI/Tests/WebKitCocoa/missingTopFrameUniqueRedirectSameSiteStrictTableSchema.db-wal: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@260841 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 7393f13 commit 9d250b4

20 files changed

+279
-47
lines changed

Source/WebKit/ChangeLog

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,64 @@
1+
2020-04-28 Kate Cheney <[email protected]>
2+
3+
Create a mechanism to add missing ITP Database tables when the schema is updated
4+
https://bugs.webkit.org/show_bug.cgi?id=211004
5+
<rdar://problem/62261187>
6+
7+
Reviewed by John Wilander.
8+
9+
This patch updates the ITP database to better handle added tables to
10+
the schema. Currently the database store deletes and re-creates the
11+
database when any schema change is encountered. This is simple but
12+
would result in ITP data loss during schema updates, so this patch
13+
searches the schema for missing tables and adds any it finds.
14+
15+
* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
16+
(WebKit::createTableQueries):
17+
Convert the tables array to a mapping of table names to their
18+
respective CREATE TABLE queries so we can add missing tables on the
19+
fly.
20+
(WebKit::ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore):
21+
(WebKit::ResourceLoadStatisticsDatabaseStore::openITPDatabase):
22+
Remove call to createSchema() from the constructor. It makes more
23+
sense to base this on whether the file is new as opposed to whether
24+
one table exists.
25+
(WebKit::ResourceLoadStatisticsDatabaseStore::checkForMissingTablesInSchema):
26+
(WebKit::ResourceLoadStatisticsDatabaseStore::migrateDataToNewTablesIfNecessary):
27+
(WebKit::ResourceLoadStatisticsDatabaseStore::addMissingTablesIfNecessary):
28+
Checks for missing tables and adds them using a best-effort approach.
29+
Call createUniqueIndices() to call all CREATE UNIQUE INDEX queries,
30+
even though we may not need them all. It is much simpler than to
31+
associate each query with its table, and it doesn't hurt to call
32+
again.
33+
34+
(WebKit::ResourceLoadStatisticsDatabaseStore::openAndUpdateSchemaIfNecessary):
35+
Add missing tables instead of deleting the old database file. Changed
36+
the function name to reflect this. Deleted a FIXME which this patch
37+
addresses but added a new FIXME for migrating data when adding new
38+
columns, which this patch does not address.
39+
(WebKit::ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema): Deleted.
40+
(WebKit::ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary): Deleted.
41+
* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
42+
* NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
43+
(WebKit::WebResourceLoadStatisticsStore::statisticsDatabaseHasAllTables):
44+
* NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
45+
* NetworkProcess/NetworkProcess.cpp:
46+
(WebKit::NetworkProcess::statisticsDatabaseHasAllTables):
47+
* NetworkProcess/NetworkProcess.h:
48+
* NetworkProcess/NetworkProcess.messages.in:
49+
* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
50+
(-[WKWebsiteDataStore _statisticsDatabaseHasAllTables:]):
51+
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
52+
* UIProcess/Network/NetworkProcessProxy.cpp:
53+
(WebKit::NetworkProcessProxy::statisticsDatabaseHasAllTables):
54+
* UIProcess/Network/NetworkProcessProxy.h:
55+
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
56+
(WebKit::WebsiteDataStore::statisticsDatabaseHasAllTables):
57+
* UIProcess/WebsiteData/WebsiteDataStore.h:
58+
Added an SPI call to test that the database schema includes all
59+
tables. This tests the database is not dropped when a new
60+
table is added upon opening the database.
61+
162
2020-04-28 Per Arne Vollan <[email protected]>
263

364
[Cocoa] Global preferences are not accessible in the WebContent process when CFPrefs direct mode is enabled

Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,6 @@ constexpr auto observedDomainsExistsQuery = "SELECT EXISTS (SELECT * FROM Observ
146146
// DELETE Queries
147147
constexpr auto removeAllDataQuery = "DELETE FROM ObservedDomains WHERE domainID = ?"_s;
148148

149-
const char* tables[] = {
150-
"ObservedDomains",
151-
"TopLevelDomains",
152-
"StorageAccessUnderTopFrameDomains",
153-
"TopFrameUniqueRedirectsTo",
154-
"TopFrameUniqueRedirectsToSinceSameSiteStrictEnforcement",
155-
"TopFrameUniqueRedirectsFrom",
156-
"TopFrameLinkDecorationsFrom",
157-
"TopFrameLoadedThirdPartyScripts",
158-
"SubframeUnderTopFrameDomains",
159-
"SubresourceUnderTopFrameDomains",
160-
"SubresourceUniqueRedirectsTo",
161-
"SubresourceUniqueRedirectsFrom"
162-
};
163-
164-
// CREATE TABLE Queries
165149
constexpr auto createObservedDomain = "CREATE TABLE ObservedDomains ("
166150
"domainID INTEGER PRIMARY KEY, registrableDomain TEXT NOT NULL UNIQUE ON CONFLICT FAIL, lastSeen REAL NOT NULL, "
167151
"hadUserInteraction INTEGER NOT NULL, mostRecentUserInteractionTime REAL NOT NULL, grandfathered INTEGER NOT NULL, "
@@ -267,6 +251,27 @@ static bool needsNewCreateTableSchema(const String& schema)
267251
return schema.contains("REFERENCES TopLevelDomains");
268252
}
269253

254+
static const HashMap<String, String>& createTableQueries()
255+
{
256+
static auto createTableQueries = makeNeverDestroyed(HashMap<String, String> {
257+
{ "ObservedDomains"_s, createObservedDomain},
258+
{ "TopLevelDomains"_s, createTopLevelDomains},
259+
{ "StorageAccessUnderTopFrameDomains"_s, createStorageAccessUnderTopFrameDomains},
260+
{ "TopFrameUniqueRedirectsTo"_s, createTopFrameUniqueRedirectsTo},
261+
{ "TopFrameUniqueRedirectsToSinceSameSiteStrictEnforcement"_s, createTopFrameUniqueRedirectsToSinceSameSiteStrictEnforcement},
262+
{ "TopFrameUniqueRedirectsFrom"_s, createTopFrameUniqueRedirectsFrom},
263+
{ "TopFrameLinkDecorationsFrom"_s, createTopFrameLinkDecorationsFrom},
264+
{ "TopFrameLoadedThirdPartyScripts"_s, createTopFrameLoadedThirdPartyScripts},
265+
{ "SubframeUnderTopFrameDomains"_s, createSubframeUnderTopFrameDomains},
266+
{ "SubresourceUnderTopFrameDomains"_s, createSubresourceUnderTopFrameDomains},
267+
{ "SubresourceUniqueRedirectsTo"_s, createSubresourceUniqueRedirectsTo},
268+
{ "SubresourceUniqueRedirectsFrom"_s, createSubresourceUniqueRedirectsFrom}
269+
});
270+
271+
return createTableQueries;
272+
}
273+
274+
270275
ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore(WebResourceLoadStatisticsStore& store, WorkQueue& workQueue, ShouldIncludeLocalhost shouldIncludeLocalhost, const String& storageDirectoryPath, PAL::SessionID sessionID)
271276
: ResourceLoadStatisticsStore(store, workQueue, shouldIncludeLocalhost)
272277
, m_storageDirectoryPath(storageDirectoryPath + "/observations.db")
@@ -312,19 +317,11 @@ ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore(WebReso
312317
{
313318
ASSERT(!RunLoop::isMain());
314319

315-
openAndDropOldDatabaseIfNecessary();
320+
openAndUpdateSchemaIfNecessary();
316321
enableForeignKeys();
317322

318323
// Since we are using a workerQueue, the sequential dispatch blocks may be called by different threads.
319324
m_database.disableThreadingChecks();
320-
321-
if (!m_database.tableExists("ObservedDomains"_s)) {
322-
if (!createSchema()) {
323-
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::createSchema failed, error message: %" PUBLIC_LOG_STRING ", database path: %" PUBLIC_LOG_STRING, this, m_database.lastErrorMsg(), m_storageDirectoryPath.utf8().data());
324-
ASSERT_NOT_REACHED();
325-
return;
326-
}
327-
}
328325

329326
if (!m_database.turnOnIncrementalAutoVacuum())
330327
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::turnOnIncrementalAutoVacuum failed, error message: %" PUBLIC_LOG_STRING, this, m_database.lastErrorMsg());
@@ -352,6 +349,14 @@ void ResourceLoadStatisticsDatabaseStore::openITPDatabase()
352349
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::open failed, error message: %" PUBLIC_LOG_STRING ", database path: %" PUBLIC_LOG_STRING, this, m_database.lastErrorMsg(), m_storageDirectoryPath.utf8().data());
353350
ASSERT_NOT_REACHED();
354351
}
352+
353+
if (m_isNewResourceLoadStatisticsDatabaseFile) {
354+
if (!createSchema()) {
355+
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::createSchema failed, error message: %" PUBLIC_LOG_STRING ", database path: %" PUBLIC_LOG_STRING, this, m_database.lastErrorMsg(), m_storageDirectoryPath.utf8().data());
356+
ASSERT_NOT_REACHED();
357+
return;
358+
}
359+
}
355360
}
356361

357362
static void resetStatement(SQLiteStatement& statement)
@@ -360,27 +365,30 @@ static void resetStatement(SQLiteStatement& statement)
360365
ASSERT_UNUSED(resetResult, resetResult == SQLITE_OK);
361366
}
362367

363-
bool ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema()
368+
Optional<Vector<String>> ResourceLoadStatisticsDatabaseStore::checkForMissingTablesInSchema()
364369
{
370+
Vector<String> missingTables;
365371
SQLiteStatement statement(m_database, "SELECT 1 from sqlite_master WHERE type='table' and tbl_name=?");
366372
if (statement.prepare() != SQLITE_OK) {
367-
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema failed to prepare, error message: %" PUBLIC_LOG_STRING, this, m_database.lastErrorMsg());
368-
return false;
373+
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::checkForMissingTablesInSchema failed to prepare, error message: %" PUBLIC_LOG_STRING, this, m_database.lastErrorMsg());
374+
return WTF::nullopt;
369375
}
370376

371-
bool hasAllTables = true;
372-
for (auto table : tables) {
377+
for (auto& table : createTableQueries().keys()) {
373378
if (statement.bindText(1, table) != SQLITE_OK) {
374-
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema failed to bind, error message: %" PUBLIC_LOG_STRING, this, m_database.lastErrorMsg());
375-
return false;
379+
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::checkForMissingTablesInSchema failed to bind, error message: %" PUBLIC_LOG_STRING, this, m_database.lastErrorMsg());
380+
return WTF::nullopt;
376381
}
377382
if (statement.step() != SQLITE_ROW) {
378-
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema schema is missing table: %s", this, table);
379-
hasAllTables = false;
383+
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::checkForMissingTablesInSchema schema is missing table: %s", this, table.ascii().data());
384+
missingTables.append(String(table));
380385
}
381386
resetStatement(statement);
382387
}
383-
return hasAllTables;
388+
if (missingTables.isEmpty())
389+
return WTF::nullopt;
390+
391+
return missingTables;
384392
}
385393

386394
void ResourceLoadStatisticsDatabaseStore::enableForeignKeys()
@@ -424,7 +432,7 @@ void ResourceLoadStatisticsDatabaseStore::migrateDataToNewTablesIfNecessary()
424432
SQLiteTransaction transaction(m_database);
425433
transaction.begin();
426434

427-
for (auto& table : tables) {
435+
for (auto& table : createTableQueries().keys()) {
428436
auto query = makeString("ALTER TABLE ", table, " RENAME TO _", table);
429437
SQLiteStatement alterTable(m_database, query);
430438
if (alterTable.prepare() != SQLITE_OK || alterTable.step() != SQLITE_DONE) {
@@ -440,7 +448,7 @@ void ResourceLoadStatisticsDatabaseStore::migrateDataToNewTablesIfNecessary()
440448
return;
441449
}
442450

443-
for (auto& table : tables) {
451+
for (auto& table : createTableQueries().keys()) {
444452
auto query = makeString("INSERT INTO ", table, " SELECT * FROM _", table);
445453
SQLiteStatement migrateTableData(m_database, query);
446454
if (migrateTableData.prepare() != SQLITE_OK || migrateTableData.step() != SQLITE_DONE) {
@@ -467,17 +475,29 @@ void ResourceLoadStatisticsDatabaseStore::migrateDataToNewTablesIfNecessary()
467475
}
468476
}
469477

470-
void ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary()
478+
void ResourceLoadStatisticsDatabaseStore::addMissingTablesIfNecessary()
471479
{
472-
openITPDatabase();
480+
auto missingTables = checkForMissingTablesInSchema();
481+
if (!missingTables)
482+
return;
473483

474-
if (!isCorrectTableSchema()) {
475-
m_database.close();
476-
// FIXME: Migrate existing data to new database file instead of deleting it (204482).
477-
FileSystem::deleteFile(m_storageDirectoryPath);
478-
openITPDatabase();
484+
for (auto& table : *missingTables) {
485+
auto createTableQuery = createTableQueries().get(table);
486+
if (!m_database.executeCommand(createTableQuery))
487+
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::addMissingTables failed to execute, error message: %" PUBLIC_LOG_STRING, this, m_database.lastErrorMsg());
488+
}
489+
490+
if (!createUniqueIndices()) {
491+
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::addMissingTables failed to create unique indices, error message: %{private}s", this, m_database.lastErrorMsg());
492+
ASSERT_NOT_REACHED();
479493
return;
480494
}
495+
}
496+
497+
void ResourceLoadStatisticsDatabaseStore::openAndUpdateSchemaIfNecessary()
498+
{
499+
openITPDatabase();
500+
addMissingTablesIfNecessary();
481501

482502
String currentSchema;
483503
{
@@ -503,7 +523,8 @@ void ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary()
503523

504524
ASSERT(!currentSchema.isEmpty());
505525

506-
// If the schema in the ResourceLoadStatistics directory is not the current schema, delete the database file.
526+
// If the ObservedDomains schema in the ResourceLoadStatistics directory is not the current schema, delete the database file.
527+
// FIXME: Migrate old ObservedDomains data to new table schema.
507528
if (currentSchema != ObservedDomainsTableSchemaV1() && currentSchema != ObservedDomainsTableSchemaV1Alternate()) {
508529
m_database.close();
509530
FileSystem::deleteFile(m_storageDirectoryPath);

Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,17 @@ class ResourceLoadStatisticsDatabaseStore final : public ResourceLoadStatisticsS
140140
void setIsNewResourceLoadStatisticsDatabaseFile(bool isNewResourceLoadStatisticsDatabaseFile) { m_isNewResourceLoadStatisticsDatabaseFile = isNewResourceLoadStatisticsDatabaseFile; }
141141
void removeDataForDomain(const RegistrableDomain&) override;
142142
bool domainIDExistsInDatabase(int);
143+
Optional<Vector<String>> checkForMissingTablesInSchema();
143144

144145
private:
145146
void openITPDatabase();
146-
bool isCorrectTableSchema();
147+
void addMissingTablesIfNecessary();
147148
void enableForeignKeys();
148149
bool isMigrationNecessary();
149150
void migrateDataToNewTablesIfNecessary();
150151
bool hasStorageAccess(const TopFrameDomain&, const SubFrameDomain&) const;
151152
Vector<WebResourceLoadStatisticsStore::ThirdPartyDataForSpecificFirstParty> getThirdPartyDataForSpecificFirstPartyDomains(unsigned, const RegistrableDomain&) const;
152-
void openAndDropOldDatabaseIfNecessary();
153+
void openAndUpdateSchemaIfNecessary();
153154
String getDomainStringFromDomainID(unsigned) const;
154155
String getSubStatisticStatement(const String&) const;
155156
void appendSubStatisticList(StringBuilder&, const String& tableName, const String& domain) const;

Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,23 @@ void WebResourceLoadStatisticsStore::scheduleStatisticsAndDataRecordsProcessing(
322322
});
323323
}
324324

325+
void WebResourceLoadStatisticsStore::statisticsDatabaseHasAllTables(CompletionHandler<void(bool)>&& completionHandler)
326+
{
327+
ASSERT(RunLoop::isMain());
328+
329+
postTask([this, completionHandler = WTFMove(completionHandler)]() mutable {
330+
if (!m_statisticsStore || !is<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore)) {
331+
completionHandler(false);
332+
ASSERT_NOT_REACHED();
333+
return;
334+
}
335+
auto missingTables = downcast<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore).checkForMissingTablesInSchema();
336+
postTaskReply([hasAllTables = missingTables ? false : true, completionHandler = WTFMove(completionHandler)] () mutable {
337+
completionHandler(hasAllTables);
338+
});
339+
});
340+
}
341+
325342
void WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated(Vector<ResourceLoadStatistics>&& statistics)
326343
{
327344
ASSERT(RunLoop::isMain());

Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ struct ThirdPartyData {
249249
void scheduleCookieBlockingUpdate(CompletionHandler<void()>&&);
250250
void scheduleCookieBlockingUpdateForDomains(const Vector<RegistrableDomain>&, CompletionHandler<void()>&&);
251251
void scheduleStatisticsAndDataRecordsProcessing(CompletionHandler<void()>&&);
252+
void statisticsDatabaseHasAllTables(CompletionHandler<void(bool)>&&);
252253
void submitTelemetry(CompletionHandler<void()>&&);
253254
void scheduleClearInMemoryAndPersistent(ShouldGrandfatherStatistics, CompletionHandler<void()>&&);
254255
void scheduleClearInMemoryAndPersistent(WallTime modifiedSince, ShouldGrandfatherStatistics, CompletionHandler<void()>&&);

Source/WebKit/NetworkProcess/NetworkProcess.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,19 @@ void NetworkProcess::scheduleStatisticsAndDataRecordsProcessing(PAL::SessionID s
828828
}
829829
}
830830

831+
void NetworkProcess::statisticsDatabaseHasAllTables(PAL::SessionID sessionID, CompletionHandler<void(bool)>&& completionHandler)
832+
{
833+
if (auto* networkSession = this->networkSession(sessionID)) {
834+
if (auto* resourceLoadStatistics = networkSession->resourceLoadStatistics())
835+
resourceLoadStatistics->statisticsDatabaseHasAllTables(WTFMove(completionHandler));
836+
else
837+
completionHandler(false);
838+
} else {
839+
ASSERT_NOT_REACHED();
840+
completionHandler(false);
841+
}
842+
}
843+
831844
void NetworkProcess::setNotifyPagesWhenDataRecordsWereScanned(PAL::SessionID sessionID, bool value, CompletionHandler<void()>&& completionHandler)
832845
{
833846
if (auto* networkSession = this->networkSession(sessionID)) {

Source/WebKit/NetworkProcess/NetworkProcess.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class NetworkProcess : public AuxiliaryProcess, private DownloadManager::Client,
237237
void getResourceLoadStatisticsDataSummary(PAL::SessionID, CompletionHandler<void(Vector<WebResourceLoadStatisticsStore::ThirdPartyData>&&)>&&);
238238
void scheduleCookieBlockingUpdate(PAL::SessionID, CompletionHandler<void()>&&);
239239
void scheduleStatisticsAndDataRecordsProcessing(PAL::SessionID, CompletionHandler<void()>&&);
240+
void statisticsDatabaseHasAllTables(PAL::SessionID, CompletionHandler<void(bool)>&&);
240241
void submitTelemetry(PAL::SessionID, CompletionHandler<void()>&&);
241242
void setCacheMaxAgeCapForPrevalentResources(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
242243
void setGrandfatheringTime(PAL::SessionID, Seconds, CompletionHandler<void()>&&);

Source/WebKit/NetworkProcess/NetworkProcess.messages.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ messages -> NetworkProcess LegacyReceiver {
111111
ScheduleClearInMemoryAndPersistent(PAL::SessionID sessionID, Optional<WallTime> modifiedSince, enum:bool WebKit::ShouldGrandfatherStatistics shouldGrandfather) -> () Async
112112
ScheduleCookieBlockingUpdate(PAL::SessionID sessionID) -> () Async
113113
ScheduleStatisticsAndDataRecordsProcessing(PAL::SessionID sessionID) -> () Async
114+
StatisticsDatabaseHasAllTables(PAL::SessionID sessionID) -> (bool hasAllTables) Async
114115
SubmitTelemetry(PAL::SessionID sessionID) -> () Async
115116
SetCacheMaxAgeCapForPrevalentResources(PAL::SessionID sessionID, Seconds seconds) -> () Async
116117
SetGrandfathered(PAL::SessionID sessionID, WebCore::RegistrableDomain resourceDomain, bool isGrandfathered) -> () Async

Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,17 @@ - (void)_isRegisteredAsSubresourceUnderFirstParty:(NSURL *)firstPartyURL thirdPa
562562
#endif
563563
}
564564

565+
- (void)_statisticsDatabaseHasAllTables:(void (^)(BOOL))completionHandler
566+
{
567+
#if ENABLE(RESOURCE_LOAD_STATISTICS)
568+
_websiteDataStore->statisticsDatabaseHasAllTables([completionHandler = makeBlockPtr(completionHandler)](bool hasAllTables) {
569+
completionHandler(hasAllTables);
570+
});
571+
#else
572+
completionHandler(NO);
573+
#endif
574+
}
575+
565576
- (void)_processStatisticsAndDataRecords:(void (^)(void))completionHandler
566577
{
567578
#if ENABLE(RESOURCE_LOAD_STATISTICS)

0 commit comments

Comments
 (0)