Title: [159245] trunk/Source/WebCore
Revision
159245
Author
beid...@apple.com
Date
2013-11-13 15:08:53 -0800 (Wed, 13 Nov 2013)

Log Message

Move setIndexKeys() to the IDBServerConnection
https://bugs.webkit.org/show_bug.cgi?id=124301

Reviewed by Anders Carlsson.

This is a big step towards moving knowledge of the backing store out of the frontend.

* Modules/indexeddb/IDBBackingStoreInterface.h:

* Modules/indexeddb/IDBDatabaseBackend.cpp:
(WebCore::IDBDatabaseBackend::setIndexKeys):

* Modules/indexeddb/IDBServerConnection.h:
* Modules/indexeddb/leveldb/IDBServerConnectionLevelDB.cpp:
(WebCore::IDBServerConnectionLevelDB::setIndexKeys):
* Modules/indexeddb/leveldb/IDBServerConnectionLevelDB.h:

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

* Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.cpp:
(WebCore::IDBBackingStoreLevelDB::makeIndexWriters):
* Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (159244 => 159245)


--- trunk/Source/WebCore/ChangeLog	2013-11-13 23:04:14 UTC (rev 159244)
+++ trunk/Source/WebCore/ChangeLog	2013-11-13 23:08:53 UTC (rev 159245)
@@ -1,3 +1,29 @@
+2013-11-13  Brady Eidson  <beid...@apple.com>
+
+        Move setIndexKeys() to the IDBServerConnection
+        https://bugs.webkit.org/show_bug.cgi?id=124301
+
+        Reviewed by Anders Carlsson.
+
+        This is a big step towards moving knowledge of the backing store out of the frontend.
+
+        * Modules/indexeddb/IDBBackingStoreInterface.h:
+
+        * Modules/indexeddb/IDBDatabaseBackend.cpp:
+        (WebCore::IDBDatabaseBackend::setIndexKeys):
+
+        * Modules/indexeddb/IDBServerConnection.h:
+        * Modules/indexeddb/leveldb/IDBServerConnectionLevelDB.cpp:
+        (WebCore::IDBServerConnectionLevelDB::setIndexKeys):
+        * Modules/indexeddb/leveldb/IDBServerConnectionLevelDB.h:
+
+        * Modules/indexeddb/IDBTransactionBackendOperations.cpp:
+        (WebCore::PutOperation::perform):
+
+        * Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.cpp:
+        (WebCore::IDBBackingStoreLevelDB::makeIndexWriters):
+        * Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.h:
+
 2013-11-13  Joseph Pecoraro  <pecor...@apple.com>
 
         Web Inspector: Extract InspectorFrontendDispatchers from InspectorFrontend

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBBackingStoreInterface.h (159244 => 159245)


--- trunk/Source/WebCore/Modules/indexeddb/IDBBackingStoreInterface.h	2013-11-13 23:04:14 UTC (rev 159244)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBBackingStoreInterface.h	2013-11-13 23:08:53 UTC (rev 159245)
@@ -91,7 +91,7 @@
     virtual bool getKeyGeneratorCurrentNumber(IDBBackingStoreTransactionInterface&, int64_t databaseId, int64_t objectStoreId, int64_t& keyGeneratorCurrentNumber) = 0;
     virtual bool maybeUpdateKeyGeneratorCurrentNumber(IDBBackingStoreTransactionInterface&, int64_t databaseId, int64_t objectStoreId, int64_t newState, bool checkCurrent) = 0;
 
-    virtual bool makeIndexWriters(IDBTransactionBackend&, int64_t databaseId, const IDBObjectStoreMetadata&, IDBKey& primaryKey, bool keyWasGenerated, const Vector<int64_t>& indexIds, const Vector<Vector<RefPtr<IDBKey>>>&, Vector<RefPtr<IDBIndexWriter>>& indexWriters, String* errorMessage, bool& completed) = 0;
+    virtual bool makeIndexWriters(int64_t transactionID, int64_t databaseId, const IDBObjectStoreMetadata&, IDBKey& primaryKey, bool keyWasGenerated, const Vector<int64_t>& indexIds, const Vector<Vector<RefPtr<IDBKey>>>&, Vector<RefPtr<IDBIndexWriter>>& indexWriters, String* errorMessage, bool& completed) = 0;
 
     virtual PassRefPtr<IDBKey> generateKey(IDBTransactionBackend&, int64_t databaseId, int64_t objectStoreId) = 0;
     virtual bool updateKeyGenerator(IDBTransactionBackend&, int64_t databaseId, int64_t objectStoreId, const IDBKey&, bool checkCurrent) = 0;

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackend.cpp (159244 => 159245)


--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackend.cpp	2013-11-13 23:04:14 UTC (rev 159244)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackend.cpp	2013-11-13 23:08:53 UTC (rev 159245)
@@ -28,12 +28,10 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
-#include "IDBBackingStoreInterface.h"
 #include "IDBCursorBackend.h"
 #include "IDBDatabaseCallbacks.h"
 #include "IDBDatabaseException.h"
 #include "IDBFactoryBackendInterface.h"
-#include "IDBIndexWriter.h"
 #include "IDBKeyRange.h"
 #include "IDBRecordIdentifier.h"
 #include "IDBTransactionBackend.h"
@@ -241,50 +239,22 @@
     transaction->schedulePutOperation(objectStoreMetadata, value, key, putMode, callbacks, indexIds, indexKeys);
 }
 
-void IDBDatabaseBackend::setIndexKeys(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBKey> prpPrimaryKey, const Vector<int64_t>& indexIds, const Vector<IndexKeys>& indexKeys)
+void IDBDatabaseBackend::setIndexKeys(int64_t transactionID, int64_t objectStoreID, PassRefPtr<IDBKey> prpPrimaryKey, const Vector<int64_t>& indexIDs, const Vector<IndexKeys>& indexKeys)
 {
     LOG(StorageAPI, "IDBDatabaseBackend::setIndexKeys");
     ASSERT(prpPrimaryKey);
+    ASSERT(m_metadata.objectStores.contains(objectStoreID));
 
-    IDBTransactionBackend* transaction = m_transactions.get(transactionId);
+    RefPtr<IDBTransactionBackend> transaction = m_transactions.get(transactionID);
     if (!transaction)
         return;
     ASSERT(transaction->mode() == IndexedDB::TransactionVersionChange);
 
     RefPtr<IDBKey> primaryKey = prpPrimaryKey;
-    RefPtr<IDBBackingStoreInterface> store = m_serverConnection->deprecatedBackingStore();
-    // FIXME: This method could be asynchronous, but we need to evaluate if it's worth the extra complexity.
-    RefPtr<IDBRecordIdentifier> recordIdentifier;
-    bool ok = store->keyExistsInObjectStore(transaction->deprecatedBackingStoreTransaction(), m_metadata.id, objectStoreId, *primaryKey, recordIdentifier);
-    if (!ok) {
-        transaction->abort(IDBDatabaseError::create(IDBDatabaseException::UnknownError, "Internal error setting index keys."));
-        return;
-    }
-    if (!recordIdentifier) {
-        RefPtr<IDBDatabaseError> error = IDBDatabaseError::create(IDBDatabaseException::UnknownError, String::format("Internal error setting index keys for object store."));
-        transaction->abort(error.release());
-        return;
-    }
-
-    Vector<RefPtr<IDBIndexWriter>> indexWriters;
-    String errorMessage;
-    bool obeysConstraints = false;
-    ASSERT(m_metadata.objectStores.contains(objectStoreId));
-    const IDBObjectStoreMetadata& objectStoreMetadata = m_metadata.objectStores.get(objectStoreId);
-    bool backingStoreSuccess = store->makeIndexWriters(*transaction, id(), objectStoreMetadata, *primaryKey, false, indexIds, indexKeys, indexWriters, &errorMessage, obeysConstraints);
-    if (!backingStoreSuccess) {
-        transaction->abort(IDBDatabaseError::create(IDBDatabaseException::UnknownError, "Internal error: backing store error updating index keys."));
-        return;
-    }
-    if (!obeysConstraints) {
-        transaction->abort(IDBDatabaseError::create(IDBDatabaseException::ConstraintError, errorMessage));
-        return;
-    }
-
-    for (size_t i = 0; i < indexWriters.size(); ++i) {
-        IDBIndexWriter* indexWriter = indexWriters[i].get();
-        indexWriter->writeIndexKeys(recordIdentifier.get(), *store.get(), transaction->deprecatedBackingStoreTransaction(), id(), objectStoreId);
-    }
+    m_serverConnection->setIndexKeys(transactionID, m_metadata.id, objectStoreID, m_metadata.objectStores.get(objectStoreID), *primaryKey, indexIDs, indexKeys, [transaction](PassRefPtr<IDBDatabaseError> error) {
+        if (error)
+            transaction->abort(error);
+    });
 }
 
 void IDBDatabaseBackend::setIndexesReady(int64_t transactionId, int64_t, const Vector<int64_t>& indexIds)

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBServerConnection.h (159244 => 159245)


--- trunk/Source/WebCore/Modules/indexeddb/IDBServerConnection.h	2013-11-13 23:04:14 UTC (rev 159244)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBServerConnection.h	2013-11-13 23:08:53 UTC (rev 159245)
@@ -39,7 +39,11 @@
 
 class IDBBackingStoreInterface;
 class IDBBackingStoreTransactionInterface;
+class IDBDatabaseError;
+class IDBKey;
 
+struct IDBObjectStoreMetadata;
+
 // This interface provides a single asynchronous layer between the web-facing frontend
 // and the I/O performing backend of IndexedDatabase.
 // If an operation's completion needs to be confirmed that must be done through use of a callback function.
@@ -68,6 +72,8 @@
     virtual void commitTransaction(int64_t transactionID, BoolCallbackFunction successCallback) = 0;
     virtual void resetTransaction(int64_t transactionID, std::function<void()> completionCallback) = 0;
     virtual void rollbackTransaction(int64_t transactionID, std::function<void()> completionCallback) = 0;
+    virtual void setIndexKeys(int64_t transactionID, int64_t databaseID, int64_t objectStoreID, const IDBObjectStoreMetadata&, IDBKey& primaryKey, const Vector<int64_t>& indexIDs, const Vector<Vector<RefPtr<IDBKey>>>& indexKeys, std::function<void(PassRefPtr<IDBDatabaseError>)> completionCallback) = 0;
+
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendOperations.cpp (159244 => 159245)


--- trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendOperations.cpp	2013-11-13 23:04:14 UTC (rev 159244)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendOperations.cpp	2013-11-13 23:08:53 UTC (rev 159245)
@@ -235,7 +235,7 @@
     Vector<RefPtr<IDBIndexWriter>> indexWriters;
     String errorMessage;
     bool obeysConstraints = false;
-    bool backingStoreSuccess = m_transaction->database().serverConnection().deprecatedBackingStore()->makeIndexWriters(*m_transaction, m_databaseId, m_objectStore, *key, keyWasGenerated, m_indexIds, m_indexKeys, indexWriters, &errorMessage, obeysConstraints);
+    bool backingStoreSuccess = m_transaction->database().serverConnection().deprecatedBackingStore()->makeIndexWriters(m_transaction->id(), m_databaseId, m_objectStore, *key, keyWasGenerated, m_indexIds, m_indexKeys, indexWriters, &errorMessage, obeysConstraints);
     if (!backingStoreSuccess) {
         m_callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UnknownError, "Internal error: backing store error updating index keys."));
         return;

Modified: trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.cpp (159244 => 159245)


--- trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.cpp	2013-11-13 23:04:14 UTC (rev 159244)
+++ trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.cpp	2013-11-13 23:08:53 UTC (rev 159245)
@@ -1383,14 +1383,14 @@
 }
 
 
-bool IDBBackingStoreLevelDB::makeIndexWriters(IDBTransactionBackend& transaction, int64_t databaseId, const IDBObjectStoreMetadata& objectStore, IDBKey& primaryKey, bool keyWasGenerated, const Vector<int64_t>& indexIds, const Vector<IndexKeys>& indexKeys, Vector<RefPtr<IDBIndexWriter>>& indexWriters, String* errorMessage, bool& completed)
+bool IDBBackingStoreLevelDB::makeIndexWriters(int64_t transactionID, int64_t databaseID, const IDBObjectStoreMetadata& objectStore, IDBKey& primaryKey, bool keyWasGenerated, const Vector<int64_t>& indexIDs, const Vector<IndexKeys>& indexKeys, Vector<RefPtr<IDBIndexWriter>>& indexWriters, String* errorMessage, bool& completed)
 {
-    ASSERT(indexIds.size() == indexKeys.size());
+    ASSERT(indexIDs.size() == indexKeys.size());
     completed = false;
 
     HashMap<int64_t, IndexKeys> indexKeyMap;
-    for (size_t i = 0; i < indexIds.size(); ++i)
-        indexKeyMap.add(indexIds[i], indexKeys[i]);
+    for (size_t i = 0; i < indexIDs.size(); ++i)
+        indexKeyMap.add(indexIDs[i], indexKeys[i]);
 
     for (IDBObjectStoreMetadata::IndexMap::const_iterator it = objectStore.indexes.begin(); it != objectStore.indexes.end(); ++it) {
         const IDBIndexMetadata& index = it->value;
@@ -1402,8 +1402,8 @@
 
         RefPtr<IDBIndexWriter> indexWriter = IDBIndexWriter::create(index, keys);
         bool canAddKeys = false;
-        ASSERT(m_backingStoreTransactions.contains(transaction.id()));
-        bool backingStoreSuccess = indexWriter->verifyIndexKeys(*this, *m_backingStoreTransactions.get(transaction.id()), databaseId, objectStore.id, index.id, canAddKeys, &primaryKey, errorMessage);
+        ASSERT(m_backingStoreTransactions.contains(transactionID));
+        bool backingStoreSuccess = indexWriter->verifyIndexKeys(*this, *m_backingStoreTransactions.get(transactionID), databaseID, objectStore.id, index.id, canAddKeys, &primaryKey, errorMessage);
         if (!backingStoreSuccess)
             return false;
         if (!canAddKeys)

Modified: trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.h (159244 => 159245)


--- trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.h	2013-11-13 23:04:14 UTC (rev 159244)
+++ trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.h	2013-11-13 23:08:53 UTC (rev 159245)
@@ -101,7 +101,7 @@
     virtual PassRefPtr<IDBBackingStoreCursorInterface> openIndexKeyCursor(IDBBackingStoreTransactionInterface&, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange*, IndexedDB::CursorDirection) OVERRIDE;
     virtual PassRefPtr<IDBBackingStoreCursorInterface> openIndexCursor(IDBBackingStoreTransactionInterface&, int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange*, IndexedDB::CursorDirection) OVERRIDE;
 
-    virtual bool makeIndexWriters(IDBTransactionBackend&, int64_t databaseId, const IDBObjectStoreMetadata&, IDBKey& primaryKey, bool keyWasGenerated, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&, Vector<RefPtr<IDBIndexWriter>>& indexWriters, String* errorMessage, bool& completed) OVERRIDE WARN_UNUSED_RETURN;
+    virtual bool makeIndexWriters(int64_t transactionID, int64_t databaseId, const IDBObjectStoreMetadata&, IDBKey& primaryKey, bool keyWasGenerated, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&, Vector<RefPtr<IDBIndexWriter>>& indexWriters, String* errorMessage, bool& completed) OVERRIDE WARN_UNUSED_RETURN;
 
     virtual PassRefPtr<IDBKey> generateKey(IDBTransactionBackend&, int64_t databaseId, int64_t objectStoreId) OVERRIDE;
     virtual bool updateKeyGenerator(IDBTransactionBackend&, int64_t databaseId, int64_t objectStoreId, const IDBKey&, bool checkCurrent) OVERRIDE;

Modified: trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBServerConnectionLevelDB.cpp (159244 => 159245)


--- trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBServerConnectionLevelDB.cpp	2013-11-13 23:04:14 UTC (rev 159244)
+++ trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBServerConnectionLevelDB.cpp	2013-11-13 23:08:53 UTC (rev 159245)
@@ -31,6 +31,7 @@
 
 #include "IDBBackingStoreLevelDB.h"
 #include "IDBBackingStoreTransactionLevelDB.h"
+#include "IDBIndexWriter.h"
 #include <wtf/MainThread.h>
 
 namespace WebCore {
@@ -137,6 +138,55 @@
     callOnMainThread(completionCallback);
 }
 
+void IDBServerConnectionLevelDB::setIndexKeys(int64_t transactionID, int64_t databaseID, int64_t objectStoreID, const IDBObjectStoreMetadata& objectStoreMetadata, IDBKey& primaryKey, const Vector<int64_t>& indexIDs, const Vector<Vector<RefPtr<IDBKey>>>& indexKeys, std::function<void(PassRefPtr<IDBDatabaseError>)> completionCallback)
+{
+    RefPtr<IDBBackingStoreTransactionLevelDB> backingStoreTransaction = m_backingStoreTransactions.get(transactionID);
+    ASSERT(backingStoreTransaction);
+
+    RefPtr<IDBRecordIdentifier> recordIdentifier;
+    bool ok = m_backingStore->keyExistsInObjectStore(*backingStoreTransaction, databaseID, objectStoreID, primaryKey, recordIdentifier);
+    if (!ok) {
+        callOnMainThread([completionCallback]() {
+            completionCallback(IDBDatabaseError::create(IDBDatabaseException::UnknownError, "Internal error: setting index keys."));
+        });
+        return;
+    }
+    if (!recordIdentifier) {
+        callOnMainThread([completionCallback]() {
+            completionCallback(IDBDatabaseError::create(IDBDatabaseException::UnknownError, "Internal error: setting index keys for object store."));
+        });
+        return;
+    }
+
+    Vector<RefPtr<IDBIndexWriter>> indexWriters;
+    String errorMessage;
+    bool obeysConstraints = false;
+
+    bool backingStoreSuccess = m_backingStore->makeIndexWriters(transactionID, databaseID, objectStoreMetadata, primaryKey, false, indexIDs, indexKeys, indexWriters, &errorMessage, obeysConstraints);
+    if (!backingStoreSuccess) {
+        callOnMainThread([completionCallback]() {
+            completionCallback(IDBDatabaseError::create(IDBDatabaseException::UnknownError, "Internal error: backing store error updating index keys."));
+        });
+        return;
+    }
+    if (!obeysConstraints) {
+        callOnMainThread([completionCallback, errorMessage]() {
+            completionCallback(IDBDatabaseError::create(IDBDatabaseException::ConstraintError, errorMessage));
+        });
+        return;
+    }
+
+    for (size_t i = 0; i < indexWriters.size(); ++i) {
+        IDBIndexWriter* indexWriter = indexWriters[i].get();
+        indexWriter->writeIndexKeys(recordIdentifier.get(), *m_backingStore, *backingStoreTransaction, databaseID, objectStoreID);
+    }
+
+    callOnMainThread([completionCallback]() {
+        completionCallback(0);
+    });
+}
+
+
 } // namespace WebCore
 
 #endif // USE(LEVELDB)

Modified: trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBServerConnectionLevelDB.h (159244 => 159245)


--- trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBServerConnectionLevelDB.h	2013-11-13 23:04:14 UTC (rev 159244)
+++ trunk/Source/WebCore/Modules/indexeddb/leveldb/IDBServerConnectionLevelDB.h	2013-11-13 23:08:53 UTC (rev 159245)
@@ -63,6 +63,7 @@
     virtual void commitTransaction(int64_t transactionID, BoolCallbackFunction successCallback) OVERRIDE;
     virtual void resetTransaction(int64_t transactionID, std::function<void()> completionCallback) OVERRIDE;
     virtual void rollbackTransaction(int64_t transactionID, std::function<void()> completionCallback) OVERRIDE;
+    virtual void setIndexKeys(int64_t transactionID, int64_t databaseID, int64_t objectStoreID, const IDBObjectStoreMetadata&, IDBKey& primaryKey, const Vector<int64_t>& indexIDs, const Vector<Vector<RefPtr<IDBKey>>>& indexKeys, std::function<void(PassRefPtr<IDBDatabaseError>)> completionCallback);
 
 private:
     IDBServerConnectionLevelDB(IDBBackingStoreLevelDB*);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to