Stop IDB transactions to release locked database files when network process is ready...
authorsihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Apr 2019 16:08:40 +0000 (16:08 +0000)
committersihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Apr 2019 16:08:40 +0000 (16:08 +0000)
commitb3dd8c9b208f6f5148b12398ebea69db17e3f00f
tree220f45cf730e7f62b1f5c874f680d61014e61b3c
parent94d2d9862737a0b826e757e82e6640c9a5cf8a06
Stop IDB transactions to release locked database files when network process is ready to suspend
https://bugs.webkit.org/show_bug.cgi?id=196372
<rdar://problem/48930116>

Reviewed by Brady Eidson.

Source/WebCore:

Suspend IDB database thread and finish ongoing IDB transactions on the main thread before suspending network
process.

API test: IndexedDB.IndexedDBSuspendImminently

* Modules/indexeddb/server/IDBBackingStore.h:
* Modules/indexeddb/server/IDBServer.cpp:
(WebCore::IDBServer::IDBServer::tryStop):
(WebCore::IDBServer::IDBServer::resume):
* Modules/indexeddb/server/IDBServer.h:
* Modules/indexeddb/server/MemoryIDBBackingStore.h:
* Modules/indexeddb/server/SQLiteIDBBackingStore.cpp: Remove some error log messages, because now we may try
performing database operations without an active transaction if the transaction is finished on the main thread.
(WebCore::IDBServer::SQLiteIDBBackingStore::createObjectStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::deleteObjectStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::renameObjectStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::clearObjectStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::createIndex):
(WebCore::IDBServer::SQLiteIDBBackingStore::deleteIndex):
(WebCore::IDBServer::SQLiteIDBBackingStore::renameIndex):
(WebCore::IDBServer::SQLiteIDBBackingStore::keyExistsInObjectStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::deleteRange):
(WebCore::IDBServer::SQLiteIDBBackingStore::addRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::getRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::getAllObjectStoreRecords):
(WebCore::IDBServer::SQLiteIDBBackingStore::getAllIndexRecords):
(WebCore::IDBServer::SQLiteIDBBackingStore::getIndexRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::getCount):
(WebCore::IDBServer::SQLiteIDBBackingStore::generateKeyNumber):
(WebCore::IDBServer::SQLiteIDBBackingStore::revertGeneratedKeyNumber):
(WebCore::IDBServer::SQLiteIDBBackingStore::maybeUpdateKeyGeneratorNumber):
(WebCore::IDBServer::SQLiteIDBBackingStore::openCursor):
(WebCore::IDBServer::SQLiteIDBBackingStore::iterateCursor):
(WebCore::IDBServer::SQLiteIDBBackingStore::hasTransaction const):
* Modules/indexeddb/server/SQLiteIDBBackingStore.h:
* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::prepareToFinishTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::commitTransactionAfterQuotaCheck):
(WebCore::IDBServer::UniqueIDBDatabase::didPerformCommitTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::abortTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::didPerformAbortTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::abortTransactionOnMainThread):
(WebCore::IDBServer::UniqueIDBDatabase::commitTransactionOnMainThread):
(WebCore::IDBServer::UniqueIDBDatabase::finishActiveTransactions):
* Modules/indexeddb/server/UniqueIDBDatabase.h:
* Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h:
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::setState):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::state const):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::setResult):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::result const):
* platform/sql/SQLiteDatabaseTracker.cpp:
(WebCore::SQLiteDatabaseTracker::hasTransactionInProgress):
* platform/sql/SQLiteDatabaseTracker.h:

Source/WebKit:

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::processWillSuspendImminently):
(WebKit::NetworkProcess::prepareToSuspend):
(WebKit::NetworkProcess::resume):

Source/WTF:

Provide a method to suspend the thread and block main thread until the thread is suspended.

* wtf/CrossThreadTaskHandler.cpp:
(WTF::CrossThreadTaskHandler::taskRunLoop):
(WTF::CrossThreadTaskHandler::suspendAndWait):
(WTF::CrossThreadTaskHandler::resume):
* wtf/CrossThreadTaskHandler.h:

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/IndexedDBSuspendImminently.html: Added.
* TestWebKitAPI/Tests/WebKitCocoa/IndexedDBSuspendImminently.mm: Added.
(-[IndexedDBSuspendImminentlyMessageHandler userContentController:didReceiveScriptMessage:]):
(runTestAndCheckResult):
(keepNetworkProcessActive):
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244687 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/CrossThreadTaskHandler.cpp
Source/WTF/wtf/CrossThreadTaskHandler.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h
Source/WebCore/Modules/indexeddb/server/IDBServer.cpp
Source/WebCore/Modules/indexeddb/server/IDBServer.h
Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h
Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp
Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h
Source/WebCore/platform/sql/SQLiteDatabaseTracker.cpp
Source/WebCore/platform/sql/SQLiteDatabaseTracker.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBSuspendImminently.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBSuspendImminently.mm [new file with mode: 0644]