DatabaseProcess: Implement openTransaction()
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Dec 2013 23:23:34 +0000 (23:23 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Dec 2013 23:23:34 +0000 (23:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=125794

Reviewed by Darin Adler.

This patch hooks up all of the necessary infrastructure to open a uniquely
identified transaction in the DatabaseProcess backing store.

The transaction itself is not yet functional.

Add openTransaction messaging to the WebProcess side:
* WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp:
(WebKit::WebIDBServerConnection::isClosed):
(WebKit::WebIDBServerConnection::getOrEstablishIDBDatabaseMetadata):
(WebKit::WebIDBServerConnection::didGetOrEstablishIDBDatabaseMetadata):
(WebKit::WebIDBServerConnection::openTransaction):
(WebKit::WebIDBServerConnection::didOpenTransaction):
(WebKit::WebIDBServerConnection::deleteObjectStore):
* WebProcess/Databases/IndexedDB/WebIDBServerConnection.h:
* WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in:

Add openTransaction messaging to the DatabaseProcess side:
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
(WebKit::DatabaseProcessIDBConnection::openTransaction):
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.messages.in:

Add a hashable identifier that represents a connection/transactionID pair:
* DatabaseProcess/IndexedDB/IDBTransactionIdentifier.h: Added.
(WebKit::IDBTransactionIdentifier::IDBTransactionIdentifier):
(WebKit::IDBTransactionIdentifier::isolatedCopy):
(WebKit::IDBTransactionIdentifier::isEmpty):
(WebKit::IDBTransactionIdentifier::hash):
(WebKit::IDBTransactionIdentifier::operator==):
(WebKit::IDBTransactionIdentifier::isHashTableDeletedValue):
(WebKit::IDBTransactionIdentifierHash::hash):
(WebKit::IDBTransactionIdentifierHash::equal):
(WebKit::IDBTransactionIdentifierHashTraits::isEmptyValue):

Allow that identifier to be cross-thread copied:
* Shared/WebCrossThreadCopier.cpp:
(WebCore::::copy):
* Shared/WebCrossThreadCopier.h:

Ask the backing store to open this uniquely identified transaction:
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
(WebKit::UniqueIDBDatabase::openTransaction):
(WebKit::UniqueIDBDatabase::openBackingStoreTransaction):
(WebKit::UniqueIDBDatabase::didOpenBackingStoreTransaction):
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:

Add the backing store implementation for opening a transaction:
* DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:
* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::~UniqueIDBDatabaseBackingStoreSQLite):
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::establishTransaction):
* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:

Object to represent the backing store transaction itself, to be used in future patches:
* DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.cpp:
(WebKit::SQLiteIDBTransaction::SQLiteIDBTransaction):
* DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.h:
(WebKit::SQLiteIDBTransaction::create):
(WebKit::SQLiteIDBTransaction::identifier):

* WebKit2.xcodeproj/project.pbxproj:

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

18 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/IDBTransactionIdentifier.h [new file with mode: 0644]
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 [new file with mode: 0644]
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.h [new file with mode: 0644]
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h
Source/WebKit2/Shared/WebCrossThreadCopier.cpp
Source/WebKit2/Shared/WebCrossThreadCopier.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.h
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in

index 0624528..3227a76 100644 (file)
@@ -1,3 +1,72 @@
+2013-12-16  Brady Eidson  <beidson@apple.com>
+
+        DatabaseProcess: Implement openTransaction()
+        https://bugs.webkit.org/show_bug.cgi?id=125794
+
+        Reviewed by Darin Adler.
+
+        This patch hooks up all of the necessary infrastructure to open a uniquely
+        identified transaction in the DatabaseProcess backing store.
+
+        The transaction itself is not yet functional.
+
+        Add openTransaction messaging to the WebProcess side:
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp:
+        (WebKit::WebIDBServerConnection::isClosed):
+        (WebKit::WebIDBServerConnection::getOrEstablishIDBDatabaseMetadata):
+        (WebKit::WebIDBServerConnection::didGetOrEstablishIDBDatabaseMetadata):
+        (WebKit::WebIDBServerConnection::openTransaction):
+        (WebKit::WebIDBServerConnection::didOpenTransaction):
+        (WebKit::WebIDBServerConnection::deleteObjectStore):
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.h:
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in:
+
+        Add openTransaction messaging to the DatabaseProcess side:
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
+        (WebKit::DatabaseProcessIDBConnection::openTransaction):
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.messages.in:
+
+        Add a hashable identifier that represents a connection/transactionID pair:
+        * DatabaseProcess/IndexedDB/IDBTransactionIdentifier.h: Added.
+        (WebKit::IDBTransactionIdentifier::IDBTransactionIdentifier):
+        (WebKit::IDBTransactionIdentifier::isolatedCopy):
+        (WebKit::IDBTransactionIdentifier::isEmpty):
+        (WebKit::IDBTransactionIdentifier::hash):
+        (WebKit::IDBTransactionIdentifier::operator==):
+        (WebKit::IDBTransactionIdentifier::isHashTableDeletedValue):
+        (WebKit::IDBTransactionIdentifierHash::hash):
+        (WebKit::IDBTransactionIdentifierHash::equal):
+        (WebKit::IDBTransactionIdentifierHashTraits::isEmptyValue):
+
+        Allow that identifier to be cross-thread copied:
+        * Shared/WebCrossThreadCopier.cpp:
+        (WebCore::::copy):
+        * Shared/WebCrossThreadCopier.h:
+
+        Ask the backing store to open this uniquely identified transaction:
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
+        (WebKit::UniqueIDBDatabase::openTransaction):
+        (WebKit::UniqueIDBDatabase::openBackingStoreTransaction):
+        (WebKit::UniqueIDBDatabase::didOpenBackingStoreTransaction):
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:
+
+        Add the backing store implementation for opening a transaction:
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::~UniqueIDBDatabaseBackingStoreSQLite):
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::establishTransaction):
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:
+
+        Object to represent the backing store transaction itself, to be used in future patches:
+        * DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.cpp:
+        (WebKit::SQLiteIDBTransaction::SQLiteIDBTransaction):
+        * DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.h:
+        (WebKit::SQLiteIDBTransaction::create):
+        (WebKit::SQLiteIDBTransaction::identifier):
+
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2013-12-16  Anders Carlsson  <andersca@apple.com>
 
         Fix crash when trying to load a null HTML string
index 72e158a..947df4b 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "DatabaseProcess.h"
 #include "DatabaseToWebProcessConnection.h"
+#include "IDBTransactionIdentifier.h"
 #include "UniqueIDBDatabase.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebIDBServerConnectionMessages.h"
@@ -72,6 +73,16 @@ void DatabaseProcessIDBConnection::getOrEstablishIDBDatabaseMetadata(uint64_t re
     });
 }
 
+void DatabaseProcessIDBConnection::openTransaction(uint64_t requestID, int64_t transactionID, int64_t)
+{
+    ASSERT(m_uniqueIDBDatabase);
+
+    RefPtr<DatabaseProcessIDBConnection> connection(this);
+    m_uniqueIDBDatabase->openTransaction(IDBTransactionIdentifier(*this, transactionID), [connection, requestID](bool success) {
+        connection->send(Messages::WebIDBServerConnection::DidOpenTransaction(requestID, success));
+    });
+}
+
 CoreIPC::Connection* DatabaseProcessIDBConnection::messageSenderConnection()
 {
     return m_connection->connection();
index 7ca74eb..177810e 100644 (file)
@@ -63,6 +63,7 @@ private:
     // Message handlers.
     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);
 
     Ref<DatabaseToWebProcessConnection> m_connection;
     uint64_t m_serverConnectionIdentifier;
index 91dbb44..8cbaa77 100644 (file)
@@ -25,6 +25,7 @@
 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)
 }
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
diff --git a/Source/WebKit2/DatabaseProcess/IndexedDB/IDBTransactionIdentifier.h b/Source/WebKit2/DatabaseProcess/IndexedDB/IDBTransactionIdentifier.h
new file mode 100644 (file)
index 0000000..ff87ab6
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef IDBTransactionIdentifier_h
+#define IDBTransactionIdentifier_h
+
+#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
+
+#include <wtf/HashTraits.h>
+#include <wtf/StringHasher.h>
+
+namespace WebKit {
+
+class DatabaseProcessIDBConnection;
+
+class IDBTransactionIdentifier {
+public:
+    IDBTransactionIdentifier()
+        : m_connection(nullptr)
+        , m_transactionID(0)
+    {
+    }
+
+    IDBTransactionIdentifier(DatabaseProcessIDBConnection& connection, int64_t transactionID)
+        : m_connection(&connection)
+        , m_transactionID(transactionID)
+    {
+    }
+
+    IDBTransactionIdentifier isolatedCopy() const
+    {
+        return *this;
+    }
+
+    bool isEmpty() const
+    {
+        return !m_connection && !m_transactionID;
+    }
+
+    unsigned hash() const
+    {
+        uint64_t hashCodes[2] = { reinterpret_cast<uint64_t>(m_connection), static_cast<uint64_t>(m_transactionID) };
+        return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
+    }
+
+    bool operator==(const IDBTransactionIdentifier& other) const
+    {
+        return m_connection == other.m_connection && m_transactionID == other.m_transactionID;
+    }
+
+    IDBTransactionIdentifier(WTF::HashTableDeletedValueType)
+        : m_connection(nullptr)
+        , m_transactionID(-1)
+    {
+    }
+
+    bool isHashTableDeletedValue() const
+    {
+        return !m_connection && m_transactionID == -1;
+    }
+
+private:
+    // If any members are added that cannot be safely copied across threads, isolatedCopy() must be updated.
+    DatabaseProcessIDBConnection* m_connection;
+    int64_t m_transactionID;
+};
+
+struct IDBTransactionIdentifierHash {
+    static unsigned hash(const IDBTransactionIdentifier& a) { return a.hash(); }
+    static bool equal(const IDBTransactionIdentifier& a, const IDBTransactionIdentifier& b) { return a == b; }
+    static const bool safeToCompareToEmptyOrDeleted = false;
+};
+
+struct IDBTransactionIdentifierHashTraits : WTF::SimpleClassHashTraits<IDBTransactionIdentifier> {
+    static const bool hasIsEmptyValueFunction = true;
+    static bool isEmptyValue(const IDBTransactionIdentifier& info) { return info.isEmpty(); }
+};
+
+} // namespace WebKit
+
+namespace WTF {
+
+template<> struct HashTraits<WebKit::IDBTransactionIdentifier> : WebKit::IDBTransactionIdentifierHashTraits { };
+template<> struct DefaultHash<WebKit::IDBTransactionIdentifier> {
+    typedef WebKit::IDBTransactionIdentifierHash Hash;
+};
+
+} // namespace WTF
+
+#endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
+#endif // IDBTransactionIdentifier_h
index e7cd847..aa66bb4 100644 (file)
@@ -196,6 +196,48 @@ void UniqueIDBDatabase::didOpenBackingStoreAndReadMetadata(const IDBDatabaseMeta
     }
 }
 
+void UniqueIDBDatabase::openTransaction(const IDBTransactionIdentifier& identifier, std::function<void(bool)> successCallback)
+{
+    ASSERT(isMainThread());
+
+    if (!m_acceptingNewRequests) {
+        successCallback(false);
+        return;
+    }
+
+    postDatabaseTask(createAsyncTask(*this, &UniqueIDBDatabase::openBackingStoreTransaction, identifier));
+
+    RefPtr<AsyncRequest> request = AsyncRequestImpl<bool>::create([successCallback](bool success) {
+        successCallback(success);
+    }, [successCallback]() {
+        successCallback(false);
+    });
+
+    m_pendingOpenTransactionRequests.set(identifier, request.release());
+}
+
+void UniqueIDBDatabase::openBackingStoreTransaction(const IDBTransactionIdentifier& identifier)
+{
+    ASSERT(!isMainThread());
+    ASSERT(m_backingStore);
+
+    bool success = m_backingStore->establishTransaction(identifier);
+
+    postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didOpenBackingStoreTransaction, identifier, success));
+}
+
+void UniqueIDBDatabase::didOpenBackingStoreTransaction(const IDBTransactionIdentifier& identifier, bool success)
+{
+    ASSERT(isMainThread());
+
+    RefPtr<AsyncRequest> request = m_pendingOpenTransactionRequests.take(identifier);
+
+    if (!request)
+        return;
+
+    request->completeRequest(success);
+}
+
 String UniqueIDBDatabase::absoluteDatabaseDirectory() const
 {
     ASSERT(isMainThread());
index f21d4f5..ecac519 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
 
+#include "IDBTransactionIdentifier.h"
 #include "UniqueIDBDatabaseIdentifier.h"
 #include <functional>
 #include <wtf/Deque.h>
@@ -64,6 +65,7 @@ public:
     void unregisterConnection(DatabaseProcessIDBConnection&);
 
     void getOrEstablishIDBDatabaseMetadata(std::function<void(bool, const WebCore::IDBDatabaseMetadata&)> completionCallback);
+    void openTransaction(const IDBTransactionIdentifier&, std::function<void(bool)> successCallback);
 
 private:
     UniqueIDBDatabase(const UniqueIDBDatabaseIdentifier&);
@@ -94,14 +96,18 @@ private:
     void performNextDatabaseTask();
     void postMainThreadTask(std::unique_ptr<AsyncTask>);
     void openBackingStoreAndReadMetadata(const UniqueIDBDatabaseIdentifier&, const String& databaseDirectory);
+    void openBackingStoreTransaction(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);
 
-    Deque<RefPtr<AsyncRequest>> m_pendingMetadataRequests;
     bool m_acceptingNewRequests;
 
+    Deque<RefPtr<AsyncRequest>> m_pendingMetadataRequests;
+    HashMap<IDBTransactionIdentifier, RefPtr<AsyncRequest>> m_pendingOpenTransactionRequests;
+
     std::unique_ptr<WebCore::IDBDatabaseMetadata> m_metadata;
     bool m_didGetMetadataFromBackingStore;
 
index 24b8d01..2c776f2 100644 (file)
@@ -36,11 +36,14 @@ struct IDBDatabaseMetadata;
 
 namespace WebKit {
 
+class IDBTransactionIdentifier;
+
 class UniqueIDBDatabaseBackingStore : public RefCounted<UniqueIDBDatabaseBackingStore> {
 public:
     virtual ~UniqueIDBDatabaseBackingStore() { }
 
     virtual std::unique_ptr<WebCore::IDBDatabaseMetadata> getOrEstablishMetadata() = 0;
+    virtual bool establishTransaction(const IDBTransactionIdentifier&) = 0;
 };
 
 } // namespace WebKit
diff --git a/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.cpp b/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.cpp
new file mode 100644 (file)
index 0000000..2a6fe0a
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "config.h"
+#include "SQLiteIDBTransaction.h"
+
+#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
+
+namespace WebKit {
+
+SQLiteIDBTransaction::SQLiteIDBTransaction(const IDBTransactionIdentifier& identifier)
+    : m_identifier(identifier)
+{
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
diff --git a/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.h b/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.h
new file mode 100644 (file)
index 0000000..8cf390f
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SQLiteIDBTransaction_h
+#define SQLiteIDBTransaction_h
+
+#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
+
+#include "IDBTransactionIdentifier.h"
+#include <wtf/Noncopyable.h>
+
+namespace WebKit {
+
+class SQLiteIDBTransaction {
+    WTF_MAKE_NONCOPYABLE(SQLiteIDBTransaction);
+public:
+    static std::unique_ptr<SQLiteIDBTransaction> create(const IDBTransactionIdentifier& identifier)
+    {
+        return std::unique_ptr<SQLiteIDBTransaction>(new SQLiteIDBTransaction(identifier));
+    }
+
+    const IDBTransactionIdentifier& identifier() const { return m_identifier; }
+
+private:
+    SQLiteIDBTransaction(const IDBTransactionIdentifier&);
+
+    IDBTransactionIdentifier m_identifier;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
+#endif // SQLiteIDBTransaction_h
index 92d1c42..54254f4 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
 
+#include "SQLiteIDBTransaction.h"
 #include <WebCore/FileSystem.h>
 #include <WebCore/IDBDatabaseMetadata.h>
 #include <WebCore/SQLiteDatabase.h>
@@ -57,6 +58,11 @@ UniqueIDBDatabaseBackingStoreSQLite::UniqueIDBDatabaseBackingStoreSQLite(const U
     ASSERT(!isMainThread());
 }
 
+UniqueIDBDatabaseBackingStoreSQLite::~UniqueIDBDatabaseBackingStoreSQLite()
+{
+    ASSERT(!isMainThread());
+}
+
 std::unique_ptr<WebCore::IDBDatabaseMetadata> UniqueIDBDatabaseBackingStoreSQLite::createAndPopulateInitialMetadata()
 {
     ASSERT(!isMainThread());
@@ -187,6 +193,16 @@ std::unique_ptr<IDBDatabaseMetadata> UniqueIDBDatabaseBackingStoreSQLite::getOrE
     return metadata;
 }
 
+bool UniqueIDBDatabaseBackingStoreSQLite::establishTransaction(const IDBTransactionIdentifier& identifier)
+{
+    ASSERT(!isMainThread());
+    ASSERT(!m_transactions.contains(identifier));
+
+    m_transactions.add(identifier, SQLiteIDBTransaction::create(identifier));
+
+    return true;
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
index abf6c95..d62aee8 100644 (file)
@@ -40,6 +40,8 @@ struct IDBDatabaseMetadata;
 
 namespace WebKit {
 
+class SQLiteIDBTransaction;
+
 class UniqueIDBDatabaseBackingStoreSQLite FINAL : public UniqueIDBDatabaseBackingStore {
 public:
     static PassRefPtr<UniqueIDBDatabaseBackingStore> create(const UniqueIDBDatabaseIdentifier& identifier, const String& databaseDirectory)
@@ -47,7 +49,10 @@ public:
         return adoptRef(new UniqueIDBDatabaseBackingStoreSQLite(identifier, databaseDirectory));
     }
 
+    virtual ~UniqueIDBDatabaseBackingStoreSQLite();
+
     virtual std::unique_ptr<WebCore::IDBDatabaseMetadata> getOrEstablishMetadata() OVERRIDE;
+    virtual bool establishTransaction(const IDBTransactionIdentifier&) OVERRIDE;
 
 private:
     UniqueIDBDatabaseBackingStoreSQLite(const UniqueIDBDatabaseIdentifier&, const String& databaseDirectory);
@@ -60,6 +65,8 @@ private:
     String m_absoluteDatabaseDirectory;
 
     std::unique_ptr<WebCore::SQLiteDatabase> m_metadataDB;
+
+    HashMap<IDBTransactionIdentifier, std::unique_ptr<SQLiteIDBTransaction>> m_transactions;
 };
 
 } // namespace WebKit
index 515767f..d6c9c7f 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
+#include "IDBTransactionIdentifier.h"
 #include "UniqueIDBDatabaseIdentifier.h"
 
 using namespace WebKit;
@@ -38,6 +39,11 @@ UniqueIDBDatabaseIdentifier CrossThreadCopierBase<false, false, UniqueIDBDatabas
     return identifier.isolatedCopy();
 }
 
+IDBTransactionIdentifier CrossThreadCopierBase<false, false, IDBTransactionIdentifier>::copy(const IDBTransactionIdentifier& identifier)
+{
+    return identifier.isolatedCopy();
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(INDEXED_DATABASE)
index bfeda46..987cdd1 100644 (file)
@@ -31,6 +31,7 @@
 #if ENABLE(INDEXED_DATABASE)
 
 namespace WebKit {
+class IDBTransactionIdentifier;
 class UniqueIDBDatabaseIdentifier;
 }
 
@@ -40,6 +41,10 @@ template<> struct CrossThreadCopierBase<false, false, WebKit::UniqueIDBDatabaseI
     static WebKit::UniqueIDBDatabaseIdentifier copy(const WebKit::UniqueIDBDatabaseIdentifier&);
 };
 
+template<> struct CrossThreadCopierBase<false, false, WebKit::IDBTransactionIdentifier> {
+    static WebKit::IDBTransactionIdentifier copy(const WebKit::IDBTransactionIdentifier&);
+};
+
 } // namespace WebCore
 
 #endif // ENABLE(INDEXED_DATABASE)
index 206b401..559e816 100644 (file)
                511B24A7132E095700065A0C /* WebIconDatabaseProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 511B24A5132E095700065A0C /* WebIconDatabaseProxy.h */; };
                511B24AA132E097200065A0C /* WebIconDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511B24A8132E097200065A0C /* WebIconDatabase.cpp */; };
                511B24AB132E097200065A0C /* WebIconDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 511B24A9132E097200065A0C /* WebIconDatabase.h */; };
+               511D81FF185BBDEE001AED56 /* SQLiteIDBTransaction.h in Headers */ = {isa = PBXBuildFile; fileRef = 511D81FD185BBDEE001AED56 /* SQLiteIDBTransaction.h */; };
+               511D8201185BC217001AED56 /* SQLiteIDBTransaction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511D8200185BC217001AED56 /* SQLiteIDBTransaction.cpp */; };
                511F8A7B138B460900A95F44 /* SecItemShimLibrary.h in Headers */ = {isa = PBXBuildFile; fileRef = 511F8A77138B460900A95F44 /* SecItemShimLibrary.h */; };
                511F8A81138B485D00A95F44 /* SecItemShimLibrary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 511F8A78138B460900A95F44 /* SecItemShimLibrary.mm */; };
                51217460164C20E30037A5C1 /* ShareableResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5121745E164C20E30037A5C1 /* ShareableResource.cpp */; };
                51D130551382EAC000351EDD /* SecItemResponseData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D130511382EAC000351EDD /* SecItemResponseData.cpp */; };
                51D130561382EAC000351EDD /* SecItemResponseData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51D130521382EAC000351EDD /* SecItemResponseData.h */; };
                51D130581382F10500351EDD /* WebProcessProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51D130571382F10500351EDD /* WebProcessProxyMac.mm */; };
+               51D54A73185BAC42000CAED2 /* IDBTransactionIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 51D54A72185BAC42000CAED2 /* IDBTransactionIdentifier.h */; };
                51DD9F2816367DA2001578E9 /* NetworkConnectionToWebProcessMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51DD9F2616367DA2001578E9 /* NetworkConnectionToWebProcessMessageReceiver.cpp */; };
                51DD9F2916367DA2001578E9 /* NetworkConnectionToWebProcessMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51DD9F2716367DA2001578E9 /* NetworkConnectionToWebProcessMessages.h */; };
                51E351CA180F2CCC00E53BE9 /* IDBUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E351C8180F2CCC00E53BE9 /* IDBUtilities.cpp */; };
                511B24A5132E095700065A0C /* WebIconDatabaseProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebIconDatabaseProxy.h; path = IconDatabase/WebIconDatabaseProxy.h; sourceTree = "<group>"; };
                511B24A8132E097200065A0C /* WebIconDatabase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebIconDatabase.cpp; sourceTree = "<group>"; };
                511B24A9132E097200065A0C /* WebIconDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebIconDatabase.h; sourceTree = "<group>"; };
+               511D81FD185BBDEE001AED56 /* SQLiteIDBTransaction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQLiteIDBTransaction.h; sourceTree = "<group>"; };
+               511D8200185BC217001AED56 /* SQLiteIDBTransaction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SQLiteIDBTransaction.cpp; sourceTree = "<group>"; };
                511F8A77138B460900A95F44 /* SecItemShimLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SecItemShimLibrary.h; path = ../../WebProcess/mac/SecItemShimLibrary.h; sourceTree = "<group>"; };
                511F8A78138B460900A95F44 /* SecItemShimLibrary.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SecItemShimLibrary.mm; path = ../../WebProcess/mac/SecItemShimLibrary.mm; sourceTree = "<group>"; };
                5121745E164C20E30037A5C1 /* ShareableResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShareableResource.cpp; sourceTree = "<group>"; };
                51D130511382EAC000351EDD /* SecItemResponseData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecItemResponseData.cpp; sourceTree = "<group>"; };
                51D130521382EAC000351EDD /* SecItemResponseData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecItemResponseData.h; sourceTree = "<group>"; };
                51D130571382F10500351EDD /* WebProcessProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessProxyMac.mm; sourceTree = "<group>"; };
+               51D54A72185BAC42000CAED2 /* IDBTransactionIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBTransactionIdentifier.h; sourceTree = "<group>"; };
                51DD9F2616367DA2001578E9 /* NetworkConnectionToWebProcessMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkConnectionToWebProcessMessageReceiver.cpp; sourceTree = "<group>"; };
                51DD9F2716367DA2001578E9 /* NetworkConnectionToWebProcessMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkConnectionToWebProcessMessages.h; sourceTree = "<group>"; };
                51E351C8180F2CCC00E53BE9 /* IDBUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBUtilities.cpp; sourceTree = "<group>"; };
                51654EF0184EF241007DC837 /* sqlite */ = {
                        isa = PBXGroup;
                        children = (
+                               511D8200185BC217001AED56 /* SQLiteIDBTransaction.cpp */,
+                               511D81FD185BBDEE001AED56 /* SQLiteIDBTransaction.h */,
                                51654EFB184EF33F007DC837 /* UniqueIDBDatabaseBackingStoreSQLite.cpp */,
                                51654EFC184EF33F007DC837 /* UniqueIDBDatabaseBackingStoreSQLite.h */,
                        );
                                51D0D42E183B34130097041D /* DatabaseProcessIDBConnection.cpp */,
                                51D0D42F183B34130097041D /* DatabaseProcessIDBConnection.h */,
                                51D0D430183B34130097041D /* DatabaseProcessIDBConnection.messages.in */,
+                               51D54A72185BAC42000CAED2 /* IDBTransactionIdentifier.h */,
                                515E772D184015800007203F /* UniqueIDBDatabase.cpp */,
                                515E772E184015800007203F /* UniqueIDBDatabase.h */,
                                51654EFF184EF34A007DC837 /* UniqueIDBDatabaseBackingStore.h */,
                                1AB474E6184D44B40051B622 /* WKBundlePageFullScreenClient.h in Headers */,
                                1AB31A9716BC688100F6DBC9 /* StorageManagerMessages.h in Headers */,
                                296BD85D15019BC30071F424 /* StringUtilities.h in Headers */,
+                               511D81FF185BBDEE001AED56 /* SQLiteIDBTransaction.h in Headers */,
                                1AB474E4184D44980051B622 /* WKBundlePageContextMenuClient.h in Headers */,
                                1AA417CB12C00CCA002BE67B /* TextChecker.h in Headers */,
                                1QQ417CB12C00CCA002BE67B /* TextCheckerCompletion.h in Headers */,
                                1AC8702D130B49A2002C1257 /* WebPluginSiteDataManager.h in Headers */,
                                BCB9F8B01124E07700A137E0 /* WebPolicyClient.h in Headers */,
                                BC5744F012638FB3006F0F12 /* WebPopupItem.h in Headers */,
+                               51D54A73185BAC42000CAED2 /* IDBTransactionIdentifier.h in Headers */,
                                D3B9484711FF4B6500032B39 /* WebPopupMenu.h in Headers */,
                                BC574E631267D080006F0F12 /* WebPopupMenuProxy.h in Headers */,
                                BC5750971268F3C6006F0F12 /* WebPopupMenuProxyMac.h in Headers */,
                                31A2EC4D148997C200810D71 /* WebNotificationProvider.cpp in Sources */,
                                BC857FB612B830E600EDEB2E /* WebOpenPanelParameters.cpp in Sources */,
                                BC857F8612B82D0B00EDEB2E /* WebOpenPanelResultListener.cpp in Sources */,
+                               511D8201185BC217001AED56 /* SQLiteIDBTransaction.cpp in Sources */,
                                BC857F7E12B82CEE00EDEB2E /* WebOpenPanelResultListenerProxy.cpp in Sources */,
                                BC963D6B113DD19200574BE2 /* WebPage.cpp in Sources */,
                                5153569C1291B1D2000749DC /* WebPageContextMenuClient.cpp in Sources */,
index 1d07a1a..e4e519e 100644 (file)
@@ -74,6 +74,7 @@ WebIDBServerConnection::~WebIDBServerConnection()
 
 bool WebIDBServerConnection::isClosed()
 {
+    // FIXME: Return real value here.
     return true;
 }
 
@@ -91,7 +92,8 @@ void WebIDBServerConnection::getOrEstablishIDBDatabaseMetadata(GetIDBDatabaseMet
     });
 
     uint64_t requestID = serverRequest->requestID();
-    m_serverRequests.set(requestID, serverRequest.release());
+    ASSERT(!m_serverRequests.contains(requestID));
+    m_serverRequests.add(requestID, serverRequest.release());
 
     send(Messages::DatabaseProcessIDBConnection::GetOrEstablishIDBDatabaseMetadata(requestID));
 }
@@ -99,7 +101,9 @@ void WebIDBServerConnection::getOrEstablishIDBDatabaseMetadata(GetIDBDatabaseMet
 void WebIDBServerConnection::didGetOrEstablishIDBDatabaseMetadata(uint64_t requestID, bool success, const IDBDatabaseMetadata& metadata)
 {
     RefPtr<AsyncRequest> serverRequest = m_serverRequests.take(requestID);
-    ASSERT(serverRequest);
+
+    if (!serverRequest)
+        return;
 
     serverRequest->completeRequest(metadata, success);
 }
@@ -108,8 +112,29 @@ void WebIDBServerConnection::close()
 {
 }
 
-void WebIDBServerConnection::openTransaction(int64_t transactionID, const HashSet<int64_t>& objectStoreIds, IndexedDB::TransactionMode, BoolCallbackFunction successCallback)
+void WebIDBServerConnection::openTransaction(int64_t transactionID, const HashSet<int64_t>&, IndexedDB::TransactionMode mode, 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::OpenTransaction(requestID, transactionID, mode));
+}
+
+void WebIDBServerConnection::didOpenTransaction(uint64_t requestID, bool success)
 {
+    RefPtr<AsyncRequest> serverRequest = m_serverRequests.take(requestID);
+
+    if (!serverRequest)
+        return;
+
+    serverRequest->completeRequest(success);
 }
 
 void WebIDBServerConnection::beginTransaction(int64_t transactionID, std::function<void()> completionCallback)
@@ -170,8 +195,8 @@ void WebIDBServerConnection::clearObjectStore(IDBTransactionBackend&, const Clea
 
 void WebIDBServerConnection::deleteObjectStore(IDBTransactionBackend&, const DeleteObjectStoreOperation&, std::function<void(PassRefPtr<IDBDatabaseError>)> completionCallback)
 {
-
 }
+
 void WebIDBServerConnection::changeDatabaseVersion(IDBTransactionBackend&, const IDBDatabaseBackend::VersionChangeOperation&, std::function<void(PassRefPtr<IDBDatabaseError>)> completionCallback)
 {
 }
index 9576838..9c8d4fa 100644 (file)
@@ -94,6 +94,7 @@ private:
     virtual CoreIPC::Connection* messageSenderConnection() OVERRIDE;
 
     void didGetOrEstablishIDBDatabaseMetadata(uint64_t requestID, bool success, const WebCore::IDBDatabaseMetadata&);
+    void didOpenTransaction(uint64_t requestID, bool success);
 
     uint64_t m_serverConnectionIdentifier;
 
index b947b7c..8f1327f 100644 (file)
@@ -24,6 +24,7 @@
 
 messages -> WebIDBServerConnection LegacyReceiver {
     DidGetOrEstablishIDBDatabaseMetadata(uint64_t requestID, bool success, WebCore::IDBDatabaseMetadata metadata)
+    DidOpenTransaction(uint64_t requestID, bool success)
 }
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)