Modern IDB: Make the result data for a "get" request be an IDBGetResult.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Nov 2015 01:12:55 +0000 (01:12 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Nov 2015 01:12:55 +0000 (01:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150985

Reviewed by Alex Christensen.

Source/WebCore:

No new tests (Refactor, no change in behavior).

* Modules/indexeddb/IDBGetResult.h:
(WebCore::IDBGetResult::IDBGetResult):
(WebCore::IDBGetResult::dataFromBuffer):
(WebCore::IDBGetResult::isolatedCopy):

* Modules/indexeddb/client/IDBTransactionImpl.cpp:
(WebCore::IDBClient::IDBTransaction::didGetRecordOnServer):

* Modules/indexeddb/legacy/IDBTransactionBackendOperations.cpp:
(WebCore::GetOperation::perform):

* Modules/indexeddb/server/IDBBackingStore.h:

* Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
(WebCore::IDBServer::MemoryIDBBackingStore::getIndexRecord):
* Modules/indexeddb/server/MemoryIDBBackingStore.h:

* Modules/indexeddb/server/MemoryIndex.cpp:
(WebCore::IDBServer::MemoryIndex::valueForKeyRange):
* Modules/indexeddb/server/MemoryIndex.h:

* Modules/indexeddb/server/MemoryObjectStore.cpp:
(WebCore::IDBServer::MemoryObjectStore::indexValueForKeyRange):
* Modules/indexeddb/server/MemoryObjectStore.h:

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::storeCallback):
(WebCore::IDBServer::UniqueIDBDatabase::getRecord):
(WebCore::IDBServer::UniqueIDBDatabase::performGetIndexRecord):
(WebCore::IDBServer::UniqueIDBDatabase::didPerformGetRecord):
(WebCore::IDBServer::UniqueIDBDatabase::performGetResultCallback):
(WebCore::IDBServer::UniqueIDBDatabase::performValueDataCallback): Deleted.
* Modules/indexeddb/server/UniqueIDBDatabase.h:

* Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp:
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::getRecord):

* Modules/indexeddb/shared/IDBResultData.cpp:
(WebCore::IDBResultData::IDBResultData):
(WebCore::IDBResultData::getRecordSuccess):
(WebCore::IDBResultData::getResult):
* Modules/indexeddb/shared/IDBResultData.h:
(WebCore::IDBResultData::resultData): Deleted.

Source/WebKit2:

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<IDBGetResult>::encode):
(IPC::ArgumentCoder<IDBGetResult>::decode):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192123 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBGetResult.h
Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp
Source/WebCore/Modules/indexeddb/legacy/IDBTransactionBackendOperations.cpp
Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h
Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp
Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h
Source/WebCore/Modules/indexeddb/server/MemoryIndex.cpp
Source/WebCore/Modules/indexeddb/server/MemoryIndex.h
Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp
Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp
Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp
Source/WebCore/Modules/indexeddb/shared/IDBResultData.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

index 8943bf5..6bf3987 100644 (file)
@@ -1,3 +1,56 @@
+2015-11-06  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Make the result data for a "get" request be an IDBGetResult.
+        https://bugs.webkit.org/show_bug.cgi?id=150985
+
+        Reviewed by Alex Christensen.
+
+        No new tests (Refactor, no change in behavior).
+
+        * Modules/indexeddb/IDBGetResult.h:
+        (WebCore::IDBGetResult::IDBGetResult):
+        (WebCore::IDBGetResult::dataFromBuffer):
+        (WebCore::IDBGetResult::isolatedCopy):
+        
+        * Modules/indexeddb/client/IDBTransactionImpl.cpp:
+        (WebCore::IDBClient::IDBTransaction::didGetRecordOnServer):
+        
+        * Modules/indexeddb/legacy/IDBTransactionBackendOperations.cpp:
+        (WebCore::GetOperation::perform):
+        
+        * Modules/indexeddb/server/IDBBackingStore.h:
+        
+        * Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
+        (WebCore::IDBServer::MemoryIDBBackingStore::getIndexRecord):
+        * Modules/indexeddb/server/MemoryIDBBackingStore.h:
+        
+        * Modules/indexeddb/server/MemoryIndex.cpp:
+        (WebCore::IDBServer::MemoryIndex::valueForKeyRange):
+        * Modules/indexeddb/server/MemoryIndex.h:
+        
+        * Modules/indexeddb/server/MemoryObjectStore.cpp:
+        (WebCore::IDBServer::MemoryObjectStore::indexValueForKeyRange):
+        * Modules/indexeddb/server/MemoryObjectStore.h:
+        
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::storeCallback):
+        (WebCore::IDBServer::UniqueIDBDatabase::getRecord):
+        (WebCore::IDBServer::UniqueIDBDatabase::performGetIndexRecord):
+        (WebCore::IDBServer::UniqueIDBDatabase::didPerformGetRecord):
+        (WebCore::IDBServer::UniqueIDBDatabase::performGetResultCallback):
+        (WebCore::IDBServer::UniqueIDBDatabase::performValueDataCallback): Deleted.
+        * Modules/indexeddb/server/UniqueIDBDatabase.h:
+        
+        * Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabaseTransaction::getRecord):
+        
+        * Modules/indexeddb/shared/IDBResultData.cpp:
+        (WebCore::IDBResultData::IDBResultData):
+        (WebCore::IDBResultData::getRecordSuccess):
+        (WebCore::IDBResultData::getResult):
+        * Modules/indexeddb/shared/IDBResultData.h:
+        (WebCore::IDBResultData::resultData): Deleted.
+
 2015-11-06  Chris Dumez  <cdumez@apple.com>
 
         Remove unused HTMLFormControlsCollection::namedItem()
index ec0c72b..f3bef37 100644 (file)
@@ -32,6 +32,7 @@
 #include "IDBKeyData.h"
 #include "IDBKeyPath.h"
 #include "SharedBuffer.h"
+#include "ThreadSafeDataBuffer.h"
 
 namespace WebCore {
 
@@ -41,6 +42,12 @@ struct IDBGetResult {
     }
 
     IDBGetResult(PassRefPtr<SharedBuffer> buffer)
+    {
+        if (buffer)
+            dataFromBuffer(*buffer);
+    }
+
+    IDBGetResult(const ThreadSafeDataBuffer& buffer)
         : valueBuffer(buffer)
     {
     }
@@ -56,24 +63,31 @@ struct IDBGetResult {
     }
 
     IDBGetResult(PassRefPtr<SharedBuffer> buffer, PassRefPtr<IDBKey> key, const IDBKeyPath& path)
-        : valueBuffer(buffer)
-        , keyData(key.get())
+        : keyData(key.get())
         , keyPath(path)
     {
+        if (buffer)
+            dataFromBuffer(*buffer);
+    }
+
+    void dataFromBuffer(SharedBuffer& buffer)
+    {
+        Vector<uint8_t> data(buffer.size());
+        memcpy(data.data(), buffer.data(), buffer.size());
+
+        valueBuffer = ThreadSafeDataBuffer::adoptVector(data);
     }
 
     IDBGetResult isolatedCopy() const
     {
         IDBGetResult result;
-        if (valueBuffer)
-            result.valueBuffer = valueBuffer->copy();
-
+        result.valueBuffer = valueBuffer;
         result.keyData = keyData.isolatedCopy();
         result.keyPath = keyPath.isolatedCopy();
         return result;
     }
 
-    RefPtr<SharedBuffer> valueBuffer;
+    ThreadSafeDataBuffer valueBuffer;
     IDBKeyData keyData;
     IDBKeyPath keyPath;
 };
index fb801a2..cef1055 100644 (file)
@@ -490,8 +490,8 @@ void IDBTransaction::didGetRecordOnServer(IDBRequest& request, const IDBResultDa
         else
             request.setResultToUndefined();
     } else {
-        if (resultData.resultData().data())
-            request.setResultToStructuredClone(resultData.resultData());
+        if (resultData.getResult().valueBuffer.data())
+            request.setResultToStructuredClone(resultData.getResult().valueBuffer);
         else
             request.setResultToUndefined();
     }
index b0f6e10..0777d7d 100644 (file)
@@ -100,16 +100,17 @@ void GetOperation::perform(std::function<void()> completionCallback)
         if (error)
             m_callbacks->onError(error);
         else {
-            if (!result.valueBuffer) {
+            if (!result.valueBuffer.data()) {
                 if (result.keyData.isNull())
                     m_callbacks->onSuccess();
                 else
                     m_callbacks->onSuccess(result.keyData.maybeCreateIDBKey());
             } else {
+                auto valueBuffer = SharedBuffer::create(result.valueBuffer.data()->data(), result.valueBuffer.data()->size());
                 if (!result.keyData.isNull())
-                    m_callbacks->onSuccess(result.valueBuffer, result.keyData.maybeCreateIDBKey(), result.keyPath);
+                    m_callbacks->onSuccess(valueBuffer, result.keyData.maybeCreateIDBKey(), result.keyPath);
                 else
-                    m_callbacks->onSuccess(result.valueBuffer.get());
+                    m_callbacks->onSuccess(valueBuffer);
             }
         }
 
index 7a8c24d..e6ba669 100644 (file)
@@ -40,6 +40,7 @@ class IDBResourceIdentifier;
 class IDBTransactionInfo;
 class ThreadSafeDataBuffer;
 
+struct IDBGetResult;
 struct IDBKeyRangeData;
 
 namespace IndexedDB {
@@ -66,7 +67,7 @@ public:
     virtual IDBError deleteRange(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&) = 0;
     virtual IDBError putRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, const ThreadSafeDataBuffer& value) = 0;
     virtual IDBError getRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&, ThreadSafeDataBuffer& outValue) = 0;
-    virtual IDBError getIndexRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, IndexedDB::IndexRecordType, const IDBKeyRangeData&, ThreadSafeDataBuffer& outValue) = 0;
+    virtual IDBError getIndexRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, IndexedDB::IndexRecordType, const IDBKeyRangeData&, IDBGetResult& outValue) = 0;
     virtual IDBError getCount(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData&, uint64_t& outCount) = 0;
     virtual IDBError generateKeyNumber(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t& keyNumber) = 0;
 
index 0fedb89..37843e5 100644 (file)
@@ -279,7 +279,7 @@ IDBError MemoryIDBBackingStore::getRecord(const IDBResourceIdentifier& transacti
     return IDBError();
 }
 
-IDBError MemoryIDBBackingStore::getIndexRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, IndexedDB::IndexRecordType recordType, const IDBKeyRangeData& range, ThreadSafeDataBuffer& outValue)
+IDBError MemoryIDBBackingStore::getIndexRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, IndexedDB::IndexRecordType recordType, const IDBKeyRangeData& range, IDBGetResult& outValue)
 {
     LOG(IndexedDB, "MemoryIDBBackingStore::getIndexRecord");
 
index d8504fa..1b3d6cf 100644 (file)
@@ -60,7 +60,7 @@ public:
     virtual IDBError deleteRange(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&) override final;
     virtual IDBError putRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, const ThreadSafeDataBuffer& value) override final;
     virtual IDBError getRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&, ThreadSafeDataBuffer& outValue) override final;
-    virtual IDBError getIndexRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, IndexedDB::IndexRecordType, const IDBKeyRangeData&, ThreadSafeDataBuffer& outValue) override final;
+    virtual IDBError getIndexRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, IndexedDB::IndexRecordType, const IDBKeyRangeData&, IDBGetResult& outValue) override final;
     virtual IDBError getCount(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData&, uint64_t& outCount) override final;
     virtual IDBError generateKeyNumber(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t& keyNumber) override final;
 
index 25fb265..85cee0f 100644 (file)
@@ -28,7 +28,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
-#include "ThreadSafeDataBuffer.h"
+#include "IDBGetResult.h"
 
 namespace WebCore {
 namespace IDBServer {
@@ -47,7 +47,7 @@ MemoryIndex::~MemoryIndex()
 {
 }
 
-ThreadSafeDataBuffer MemoryIndex::valueForKeyRange(IndexedDB::IndexRecordType, const IDBKeyRangeData&) const
+IDBGetResult MemoryIndex::valueForKeyRange(IndexedDB::IndexRecordType, const IDBKeyRangeData&) const
 {
     // FIXME: Once indexes actually index, we'll return something real.
     // https://bugs.webkit.org/show_bug.cgi?id=150939
index d9fddb1..5ca0d97 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
+#include "IDBGetResult.h"
 #include "IDBIndexInfo.h"
 
 namespace WebCore {
@@ -51,7 +52,7 @@ public:
 
     const IDBIndexInfo& info() const { return m_info; }
 
-    ThreadSafeDataBuffer valueForKeyRange(IndexedDB::IndexRecordType, const IDBKeyRangeData&) const;
+    IDBGetResult valueForKeyRange(IndexedDB::IndexRecordType, const IDBKeyRangeData&) const;
     uint64_t countForKeyRange(const IDBKeyRangeData&);
     
 private:
index 7419baf..ce9fc98 100644 (file)
@@ -215,7 +215,7 @@ ThreadSafeDataBuffer MemoryObjectStore::valueForKeyRange(const IDBKeyRangeData&
     return m_keyValueStore->get(key);
 }
 
-ThreadSafeDataBuffer MemoryObjectStore::indexValueForKeyRange(uint64_t indexIdentifier, IndexedDB::IndexRecordType recordType, const IDBKeyRangeData& range) const
+IDBGetResult MemoryObjectStore::indexValueForKeyRange(uint64_t indexIdentifier, IndexedDB::IndexRecordType recordType, const IDBKeyRangeData& range) const
 {
     LOG(IndexedDB, "MemoryObjectStore::indexValueForKeyRange");
 
index f9049c0..5389090 100644 (file)
@@ -78,7 +78,7 @@ public:
     void replaceKeyValueStore(std::unique_ptr<KeyValueMap>&&);
 
     ThreadSafeDataBuffer valueForKeyRange(const IDBKeyRangeData&) const;
-    ThreadSafeDataBuffer indexValueForKeyRange(uint64_t indexIdentifier, IndexedDB::IndexRecordType, const IDBKeyRangeData&) const;
+    IDBGetResult indexValueForKeyRange(uint64_t indexIdentifier, IndexedDB::IndexRecordType, const IDBKeyRangeData&) const;
     uint64_t countForKeyRange(uint64_t indexIdentifier, const IDBKeyRangeData&) const;
 
     const IDBObjectStoreInfo& info() const { return m_info; }
index becba28..a22406a 100644 (file)
@@ -149,11 +149,11 @@ uint64_t UniqueIDBDatabase::storeCallback(KeyDataCallback callback)
     return identifier;
 }
 
-uint64_t UniqueIDBDatabase::storeCallback(ValueDataCallback callback)
+uint64_t UniqueIDBDatabase::storeCallback(GetResultCallback callback)
 {
     uint64_t identifier = generateUniqueCallbackIdentifier();
-    ASSERT(!m_valueDataCallbacks.contains(identifier));
-    m_valueDataCallbacks.add(identifier, callback);
+    ASSERT(!m_getResultCallbacks.contains(identifier));
+    m_getResultCallbacks.add(identifier, callback);
     return identifier;
 }
 
@@ -447,7 +447,7 @@ void UniqueIDBDatabase::didPerformPutOrAdd(uint64_t callbackIdentifier, const ID
     performKeyDataCallback(callbackIdentifier, error, resultKey);
 }
 
-void UniqueIDBDatabase::getRecord(const IDBRequestData& requestData, const IDBKeyRangeData& range, ValueDataCallback callback)
+void UniqueIDBDatabase::getRecord(const IDBRequestData& requestData, const IDBKeyRangeData& range, GetResultCallback callback)
 {
     ASSERT(isMainThread());
     LOG(IndexedDB, "(main) UniqueIDBDatabase::getRecord");
@@ -480,18 +480,18 @@ void UniqueIDBDatabase::performGetIndexRecord(uint64_t callbackIdentifier, const
 
     ASSERT(m_backingStore);
 
-    ThreadSafeDataBuffer valueData;
-    IDBError error = m_backingStore->getIndexRecord(transactionIdentifier, objectStoreIdentifier, indexIdentifier, recordType, range, valueData);
+    IDBGetResult result;
+    IDBError error = m_backingStore->getIndexRecord(transactionIdentifier, objectStoreIdentifier, indexIdentifier, recordType, range, result);
 
-    m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::didPerformGetRecord, callbackIdentifier, error, valueData));
+    m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::didPerformGetRecord, callbackIdentifier, error, result));
 }
 
-void UniqueIDBDatabase::didPerformGetRecord(uint64_t callbackIdentifier, const IDBError& error, const ThreadSafeDataBuffer& resultData)
+void UniqueIDBDatabase::didPerformGetRecord(uint64_t callbackIdentifier, const IDBError& error, const IDBGetResult& result)
 {
     ASSERT(isMainThread());
     LOG(IndexedDB, "(main) UniqueIDBDatabase::didPerformGetRecord");
 
-    performValueDataCallback(callbackIdentifier, error, resultData);
+    performGetResultCallback(callbackIdentifier, error, result);
 }
 
 void UniqueIDBDatabase::getCount(const IDBRequestData& requestData, const IDBKeyRangeData& range, CountCallback callback)
@@ -815,9 +815,9 @@ void UniqueIDBDatabase::performKeyDataCallback(uint64_t callbackIdentifier, cons
     callback(error, resultKey);
 }
 
-void UniqueIDBDatabase::performValueDataCallback(uint64_t callbackIdentifier, const IDBError& error, const ThreadSafeDataBuffer& resultData)
+void UniqueIDBDatabase::performGetResultCallback(uint64_t callbackIdentifier, const IDBError& error, const IDBGetResult& resultData)
 {
-    auto callback = m_valueDataCallbacks.take(callbackIdentifier);
+    auto callback = m_getResultCallbacks.take(callbackIdentifier);
     ASSERT(callback);
     callback(error, resultData);
 }
index 4f7298d..727b34e 100644 (file)
@@ -31,6 +31,7 @@
 #include "IDBBackingStore.h"
 #include "IDBDatabaseIdentifier.h"
 #include "IDBDatabaseInfo.h"
+#include "IDBGetResult.h"
 #include "IDBServerOperation.h"
 #include "ThreadSafeDataBuffer.h"
 #include "Timer.h"
@@ -59,7 +60,7 @@ class IDBServer;
 
 typedef std::function<void(const IDBError&)> ErrorCallback;
 typedef std::function<void(const IDBError&, const IDBKeyData&)> KeyDataCallback;
-typedef std::function<void(const IDBError&, const ThreadSafeDataBuffer&)> ValueDataCallback;
+typedef std::function<void(const IDBError&, const IDBGetResult&)> GetResultCallback;
 typedef std::function<void(const IDBError&, uint64_t)> CountCallback;
 
 class UniqueIDBDatabase : public ThreadSafeRefCounted<UniqueIDBDatabase> {
@@ -79,7 +80,7 @@ public:
     void clearObjectStore(UniqueIDBDatabaseTransaction&, uint64_t objectStoreIdentifier, ErrorCallback);
     void createIndex(UniqueIDBDatabaseTransaction&, const IDBIndexInfo&, ErrorCallback);
     void putOrAdd(const IDBRequestData&, const IDBKeyData&, const ThreadSafeDataBuffer& valueData, IndexedDB::ObjectStoreOverwriteMode, KeyDataCallback);
-    void getRecord(const IDBRequestData&, const IDBKeyRangeData&, ValueDataCallback);
+    void getRecord(const IDBRequestData&, const IDBKeyRangeData&, GetResultCallback);
     void getCount(const IDBRequestData&, const IDBKeyRangeData&, CountCallback);
     void deleteRecord(const IDBRequestData&, const IDBKeyRangeData&, ErrorCallback);
     void commitTransaction(UniqueIDBDatabaseTransaction&, ErrorCallback);
@@ -125,7 +126,7 @@ private:
     void didPerformClearObjectStore(uint64_t callbackIdentifier, const IDBError&);
     void didPerformCreateIndex(uint64_t callbackIdentifier, const IDBError&, const IDBIndexInfo&);
     void didPerformPutOrAdd(uint64_t callbackIdentifier, const IDBError&, const IDBKeyData&);
-    void didPerformGetRecord(uint64_t callbackIdentifier, const IDBError&, const ThreadSafeDataBuffer&);
+    void didPerformGetRecord(uint64_t callbackIdentifier, const IDBError&, const IDBGetResult&);
     void didPerformGetCount(uint64_t callbackIdentifier, const IDBError&, uint64_t);
     void didPerformDeleteRecord(uint64_t callbackIdentifier, const IDBError&);
     void didPerformCommitTransaction(uint64_t callbackIdentifier, const IDBError&, const IDBResourceIdentifier& transactionIdentifier);
@@ -134,12 +135,12 @@ private:
 
     uint64_t storeCallback(ErrorCallback);
     uint64_t storeCallback(KeyDataCallback);
-    uint64_t storeCallback(ValueDataCallback);
+    uint64_t storeCallback(GetResultCallback);
     uint64_t storeCallback(CountCallback);
 
     void performErrorCallback(uint64_t callbackIdentifier, const IDBError&);
     void performKeyDataCallback(uint64_t callbackIdentifier, const IDBError&, const IDBKeyData&);
-    void performValueDataCallback(uint64_t callbackIdentifier, const IDBError&, const ThreadSafeDataBuffer&);
+    void performGetResultCallback(uint64_t callbackIdentifier, const IDBError&, const IDBGetResult&);
     void performCountCallback(uint64_t callbackIdentifier, const IDBError&, uint64_t);
 
     void invokeTransactionScheduler();
@@ -163,7 +164,7 @@ private:
 
     HashMap<uint64_t, ErrorCallback> m_errorCallbacks;
     HashMap<uint64_t, KeyDataCallback> m_keyDataCallbacks;
-    HashMap<uint64_t, ValueDataCallback> m_valueDataCallbacks;
+    HashMap<uint64_t, GetResultCallback> m_getResultCallbacks;
     HashMap<uint64_t, CountCallback> m_countCallbacks;
 
     Timer m_transactionSchedulingTimer;
index fc9ae2f..fd43b1f 100644 (file)
@@ -188,11 +188,11 @@ void UniqueIDBDatabaseTransaction::getRecord(const IDBRequestData& requestData,
     ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
 
     RefPtr<UniqueIDBDatabaseTransaction> self(this);
-    m_databaseConnection->database().getRecord(requestData, keyRangeData, [this, self, requestData](const IDBError& error, const ThreadSafeDataBuffer& valueData) {
+    m_databaseConnection->database().getRecord(requestData, keyRangeData, [this, self, requestData](const IDBError& error, const IDBGetResult& result) {
         LOG(IndexedDB, "UniqueIDBDatabaseTransaction::getRecord (callback)");
 
         if (error.isNull())
-            m_databaseConnection->connectionToClient().didGetRecord(IDBResultData::getRecordSuccess(requestData.requestIdentifier(), valueData));
+            m_databaseConnection->connectionToClient().didGetRecord(IDBResultData::getRecordSuccess(requestData.requestIdentifier(), result));
         else
             m_databaseConnection->connectionToClient().didGetRecord(IDBResultData::error(requestData.requestIdentifier(), error));
     });
index d7187d8..37da733 100644 (file)
@@ -51,7 +51,6 @@ IDBResultData::IDBResultData(const IDBResultData& other)
     , m_error(other.m_error)
     , m_databaseConnectionIdentifier(other.m_databaseConnectionIdentifier)
     , m_resultInteger(other.m_resultInteger)
-    , m_resultData(other.m_resultData)
 {
     if (other.m_databaseInfo)
         m_databaseInfo = std::make_unique<IDBDatabaseInfo>(*other.m_databaseInfo);
@@ -59,6 +58,8 @@ IDBResultData::IDBResultData(const IDBResultData& other)
         m_transactionInfo = std::make_unique<IDBTransactionInfo>(*other.m_transactionInfo);
     if (other.m_resultKey)
         m_resultKey = std::make_unique<IDBKeyData>(*other.m_resultKey);
+    if (other.m_getResult)
+        m_getResult = std::make_unique<IDBGetResult>(*other.m_getResult);
 }
 
 IDBResultData IDBResultData::error(const IDBResourceIdentifier& requestIdentifier, const IDBError& error)
@@ -116,10 +117,10 @@ IDBResultData IDBResultData::putOrAddSuccess(const IDBResourceIdentifier& reques
     return result;
 }
 
-IDBResultData IDBResultData::getRecordSuccess(const IDBResourceIdentifier& requestIdentifier, const ThreadSafeDataBuffer& valueData)
+IDBResultData IDBResultData::getRecordSuccess(const IDBResourceIdentifier& requestIdentifier, const IDBGetResult& getResult)
 {
     IDBResultData result(IDBResultType::GetRecordSuccess, requestIdentifier);
-    result.m_resultData = valueData;
+    result.m_getResult = std::make_unique<IDBGetResult>(getResult);
     return result;
 }
 
@@ -147,6 +148,12 @@ const IDBTransactionInfo& IDBResultData::transactionInfo() const
     return *m_transactionInfo;
 }
 
+const IDBGetResult& IDBResultData::getResult() const
+{
+    RELEASE_ASSERT(m_getResult);
+    return *m_getResult;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(INDEXED_DATABASE)
index 6956aec..d8226b6 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "IDBDatabaseInfo.h"
 #include "IDBError.h"
+#include "IDBGetResult.h"
 #include "IDBKeyData.h"
 #include "IDBResourceIdentifier.h"
 #include "IDBTransactionInfo.h"
@@ -69,7 +70,7 @@ public:
     static IDBResultData clearObjectStoreSuccess(const IDBResourceIdentifier&);
     static IDBResultData createIndexSuccess(const IDBResourceIdentifier&);
     static IDBResultData putOrAddSuccess(const IDBResourceIdentifier&, const IDBKeyData&);
-    static IDBResultData getRecordSuccess(const IDBResourceIdentifier&, const ThreadSafeDataBuffer& valueData);
+    static IDBResultData getRecordSuccess(const IDBResourceIdentifier&, const IDBGetResult&);
     static IDBResultData getCountSuccess(const IDBResourceIdentifier&, uint64_t count);
     static IDBResultData deleteRecordSuccess(const IDBResourceIdentifier&);
 
@@ -85,9 +86,10 @@ public:
     const IDBTransactionInfo& transactionInfo() const;
 
     const IDBKeyData* resultKey() const { return m_resultKey.get(); }
-    const ThreadSafeDataBuffer& resultData() const { return m_resultData; }
     uint64_t resultInteger() const { return m_resultInteger; }
 
+    const IDBGetResult& getResult() const;
+
 private:
     IDBResultData(const IDBResourceIdentifier&);
     IDBResultData(IDBResultType, const IDBResourceIdentifier&);
@@ -100,8 +102,8 @@ private:
     std::unique_ptr<IDBDatabaseInfo> m_databaseInfo;
     std::unique_ptr<IDBTransactionInfo> m_transactionInfo;
     std::unique_ptr<IDBKeyData> m_resultKey;
+    std::unique_ptr<IDBGetResult> m_getResult;
     uint64_t m_resultInteger { 0 };
-    ThreadSafeDataBuffer m_resultData;
 };
 
 } // namespace WebCore
index efca9ed..33c137d 100644 (file)
@@ -1,3 +1,14 @@
+2015-11-06  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Make the result data for a "get" request be an IDBGetResult.
+        https://bugs.webkit.org/show_bug.cgi?id=150985
+
+        Reviewed by Alex Christensen.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<IDBGetResult>::encode):
+        (IPC::ArgumentCoder<IDBGetResult>::decode):
+
 2015-11-06  Tim Horton  <timothy_horton@apple.com>
 
         Add preliminary (SPI) support for NSTextFinder on WKWebView
index f0e2636..befce42 100644 (file)
@@ -1827,11 +1827,11 @@ bool ArgumentCoder<FilterOperations>::decode(ArgumentDecoder& decoder, FilterOpe
 
 void ArgumentCoder<IDBGetResult>::encode(ArgumentEncoder& encoder, const IDBGetResult& result)
 {
-    bool nullData = !result.valueBuffer;
+    bool nullData = !result.valueBuffer.data();
     encoder << nullData;
 
     if (!nullData)
-        encoder << DataReference(reinterpret_cast<const uint8_t*>(result.valueBuffer->data()), result.valueBuffer->size());
+        encoder << DataReference(result.valueBuffer.data()->data(), result.valueBuffer.data()->size());
 
     encoder << result.keyData << result.keyPath;
 }
@@ -1843,13 +1843,15 @@ bool ArgumentCoder<IDBGetResult>::decode(ArgumentDecoder& decoder, IDBGetResult&
         return false;
 
     if (nullData)
-        result.valueBuffer = nullptr;
+        result.valueBuffer = { };
     else {
         DataReference data;
         if (!decoder.decode(data))
             return false;
 
-        result.valueBuffer = SharedBuffer::create(data.data(), data.size());
+        Vector<uint8_t> vector(data.size());
+        memcpy(vector.data(), data.data(), data.size());
+        result.valueBuffer = ThreadSafeDataBuffer::adoptVector(vector);
     }
 
     if (!decoder.decode(result.keyData))