Modern IDB: Support IDBDatabase.close().
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Oct 2015 17:18:57 +0000 (17:18 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Oct 2015 17:18:57 +0000 (17:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150150

Reviewed by Alex Christensen.

Source/WebCore:

No new tests (Covered by changes to storage/indexeddb/modern/opendatabase-versions.html).

* Modules/indexeddb/client/IDBConnectionToServer.cpp:
(WebCore::IDBClient::IDBConnectionToServer::databaseConnectionClosed):
* Modules/indexeddb/client/IDBConnectionToServer.h:
* Modules/indexeddb/client/IDBConnectionToServerDelegate.h:

* Modules/indexeddb/client/IDBDatabaseImpl.cpp:
(WebCore::IDBClient::IDBDatabase::IDBDatabase):
(WebCore::IDBClient::IDBDatabase::~IDBDatabase):
(WebCore::IDBClient::IDBDatabase::close):
(WebCore::IDBClient::IDBDatabase::maybeCloseInServer):
(WebCore::IDBClient::IDBDatabase::commitTransaction):
* Modules/indexeddb/client/IDBDatabaseImpl.h:
(WebCore::IDBClient::IDBDatabase::databaseConnectionIdentifier):

* Modules/indexeddb/client/IDBRequestImpl.cpp:
(WebCore::IDBClient::IDBRequest::result):

* Modules/indexeddb/server/IDBServer.cpp:
(WebCore::IDBServer::IDBServer::databaseConnectionClosed):
* Modules/indexeddb/server/IDBServer.h:

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::connectionClosedFromClient):
(WebCore::IDBServer::UniqueIDBDatabase::handleOpenDatabaseOperations): Deleted.
* Modules/indexeddb/server/UniqueIDBDatabase.h:

* Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp:
(WebCore::IDBServer::UniqueIDBDatabaseConnection::UniqueIDBDatabaseConnection):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::~UniqueIDBDatabaseConnection):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::hasNonFinishedTransactions):
(WebCore::IDBServer::UniqueIDBDatabaseConnection::connectionClosedFromClient):
* Modules/indexeddb/server/UniqueIDBDatabaseConnection.h:

* Modules/indexeddb/shared/InProcessIDBServer.cpp:
(WebCore::InProcessIDBServer::databaseConnectionClosed):
* Modules/indexeddb/shared/InProcessIDBServer.h:

LayoutTests:

* storage/indexeddb/modern/opendatabase-versions-expected.txt:
* storage/indexeddb/modern/opendatabase-versions.html:

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

21 files changed:
LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/modern/opendatabase-versions-expected.txt
LayoutTests/storage/indexeddb/modern/opendatabase-versions.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServerDelegate.h
Source/WebCore/Modules/indexeddb/client/IDBDatabaseImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBDatabaseImpl.h
Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.h
Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.h
Source/WebCore/Modules/indexeddb/server/IDBServer.cpp
Source/WebCore/Modules/indexeddb/server/IDBServer.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseConnection.h
Source/WebCore/Modules/indexeddb/shared/IDBError.cpp
Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp
Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h

index b3b7188..f08ccf6 100644 (file)
@@ -1,3 +1,13 @@
+2015-10-16  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Support IDBDatabase.close().
+        https://bugs.webkit.org/show_bug.cgi?id=150150
+
+        Reviewed by Alex Christensen.
+
+        * storage/indexeddb/modern/opendatabase-versions-expected.txt:
+        * storage/indexeddb/modern/opendatabase-versions.html:
+
 2015-10-16  Chris Dumez  <cdumez@apple.com>
 
         HTMLPreloadScanner should preload iframes
index ebcc163..09678f6 100644 (file)
@@ -4,6 +4,12 @@ ALERT: [object IDBTransaction]
 ALERT: Version change complete (firstPhase). Database version is now - 1
 ALERT: [object IDBOpenDBRequest] (secondPhase)
 ALERT: Successfully opened database at version 1 (secondPhase)
+ALERT: [object IDBOpenDBRequest] (thirdPhase)
+ALERT: upgradeneeded (thirdPhase): old version - 1 new version - 2
+ALERT: [object IDBTransaction]
+ALERT: Version change complete (thirdPhase). Database version is now - 2
+ALERT: [object IDBOpenDBRequest] (fourthPhase)
+ALERT: Expected error (fourthPhase) - VersionError
 ALERT: Done
 This test creates a new database with the default version, commits that versionchange transaction, and then reopens it at different versions to make sure the IDBOpenDBRequests behave appropriately.
 
index 7be934c..8c575c8 100644 (file)
@@ -34,6 +34,7 @@ request.onupgradeneeded = function(e)
     request.transaction.oncomplete = function()
     {
         alert("Version change complete (firstPhase). Database version is now - " + request.transaction.db.version);
+        request.transaction.db.close();
         secondPhase();
     }
     request.transaction.onabort = function()
@@ -55,10 +56,9 @@ function secondPhase()
     request.onsuccess = function()
     {
         alert("Successfully opened database at version 1 (secondPhase)");
-
-        // FIXME: The following call will be used once bugs 150147-150150 are resolved.
-        // thirdPhase();
-        done();
+        request.result.close();
+        request.result.close(); // Close it twice just for the heck of it
+        thirdPhase();
     }
     request.onerror = function(e)
     {
@@ -78,13 +78,13 @@ function thirdPhase()
     alert(request + " (thirdPhase)");
     request.onsuccess = function()
     {
-     alert("Unexpected success (thirdPhase)");
-     done();
+        alert("Unexpected success (thirdPhase)");
+        done();
     }
     request.onerror = function(e)
     {
-     alert("Unexpected error (thirdPhase)");
-     done();
+        alert("Unexpected error (thirdPhase)");
+        done();
     }
     request.onupgradeneeded = function(e)
     {
@@ -93,6 +93,7 @@ function thirdPhase()
         request.transaction.oncomplete = function()
         {
             alert("Version change complete (thirdPhase). Database version is now - " + request.transaction.db.version);
+            request.transaction.db.close();
             fourthPhase();
         }
         request.transaction.onabort = function()
@@ -110,13 +111,24 @@ function thirdPhase()
 
 function fourthPhase()
 {
-    try {
-        // We've upgraded to version 2, so version 1 should not be openable.
-        window.indexedDB.open("VersionTestDatabase", 1);
-    } catch (e) {
-        alert("Caught exception " + e);
+    // We've upgraded to version 2, so version 1 should not be openable.
+    var request = window.indexedDB.open("VersionTestDatabase", 1);
+    alert(request + " (fourthPhase)");
+    request.onsuccess = function()
+    {
+        alert("Unexpected success (fourthPhase)");
+        done();
     }
-    done();
+    request.onerror = function(e)
+    {
+        alert("Expected error (fourthPhase) - " + request.error.name);
+        done();
+    }
+    request.onupgradeneeded = function(e)
+    {
+        alert("Unexpected upgradeneeded (fourthPhase)");
+        done();
+    } 
 }
 
 </script>
index b9da594..769feff 100644 (file)
@@ -1,3 +1,49 @@
+2015-10-16  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Support IDBDatabase.close().
+        https://bugs.webkit.org/show_bug.cgi?id=150150
+
+        Reviewed by Alex Christensen.
+
+        No new tests (Covered by changes to storage/indexeddb/modern/opendatabase-versions.html).
+
+        * Modules/indexeddb/client/IDBConnectionToServer.cpp:
+        (WebCore::IDBClient::IDBConnectionToServer::databaseConnectionClosed):
+        * Modules/indexeddb/client/IDBConnectionToServer.h:
+        * Modules/indexeddb/client/IDBConnectionToServerDelegate.h:
+
+        * Modules/indexeddb/client/IDBDatabaseImpl.cpp:
+        (WebCore::IDBClient::IDBDatabase::IDBDatabase):
+        (WebCore::IDBClient::IDBDatabase::~IDBDatabase):
+        (WebCore::IDBClient::IDBDatabase::close):
+        (WebCore::IDBClient::IDBDatabase::maybeCloseInServer):
+        (WebCore::IDBClient::IDBDatabase::commitTransaction):
+        * Modules/indexeddb/client/IDBDatabaseImpl.h:
+        (WebCore::IDBClient::IDBDatabase::databaseConnectionIdentifier):
+
+        * Modules/indexeddb/client/IDBRequestImpl.cpp:
+        (WebCore::IDBClient::IDBRequest::result):
+
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::IDBServer::databaseConnectionClosed):
+        * Modules/indexeddb/server/IDBServer.h:
+
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::connectionClosedFromClient):
+        (WebCore::IDBServer::UniqueIDBDatabase::handleOpenDatabaseOperations): Deleted.
+        * Modules/indexeddb/server/UniqueIDBDatabase.h:
+
+        * Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::UniqueIDBDatabaseConnection):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::~UniqueIDBDatabaseConnection):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::hasNonFinishedTransactions):
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::connectionClosedFromClient):
+        * Modules/indexeddb/server/UniqueIDBDatabaseConnection.h:
+
+        * Modules/indexeddb/shared/InProcessIDBServer.cpp:
+        (WebCore::InProcessIDBServer::databaseConnectionClosed):
+        * Modules/indexeddb/shared/InProcessIDBServer.h:
+
 2015-10-16  Chris Dumez  <cdumez@apple.com>
 
         HTMLPreloadScanner should preload iframes
index 018fc0e..ddd0fff 100644 (file)
@@ -120,6 +120,13 @@ void IDBConnectionToServer::fireVersionChangeEvent(uint64_t /*databaseConnection
     // FIXME: Implement versionchange events firing on already-open transactions.
 }
 
+void IDBConnectionToServer::databaseConnectionClosed(IDBDatabase& database)
+{
+    LOG(IndexedDB, "IDBConnectionToServer::databaseConnectionClosed");
+
+    m_delegate->databaseConnectionClosed(database.databaseConnectionIdentifier());
+}
+
 void IDBConnectionToServer::registerDatabaseConnection(IDBDatabase& database)
 {
     ASSERT(!m_databaseConnections.contains(&database));
index 4468f98..41ad432 100644 (file)
@@ -63,6 +63,7 @@ public:
 
     void fireVersionChangeEvent(uint64_t databaseConnectionIdentifier, uint64_t requestedVersion);
 
+    void databaseConnectionClosed(IDBDatabase&);
     void registerDatabaseConnection(IDBDatabase&);
     void unregisterDatabaseConnection(IDBDatabase&);
 
index 6d2288e..5607bbb 100644 (file)
@@ -43,6 +43,7 @@ public:
     virtual void deleteDatabase(IDBRequestData&) = 0;
     virtual void openDatabase(IDBRequestData&) = 0;
     virtual void commitTransaction(IDBResourceIdentifier&) = 0;
+    virtual void databaseConnectionClosed(uint64_t databaseConnectionIdentifier) = 0;
 
     virtual void ref() = 0;
     virtual void deref() = 0;
index 6034b3f..7e7f548 100644 (file)
@@ -44,17 +44,18 @@ Ref<IDBDatabase> IDBDatabase::create(ScriptExecutionContext& context, IDBConnect
 
 IDBDatabase::IDBDatabase(ScriptExecutionContext& context, IDBConnectionToServer& connection, const IDBResultData& resultData)
     : WebCore::IDBDatabase(&context)
-    , m_connection(connection)
+    , m_serverConnection(connection)
     , m_info(resultData.databaseInfo())
+    , m_databaseConnectionIdentifier(resultData.databaseConnectionIdentifier())
 {
     suspendIfNeeded();
     relaxAdoptionRequirement();
-    m_connection->registerDatabaseConnection(*this);
+    m_serverConnection->registerDatabaseConnection(*this);
 }
 
 IDBDatabase::~IDBDatabase()
 {
-    m_connection->unregisterDatabaseConnection(*this);
+    m_serverConnection->unregisterDatabaseConnection(*this);
 }
 
 const String IDBDatabase::name() const
@@ -104,7 +105,23 @@ void IDBDatabase::deleteObjectStore(const String&, ExceptionCode&)
 
 void IDBDatabase::close()
 {
-    ASSERT_NOT_REACHED();
+    m_closePending = true;
+    maybeCloseInServer();
+}
+
+void IDBDatabase::maybeCloseInServer()
+{
+    if (m_closedInServer)
+        return;
+
+    // 3.3.9 Database closing steps
+    // Wait for all transactions created using this connection to complete.
+    // Once they are complete, this connection is closed.
+    if (!m_activeTransactions.isEmpty() || !m_committingTransactions.isEmpty())
+        return;
+
+    m_closedInServer = true;
+    m_serverConnection->databaseConnectionClosed(*this);
 }
 
 const char* IDBDatabase::activeDOMObjectName() const
@@ -142,7 +159,7 @@ void IDBDatabase::commitTransaction(IDBTransaction& transaction)
     ASSERT(refTransaction);
     m_committingTransactions.set(transaction.info().identifier(), WTF::move(refTransaction));
 
-    m_connection->commitTransaction(transaction);
+    m_serverConnection->commitTransaction(transaction);
 }
 
 void IDBDatabase::didCommitTransaction(IDBTransaction& transaction)
index fe31c2f..5ff67ac 100644 (file)
@@ -70,6 +70,7 @@ public:
     virtual bool canSuspendForPageCache() const override final;
 
     const IDBDatabaseInfo& info() const { return m_info; }
+    uint64_t databaseConnectionIdentifier() const { return m_databaseConnectionIdentifier; }
 
     Ref<IDBTransaction> startVersionChangeTransaction(const IDBTransactionInfo&);
     void commitTransaction(IDBTransaction&);
@@ -80,9 +81,15 @@ private:
     IDBDatabase(ScriptExecutionContext&, IDBConnectionToServer&, const IDBResultData&);
 
     void didCommitOrAbortTransaction(IDBTransaction&);
-    
-    Ref<IDBConnectionToServer> m_connection;
+
+    void maybeCloseInServer();
+
+    Ref<IDBConnectionToServer> m_serverConnection;
     IDBDatabaseInfo m_info;
+    uint64_t m_databaseConnectionIdentifier { 0 };
+
+    bool m_closePending { false };
+    bool m_closedInServer { false };
 
     RefPtr<IDBTransaction> m_versionChangeTransaction;
     HashMap<IDBResourceIdentifier, RefPtr<IDBTransaction>> m_activeTransactions;
index a06daeb..d5d6e3c 100644 (file)
@@ -45,7 +45,7 @@ public:
     static Ref<IDBOpenDBRequest> createDeleteRequest(IDBConnectionToServer&, ScriptExecutionContext*, const IDBDatabaseIdentifier&);
     static Ref<IDBOpenDBRequest> createOpenRequest(IDBConnectionToServer&, ScriptExecutionContext*, const IDBDatabaseIdentifier&, uint64_t version);
 
-    virtual ~IDBOpenDBRequest();
+    virtual ~IDBOpenDBRequest() override final;
     
     const IDBDatabaseIdentifier& databaseIdentifier() const { return m_databaseIdentifier; }
     uint64_t version() const { return m_version; }
@@ -61,7 +61,6 @@ private:
 
     IDBDatabaseIdentifier m_databaseIdentifier;
     uint64_t m_version { 0 };
-    RefPtr<DOMError> m_domError;
 };
 
 } // namespace IDBClient
index 664e082..b0f7947 100644 (file)
@@ -42,9 +42,13 @@ IDBRequest::IDBRequest(IDBConnectionToServer& connection, ScriptExecutionContext
 {
 }
 
+IDBRequest::~IDBRequest()
+{
+}
+
 RefPtr<WebCore::IDBAny> IDBRequest::result(ExceptionCode&) const
 {
-    return nullptr;
+    return m_result;
 }
 
 unsigned short IDBRequest::errorCode(ExceptionCode&) const
@@ -54,7 +58,7 @@ unsigned short IDBRequest::errorCode(ExceptionCode&) const
 
 RefPtr<DOMError> IDBRequest::error(ExceptionCode&) const
 {
-    return nullptr;
+    return m_domError;
 }
 
 RefPtr<WebCore::IDBAny> IDBRequest::source() const
index 331325d..d462411 100644 (file)
@@ -47,6 +47,8 @@ class IDBRequest : public WebCore::IDBOpenDBRequest, public RefCounted<IDBReques
 public:
     const IDBResourceIdentifier& resourceIdentifier() const { return m_resourceIdentifier; }
 
+    virtual ~IDBRequest() override;
+
     virtual RefPtr<WebCore::IDBAny> result(ExceptionCode&) const override;
     virtual unsigned short errorCode(ExceptionCode&) const override;
     virtual RefPtr<DOMError> error(ExceptionCode&) const override;
@@ -79,6 +81,7 @@ protected:
     IDBRequestReadyState m_readyState { IDBRequestReadyState::Pending };
     RefPtr<IDBAny> m_result;
     RefPtr<IDBTransaction> m_transaction;
+    RefPtr<DOMError> m_domError;
 
 private:
     IDBConnectionToServer& m_connection;
index 6e91285..45e16fe 100644 (file)
@@ -156,6 +156,17 @@ void IDBServer::commitTransaction(const IDBResourceIdentifier& transactionIdenti
     transaction->commit();
 }
 
+void IDBServer::databaseConnectionClosed(uint64_t databaseConnectionIdentifier)
+{
+    LOG(IndexedDB, "IDBServer::databaseConnectionClosed");
+
+    auto databaseConnection = m_databaseConnections.get(databaseConnectionIdentifier);
+    if (!databaseConnection)
+        return;
+
+    databaseConnection->connectionClosedFromClient();
+}
+
 void IDBServer::postDatabaseTask(std::unique_ptr<CrossThreadTask>&& task)
 {
     ASSERT(isMainThread());
index 00d71ae..f07e87d 100644 (file)
@@ -58,6 +58,7 @@ public:
     void openDatabase(const IDBRequestData&);
     void deleteDatabase(const IDBRequestData&);
     void commitTransaction(const IDBResourceIdentifier&);
+    void databaseConnectionClosed(uint64_t databaseConnectionIdentifier);
 
     void postDatabaseTask(std::unique_ptr<CrossThreadTask>&&);
     void postDatabaseTaskReply(std::unique_ptr<CrossThreadTask>&&);
index 9ff1c8e..a6c2f3d 100644 (file)
@@ -92,7 +92,6 @@ void UniqueIDBDatabase::handleOpenDatabaseOperations()
 
     Ref<UniqueIDBDatabaseConnection> connection = UniqueIDBDatabaseConnection::create(*this, operation->connection());
     UniqueIDBDatabaseConnection* rawConnection = &connection.get();
-    m_server.registerDatabaseConnection(*rawConnection);
 
     if (requestedVersion == m_databaseInfo->version()) {
         addOpenDatabaseConnection(WTF::move(connection));
@@ -251,6 +250,26 @@ void UniqueIDBDatabase::transactionDestroyed(UniqueIDBDatabaseTransaction& trans
         m_versionChangeTransaction = nullptr;
 }
 
+void UniqueIDBDatabase::connectionClosedFromClient(UniqueIDBDatabaseConnection& connection)
+{
+    ASSERT(isMainThread());
+    LOG(IndexedDB, "(main) UniqueIDBDatabase::connectionClosedFromClient");
+
+    if (m_versionChangeDatabaseConnection == &connection)
+        m_versionChangeDatabaseConnection = nullptr;
+
+    ASSERT(m_openDatabaseConnections.contains(&connection));
+
+    auto removedConnection = m_openDatabaseConnections.take(&connection);
+    if (removedConnection->hasNonFinishedTransactions()) {
+        m_closePendingDatabaseConnections.add(WTF::move(removedConnection));
+        return;
+    }
+
+    // FIXME: Now that a database connection has closed, previously blocked transactions might be runnable.
+    // Try to run them now.
+}
+
 void UniqueIDBDatabase::performErrorCallback(uint64_t callbackIdentifier, const IDBError& error)
 {
     auto callback = m_errorCallbacks.take(callbackIdentifier);
index ce68452..4dcf308 100644 (file)
@@ -65,6 +65,7 @@ public:
 
     void commitTransaction(UniqueIDBDatabaseTransaction&, ErrorCallback);
     void transactionDestroyed(UniqueIDBDatabaseTransaction&);
+    void connectionClosedFromClient(UniqueIDBDatabaseConnection&);
 
 private:
     UniqueIDBDatabase(IDBServer&, const IDBDatabaseIdentifier&);
@@ -94,6 +95,7 @@ private:
     Deque<Ref<IDBServerOperation>> m_pendingOpenDatabaseOperations;
 
     HashSet<RefPtr<UniqueIDBDatabaseConnection>> m_openDatabaseConnections;
+    HashSet<RefPtr<UniqueIDBDatabaseConnection>> m_closePendingDatabaseConnections;
 
     RefPtr<IDBServerOperation> m_versionChangeOperation;
     RefPtr<UniqueIDBDatabaseConnection> m_versionChangeDatabaseConnection;
index d7c4ac2..2b0bbc6 100644 (file)
 #if ENABLE(INDEXED_DATABASE)
 
 #include "IDBConnectionToClient.h"
+#include "IDBServer.h"
 #include "IDBTransactionInfo.h"
 #include "Logging.h"
+#include "UniqueIDBDatabase.h"
 
 namespace WebCore {
 namespace IDBServer {
@@ -51,6 +53,25 @@ UniqueIDBDatabaseConnection::UniqueIDBDatabaseConnection(UniqueIDBDatabase& data
     , m_database(database)
     , m_connectionToClient(connection)
 {
+    m_database.server().registerDatabaseConnection(*this);
+}
+
+UniqueIDBDatabaseConnection::~UniqueIDBDatabaseConnection()
+{
+    m_database.server().unregisterDatabaseConnection(*this);
+}
+
+bool UniqueIDBDatabaseConnection::hasNonFinishedTransactions() const
+{
+    return !m_transactionMap.isEmpty();
+}
+
+void UniqueIDBDatabaseConnection::connectionClosedFromClient()
+{
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::connectionClosedFromClient");
+
+    m_closePending = true;
+    m_database.connectionClosedFromClient(*this);
 }
 
 void UniqueIDBDatabaseConnection::fireVersionChangeEvent(uint64_t requestedVersion)
index 59850a8..6ee8e7f 100644 (file)
@@ -47,12 +47,18 @@ class UniqueIDBDatabaseConnection : public RefCounted<UniqueIDBDatabaseConnectio
 public:
     static Ref<UniqueIDBDatabaseConnection> create(UniqueIDBDatabase&, IDBConnectionToClient&);
 
+    ~UniqueIDBDatabaseConnection();
+
     uint64_t identifier() const { return m_identifier; }
     UniqueIDBDatabase& database() { return m_database; }
     IDBConnectionToClient& connectionToClient() { return m_connectionToClient; }
 
+    void connectionClosedFromClient();
+
     bool closePending() const { return m_closePending; }
 
+    bool hasNonFinishedTransactions() const;
+
     void fireVersionChangeEvent(uint64_t requestedVersion);
     UniqueIDBDatabaseTransaction& createVersionChangeTransaction(uint64_t newVersion);
 
index d993628..97333f6 100644 (file)
 
 namespace WebCore {
 
-static const std::pair<String, String>& idbExceptionEntry(IDBExceptionCode code)
+static const String& idbErrorName(IDBExceptionCode code)
 {
-    NeverDestroyed<Vector<std::pair<String, String>>> entries;
-    if (entries.get().isEmpty()) {
-        entries.get().append(std::make_pair<String, String>(
-            ASCIILiteral("UnknownError"),
-            ASCIILiteral("Operation failed for reasons unrelated to the database itself and not covered by any other errors.")));
+    switch (code) {
+    case IDBExceptionCode::Unknown: {
+        static NeverDestroyed<String> entry = ASCIILiteral("UnknownError");
+        return entry;
+    }
+    case IDBExceptionCode::VersionError: {
+        static NeverDestroyed<String> entry = ASCIILiteral("VersionError");
+        return entry;
+    }
+    case IDBExceptionCode::None:
+        RELEASE_ASSERT_NOT_REACHED();
+    }
+
+    RELEASE_ASSERT_NOT_REACHED();
+}
+
+static const String& idbErrorDescription(IDBExceptionCode code)
+{
+    switch (code) {
+    case IDBExceptionCode::Unknown: {
+        NeverDestroyed<String> entry = ASCIILiteral("Operation failed for reasons unrelated to the database itself and not covered by any other errors.");
+        return entry.get();
+    }
+    case IDBExceptionCode::VersionError: {
+        NeverDestroyed<String> entry = ASCIILiteral("An attempt was made to open a database using a lower version than the existing version.");
+        return entry.get();
+    }
+    case IDBExceptionCode::None:
+        RELEASE_ASSERT_NOT_REACHED();
     }
 
-    return entries.get()[(int)code - 1];
+    RELEASE_ASSERT_NOT_REACHED();
 }
 
 IDBError::IDBError(IDBExceptionCode code)
@@ -69,7 +93,7 @@ IDBError& IDBError::operator=(const IDBError& other)
 
 const String& IDBError::name() const
 {
-    return idbExceptionEntry(m_code).first;
+    return idbErrorName(m_code);
 }
 
 const String& IDBError::message() const
@@ -77,7 +101,7 @@ const String& IDBError::message() const
     if (!m_message.isEmpty())
         return m_message;
 
-    return idbExceptionEntry(m_code).second;
+    return idbErrorDescription(m_code);
 }
 
 } // namespace WebCore
index 080a186..7c2f9bf 100644 (file)
@@ -127,6 +127,14 @@ void InProcessIDBServer::fireVersionChangeEvent(IDBServer::UniqueIDBDatabaseConn
     });
 }
 
+void InProcessIDBServer::databaseConnectionClosed(uint64_t databaseConnectionIdentifier)
+{
+    RefPtr<InProcessIDBServer> self(this);
+    RunLoop::current().dispatch([this, self, databaseConnectionIdentifier] {
+        m_server->databaseConnectionClosed(databaseConnectionIdentifier);
+    });
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(INDEXED_DATABASE)
index 0f1c393..dc09451 100644 (file)
@@ -57,6 +57,7 @@ public:
     virtual void deleteDatabase(IDBRequestData&) override final;
     virtual void openDatabase(IDBRequestData&) override final;
     virtual void commitTransaction(IDBResourceIdentifier&) override final;
+    virtual void databaseConnectionClosed(uint64_t databaseConnectionIdentifier) override final;
 
     // IDBConnectionToClient
     virtual uint64_t identifier() const override;