Modern IDB: Refactor memory objectstore/transaction interation.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Nov 2015 18:36:45 +0000 (18:36 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Nov 2015 18:36:45 +0000 (18:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151014

Reviewed by Darin Adler.

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

* Modules/indexeddb/server/IDBBackingStore.h:

* Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
(WebCore::IDBServer::MemoryBackingStoreTransaction::recordValueChanged):
(WebCore::IDBServer::MemoryBackingStoreTransaction::abort):
* Modules/indexeddb/server/MemoryBackingStoreTransaction.h:

* Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
(WebCore::IDBServer::MemoryIDBBackingStore::addRecord):
(WebCore::IDBServer::MemoryIDBBackingStore::putRecord): Deleted. Renamed to addRecord.
* Modules/indexeddb/server/MemoryIDBBackingStore.h:

* Modules/indexeddb/server/MemoryObjectStore.cpp:
(WebCore::IDBServer::MemoryObjectStore::deleteRecord):
(WebCore::IDBServer::MemoryObjectStore::addRecord):
(WebCore::IDBServer::MemoryObjectStore::putRecord): Deleted. Renamed to addRecord.
(WebCore::IDBServer::MemoryObjectStore::setKeyValue): Deleted. Folded into addRecord.
* Modules/indexeddb/server/MemoryObjectStore.h:

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::performPutOrAdd):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h
Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp
Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.h
Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp
Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h
Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp
Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp

index fb32766..aff36e4 100644 (file)
@@ -1,3 +1,34 @@
+2015-11-09  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Refactor memory objectstore/transaction interation.
+        https://bugs.webkit.org/show_bug.cgi?id=151014
+
+        Reviewed by Darin Adler.
+
+        No new tests (Refactor, no change in behavior).
+
+        * Modules/indexeddb/server/IDBBackingStore.h:
+        
+        * Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::recordValueChanged):
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::abort):
+        * Modules/indexeddb/server/MemoryBackingStoreTransaction.h:
+        
+        * Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
+        (WebCore::IDBServer::MemoryIDBBackingStore::addRecord):
+        (WebCore::IDBServer::MemoryIDBBackingStore::putRecord): Deleted. Renamed to addRecord.
+        * Modules/indexeddb/server/MemoryIDBBackingStore.h:
+        
+        * Modules/indexeddb/server/MemoryObjectStore.cpp:
+        (WebCore::IDBServer::MemoryObjectStore::deleteRecord):
+        (WebCore::IDBServer::MemoryObjectStore::addRecord):
+        (WebCore::IDBServer::MemoryObjectStore::putRecord): Deleted. Renamed to addRecord.
+        (WebCore::IDBServer::MemoryObjectStore::setKeyValue): Deleted. Folded into addRecord.
+        * Modules/indexeddb/server/MemoryObjectStore.h:
+        
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::performPutOrAdd):
+
 2015-11-09  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         REGRESSION (r190883): Error calculating the tile size for an SVG with no intrinsic size but with large floating intrinsic ratio
index e6ba669..40a9d2b 100644 (file)
@@ -65,7 +65,7 @@ public:
     virtual IDBError createIndex(const IDBResourceIdentifier& transactionIdentifier, const IDBIndexInfo&) = 0;
     virtual IDBError keyExistsInObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, bool& keyExists) = 0;
     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 addRecord(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&, IDBGetResult& outValue) = 0;
     virtual IDBError getCount(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData&, uint64_t& outCount) = 0;
index d8f16be..d3d0021 100644 (file)
@@ -132,7 +132,7 @@ void MemoryBackingStoreTransaction::objectStoreCleared(MemoryObjectStore& object
     addResult.iterator->value = WTF::move(keyValueMap);
 }
 
-void MemoryBackingStoreTransaction::recordValueChanged(MemoryObjectStore& objectStore, const IDBKeyData& key)
+void MemoryBackingStoreTransaction::recordValueChanged(MemoryObjectStore& objectStore, const IDBKeyData& key, ThreadSafeDataBuffer* value)
 {
     ASSERT(m_objectStores.contains(&objectStore));
 
@@ -154,7 +154,8 @@ void MemoryBackingStoreTransaction::recordValueChanged(MemoryObjectStore& object
     if (!addResult.isNewEntry)
         return;
 
-    addResult.iterator->value = objectStore.valueForKeyRange(IDBKeyRangeData(key));
+    if (value)
+        addResult.iterator->value = *value;
 }
 
 void MemoryBackingStoreTransaction::abort()
@@ -197,7 +198,7 @@ void MemoryBackingStoreTransaction::abort()
 
         for (auto entry : *keyValueMap) {
             objectStore->deleteRecord(entry.key);
-            objectStore->setKeyValue(entry.key, entry.value);
+            objectStore->addRecord(*this, entry.key, entry.value);
         }
     }
 
index d7e6d0c..79cdffe 100644 (file)
@@ -59,7 +59,8 @@ public:
 
     void addNewObjectStore(MemoryObjectStore&);
     void addExistingObjectStore(MemoryObjectStore&);
-    void recordValueChanged(MemoryObjectStore&, const IDBKeyData&);
+    
+    void recordValueChanged(MemoryObjectStore&, const IDBKeyData&, ThreadSafeDataBuffer*);
     void objectStoreDeleted(std::unique_ptr<MemoryObjectStore>);
     void objectStoreCleared(MemoryObjectStore&, std::unique_ptr<KeyValueMap>&&);
 
index 37843e5..18f8624 100644 (file)
@@ -244,9 +244,9 @@ IDBError MemoryIDBBackingStore::deleteRange(const IDBResourceIdentifier& transac
     return IDBError();
 }
 
-IDBError MemoryIDBBackingStore::putRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData& keyData, const ThreadSafeDataBuffer& value)
+IDBError MemoryIDBBackingStore::addRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData& keyData, const ThreadSafeDataBuffer& value)
 {
-    LOG(IndexedDB, "MemoryIDBBackingStore::putRecord");
+    LOG(IndexedDB, "MemoryIDBBackingStore::addRecord");
 
     ASSERT(objectStoreIdentifier);
 
@@ -258,7 +258,7 @@ IDBError MemoryIDBBackingStore::putRecord(const IDBResourceIdentifier& transacti
     if (!objectStore)
         return IDBError(IDBExceptionCode::Unknown, WTF::ASCIILiteral("No backing store object store found to put record"));
 
-    objectStore->putRecord(*transaction, keyData, value);
+    objectStore->addRecord(*transaction, keyData, value);
     return IDBError();
 }
 
index 1b3d6cf..f21e4ef 100644 (file)
@@ -58,7 +58,7 @@ public:
     virtual IDBError createIndex(const IDBResourceIdentifier& transactionIdentifier, const IDBIndexInfo&) override final;
     virtual IDBError keyExistsInObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, bool& keyExists) override final;
     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 addRecord(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&, IDBGetResult& outValue) override final;
     virtual IDBError getCount(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData&, uint64_t& outCount) override final;
index ce9fc98..082a4ce 100644 (file)
@@ -115,14 +115,22 @@ void MemoryObjectStore::deleteRecord(const IDBKeyData& key)
     LOG(IndexedDB, "MemoryObjectStore::deleteRecord");
 
     ASSERT(m_writeTransaction);
-    m_writeTransaction->recordValueChanged(*this, key);
 
-    if (!m_keyValueStore)
+    if (!m_keyValueStore) {
+        m_writeTransaction->recordValueChanged(*this, key, nullptr);
         return;
+    }
 
     ASSERT(m_orderedKeys);
 
-    m_keyValueStore->remove(key);
+    auto iterator = m_keyValueStore->find(key);
+    if (iterator == m_keyValueStore->end()) {
+        m_writeTransaction->recordValueChanged(*this, key, nullptr);
+        return;
+    }
+
+    m_writeTransaction->recordValueChanged(*this, key, &iterator->value);
+    m_keyValueStore->remove(iterator);
     m_orderedKeys->erase(key);
 }
 
@@ -150,20 +158,15 @@ void MemoryObjectStore::deleteRange(const IDBKeyRangeData& inputRange)
     }
 }
 
-void MemoryObjectStore::putRecord(MemoryBackingStoreTransaction& transaction, const IDBKeyData& keyData, const ThreadSafeDataBuffer& value)
+void MemoryObjectStore::addRecord(MemoryBackingStoreTransaction& transaction, const IDBKeyData& keyData, const ThreadSafeDataBuffer& value)
 {
-    LOG(IndexedDB, "MemoryObjectStore::putRecord");
+    LOG(IndexedDB, "MemoryObjectStore::addRecord");
 
     ASSERT(m_writeTransaction);
     ASSERT_UNUSED(transaction, m_writeTransaction == &transaction);
+    ASSERT(!m_keyValueStore || !m_keyValueStore->contains(keyData));
+    ASSERT(!m_orderedKeys || m_orderedKeys->find(keyData) == m_orderedKeys->end());
 
-    m_writeTransaction->recordValueChanged(*this, keyData);
-
-    setKeyValue(keyData, value);
-}
-
-void MemoryObjectStore::setKeyValue(const IDBKeyData& keyData, const ThreadSafeDataBuffer& value)
-{
     if (!m_keyValueStore) {
         ASSERT(!m_orderedKeys);
         m_keyValueStore = std::make_unique<KeyValueMap>();
index 5389090..66b9c2a 100644 (file)
@@ -67,9 +67,7 @@ public:
     bool containsRecord(const IDBKeyData&);
     void deleteRecord(const IDBKeyData&);
     void deleteRange(const IDBKeyRangeData&);
-    void putRecord(MemoryBackingStoreTransaction&, const IDBKeyData&, const ThreadSafeDataBuffer& value);
-
-    void setKeyValue(const IDBKeyData&, const ThreadSafeDataBuffer& value);
+    void addRecord(MemoryBackingStoreTransaction&, const IDBKeyData&, const ThreadSafeDataBuffer& value);
 
     uint64_t currentKeyGeneratorValue() const { return m_keyGeneratorValue; }
     void setKeyGeneratorValue(uint64_t value) { m_keyGeneratorValue = value; }
index a22406a..db8379e 100644 (file)
@@ -434,7 +434,7 @@ void UniqueIDBDatabase::performPutOrAdd(uint64_t callbackIdentifier, const IDBRe
         return;
     }
 
-    error = m_backingStore->putRecord(transactionIdentifier, objectStoreIdentifier, usedKey, valueData);
+    error = m_backingStore->addRecord(transactionIdentifier, objectStoreIdentifier, usedKey, valueData);
 
     m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::didPerformPutOrAdd, callbackIdentifier, error, usedKey));
 }