Changeset 239358 in webkit


Ignore:
Timestamp:
Dec 18, 2018 3:56:23 PM (5 years ago)
Author:
sihui_liu@apple.com
Message:

Clean up IndexedDB files between tests
https://bugs.webkit.org/show_bug.cgi?id=192796

Reviewed by Geoffrey Garen.

Source/WebCore:

We should clean up the IndexedDB files between tests to make sure each test is independent of others.

This patch also fixes some issues in IDB.

Covered by existing tests.

  • Modules/indexeddb/server/IDBServer.cpp:

(WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesModifiedSince):
We should shut down all open databases instead of databases from open database connections before deleting
files, because database starts accessing files before connection to database is established.

  • Modules/indexeddb/server/UniqueIDBDatabase.cpp:

(WebCore::IDBServer::UniqueIDBDatabase::shutdownForClose):
We should shutdown database after tasks in queue are completed, because tasks have pointer of UniqueIDBDatabase
and UniqueIDBDatabase can be destructed after shutdown.

(WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore):
didDeleteBackingStore can be posted to main thread after immediateCloseForUserDelete, and timer should not be
invoked during the hard close.

(WebCore::IDBServer::UniqueIDBDatabase::handleDatabaseOperations):
Tasks like didOpenBackingStore could be posted from database thread to main thread after
immediateCloseForUserDelete, but we know the backing store will be deleted soon, so no need to handle any
database operation.

(WebCore::IDBServer::UniqueIDBDatabase::performPrefetchCursor):
performPrefetchCursor needs to be aware of whether UniqueIDBDatabase is being closed, so that it will not access
m_backingStore when m_backingStore may already be deleted.

(WebCore::IDBServer::UniqueIDBDatabase::immediateCloseForUserDelete):
immediateCloseForUserDelete does not handle transactions that are in the process of commit or abort.
m_objectStoreTransactionCounts and m_objectStoreWriteTransactions may be used by those transactions in
transactionCompleted, so they do not need to be cleared here.

Source/WebKit:

  • UIProcess/API/C/WKWebsiteDataStoreRef.cpp:

(WKWebsiteDataStoreRemoveAllIndexedDatabasesSync):

  • UIProcess/API/C/WKWebsiteDataStoreRef.h:

Tools:

  • DumpRenderTree/mac/DumpRenderTree.mm:

(runTest):

  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::resetStateToConsistentValues):
(WTR::RemoveAllIndexedDatabasesCallbackContext::RemoveAllIndexedDatabasesCallbackContext):
(WTR::RemoveAllIndexedDatabasesCallback):
(WTR::TestController::ClearIndexedDatabases):

  • WebKitTestRunner/TestController.h:
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r239357 r239358  
     12018-12-18  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Clean up IndexedDB files between tests
     4        https://bugs.webkit.org/show_bug.cgi?id=192796
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        We should clean up the IndexedDB files between tests to make sure each test is independent of others.
     9
     10        This patch also fixes some issues in IDB.
     11
     12        Covered by existing tests.
     13
     14        * Modules/indexeddb/server/IDBServer.cpp:
     15        (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesModifiedSince):
     16        We should shut down all open databases instead of databases from open database connections before deleting
     17        files, because database starts accessing files before connection to database is established.
     18
     19        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
     20        (WebCore::IDBServer::UniqueIDBDatabase::shutdownForClose):
     21        We should shutdown database after tasks in queue are completed, because tasks have pointer of UniqueIDBDatabase
     22        and UniqueIDBDatabase can be destructed after shutdown.
     23
     24        (WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore):
     25        didDeleteBackingStore can be posted to main thread after immediateCloseForUserDelete, and timer should not be
     26        invoked during the hard close.
     27
     28        (WebCore::IDBServer::UniqueIDBDatabase::handleDatabaseOperations):
     29        Tasks like didOpenBackingStore could be posted from database thread to main thread after
     30        immediateCloseForUserDelete, but we know the backing store will be deleted soon, so no need to handle any
     31        database operation.
     32
     33        (WebCore::IDBServer::UniqueIDBDatabase::performPrefetchCursor):
     34        performPrefetchCursor needs to be aware of whether UniqueIDBDatabase is being closed, so that it will not access
     35        m_backingStore when m_backingStore may already be deleted.
     36
     37        (WebCore::IDBServer::UniqueIDBDatabase::immediateCloseForUserDelete):
     38        immediateCloseForUserDelete does not handle transactions that are in the process of commit or abort.
     39        m_objectStoreTransactionCounts and m_objectStoreWriteTransactions may be used by those transactions in
     40        transactionCompleted, so they do not need to be cleared here.
     41
    1422018-12-18  Myles C. Maxfield  <mmaxfield@apple.com>
    243
  • trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp

    r237700 r239358  
    510510
    511511    HashSet<UniqueIDBDatabase*> openDatabases;
    512     for (auto* connection : m_databaseConnections.values())
    513         openDatabases.add(connection->database());
     512    for (auto& database : m_uniqueIDBDatabaseMap.values())
     513        openDatabases.add(database.get());
    514514
    515515    for (auto& database : openDatabases)
  • trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp

    r239266 r239358  
    295295    m_backingStoreIsEphemeral = false;
    296296
    297     ASSERT(m_databaseQueue.isEmpty());
     297    if (!m_databaseQueue.isEmpty()) {
     298        postDatabaseTask(createCrossThreadTask(*this, &UniqueIDBDatabase::shutdownForClose));
     299        return;
     300    }
    298301    m_databaseQueue.kill();
    299302
     
    337340
    338341    m_deleteBackingStoreInProgress = false;
    339     invokeOperationAndTransactionTimer();
     342
     343    if (!m_hardClosedForUserDelete)
     344        invokeOperationAndTransactionTimer();
    340345}
    341346
     
    344349    ASSERT(isMainThread());
    345350    LOG(IndexedDB, "(main) UniqueIDBDatabase::handleDatabaseOperations - There are %u pending", m_pendingOpenDBRequests.size());
    346     ASSERT(!m_hardClosedForUserDelete);
     351
     352    if (m_hardClosedForUserDelete)
     353        return;
    347354
    348355    if (m_deleteBackingStoreInProgress)
     
    12791286    LOG(IndexedDB, "(db) UniqueIDBDatabase::performPrefetchCursor");
    12801287
     1288    if (m_owningPointerForClose)
     1289        return;
     1290
    12811291    if (m_backingStore->prefetchCursor(transactionIdentifier, cursorIdentifier))
    12821292        postDatabaseTask(createCrossThreadTask(*this, &UniqueIDBDatabase::performPrefetchCursor, transactionIdentifier, cursorIdentifier));
     
    18191829        transaction->databaseConnection().deleteTransaction(*transaction);
    18201830    m_pendingTransactions.clear();
    1821     m_objectStoreTransactionCounts.clear();
    1822     m_objectStoreWriteTransactions.clear();
    18231831
    18241832    // Error out all pending callbacks
  • trunk/Source/WebKit/ChangeLog

    r239348 r239358  
     12018-12-18  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Clean up IndexedDB files between tests
     4        https://bugs.webkit.org/show_bug.cgi?id=192796
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
     9        (WKWebsiteDataStoreRemoveAllIndexedDatabasesSync):
     10        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
     11
    1122018-12-18  Vivek Seth  <v_seth@apple.com>
    213
  • trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp

    r238771 r239358  
    512512}
    513513
    514 void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef)
     514void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveAllIndexedDatabasesCallback callback)
    515515{
    516516    OptionSet<WebKit::WebsiteDataType> dataTypes = WebKit::WebsiteDataType::IndexedDBDatabases;
    517     WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, -WallTime::infinity(), [] { });
     517    WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, -WallTime::infinity(), [context, callback] {
     518        if (callback)
     519            callback(context);
     520    });
    518521}
    519522
  • trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h

    r238125 r239358  
    104104WK_EXPORT void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveAllServiceWorkerRegistrationsCallback callback);
    105105
    106 WK_EXPORT void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef);
     106typedef void (*WKWebsiteDataStoreRemoveAllIndexedDatabasesCallback)(void* functionContext);
     107WK_EXPORT void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveAllIndexedDatabasesCallback callback);
    107108
    108109typedef void (*WKWebsiteDataStoreGetFetchCacheOriginsFunction)(WKArrayRef, void*);
  • trunk/Tools/ChangeLog

    r239356 r239358  
     12018-12-18  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Clean up IndexedDB files between tests
     4        https://bugs.webkit.org/show_bug.cgi?id=192796
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * DumpRenderTree/mac/DumpRenderTree.mm:
     9        (runTest):
     10        * WebKitTestRunner/TestController.cpp:
     11        (WTR::TestController::resetStateToConsistentValues):
     12        (WTR::RemoveAllIndexedDatabasesCallbackContext::RemoveAllIndexedDatabasesCallbackContext):
     13        (WTR::RemoveAllIndexedDatabasesCallback):
     14        (WTR::TestController::ClearIndexedDatabases):
     15        * WebKitTestRunner/TestController.h:
     16
    1172018-12-18  Alex Christensen  <achristensen@webkit.org>
    218
  • trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm

    r238262 r239358  
    20132013    gTestRunner->setIconDatabaseEnabled(false);
    20142014    gTestRunner->clearAllApplicationCaches();
     2015    gTestRunner->clearAllDatabases();
     2016    gTestRunner->setIDBPerOriginQuota(50 * MB);
    20152017
    20162018    if (disallowedURLs)
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r239277 r239358  
    868868    WKContextClearCachedCredentials(TestController::singleton().context());
    869869
     870    ClearIndexedDatabases();
     871    setIDBPerOriginQuota(50 * MB);
     872
    870873    clearServiceWorkerRegistrations();
    871874    clearDOMCaches();
     
    27602763}
    27612764
     2765struct RemoveAllIndexedDatabasesCallbackContext {
     2766    explicit RemoveAllIndexedDatabasesCallbackContext(TestController& controller)
     2767        : testController(controller)
     2768        {
     2769        }
     2770    TestController& testController;
     2771    bool done { false };
     2772};
     2773static void RemoveAllIndexedDatabasesCallback(void* userData)
     2774{
     2775    auto* context = static_cast<RemoveAllIndexedDatabasesCallbackContext*>(userData);
     2776    context->done = true;
     2777    context->testController.notifyDone();
     2778}
     2779void TestController::ClearIndexedDatabases()
     2780{
     2781    auto websiteDataStore = WKContextGetWebsiteDataStore(platformContext());
     2782    RemoveAllIndexedDatabasesCallbackContext context(*this);
     2783    WKWebsiteDataStoreRemoveAllIndexedDatabases(websiteDataStore, &context, RemoveAllIndexedDatabasesCallback);
     2784    runUntil(context.done, noTimeout);
     2785}
     2786
    27622787struct FetchCacheOriginsCallbackContext {
    27632788    FetchCacheOriginsCallbackContext(TestController& controller, WKStringRef origin)
  • trunk/Tools/WebKitTestRunner/TestController.h

    r238939 r239358  
    243243    void removeAllSessionCredentials();
    244244
     245    void ClearIndexedDatabases();
     246
    245247    void clearServiceWorkerRegistrations();
    246248
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r238512 r239358  
    904904   
    905905    if (WKStringIsEqualToUTF8CString(messageName, "DeleteAllIndexedDatabases")) {
    906         WKWebsiteDataStoreRemoveAllIndexedDatabases(WKContextGetWebsiteDataStore(TestController::singleton().context()));
     906        WKWebsiteDataStoreRemoveAllIndexedDatabases(WKContextGetWebsiteDataStore(TestController::singleton().context()), nullptr, { });
    907907        return nullptr;
    908908    }
Note: See TracChangeset for help on using the changeset viewer.