Modern IDB: Make IDBGetResult contain an IDBValue instead of a buffer, and remove...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Apr 2016 21:11:37 +0000 (21:11 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Apr 2016 21:11:37 +0000 (21:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156416

Reviewed by Alex Christensen.

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

* Modules/indexeddb/IDBCursor.cpp:
(WebCore::IDBCursor::setGetResult):

* Modules/indexeddb/IDBGetResult.cpp:
(WebCore::IDBGetResult::dataFromBuffer):
(WebCore::IDBGetResult::isolatedCopy):
* Modules/indexeddb/IDBGetResult.h:
(WebCore::IDBGetResult::IDBGetResult):
(WebCore::IDBGetResult::value):
(WebCore::IDBGetResult::encode):
(WebCore::IDBGetResult::decode):
(WebCore::IDBGetResult::valueBuffer): Deleted.
(WebCore::IDBGetResult::setValueBuffer): Deleted.
(WebCore::IDBGetResult::setKeyData): Deleted.
(WebCore::IDBGetResult::setPrimaryKeyData): Deleted.
(WebCore::IDBGetResult::setKeyPath): Deleted.

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

* Modules/indexeddb/IDBValue.cpp:
(WebCore::IDBValue::IDBValue):
* Modules/indexeddb/IDBValue.h:

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

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBCursor.cpp
Source/WebCore/Modules/indexeddb/IDBGetResult.cpp
Source/WebCore/Modules/indexeddb/IDBGetResult.h
Source/WebCore/Modules/indexeddb/IDBTransaction.cpp
Source/WebCore/Modules/indexeddb/IDBValue.cpp
Source/WebCore/Modules/indexeddb/IDBValue.h
Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp

index 8d1c5c9..396a120 100644 (file)
@@ -1,3 +1,39 @@
+2016-04-08  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Make IDBGetResult contain an IDBValue instead of a buffer, and remove unused methods.
+        https://bugs.webkit.org/show_bug.cgi?id=156416
+
+        Reviewed by Alex Christensen.
+
+        No new tests (Refactor, no change in behavior).
+
+        * Modules/indexeddb/IDBCursor.cpp:
+        (WebCore::IDBCursor::setGetResult):
+        
+        * Modules/indexeddb/IDBGetResult.cpp:
+        (WebCore::IDBGetResult::dataFromBuffer):
+        (WebCore::IDBGetResult::isolatedCopy):
+        * Modules/indexeddb/IDBGetResult.h:
+        (WebCore::IDBGetResult::IDBGetResult):
+        (WebCore::IDBGetResult::value):
+        (WebCore::IDBGetResult::encode):
+        (WebCore::IDBGetResult::decode):
+        (WebCore::IDBGetResult::valueBuffer): Deleted.
+        (WebCore::IDBGetResult::setValueBuffer): Deleted.
+        (WebCore::IDBGetResult::setKeyData): Deleted.
+        (WebCore::IDBGetResult::setPrimaryKeyData): Deleted.
+        (WebCore::IDBGetResult::setKeyPath): Deleted.
+        
+        * Modules/indexeddb/IDBTransaction.cpp:
+        (WebCore::IDBTransaction::didGetRecordOnServer):
+        
+        * Modules/indexeddb/IDBValue.cpp:
+        (WebCore::IDBValue::IDBValue):
+        * Modules/indexeddb/IDBValue.h:
+        
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+        (WebCore::IDBServer::SQLiteIDBBackingStore::getIndexRecord):
+
 2016-04-08  Zalan Bujtas  <zalan@apple.com>
 
         Focus ring drawn at incorrect location on image map with CSS transform.
index c7b3b3c..9980828 100644 (file)
@@ -418,7 +418,7 @@ void IDBCursor::setGetResult(IDBRequest& request, const IDBGetResult& getResult)
     if (isKeyCursor())
         m_deprecatedCurrentValue = { };
     else
-        m_deprecatedCurrentValue = deserializeIDBValueData(*context, getResult.valueBuffer());
+        m_deprecatedCurrentValue = deserializeIDBValueData(*context, getResult.value().data());
 
     m_gotValue = true;
 }
index 42ac268..998dd32 100644 (file)
@@ -35,13 +35,13 @@ void IDBGetResult::dataFromBuffer(SharedBuffer& buffer)
     Vector<uint8_t> data(buffer.size());
     memcpy(data.data(), buffer.data(), buffer.size());
 
-    m_valueBuffer = ThreadSafeDataBuffer::adoptVector(data);
+    m_value = ThreadSafeDataBuffer::adoptVector(data);
 }
 
 IDBGetResult IDBGetResult::isolatedCopy() const
 {
     IDBGetResult result;
-    result.m_valueBuffer = m_valueBuffer;
+    result.m_value = m_value.isolatedCopy();
     result.m_keyData = m_keyData.isolatedCopy();
     result.m_primaryKeyData = m_primaryKeyData.isolatedCopy();
     result.m_keyPath = m_keyPath.isolatedCopy();
index 3dcd7a7..d5b8680 100644 (file)
@@ -31,8 +31,8 @@
 #include "IDBKey.h"
 #include "IDBKeyData.h"
 #include "IDBKeyPath.h"
+#include "IDBValue.h"
 #include "SharedBuffer.h"
-#include "ThreadSafeDataBuffer.h"
 
 namespace WebCore {
 
@@ -43,14 +43,14 @@ public:
     {
     }
 
-    IDBGetResult(SharedBuffer* buffer)
+    IDBGetResult(Ref<SharedBuffer>&& buffer, const IDBKeyData& currentPrimaryKey)
+        : m_primaryKeyData(currentPrimaryKey)
     {
-        if (buffer)
-            dataFromBuffer(*buffer);
+        dataFromBuffer(buffer.get());
     }
 
     IDBGetResult(const ThreadSafeDataBuffer& buffer)
-        : m_valueBuffer(buffer)
+        : m_value(buffer)
     {
     }
 
@@ -79,7 +79,7 @@ public:
     }
 
     IDBGetResult(const IDBKeyData& keyData, const IDBKeyData& primaryKeyData, const ThreadSafeDataBuffer& valueBuffer)
-        : m_valueBuffer(valueBuffer)
+        : m_value(valueBuffer)
         , m_keyData(keyData)
         , m_primaryKeyData(primaryKeyData)
     {
@@ -87,7 +87,7 @@ public:
 
     IDBGetResult isolatedCopy() const;
 
-    const ThreadSafeDataBuffer& valueBuffer() const { return m_valueBuffer; }
+    const IDBValue& value() const { return m_value; }
     const IDBKeyData& keyData() const { return m_keyData; }
     const IDBKeyData& primaryKeyData() const { return m_primaryKeyData; }
     const IDBKeyPath& keyPath() const { return m_keyPath; }
@@ -96,18 +96,10 @@ public:
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static bool decode(Decoder&, IDBGetResult&);
 
-    // FIXME: When removing LegacyIDB, remove these setters.
-    // https://bugs.webkit.org/show_bug.cgi?id=150854
-
-    void setValueBuffer(const ThreadSafeDataBuffer& valueBuffer) { m_valueBuffer = valueBuffer; }
-    void setKeyData(const IDBKeyData& keyData) { m_keyData = keyData; }
-    void setPrimaryKeyData(const IDBKeyData& keyData) { m_primaryKeyData = keyData; }
-    void setKeyPath(const IDBKeyPath& keyPath) { m_keyPath = keyPath; }
-
 private:
     WEBCORE_EXPORT void dataFromBuffer(SharedBuffer&);
 
-    ThreadSafeDataBuffer m_valueBuffer;
+    IDBValue m_value;
     IDBKeyData m_keyData;
     IDBKeyData m_primaryKeyData;
     IDBKeyPath m_keyPath;
@@ -117,11 +109,7 @@ private:
 template<class Encoder>
 void IDBGetResult::encode(Encoder& encoder) const
 {
-    encoder << m_keyData << m_primaryKeyData << m_keyPath << m_isDefined;
-
-    encoder << !!m_valueBuffer.data();
-    if (m_valueBuffer.data())
-        encoder << *m_valueBuffer.data();
+    encoder << m_keyData << m_primaryKeyData << m_keyPath << m_isDefined << m_value;
 }
 
 template<class Decoder>
@@ -139,17 +127,9 @@ bool IDBGetResult::decode(Decoder& decoder, IDBGetResult& result)
     if (!decoder.decode(result.m_isDefined))
         return false;
 
-    bool hasObject;
-    if (!decoder.decode(hasObject))
+    if (!decoder.decode(result.m_value))
         return false;
 
-    if (hasObject) {
-        Vector<uint8_t> value;
-        if (!decoder.decode(value))
-            return false;
-        result.m_valueBuffer = ThreadSafeDataBuffer::adoptVector(value);
-    }
-
     return true;
 }
 
index c7e10de..561563b 100644 (file)
@@ -737,8 +737,8 @@ void IDBTransaction::didGetRecordOnServer(IDBRequest& request, const IDBResultDa
         else
             request.setResultToUndefined();
     } else {
-        if (resultData.getResult().valueBuffer().data())
-            request.setResultToStructuredClone(resultData.getResult().valueBuffer());
+        if (resultData.getResult().value().data().data())
+            request.setResultToStructuredClone(resultData.getResult().value().data());
         else
             request.setResultToUndefined();
     }
index 921ec33..1d777f9 100644 (file)
@@ -42,6 +42,11 @@ IDBValue::IDBValue(const SerializedScriptValue& scriptValue)
 {
 }
 
+IDBValue::IDBValue(const ThreadSafeDataBuffer& value)
+    : m_data(value)
+{
+}
+
 IDBValue::IDBValue(const SerializedScriptValue& scriptValue, const Vector<String>& blobURLs, const Vector<String>& blobFilePaths)
     : m_data(ThreadSafeDataBuffer::copyVector(scriptValue.data()))
     , m_blobURLs(blobURLs)
index f44738d..7e7813d 100644 (file)
@@ -37,6 +37,7 @@ class IDBValue {
 public:
     WEBCORE_EXPORT IDBValue();
     IDBValue(const SerializedScriptValue&);
+    IDBValue(const ThreadSafeDataBuffer&);
     IDBValue(const SerializedScriptValue&, const Vector<String>& blobURLs, const Vector<String>& blobFilePaths);
 
     IDBValue isolatedCopy() const;
index 8dba54c..62ed29a 100644 (file)
@@ -1630,10 +1630,8 @@ IDBError SQLiteIDBBackingStore::getIndexRecord(const IDBResourceIdentifier& tran
     else {
         if (type == IndexedDB::IndexRecordType::Key)
             getResult = { cursor->currentPrimaryKey() };
-        else {
-            getResult = { SharedBuffer::create(cursor->currentValueBuffer().data(), cursor->currentValueBuffer().size()).ptr() };
-            getResult.setKeyData(cursor->currentPrimaryKey());
-        }
+        else
+            getResult = { SharedBuffer::create(cursor->currentValueBuffer().data(), cursor->currentValueBuffer().size()), cursor->currentPrimaryKey() };
     }
 
     return { };