DatabaseProcess: Plumb through messaging for the 4 basic transaction operations
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Dec 2013 01:12:23 +0000 (01:12 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Dec 2013 01:12:23 +0000 (01:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=125816

Reviewed by Alexey Proskuryakov.

The messaging begins and ends in the WebProcess:
* WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp:
(WebKit::WebIDBServerConnection::beginTransaction):
(WebKit::WebIDBServerConnection::didBeginTransaction):
(WebKit::WebIDBServerConnection::commitTransaction):
(WebKit::WebIDBServerConnection::didCommitTransaction):
(WebKit::WebIDBServerConnection::resetTransaction):
(WebKit::WebIDBServerConnection::didResetTransaction):
(WebKit::WebIDBServerConnection::rollbackTransaction):
(WebKit::WebIDBServerConnection::didRollbackTransaction):
* WebProcess/Databases/IndexedDB/WebIDBServerConnection.h:
* WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in:

It travels from the WebProcess to the DatabaseProcess connection:
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
(WebKit::DatabaseProcessIDBConnection::beginTransaction):
(WebKit::DatabaseProcessIDBConnection::commitTransaction):
(WebKit::DatabaseProcessIDBConnection::resetTransaction):
(WebKit::DatabaseProcessIDBConnection::rollbackTransaction):
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.messages.in:

It travels from the connection to the appropriate UniqueIDBDatabase:
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
(WebKit::UniqueIDBDatabase::openTransaction):
(WebKit::UniqueIDBDatabase::beginTransaction):
(WebKit::UniqueIDBDatabase::commitTransaction):
(WebKit::UniqueIDBDatabase::resetTransaction):
(WebKit::UniqueIDBDatabase::rollbackTransaction):
(WebKit::UniqueIDBDatabase::postTransactionOperation):
(WebKit::UniqueIDBDatabase::didCompleteTransactionOperation):
(WebKit::UniqueIDBDatabase::openBackingStoreTransaction):
(WebKit::UniqueIDBDatabase::beginBackingStoreTransaction):
(WebKit::UniqueIDBDatabase::commitBackingStoreTransaction):
(WebKit::UniqueIDBDatabase::resetBackingStoreTransaction):
(WebKit::UniqueIDBDatabase::rollbackBackingStoreTransaction):
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:

The UniqueIDBDatabase object performs the operation with the backing store:
* DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:
* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::establishTransaction):
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::beginTransaction):
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::commitTransaction):
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::resetTransaction):
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::rollbackTransaction):
* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:

And the SQLite backing store calls the appropriate method on the SQLite transaction:
* DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.cpp:
(WebKit::SQLiteIDBTransaction::begin): Stubbed for now.
(WebKit::SQLiteIDBTransaction::commit): Ditto.
(WebKit::SQLiteIDBTransaction::reset): Ditto.
(WebKit::SQLiteIDBTransaction::rollback): Ditto.
* DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.h:

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

14 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h
Source/WebKit2/DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.messages.in
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.h
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.h
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.h
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in

index 9fa7315..f9359ce 100644 (file)
@@ -1,3 +1,66 @@
+2013-12-16  Brady Eidson  <beidson@apple.com>
+
+        DatabaseProcess: Plumb through messaging for the 4 basic transaction operations
+        https://bugs.webkit.org/show_bug.cgi?id=125816
+
+        Reviewed by Alexey Proskuryakov.
+
+        The messaging begins and ends in the WebProcess:
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp:
+        (WebKit::WebIDBServerConnection::beginTransaction):
+        (WebKit::WebIDBServerConnection::didBeginTransaction):
+        (WebKit::WebIDBServerConnection::commitTransaction):
+        (WebKit::WebIDBServerConnection::didCommitTransaction):
+        (WebKit::WebIDBServerConnection::resetTransaction):
+        (WebKit::WebIDBServerConnection::didResetTransaction):
+        (WebKit::WebIDBServerConnection::rollbackTransaction):
+        (WebKit::WebIDBServerConnection::didRollbackTransaction):
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.h:
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in:
+
+        It travels from the WebProcess to the DatabaseProcess connection:
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
+        (WebKit::DatabaseProcessIDBConnection::beginTransaction):
+        (WebKit::DatabaseProcessIDBConnection::commitTransaction):
+        (WebKit::DatabaseProcessIDBConnection::resetTransaction):
+        (WebKit::DatabaseProcessIDBConnection::rollbackTransaction):
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.messages.in:
+
+        It travels from the connection to the appropriate UniqueIDBDatabase:
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
+        (WebKit::UniqueIDBDatabase::openTransaction):
+        (WebKit::UniqueIDBDatabase::beginTransaction):
+        (WebKit::UniqueIDBDatabase::commitTransaction):
+        (WebKit::UniqueIDBDatabase::resetTransaction):
+        (WebKit::UniqueIDBDatabase::rollbackTransaction):
+        (WebKit::UniqueIDBDatabase::postTransactionOperation):
+        (WebKit::UniqueIDBDatabase::didCompleteTransactionOperation):
+        (WebKit::UniqueIDBDatabase::openBackingStoreTransaction):
+        (WebKit::UniqueIDBDatabase::beginBackingStoreTransaction):
+        (WebKit::UniqueIDBDatabase::commitBackingStoreTransaction):
+        (WebKit::UniqueIDBDatabase::resetBackingStoreTransaction):
+        (WebKit::UniqueIDBDatabase::rollbackBackingStoreTransaction):
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:
+
+        The UniqueIDBDatabase object performs the operation with the backing store:
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::establishTransaction):
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::beginTransaction):
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::commitTransaction):
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::resetTransaction):
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::rollbackTransaction):
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:
+
+        And the SQLite backing store calls the appropriate method on the SQLite transaction:
+        * DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.cpp:
+        (WebKit::SQLiteIDBTransaction::begin): Stubbed for now.
+        (WebKit::SQLiteIDBTransaction::commit): Ditto.
+        (WebKit::SQLiteIDBTransaction::reset): Ditto.
+        (WebKit::SQLiteIDBTransaction::rollback): Ditto.
+        * DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.h:
+
 2013-12-16  Ryuan Choi  <ryuan.choi@samsung.com>
 
         Unreviewed build fix on EFL port after r160653
index 947df4b..08b24ad 100644 (file)
@@ -83,6 +83,46 @@ void DatabaseProcessIDBConnection::openTransaction(uint64_t requestID, int64_t t
     });
 }
 
+void DatabaseProcessIDBConnection::beginTransaction(uint64_t requestID, int64_t transactionID)
+{
+    ASSERT(m_uniqueIDBDatabase);
+
+    RefPtr<DatabaseProcessIDBConnection> connection(this);
+    m_uniqueIDBDatabase->beginTransaction(IDBTransactionIdentifier(*this, transactionID), [connection, requestID](bool success) {
+        connection->send(Messages::WebIDBServerConnection::DidBeginTransaction(requestID, success));
+    });
+}
+
+void DatabaseProcessIDBConnection::commitTransaction(uint64_t requestID, int64_t transactionID)
+{
+    ASSERT(m_uniqueIDBDatabase);
+
+    RefPtr<DatabaseProcessIDBConnection> connection(this);
+    m_uniqueIDBDatabase->commitTransaction(IDBTransactionIdentifier(*this, transactionID), [connection, requestID](bool success) {
+        connection->send(Messages::WebIDBServerConnection::DidCommitTransaction(requestID, success));
+    });
+}
+
+void DatabaseProcessIDBConnection::resetTransaction(uint64_t requestID, int64_t transactionID)
+{
+    ASSERT(m_uniqueIDBDatabase);
+
+    RefPtr<DatabaseProcessIDBConnection> connection(this);
+    m_uniqueIDBDatabase->resetTransaction(IDBTransactionIdentifier(*this, transactionID), [connection, requestID](bool success) {
+        connection->send(Messages::WebIDBServerConnection::DidResetTransaction(requestID, success));
+    });
+}
+
+void DatabaseProcessIDBConnection::rollbackTransaction(uint64_t requestID, int64_t transactionID)
+{
+    ASSERT(m_uniqueIDBDatabase);
+
+    RefPtr<DatabaseProcessIDBConnection> connection(this);
+    m_uniqueIDBDatabase->rollbackTransaction(IDBTransactionIdentifier(*this, transactionID), [connection, requestID](bool success) {
+        connection->send(Messages::WebIDBServerConnection::DidRollbackTransaction(requestID, success));
+    });
+}
+
 CoreIPC::Connection* DatabaseProcessIDBConnection::messageSenderConnection()
 {
     return m_connection->connection();
index 177810e..562296d 100644 (file)
@@ -64,6 +64,10 @@ private:
     void establishConnection(const String& databaseName, const SecurityOriginData& openingOrigin, const SecurityOriginData& mainFrameOrigin);
     void getOrEstablishIDBDatabaseMetadata(uint64_t requestID);
     void openTransaction(uint64_t requestID, int64_t transactionID, int64_t transactionMode);
+    void beginTransaction(uint64_t requestID, int64_t transactionID);
+    void commitTransaction(uint64_t requestID, int64_t transactionID);
+    void resetTransaction(uint64_t requestID, int64_t transactionID);
+    void rollbackTransaction(uint64_t requestID, int64_t transactionID);
 
     Ref<DatabaseToWebProcessConnection> m_connection;
     uint64_t m_serverConnectionIdentifier;
index 8cbaa77..cbe3955 100644 (file)
 messages -> DatabaseProcessIDBConnection LegacyReceiver {
     EstablishConnection(String databaseName, WebKit::SecurityOriginData openingOrigin, WebKit::SecurityOriginData mainFrameOrigin)
     GetOrEstablishIDBDatabaseMetadata(uint64_t requestID)
+
     OpenTransaction(uint64_t requestID, int64_t transactionID, int64_t transactionMode)
+    BeginTransaction(uint64_t requestID, int64_t transactionID)
+    CommitTransaction(uint64_t requestID, int64_t transactionID)
+    ResetTransaction(uint64_t requestID, int64_t transactionID)
+    RollbackTransaction(uint64_t requestID, int64_t transactionID)
 }
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
index aa66bb4..2257db8 100644 (file)
@@ -198,6 +198,31 @@ void UniqueIDBDatabase::didOpenBackingStoreAndReadMetadata(const IDBDatabaseMeta
 
 void UniqueIDBDatabase::openTransaction(const IDBTransactionIdentifier& identifier, std::function<void(bool)> successCallback)
 {
+    postTransactionOperation(&UniqueIDBDatabase::openBackingStoreTransaction, identifier, successCallback);
+}
+
+void UniqueIDBDatabase::beginTransaction(const IDBTransactionIdentifier& identifier, std::function<void(bool)> successCallback)
+{
+    postTransactionOperation(&UniqueIDBDatabase::beginBackingStoreTransaction, identifier, successCallback);
+}
+
+void UniqueIDBDatabase::commitTransaction(const IDBTransactionIdentifier& identifier, std::function<void(bool)> successCallback)
+{
+    postTransactionOperation(&UniqueIDBDatabase::commitBackingStoreTransaction, identifier, successCallback);
+}
+
+void UniqueIDBDatabase::resetTransaction(const IDBTransactionIdentifier& identifier, std::function<void(bool)> successCallback)
+{
+    postTransactionOperation(&UniqueIDBDatabase::resetBackingStoreTransaction, identifier, successCallback);
+}
+
+void UniqueIDBDatabase::rollbackTransaction(const IDBTransactionIdentifier& identifier, std::function<void(bool)> successCallback)
+{
+    postTransactionOperation(&UniqueIDBDatabase::rollbackBackingStoreTransaction, identifier, successCallback);
+}
+
+void UniqueIDBDatabase::postTransactionOperation(TransactionOperationFunction function, const IDBTransactionIdentifier& identifier, std::function<void(bool)> successCallback)
+{
     ASSERT(isMainThread());
 
     if (!m_acceptingNewRequests) {
@@ -205,7 +230,13 @@ void UniqueIDBDatabase::openTransaction(const IDBTransactionIdentifier& identifi
         return;
     }
 
-    postDatabaseTask(createAsyncTask(*this, &UniqueIDBDatabase::openBackingStoreTransaction, identifier));
+    if (m_pendingTransactionRequests.contains(identifier)) {
+        LOG_ERROR("Attempting to queue an operation for a transaction that already has an operation pending. Each transaction should only have one operation pending at a time.");
+        successCallback(false);
+        return;
+    }
+
+    postDatabaseTask(createAsyncTask(*this, function, identifier));
 
     RefPtr<AsyncRequest> request = AsyncRequestImpl<bool>::create([successCallback](bool success) {
         successCallback(success);
@@ -213,7 +244,18 @@ void UniqueIDBDatabase::openTransaction(const IDBTransactionIdentifier& identifi
         successCallback(false);
     });
 
-    m_pendingOpenTransactionRequests.set(identifier, request.release());
+    m_pendingTransactionRequests.add(identifier, request.release());
+}
+
+void UniqueIDBDatabase::didCompleteTransactionOperation(const IDBTransactionIdentifier& identifier, bool success)
+{
+    ASSERT(isMainThread());
+
+    RefPtr<AsyncRequest> request = m_pendingTransactionRequests.take(identifier);
+    if (!request)
+        return;
+
+    request->completeRequest(success);
 }
 
 void UniqueIDBDatabase::openBackingStoreTransaction(const IDBTransactionIdentifier& identifier)
@@ -223,19 +265,47 @@ void UniqueIDBDatabase::openBackingStoreTransaction(const IDBTransactionIdentifi
 
     bool success = m_backingStore->establishTransaction(identifier);
 
-    postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didOpenBackingStoreTransaction, identifier, success));
+    postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didCompleteTransactionOperation, identifier, success));
 }
 
-void UniqueIDBDatabase::didOpenBackingStoreTransaction(const IDBTransactionIdentifier& identifier, bool success)
+void UniqueIDBDatabase::beginBackingStoreTransaction(const IDBTransactionIdentifier& identifier)
 {
-    ASSERT(isMainThread());
+    ASSERT(!isMainThread());
+    ASSERT(m_backingStore);
 
-    RefPtr<AsyncRequest> request = m_pendingOpenTransactionRequests.take(identifier);
+    bool success = m_backingStore->beginTransaction(identifier);
 
-    if (!request)
-        return;
+    postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didCompleteTransactionOperation, identifier, success));
+}
 
-    request->completeRequest(success);
+void UniqueIDBDatabase::commitBackingStoreTransaction(const IDBTransactionIdentifier& identifier)
+{
+    ASSERT(!isMainThread());
+    ASSERT(m_backingStore);
+
+    bool success = m_backingStore->commitTransaction(identifier);
+
+    postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didCompleteTransactionOperation, identifier, success));
+}
+
+void UniqueIDBDatabase::resetBackingStoreTransaction(const IDBTransactionIdentifier& identifier)
+{
+    ASSERT(!isMainThread());
+    ASSERT(m_backingStore);
+
+    bool success = m_backingStore->resetTransaction(identifier);
+
+    postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didCompleteTransactionOperation, identifier, success));
+}
+
+void UniqueIDBDatabase::rollbackBackingStoreTransaction(const IDBTransactionIdentifier& identifier)
+{
+    ASSERT(!isMainThread());
+    ASSERT(m_backingStore);
+
+    bool success = m_backingStore->rollbackTransaction(identifier);
+
+    postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didCompleteTransactionOperation, identifier, success));
 }
 
 String UniqueIDBDatabase::absoluteDatabaseDirectory() const
index ecac519..333da23 100644 (file)
@@ -65,7 +65,12 @@ public:
     void unregisterConnection(DatabaseProcessIDBConnection&);
 
     void getOrEstablishIDBDatabaseMetadata(std::function<void(bool, const WebCore::IDBDatabaseMetadata&)> completionCallback);
+
     void openTransaction(const IDBTransactionIdentifier&, std::function<void(bool)> successCallback);
+    void beginTransaction(const IDBTransactionIdentifier&, std::function<void(bool)> successCallback);
+    void commitTransaction(const IDBTransactionIdentifier&, std::function<void(bool)> successCallback);
+    void resetTransaction(const IDBTransactionIdentifier&, std::function<void(bool)> successCallback);
+    void rollbackTransaction(const IDBTransactionIdentifier&, std::function<void(bool)> successCallback);
 
 private:
     UniqueIDBDatabase(const UniqueIDBDatabaseIdentifier&);
@@ -91,22 +96,29 @@ private:
 
     // Returns true if this origin can use the same databases as the given origin.
     bool canShareDatabases(const SecurityOriginData&, const SecurityOriginData&) const;
+
+    typedef void (UniqueIDBDatabase::*TransactionOperationFunction)(const IDBTransactionIdentifier&);
+    void postTransactionOperation(TransactionOperationFunction, const IDBTransactionIdentifier&, std::function<void(bool)> successCallback);
     
     // To be called from the database workqueue thread only
     void performNextDatabaseTask();
     void postMainThreadTask(std::unique_ptr<AsyncTask>);
     void openBackingStoreAndReadMetadata(const UniqueIDBDatabaseIdentifier&, const String& databaseDirectory);
     void openBackingStoreTransaction(const IDBTransactionIdentifier&);
+    void beginBackingStoreTransaction(const IDBTransactionIdentifier&);
+    void commitBackingStoreTransaction(const IDBTransactionIdentifier&);
+    void resetBackingStoreTransaction(const IDBTransactionIdentifier&);
+    void rollbackBackingStoreTransaction(const IDBTransactionIdentifier&);
 
     // Callbacks from the database workqueue thread, to be performed on the main thread only
     void performNextMainThreadTask();
     void didOpenBackingStoreAndReadMetadata(const WebCore::IDBDatabaseMetadata&, bool success);
-    void didOpenBackingStoreTransaction(const IDBTransactionIdentifier&, bool success);
+    void didCompleteTransactionOperation(const IDBTransactionIdentifier&, bool success);
 
     bool m_acceptingNewRequests;
 
     Deque<RefPtr<AsyncRequest>> m_pendingMetadataRequests;
-    HashMap<IDBTransactionIdentifier, RefPtr<AsyncRequest>> m_pendingOpenTransactionRequests;
+    HashMap<IDBTransactionIdentifier, RefPtr<AsyncRequest>> m_pendingTransactionRequests;
 
     std::unique_ptr<WebCore::IDBDatabaseMetadata> m_metadata;
     bool m_didGetMetadataFromBackingStore;
index 2c776f2..c9b0722 100644 (file)
@@ -43,7 +43,12 @@ public:
     virtual ~UniqueIDBDatabaseBackingStore() { }
 
     virtual std::unique_ptr<WebCore::IDBDatabaseMetadata> getOrEstablishMetadata() = 0;
+
     virtual bool establishTransaction(const IDBTransactionIdentifier&) = 0;
+    virtual bool beginTransaction(const IDBTransactionIdentifier&) = 0;
+    virtual bool commitTransaction(const IDBTransactionIdentifier&) = 0;
+    virtual bool resetTransaction(const IDBTransactionIdentifier&) = 0;
+    virtual bool rollbackTransaction(const IDBTransactionIdentifier&) = 0;
 };
 
 } // namespace WebKit
index 2a6fe0a..1c70386 100644 (file)
@@ -34,6 +34,26 @@ SQLiteIDBTransaction::SQLiteIDBTransaction(const IDBTransactionIdentifier& ident
 {
 }
 
+bool SQLiteIDBTransaction::begin()
+{
+    return false;
+}
+
+bool SQLiteIDBTransaction::commit()
+{
+    return false;
+}
+
+bool SQLiteIDBTransaction::reset()
+{
+    return false;
+}
+
+bool SQLiteIDBTransaction::rollback()
+{
+    return false;
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
index 8cf390f..1de6d14 100644 (file)
@@ -43,6 +43,11 @@ public:
 
     const IDBTransactionIdentifier& identifier() const { return m_identifier; }
 
+    bool begin();
+    bool commit();
+    bool reset();
+    bool rollback();
+
 private:
     SQLiteIDBTransaction(const IDBTransactionIdentifier&);
 
index 54254f4..5afde37 100644 (file)
@@ -196,13 +196,67 @@ std::unique_ptr<IDBDatabaseMetadata> UniqueIDBDatabaseBackingStoreSQLite::getOrE
 bool UniqueIDBDatabaseBackingStoreSQLite::establishTransaction(const IDBTransactionIdentifier& identifier)
 {
     ASSERT(!isMainThread());
-    ASSERT(!m_transactions.contains(identifier));
-
-    m_transactions.add(identifier, SQLiteIDBTransaction::create(identifier));
+    
+    if (!m_transactions.add(identifier, SQLiteIDBTransaction::create(identifier)).isNewEntry) {
+        LOG_ERROR("Attempt to establish transaction identifier that already exists");
+        return false;
+    }
 
     return true;
 }
 
+bool UniqueIDBDatabaseBackingStoreSQLite::beginTransaction(const IDBTransactionIdentifier& identifier)
+{
+    ASSERT(!isMainThread());
+
+    SQLiteIDBTransaction* transaction = m_transactions.get(identifier);
+    if (!transaction) {
+        LOG_ERROR("Attempt to begin a transaction that hasn't been established");
+        return false;
+    }
+
+    return transaction->begin();
+}
+
+bool UniqueIDBDatabaseBackingStoreSQLite::commitTransaction(const IDBTransactionIdentifier& identifier)
+{
+    ASSERT(!isMainThread());
+
+    SQLiteIDBTransaction* transaction = m_transactions.get(identifier);
+    if (!transaction) {
+        LOG_ERROR("Attempt to commit a transaction that hasn't been established");
+        return false;
+    }
+
+    return transaction->commit();
+}
+
+bool UniqueIDBDatabaseBackingStoreSQLite::resetTransaction(const IDBTransactionIdentifier& identifier)
+{
+    ASSERT(!isMainThread());
+
+    SQLiteIDBTransaction* transaction = m_transactions.get(identifier);
+    if (!transaction) {
+        LOG_ERROR("Attempt to reset a transaction that hasn't been established");
+        return false;
+    }
+
+    return transaction->reset();
+}
+
+bool UniqueIDBDatabaseBackingStoreSQLite::rollbackTransaction(const IDBTransactionIdentifier& identifier)
+{
+    ASSERT(!isMainThread());
+
+    SQLiteIDBTransaction* transaction = m_transactions.get(identifier);
+    if (!transaction) {
+        LOG_ERROR("Attempt to rollback a transaction that hasn't been established");
+        return false;
+    }
+
+    return transaction->rollback();
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
index d62aee8..56264cd 100644 (file)
@@ -52,7 +52,12 @@ public:
     virtual ~UniqueIDBDatabaseBackingStoreSQLite();
 
     virtual std::unique_ptr<WebCore::IDBDatabaseMetadata> getOrEstablishMetadata() OVERRIDE;
+
     virtual bool establishTransaction(const IDBTransactionIdentifier&) OVERRIDE;
+    virtual bool beginTransaction(const IDBTransactionIdentifier&) OVERRIDE;
+    virtual bool commitTransaction(const IDBTransactionIdentifier&) OVERRIDE;
+    virtual bool resetTransaction(const IDBTransactionIdentifier&) OVERRIDE;
+    virtual bool rollbackTransaction(const IDBTransactionIdentifier&) OVERRIDE;
 
 private:
     UniqueIDBDatabaseBackingStoreSQLite(const UniqueIDBDatabaseIdentifier&, const String& databaseDirectory);
index e4e519e..7678299 100644 (file)
@@ -139,18 +139,90 @@ void WebIDBServerConnection::didOpenTransaction(uint64_t requestID, bool success
 
 void WebIDBServerConnection::beginTransaction(int64_t transactionID, std::function<void()> completionCallback)
 {
+    RefPtr<AsyncRequest> serverRequest = AsyncRequestImpl<>::create(completionCallback, completionCallback);
+
+    uint64_t requestID = serverRequest->requestID();
+    ASSERT(!m_serverRequests.contains(requestID));
+    m_serverRequests.add(requestID, serverRequest.release());
+
+    send(Messages::DatabaseProcessIDBConnection::BeginTransaction(requestID, transactionID));
+}
+
+void WebIDBServerConnection::didBeginTransaction(uint64_t requestID, bool)
+{
+    RefPtr<AsyncRequest> serverRequest = m_serverRequests.take(requestID);
+
+    if (!serverRequest)
+        return;
+
+    serverRequest->completeRequest();
 }
 
 void WebIDBServerConnection::commitTransaction(int64_t transactionID, BoolCallbackFunction successCallback)
 {
+    RefPtr<AsyncRequest> serverRequest = AsyncRequestImpl<bool>::create(successCallback);
+
+    serverRequest->setAbortHandler([successCallback]() {
+        successCallback(false);
+    });
+
+    uint64_t requestID = serverRequest->requestID();
+    ASSERT(!m_serverRequests.contains(requestID));
+    m_serverRequests.add(requestID, serverRequest.release());
+
+    send(Messages::DatabaseProcessIDBConnection::CommitTransaction(requestID, transactionID));
+}
+
+void WebIDBServerConnection::didCommitTransaction(uint64_t requestID, bool success)
+{
+    RefPtr<AsyncRequest> serverRequest = m_serverRequests.take(requestID);
+
+    if (!serverRequest)
+        return;
+
+    serverRequest->completeRequest(success);
 }
 
 void WebIDBServerConnection::resetTransaction(int64_t transactionID, std::function<void()> completionCallback)
 {
+    RefPtr<AsyncRequest> serverRequest = AsyncRequestImpl<>::create(completionCallback, completionCallback);
+
+    uint64_t requestID = serverRequest->requestID();
+    ASSERT(!m_serverRequests.contains(requestID));
+    m_serverRequests.add(requestID, serverRequest.release());
+
+    send(Messages::DatabaseProcessIDBConnection::ResetTransaction(requestID, transactionID));
+}
+
+void WebIDBServerConnection::didResetTransaction(uint64_t requestID, bool)
+{
+    RefPtr<AsyncRequest> serverRequest = m_serverRequests.take(requestID);
+
+    if (!serverRequest)
+        return;
+
+    serverRequest->completeRequest();
 }
 
 void WebIDBServerConnection::rollbackTransaction(int64_t transactionID, std::function<void()> completionCallback)
 {
+    RefPtr<AsyncRequest> serverRequest = AsyncRequestImpl<>::create(completionCallback, completionCallback);
+
+    uint64_t requestID = serverRequest->requestID();
+    ASSERT(!m_serverRequests.contains(requestID));
+    m_serverRequests.add(requestID, serverRequest.release());
+
+    send(Messages::DatabaseProcessIDBConnection::RollbackTransaction(requestID, transactionID));
+}
+
+void WebIDBServerConnection::didRollbackTransaction(uint64_t requestID, bool)
+{
+    RefPtr<AsyncRequest> serverRequest = m_serverRequests.take(requestID);
+
+    if (!serverRequest)
+        return;
+
+    serverRequest->completeRequest();
 }
 
 void WebIDBServerConnection::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)
index 9c8d4fa..9783ec0 100644 (file)
@@ -95,6 +95,10 @@ private:
 
     void didGetOrEstablishIDBDatabaseMetadata(uint64_t requestID, bool success, const WebCore::IDBDatabaseMetadata&);
     void didOpenTransaction(uint64_t requestID, bool success);
+    void didBeginTransaction(uint64_t requestID, bool success);
+    void didCommitTransaction(uint64_t requestID, bool success);
+    void didResetTransaction(uint64_t requestID, bool success);
+    void didRollbackTransaction(uint64_t requestID, bool success);
 
     uint64_t m_serverConnectionIdentifier;
 
index 8f1327f..61110d0 100644 (file)
 
 messages -> WebIDBServerConnection LegacyReceiver {
     DidGetOrEstablishIDBDatabaseMetadata(uint64_t requestID, bool success, WebCore::IDBDatabaseMetadata metadata)
+
     DidOpenTransaction(uint64_t requestID, bool success)
+    DidBeginTransaction(uint64_t requestID, bool success)
+    DidCommitTransaction(uint64_t requestID, bool success)
+    DidResetTransaction(uint64_t requestID, bool success)
+    DidRollbackTransaction(uint64_t requestID, bool success)
 }
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)