DatabaseProcess: Add "UniqueIDBDatabase" that multiple WebProcesses can connect to
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 24 Nov 2013 23:12:28 +0000 (23:12 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 24 Nov 2013 23:12:28 +0000 (23:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=124819

Reviewed by Dan Bernstein.

Source/WebCore:

* Modules/indexeddb/IDBDatabaseBackend.cpp:
(WebCore::IDBDatabaseBackend::~IDBDatabaseBackend): Unregister from the IDBFactory.

Source/WebKit2:

UniqueIDBDatabase instances are per-DatabaseProcess, so it manages the set of them.
* DatabaseProcess/DatabaseProcess.cpp:
(WebKit::DatabaseProcess::getOrCreateUniqueIDBDatabase):
(WebKit::DatabaseProcess::removeUniqueIDBDatabase):
* DatabaseProcess/DatabaseProcess.h:

* DatabaseProcess/DatabaseToWebProcessConnection.h:

Start forwarding things along to the appropriate UniqueIDBDatabase.
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
(WebKit::DatabaseProcessIDBConnection::~DatabaseProcessIDBConnection):
(WebKit::DatabaseProcessIDBConnection::disconnectedFromWebProcess):
(WebKit::DatabaseProcessIDBConnection::establishConnection):
(WebKit::DatabaseProcessIDBConnection::getOrEstablishIDBDatabaseMetadata):
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:

A class that represents a single concrete IDB database that multiple WebProcesses can connect to.
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
(WebKit::UniqueIDBDatabase::UniqueIDBDatabase):
(WebKit::UniqueIDBDatabase::~UniqueIDBDatabase):
(WebKit::UniqueIDBDatabase::registerConnection):
(WebKit::UniqueIDBDatabase::unregisterConnection):
(WebKit::UniqueIDBDatabase::getIDBDatabaseMetadata):
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:
(WebKit::UniqueIDBDatabase::create):
(WebKit::UniqueIDBDatabase::identifier):

A class to help uniquely identify an IDBDatabase that can be expanded as needed.
Importantly, it knows how to be used as a key in a HashMap.
* DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.cpp: Added.
(WebKit::UniqueIDBDatabaseIdentifier::UniqueIDBDatabaseIdentifier):
(WebKit::UniqueIDBDatabaseIdentifier::isHashTableDeletedValue):
(WebKit::UniqueIDBDatabaseIdentifier::hash):
(WebKit::UniqueIDBDatabaseIdentifier::isNull):
(WebKit::operator==):
* DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.h: Added.
(WebKit::UniqueIDBDatabaseIdentifier::databaseName):
(WebKit::UniqueIDBDatabaseIdentifier::openingOrigin):
(WebKit::UniqueIDBDatabaseIdentifier::mainFrameOrigin):
(WebKit::UniqueIDBDatabaseIdentifierHash::hash):
(WebKit::UniqueIDBDatabaseIdentifierHash::equal):
(WebKit::UniqueIDBDatabaseIdentifierHashTraits::isEmptyValue):

* Shared/SecurityOriginData.cpp:
(WebKit::operator==):
* Shared/SecurityOriginData.h:

* UIProcess/WebContext.cpp:

* WebProcess/Databases/IndexedDB/WebIDBFactoryBackend.cpp:
(WebKit::WebIDBFactoryBackend::open):
(WebKit::WebIDBFactoryBackend::removeIDBDatabaseBackend):

* WebKit2.xcodeproj/project.pbxproj:

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBDatabaseBackend.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/DatabaseProcess/DatabaseProcess.cpp
Source/WebKit2/DatabaseProcess/DatabaseProcess.h
Source/WebKit2/DatabaseProcess/DatabaseToWebProcessConnection.h
Source/WebKit2/DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp [new file with mode: 0644]
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.h [new file with mode: 0644]
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.cpp [new file with mode: 0644]
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.h [new file with mode: 0644]
Source/WebKit2/Shared/SecurityOriginData.cpp
Source/WebKit2/Shared/SecurityOriginData.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBFactoryBackend.cpp

index 4daf36b..df5d068 100644 (file)
@@ -1,3 +1,13 @@
+2013-11-24  Brady Eidson  <beidson@apple.com>
+
+        DatabaseProcess: Add "UniqueIDBDatabase" that multiple WebProcesses can connect to
+        https://bugs.webkit.org/show_bug.cgi?id=124819
+
+        Reviewed by Dan Bernstein.
+
+        * Modules/indexeddb/IDBDatabaseBackend.cpp:
+        (WebCore::IDBDatabaseBackend::~IDBDatabaseBackend): Unregister from the IDBFactory.
+
 2013-11-24  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Generate toHTMLMarquee|OListElement() to cleanup static_cast<>
index 89b6c77..fd996a5 100644 (file)
@@ -124,6 +124,7 @@ void IDBDatabaseBackend::didOpenInternalAsync(const IDBDatabaseMetadata& metadat
 
 IDBDatabaseBackend::~IDBDatabaseBackend()
 {
+    m_factory->removeIDBDatabaseBackend(m_identifier);
 }
 
 void IDBDatabaseBackend::createObjectStore(int64_t transactionId, int64_t objectStoreId, const String& name, const IDBKeyPath& keyPath, bool autoIncrement)
@@ -447,7 +448,6 @@ void IDBDatabaseBackend::openConnection(PassRefPtr<IDBCallbacks> prpCallbacks, P
     processPendingCalls();
 }
 
-
 void IDBDatabaseBackend::openConnectionInternal(PassRefPtr<IDBCallbacks> prpCallbacks, PassRefPtr<IDBDatabaseCallbacks> prpDatabaseCallbacks, int64_t transactionId, uint64_t version)
 {
     ASSERT(m_pendingDeleteCalls.isEmpty());
index 8a75cc6..d165054 100644 (file)
@@ -1,3 +1,65 @@
+2013-11-24  Brady Eidson  <beidson@apple.com>
+
+        DatabaseProcess: Add "UniqueIDBDatabase" that multiple WebProcesses can connect to
+        https://bugs.webkit.org/show_bug.cgi?id=124819
+
+        Reviewed by Dan Bernstein.
+
+        UniqueIDBDatabase instances are per-DatabaseProcess, so it manages the set of them.
+        * DatabaseProcess/DatabaseProcess.cpp:
+        (WebKit::DatabaseProcess::getOrCreateUniqueIDBDatabase):
+        (WebKit::DatabaseProcess::removeUniqueIDBDatabase):
+        * DatabaseProcess/DatabaseProcess.h:
+
+        * DatabaseProcess/DatabaseToWebProcessConnection.h:
+
+        Start forwarding things along to the appropriate UniqueIDBDatabase.
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
+        (WebKit::DatabaseProcessIDBConnection::~DatabaseProcessIDBConnection):
+        (WebKit::DatabaseProcessIDBConnection::disconnectedFromWebProcess):
+        (WebKit::DatabaseProcessIDBConnection::establishConnection):
+        (WebKit::DatabaseProcessIDBConnection::getOrEstablishIDBDatabaseMetadata):
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:
+
+        A class that represents a single concrete IDB database that multiple WebProcesses can connect to.
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
+        (WebKit::UniqueIDBDatabase::UniqueIDBDatabase):
+        (WebKit::UniqueIDBDatabase::~UniqueIDBDatabase):
+        (WebKit::UniqueIDBDatabase::registerConnection):
+        (WebKit::UniqueIDBDatabase::unregisterConnection):
+        (WebKit::UniqueIDBDatabase::getIDBDatabaseMetadata):
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:
+        (WebKit::UniqueIDBDatabase::create):
+        (WebKit::UniqueIDBDatabase::identifier):
+
+        A class to help uniquely identify an IDBDatabase that can be expanded as needed.
+        Importantly, it knows how to be used as a key in a HashMap.
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.cpp: Added.
+        (WebKit::UniqueIDBDatabaseIdentifier::UniqueIDBDatabaseIdentifier):
+        (WebKit::UniqueIDBDatabaseIdentifier::isHashTableDeletedValue):
+        (WebKit::UniqueIDBDatabaseIdentifier::hash):
+        (WebKit::UniqueIDBDatabaseIdentifier::isNull):
+        (WebKit::operator==):
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.h: Added.
+        (WebKit::UniqueIDBDatabaseIdentifier::databaseName):
+        (WebKit::UniqueIDBDatabaseIdentifier::openingOrigin):
+        (WebKit::UniqueIDBDatabaseIdentifier::mainFrameOrigin):
+        (WebKit::UniqueIDBDatabaseIdentifierHash::hash):
+        (WebKit::UniqueIDBDatabaseIdentifierHash::equal):
+        (WebKit::UniqueIDBDatabaseIdentifierHashTraits::isEmptyValue):
+
+        * Shared/SecurityOriginData.cpp:
+        (WebKit::operator==):
+        * Shared/SecurityOriginData.h:
+
+        * UIProcess/WebContext.cpp:
+
+        * WebProcess/Databases/IndexedDB/WebIDBFactoryBackend.cpp:
+        (WebKit::WebIDBFactoryBackend::open):
+        (WebKit::WebIDBFactoryBackend::removeIDBDatabaseBackend):
+
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2013-11-24  Danilo Cesar Lemes de Paula  <danilo.cesar@collabora.co.uk>, Arunprasad Rajkumar  <arurajku@cisco.com>
 
         [WK2][GTK] Adding SpatialNavigation setting to webkit2
index ce3c383..3c2204a 100644 (file)
@@ -29,6 +29,7 @@
 #include "DatabaseProcessCreationParameters.h"
 #include "DatabaseProcessProxyMessages.h"
 #include "DatabaseToWebProcessConnection.h"
+#include "UniqueIDBDatabase.h"
 
 #if ENABLE(DATABASE_PROCESS)
 
@@ -68,6 +69,27 @@ void DatabaseProcess::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::St
     RunLoop::current()->stop();
 }
 
+PassRefPtr<UniqueIDBDatabase> DatabaseProcess::getOrCreateUniqueIDBDatabase(const UniqueIDBDatabaseIdentifier& identifier)
+{
+    auto addResult = m_idbDatabases.add(identifier, nullptr);
+
+    if (!addResult.isNewEntry)
+        return addResult.iterator->value;
+
+    RefPtr<UniqueIDBDatabase> database = UniqueIDBDatabase::create(identifier);
+    addResult.iterator->value = database.get();
+    return database.release();
+}
+
+void DatabaseProcess::removeUniqueIDBDatabase(const UniqueIDBDatabase& database)
+{
+    const UniqueIDBDatabaseIdentifier& identifier = database.identifier();
+    ASSERT(m_idbDatabases.contains(identifier));
+
+    // FIXME: Perform necessary shut down of the unique database before it is actually destroyed.
+    m_idbDatabases.remove(identifier);
+}
+
 void DatabaseProcess::initializeDatabaseProcess(const DatabaseProcessCreationParameters& parameters)
 {
     m_indexedDatabaseDirectory = parameters.indexedDatabaseDirectory;
index 63acdd5..b104a73 100644 (file)
 #if ENABLE(DATABASE_PROCESS)
 
 #include "ChildProcess.h"
+#include "UniqueIDBDatabaseIdentifier.h"
 
 namespace WebKit {
 
 class DatabaseToWebProcessConnection;
+class UniqueIDBDatabase;
 
 struct DatabaseProcessCreationParameters;
 
@@ -43,6 +45,9 @@ public:
 
     const String& indexedDatabaseDirectory() const { return m_indexedDatabaseDirectory; }
 
+    PassRefPtr<UniqueIDBDatabase> getOrCreateUniqueIDBDatabase(const UniqueIDBDatabaseIdentifier&);
+    void removeUniqueIDBDatabase(const UniqueIDBDatabase&);
+
 private:
     DatabaseProcess();
     ~DatabaseProcess();
@@ -66,6 +71,8 @@ private:
     Vector<RefPtr<DatabaseToWebProcessConnection>> m_databaseToWebProcessConnections;
 
     String m_indexedDatabaseDirectory;
+
+    HashMap<UniqueIDBDatabaseIdentifier, RefPtr<UniqueIDBDatabase>> m_idbDatabases;
 };
 
 } // namespace WebKit
index 0b9a97f..96ec0b5 100644 (file)
@@ -27,6 +27,7 @@
 #define DatabaseToWebProcessConnection_h
 
 #include "Connection.h"
+#include "DatabaseProcessIDBConnection.h"
 #include "MessageSender.h"
 
 #include <wtf/HashMap.h>
@@ -35,8 +36,6 @@
 
 namespace WebKit {
 
-class DatabaseProcessIDBConnection;
-
 class DatabaseToWebProcessConnection : public RefCounted<DatabaseToWebProcessConnection>, public CoreIPC::Connection::Client, public CoreIPC::MessageSender {
 public:
     static PassRefPtr<DatabaseToWebProcessConnection> create(CoreIPC::Connection::Identifier);
index 6c825b3..bdcd9db 100644 (file)
@@ -28,7 +28,9 @@
 
 #if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
 
+#include "DatabaseProcess.h"
 #include "DatabaseToWebProcessConnection.h"
+#include "UniqueIDBDatabase.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebIDBServerConnectionMessages.h"
 #include <WebCore/IDBDatabaseMetadata.h>
@@ -45,32 +47,29 @@ DatabaseProcessIDBConnection::DatabaseProcessIDBConnection(DatabaseToWebProcessC
 
 DatabaseProcessIDBConnection::~DatabaseProcessIDBConnection()
 {
+    ASSERT(!m_uniqueIDBDatabase);
 }
 
 void DatabaseProcessIDBConnection::disconnectedFromWebProcess()
 {
-    // Do any necessary cleanup work here.
+    m_uniqueIDBDatabase->unregisterConnection(*this);
+    m_uniqueIDBDatabase.clear();
 }
 
 void DatabaseProcessIDBConnection::establishConnection(const String& databaseName, const SecurityOriginData& openingOrigin, const SecurityOriginData& mainFrameOrigin)
 {
-    // This method should only be called once, so the stored database name should still be null.
-    // Also, it is invalid to set the stored database name to the null string.
-    ASSERT(m_databaseName.isNull());
-    ASSERT(!databaseName.isNull());
-
-    m_databaseName = databaseName;
-    m_openingOrigin = openingOrigin;
-    m_mainFrameOrigin = mainFrameOrigin;
+    m_uniqueIDBDatabase = DatabaseProcess::shared().getOrCreateUniqueIDBDatabase(UniqueIDBDatabaseIdentifier(databaseName, openingOrigin, mainFrameOrigin));
+    m_uniqueIDBDatabase->registerConnection(*this);
 }
 
 void DatabaseProcessIDBConnection::getOrEstablishIDBDatabaseMetadata(uint64_t requestID)
 {
-    // FIXME: This method is successfully called by messaging from the WebProcess, and calls back with dummy data.
-    // Needs real implementation.
+    ASSERT(m_uniqueIDBDatabase);
 
-    IDBDatabaseMetadata data;
-    send(Messages::WebIDBServerConnection::DidGetOrEstablishIDBDatabaseMetadata(requestID, false, data));
+    RefPtr<DatabaseProcessIDBConnection> connection(this);
+    m_uniqueIDBDatabase->getIDBDatabaseMetadata([connection, requestID](bool success, const IDBDatabaseMetadata& metadata) {
+        connection->send(Messages::WebIDBServerConnection::DidGetOrEstablishIDBDatabaseMetadata(requestID, success, metadata));
+    });
 }
 
 CoreIPC::Connection* DatabaseProcessIDBConnection::messageSenderConnection()
index 9335370..7ca74eb 100644 (file)
 #if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
 
 #include "SecurityOriginData.h"
+#include "UniqueIDBDatabaseIdentifier.h"
 #include <wtf/text/WTFString.h>
 
 namespace WebKit {
 
 class DatabaseToWebProcessConnection;
+class UniqueIDBDatabase;
 
 class DatabaseProcessIDBConnection : public RefCounted<DatabaseProcessIDBConnection>, public CoreIPC::MessageSender {
 public:
@@ -65,9 +67,7 @@ private:
     Ref<DatabaseToWebProcessConnection> m_connection;
     uint64_t m_serverConnectionIdentifier;
 
-    String m_databaseName;
-    SecurityOriginData m_openingOrigin;
-    SecurityOriginData m_mainFrameOrigin;
+    RefPtr<UniqueIDBDatabase> m_uniqueIDBDatabase;
 };
 
 } // namespace WebKit
diff --git a/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp b/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp
new file mode 100644 (file)
index 0000000..87f6f49
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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 "UniqueIDBDatabase.h"
+
+#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
+
+#include "DatabaseProcess.h"
+#include "DatabaseProcessIDBConnection.h"
+#include <WebCore/IDBDatabaseMetadata.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+UniqueIDBDatabase::UniqueIDBDatabase(const UniqueIDBDatabaseIdentifier& identifier)
+    : m_identifier(identifier)
+{
+}
+
+UniqueIDBDatabase::~UniqueIDBDatabase()
+{
+}
+
+void UniqueIDBDatabase::registerConnection(DatabaseProcessIDBConnection& connection)
+{
+    ASSERT(!m_connections.contains(&connection));
+    m_connections.add(&connection);
+}
+
+void UniqueIDBDatabase::unregisterConnection(DatabaseProcessIDBConnection& connection)
+{
+    ASSERT(m_connections.contains(&connection));
+    m_connections.remove(&connection);
+
+    if (m_connections.isEmpty())
+        DatabaseProcess::shared().removeUniqueIDBDatabase(*this);
+}
+
+void UniqueIDBDatabase::getIDBDatabaseMetadata(std::function<void(bool, const WebCore::IDBDatabaseMetadata&)> completionCallback)
+{
+    // FIXME: This method is successfully called by messaging from the WebProcess, and calls back with dummy data.
+    // Needs real implementation.
+
+    IDBDatabaseMetadata metadata;
+    completionCallback(false, metadata);
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
diff --git a/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.h b/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.h
new file mode 100644 (file)
index 0000000..7b9bfde
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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 UniqueIDBDatabase_h
+#define UniqueIDBDatabase_h
+
+#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
+
+#include "UniqueIDBDatabaseIdentifier.h"
+#include <functional>
+#include <wtf/HashSet.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+struct IDBDatabaseMetadata;
+}
+
+namespace WebKit {
+
+class DatabaseProcessIDBConnection;
+
+struct SecurityOriginData;
+
+class UniqueIDBDatabase : public RefCounted<UniqueIDBDatabase> {
+public:
+    static PassRefPtr<UniqueIDBDatabase> create(const UniqueIDBDatabaseIdentifier& identifier)
+    {
+        return adoptRef(new UniqueIDBDatabase(identifier));
+    }
+
+    ~UniqueIDBDatabase();
+
+    const UniqueIDBDatabaseIdentifier& identifier() const { return m_identifier; }
+
+    void registerConnection(DatabaseProcessIDBConnection&);
+    void unregisterConnection(DatabaseProcessIDBConnection&);
+
+    void getIDBDatabaseMetadata(std::function<void(bool, const WebCore::IDBDatabaseMetadata&)> completionCallback);
+
+private:
+    UniqueIDBDatabase(const UniqueIDBDatabaseIdentifier&);
+
+    UniqueIDBDatabaseIdentifier m_identifier;
+
+    HashSet<RefPtr<DatabaseProcessIDBConnection>> m_connections;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
+#endif // UniqueIDBDatabase_h
diff --git a/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.cpp b/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.cpp
new file mode 100644 (file)
index 0000000..ff8bd7e
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * 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 "UniqueIDBDatabaseIdentifier.h"
+
+#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
+
+#include <wtf/text/StringBuilder.h>
+
+namespace WebKit {
+
+UniqueIDBDatabaseIdentifier::UniqueIDBDatabaseIdentifier()
+{
+}
+
+UniqueIDBDatabaseIdentifier::UniqueIDBDatabaseIdentifier(const String& databaseName, const SecurityOriginData& openingOrigin, const SecurityOriginData& mainFrameOrigin)
+    : m_databaseName(databaseName)
+    , m_openingOrigin(openingOrigin)
+    , m_mainFrameOrigin(mainFrameOrigin)
+{
+    // While it is valid to have an empty database name, it is not valid to have a null one.
+    ASSERT(!m_databaseName.isNull());
+}
+
+UniqueIDBDatabaseIdentifier::UniqueIDBDatabaseIdentifier(WTF::HashTableDeletedValueType)
+    : m_databaseName(WTF::HashTableDeletedValue)
+{
+}
+
+bool UniqueIDBDatabaseIdentifier::isHashTableDeletedValue() const
+{
+    return m_databaseName.isHashTableDeletedValue();
+}
+
+unsigned UniqueIDBDatabaseIdentifier::hash() const
+{
+    unsigned hashCodes[7] = {
+        m_databaseName.impl() ? m_databaseName.impl()->hash() : 0,
+        m_openingOrigin.protocol.impl() ? m_openingOrigin.protocol.impl()->hash() : 0,
+        m_openingOrigin.host.impl() ? m_openingOrigin.host.impl()->hash() : 0,
+        static_cast<unsigned>(m_openingOrigin.port),
+        m_mainFrameOrigin.protocol.impl() ? m_mainFrameOrigin.protocol.impl()->hash() : 0,
+        m_mainFrameOrigin.host.impl() ? m_mainFrameOrigin.host.impl()->hash() : 0,
+        static_cast<unsigned>(m_mainFrameOrigin.port)
+    };
+    return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
+}
+
+bool UniqueIDBDatabaseIdentifier::isNull() const
+{
+    // Only a default constructed UniqueIDBDatabaseIdentifier can have a null database name.
+    return m_databaseName.isNull();
+}
+
+bool operator==(const UniqueIDBDatabaseIdentifier& a, const UniqueIDBDatabaseIdentifier& b)
+{
+    if (&a == &b)
+        return true;
+
+    return a.databaseName() == b.databaseName()
+        && a.openingOrigin() == b.openingOrigin()
+        && a.mainFrameOrigin() == b.mainFrameOrigin();
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
diff --git a/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.h b/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseIdentifier.h
new file mode 100644 (file)
index 0000000..bebcdc4
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * 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 UniqueIDBDatabaseIdentifier_h
+#define UniqueIDBDatabaseIdentifier_h
+
+#if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
+
+#include "SecurityOriginData.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+class UniqueIDBDatabaseIdentifier {
+public:
+    UniqueIDBDatabaseIdentifier();
+    UniqueIDBDatabaseIdentifier(const String& databaseName, const SecurityOriginData& openingOrigin, const SecurityOriginData& mainFrameOrigin);
+
+    bool isNull() const;
+
+    const String& databaseName() const { return m_databaseName; }
+    const SecurityOriginData& openingOrigin() const { return m_openingOrigin; }
+    const SecurityOriginData& mainFrameOrigin() const { return m_mainFrameOrigin; }
+
+    UniqueIDBDatabaseIdentifier(WTF::HashTableDeletedValueType);
+    bool isHashTableDeletedValue() const;
+    unsigned hash() const;
+
+private:
+    String m_databaseName;
+    SecurityOriginData m_openingOrigin;
+    SecurityOriginData m_mainFrameOrigin;
+};
+
+bool operator==(const UniqueIDBDatabaseIdentifier&, const UniqueIDBDatabaseIdentifier&);
+
+struct UniqueIDBDatabaseIdentifierHash {
+    static unsigned hash(const UniqueIDBDatabaseIdentifier& identifier) { return identifier.hash(); }
+    static bool equal(const UniqueIDBDatabaseIdentifier& a, const UniqueIDBDatabaseIdentifier& b) { return a == b; }
+    static const bool safeToCompareToEmptyOrDeleted = false;
+};
+
+struct UniqueIDBDatabaseIdentifierHashTraits : WTF::SimpleClassHashTraits<UniqueIDBDatabaseIdentifier> {
+    static const bool hasIsEmptyValueFunction = true;
+    static bool isEmptyValue(const UniqueIDBDatabaseIdentifier& info) { return info.isNull(); }
+};
+
+} // namespace WebKit
+
+namespace WTF {
+
+template<> struct HashTraits<WebKit::UniqueIDBDatabaseIdentifier> : WebKit::UniqueIDBDatabaseIdentifierHashTraits { };
+template<> struct DefaultHash<WebKit::UniqueIDBDatabaseIdentifier> {
+    typedef WebKit::UniqueIDBDatabaseIdentifierHash Hash;
+};
+
+} // namespaec WTF
+
+#endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
+#endif // UniqueIDBDatabaseIdentifier_h
index fd71880..daac6fb 100644 (file)
@@ -89,4 +89,14 @@ void performAPICallbackWithSecurityOriginDataVector(const Vector<SecurityOriginD
     callback->performCallbackWithReturnValue(API::Array::create(std::move(securityOrigins)).get());
 }
 
+bool operator==(const SecurityOriginData& a, const SecurityOriginData& b)
+{
+    if (&a == &b)
+        return true;
+
+    return a.protocol == b.protocol
+        && a.host == b.host
+        && a.port == b.port;
+}
+
 } // namespace WebKit
index f16a02b..c3f87a0 100644 (file)
@@ -56,6 +56,8 @@ struct SecurityOriginData {
 
 void performAPICallbackWithSecurityOriginDataVector(const Vector<SecurityOriginData>&, ArrayCallback*);
 
+bool operator==(const SecurityOriginData&, const SecurityOriginData&);
+
 } // namespace WebKit
 
 #endif // SecurityOriginData_h
index a66086c..58eec1d 100644 (file)
                515E7728183DD6F60007203F /* AsyncRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 515E7726183DD6F60007203F /* AsyncRequest.h */; };
                515E772B184008B90007203F /* DatabaseProcessCreationParameters.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515E7729184008B90007203F /* DatabaseProcessCreationParameters.cpp */; };
                515E772C184008B90007203F /* DatabaseProcessCreationParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 515E772A184008B90007203F /* DatabaseProcessCreationParameters.h */; };
+               515E772F184015800007203F /* UniqueIDBDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515E772D184015800007203F /* UniqueIDBDatabase.cpp */; };
+               515E7730184015800007203F /* UniqueIDBDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 515E772E184015800007203F /* UniqueIDBDatabase.h */; };
+               515E773318402D510007203F /* UniqueIDBDatabaseIdentifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515E773118402D510007203F /* UniqueIDBDatabaseIdentifier.cpp */; };
+               515E773418402D510007203F /* UniqueIDBDatabaseIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 515E773218402D510007203F /* UniqueIDBDatabaseIdentifier.h */; };
                5160BFE113381DF900918999 /* Logging.mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5160BFE013381DF900918999 /* Logging.mac.mm */; };
                516319921628980A00E22F00 /* NetworkProcessProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 516319911628980A00E22F00 /* NetworkProcessProxyMac.mm */; };
                5163199416289A6000E22F00 /* NetworkProcessMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51ACC9341628064800342550 /* NetworkProcessMessageReceiver.cpp */; };
                515E7726183DD6F60007203F /* AsyncRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncRequest.h; sourceTree = "<group>"; };
                515E7729184008B90007203F /* DatabaseProcessCreationParameters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DatabaseProcessCreationParameters.cpp; sourceTree = "<group>"; };
                515E772A184008B90007203F /* DatabaseProcessCreationParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DatabaseProcessCreationParameters.h; sourceTree = "<group>"; };
+               515E772D184015800007203F /* UniqueIDBDatabase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UniqueIDBDatabase.cpp; sourceTree = "<group>"; };
+               515E772E184015800007203F /* UniqueIDBDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UniqueIDBDatabase.h; sourceTree = "<group>"; };
+               515E773118402D510007203F /* UniqueIDBDatabaseIdentifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UniqueIDBDatabaseIdentifier.cpp; sourceTree = "<group>"; };
+               515E773218402D510007203F /* UniqueIDBDatabaseIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UniqueIDBDatabaseIdentifier.h; sourceTree = "<group>"; };
                5160BFE013381DF900918999 /* Logging.mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Logging.mac.mm; sourceTree = "<group>"; };
                516319911628980A00E22F00 /* NetworkProcessProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = NetworkProcessProxyMac.mm; path = mac/NetworkProcessProxyMac.mm; sourceTree = "<group>"; };
                5167EE9E170377BF007681CA /* DiskCacheMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiskCacheMonitor.h; sourceTree = "<group>"; };
                                51D0D42E183B34130097041D /* DatabaseProcessIDBConnection.cpp */,
                                51D0D42F183B34130097041D /* DatabaseProcessIDBConnection.h */,
                                51D0D430183B34130097041D /* DatabaseProcessIDBConnection.messages.in */,
+                               515E772D184015800007203F /* UniqueIDBDatabase.cpp */,
+                               515E772E184015800007203F /* UniqueIDBDatabase.h */,
+                               515E773118402D510007203F /* UniqueIDBDatabaseIdentifier.cpp */,
+                               515E773218402D510007203F /* UniqueIDBDatabaseIdentifier.h */,
                        );
                        path = IndexedDB;
                        sourceTree = "<group>";
                                BC032DAB10F437D10058C15A /* Connection.h in Headers */,
                                5136183E163126DA00A99DDE /* ConnectionStack.h in Headers */,
                                CDC3830C17212282008A2FC3 /* CookieStorageShimLibrary.h in Headers */,
+                               515E7730184015800007203F /* UniqueIDBDatabase.h in Headers */,
                                B878B615133428DC006888E9 /* CorrectionPanel.h in Headers */,
                                2989A414167D184B004F96D2 /* CustomProtocolManager.h in Headers */,
                                865E0485181A094A001F72F2 /* ViewState.h in Headers */,
                                BC72B9FB11E6476B001EB4EA /* WebBackForwardListProxy.h in Headers */,
                                BCF50728124329AA005955AE /* WebCertificateInfo.h in Headers */,
                                BC032D7510F4378D0058C15A /* WebChromeClient.h in Headers */,
+                               515E773418402D510007203F /* UniqueIDBDatabaseIdentifier.h in Headers */,
                                3F87B9BE158940190090FF62 /* WebColorChooser.h in Headers */,
                                3F87B9C0158940D80090FF62 /* WebColorPicker.h in Headers */,
                                BC4A6290147312BE006C681A /* WebConnection.h in Headers */,
                                BC032DAA10F437D10058C15A /* Connection.cpp in Sources */,
                                1A30EAC6115D7DA30053E937 /* ConnectionMac.cpp in Sources */,
                                5136183D163126DA00A99DDE /* ConnectionStack.cpp in Sources */,
+                               515E773318402D510007203F /* UniqueIDBDatabaseIdentifier.cpp in Sources */,
                                2DA049B7180CCD0A00AAFA9E /* GraphicsLayerCARemote.cpp in Sources */,
                                378E1A4D18208D700031007A /* WKNSURL.mm in Sources */,
+                               515E772F184015800007203F /* UniqueIDBDatabase.cpp in Sources */,
                                2DA049B3180CCCD300AAFA9E /* PlatformCALayerRemote.cpp in Sources */,
                                CDC3831017212440008A2FC3 /* CookieStorageShim.cpp in Sources */,
                                B878B616133428DC006888E9 /* CorrectionPanel.mm in Sources */,
index 2808d70..38ee9fe 100644 (file)
@@ -47,7 +47,7 @@ using namespace WebCore;
 
 namespace WebKit {
 
-typedef HashMap<String, RefPtr<IDBDatabaseBackend>> IDBDatabaseBackendMap;
+typedef HashMap<String, IDBDatabaseBackend*> IDBDatabaseBackendMap;
 
 static IDBDatabaseBackendMap& sharedDatabaseBackendMap()
 {
@@ -87,7 +87,7 @@ void WebIDBFactoryBackend::open(const String& databaseName, uint64_t version, in
     if (it == sharedDatabaseBackendMap().end()) {
         RefPtr<IDBServerConnection> serverConnection = WebIDBServerConnection::create(databaseName, openingOrigin, mainFrameOrigin);
         databaseBackend = IDBDatabaseBackend::create(databaseName, databaseIdentifier, this, *serverConnection);
-        sharedDatabaseBackendMap().set(databaseIdentifier, databaseBackend);
+        sharedDatabaseBackendMap().set(databaseIdentifier, databaseBackend.get());
     } else
         databaseBackend = it->value;
 
@@ -99,9 +99,9 @@ void WebIDBFactoryBackend::deleteDatabase(const String&, PassRefPtr<IDBCallbacks
     notImplemented();
 }
 
-void WebIDBFactoryBackend::removeIDBDatabaseBackend(const String&)
+void WebIDBFactoryBackend::removeIDBDatabaseBackend(const String& identifier)
 {
-    notImplemented();
+    sharedDatabaseBackendMap().remove(identifier);
 }
 
 } // namespace WebKit