Changeset 201232 in webkit


Ignore:
Timestamp:
May 20, 2016, 4:15:15 PM (9 years ago)
Author:
beidson@apple.com
Message:

Modern IDB: Properly handle blobs in Workers.
https://bugs.webkit.org/show_bug.cgi?id=157947

Reviewed by Alex Christensen.

Source/WebCore:

Test: storage/indexeddb/modern/blob-simple-workers.html

  • Modules/indexeddb/IDBTransaction.cpp:

(WebCore::IDBTransaction::putOrAddOnServer): Use writeBlobsToDiskForIndexedDBSynchronously from

background threads instead of the asynchronous form.

Add ability to set an existing empty IDBValue to be an isolated copy of a different IDBValue:

  • Modules/indexeddb/IDBValue.cpp:

(WebCore::IDBValue::setAsIsolatedCopy):
(WebCore::IDBValue::isolatedCopy):

  • Modules/indexeddb/IDBValue.h:

Add a method - only to be called from a non-main thread - that synchronously writes blobs to disk:

  • bindings/js/SerializedScriptValue.cpp:

(WebCore::SerializedScriptValue::writeBlobsToDiskForIndexedDBSynchronously):

  • bindings/js/SerializedScriptValue.h:

LayoutTests:

  • storage/indexeddb/modern/blob-simple-workers-expected.txt: Added.
  • storage/indexeddb/modern/blob-simple-workers.html: Added.
  • storage/indexeddb/modern/resources/blob-simple-workers.js: Added.
Location:
trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r201228 r201232  
     12016-05-20  Brady Eidson  <beidson@apple.com>
     2
     3        Modern IDB: Properly handle blobs in Workers.
     4        https://bugs.webkit.org/show_bug.cgi?id=157947
     5
     6        Reviewed by Alex Christensen.
     7
     8        * storage/indexeddb/modern/blob-simple-workers-expected.txt: Added.
     9        * storage/indexeddb/modern/blob-simple-workers.html: Added.
     10        * storage/indexeddb/modern/resources/blob-simple-workers.js: Added.
     11       
    1122016-05-20  Myles C. Maxfield  <mmaxfield@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r201229 r201232  
     12016-05-20  Brady Eidson  <beidson@apple.com>
     2
     3        Modern IDB: Properly handle blobs in Workers.
     4        https://bugs.webkit.org/show_bug.cgi?id=157947
     5
     6        Reviewed by Alex Christensen.
     7
     8        Test: storage/indexeddb/modern/blob-simple-workers.html
     9
     10        * Modules/indexeddb/IDBTransaction.cpp:
     11        (WebCore::IDBTransaction::putOrAddOnServer): Use writeBlobsToDiskForIndexedDBSynchronously from
     12          background threads instead of the asynchronous form.
     13       
     14        Add ability to set an existing empty IDBValue to be an isolated copy of a different IDBValue:
     15        * Modules/indexeddb/IDBValue.cpp:
     16        (WebCore::IDBValue::setAsIsolatedCopy):
     17        (WebCore::IDBValue::isolatedCopy):
     18        * Modules/indexeddb/IDBValue.h:
     19       
     20        Add a method - only to be called from a non-main thread - that synchronously writes blobs to disk:
     21        * bindings/js/SerializedScriptValue.cpp:
     22        (WebCore::SerializedScriptValue::writeBlobsToDiskForIndexedDBSynchronously):
     23        * bindings/js/SerializedScriptValue.h:
     24       
    1252016-05-20  Anders Carlsson  <andersca@apple.com>
    226
  • trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp

    r201098 r201232  
    939939{
    940940    LOG(IndexedDB, "IDBTransaction::putOrAddOnServer");
    941     ASSERT(currentThread() == m_database->originThreadID());
     941    ASSERT(currentThread() == originThreadID());
    942942    ASSERT(!isReadOnly());
    943943    ASSERT(value);
     
    945945    if (!value->hasBlobURLs()) {
    946946        m_database->connectionProxy().putOrAdd(operation, key.get(), *value, overwriteMode);
     947        return;
     948    }
     949
     950    // Due to current limitations on our ability to post tasks back to a worker thread,
     951    // workers currently write blobs to disk synchronously.
     952    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=157958 - Make this asynchronous after refactoring allows it.
     953    if (!isMainThread()) {
     954        auto idbValue = value->writeBlobsToDiskForIndexedDBSynchronously();
     955        if (idbValue.data().data())
     956            m_database->connectionProxy().putOrAdd(operation, key.get(), idbValue, overwriteMode);
     957        else {
     958            // If the IDBValue doesn't have any data, then something went wrong writing the blobs to disk.
     959            // In that case, we cannot successfully store this record, so we callback with an error.
     960            RefPtr<IDBClient::TransactionOperation> protectedOperation(&operation);
     961            auto result = IDBResultData::error(operation.identifier(), { IDBDatabaseException::UnknownError, ASCIILiteral("Error preparing Blob/File data to be stored in object store") });
     962            scriptExecutionContext()->postTask([protectedOperation, result](ScriptExecutionContext&) {
     963                protectedOperation->completed(result);
     964            });
     965        }
    947966        return;
    948967    }
     
    951970    RefPtr<IDBClient::TransactionOperation> protectedOperation(&operation);
    952971    value->writeBlobsToDiskForIndexedDB([protectedThis, this, protectedOperation, key, value, overwriteMode](const IDBValue& idbValue) {
     972        ASSERT(currentThread() == originThreadID());
     973        ASSERT(isMainThread());
    953974        if (idbValue.data().data()) {
    954975            m_database->connectionProxy().putOrAdd(*protectedOperation, key.get(), idbValue, overwriteMode);
  • trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp

    r199730 r201232  
    2929#if ENABLE(INDEXED_DATABASE)
    3030
     31#include "CrossThreadCopier.h"
    3132#include "SerializedScriptValue.h"
    3233
     
    7071}
    7172
     73void IDBValue::setAsIsolatedCopy(const IDBValue& other)
     74{
     75    ASSERT(m_blobURLs.isEmpty() && m_blobFilePaths.isEmpty());
     76
     77    m_data = other.m_data;
     78    m_blobURLs = CrossThreadCopier<Vector<String>>::copy(other.m_blobURLs);
     79    m_blobFilePaths = CrossThreadCopier<Vector<String>>::copy(other.m_blobFilePaths);
     80}
     81
    7282IDBValue IDBValue::isolatedCopy() const
    7383{
    7484    IDBValue result;
    75     result.m_data = m_data;
    76 
    77     result.m_blobURLs.reserveInitialCapacity(m_blobURLs.size());
    78     for (auto& url : m_blobURLs)
    79         result.m_blobURLs.uncheckedAppend(url.isolatedCopy());
    80 
    81     result.m_blobFilePaths.reserveInitialCapacity(m_blobFilePaths.size());
    82     for (auto& path : m_blobFilePaths)
    83         result.m_blobFilePaths.uncheckedAppend(path.isolatedCopy());
    84 
     85    result.setAsIsolatedCopy(*this);
    8586    return result;
    8687}
  • trunk/Source/WebCore/Modules/indexeddb/IDBValue.h

    r199524 r201232  
    4343    IDBValue(const ThreadSafeDataBuffer&, const Vector<String>& blobURLs, const Vector<String>& blobFilePaths);
    4444
     45    void setAsIsolatedCopy(const IDBValue&);
    4546    IDBValue isolatedCopy() const;
    4647
  • trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp

    r200895 r201232  
    8080#include <wtf/HashTraits.h>
    8181#include <wtf/MainThread.h>
     82#include <wtf/RunLoop.h>
    8283#include <wtf/Vector.h>
    8384
     
    28172818    });
    28182819}
     2820
     2821IDBValue SerializedScriptValue::writeBlobsToDiskForIndexedDBSynchronously()
     2822{
     2823    ASSERT(!isMainThread());
     2824
     2825    IDBValue value;
     2826    IDBValue* valuePtr = &value;
     2827
     2828    Lock lock;
     2829    Condition condition;
     2830    Condition* conditionPtr = &condition;
     2831    lock.lock();
     2832
     2833    RunLoop::main().dispatch([this, conditionPtr, valuePtr] {
     2834        writeBlobsToDiskForIndexedDB([conditionPtr, valuePtr](const IDBValue& result) {
     2835            ASSERT(isMainThread());
     2836            valuePtr->setAsIsolatedCopy(result);
     2837
     2838            conditionPtr->notifyAll();
     2839        });
     2840    });
     2841
     2842    condition.wait(lock);
     2843
     2844    return value;
     2845}
     2846
    28192847#endif // ENABLE(INDEXED_DATABASE)
    28202848
  • trunk/Source/WebCore/bindings/js/SerializedScriptValue.h

    r200558 r201232  
    8888    Vector<String> blobURLsIsolatedCopy() const;
    8989    void writeBlobsToDiskForIndexedDB(std::function<void (const IDBValue&)> completionHandler);
     90    IDBValue writeBlobsToDiskForIndexedDBSynchronously();
    9091#endif // ENABLE(INDEXED_DATABASE)
    9192
Note: See TracChangeset for help on using the changeset viewer.