Modern IDB: Have IDBServerOperations know whether they represent an open or delete...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Dec 2015 20:29:09 +0000 (20:29 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Dec 2015 20:29:09 +0000 (20:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=152351

Reviewed by NOBODY (OOPS!).

No new tests (Refactor, existing tests pass).

* Modules/indexeddb/IndexedDB.h:

* Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp:
(WebCore::IDBClient::IDBOpenDBRequest::createDeleteRequest):
(WebCore::IDBClient::IDBOpenDBRequest::createOpenRequest):
(WebCore::IDBClient::IDBOpenDBRequest::IDBOpenDBRequest):
* Modules/indexeddb/client/IDBOpenDBRequestImpl.h:

* Modules/indexeddb/client/IDBRequestImpl.h:
(WebCore::IDBClient::IDBRequest::requestType):

* Modules/indexeddb/server/IDBServerOperation.cpp:
(WebCore::IDBServer::IDBServerOperation::isOpenRequest):
(WebCore::IDBServer::IDBServerOperation::isDeleteRequest):
* Modules/indexeddb/server/IDBServerOperation.h:

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::maybeDeleteDatabase):
(WebCore::IDBServer::UniqueIDBDatabase::handleOpenDatabaseOperations):
(WebCore::IDBServer::UniqueIDBDatabase::startVersionChangeTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::notifyConnectionsOfVersionChangeForUpgrade):
(WebCore::IDBServer::UniqueIDBDatabase::operationAndTransactionTimerFired):
* Modules/indexeddb/server/UniqueIDBDatabase.h:

* Modules/indexeddb/shared/IDBRequestData.cpp:
(WebCore::IDBRequestData::IDBRequestData):
* Modules/indexeddb/shared/IDBRequestData.h:
(WebCore::IDBRequestData::isOpenRequest):
(WebCore::IDBRequestData::isDeleteRequest):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IndexedDB.h
Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.h
Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.h
Source/WebCore/Modules/indexeddb/server/IDBServerOperation.cpp
Source/WebCore/Modules/indexeddb/server/IDBServerOperation.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h
Source/WebCore/Modules/indexeddb/shared/IDBRequestData.cpp
Source/WebCore/Modules/indexeddb/shared/IDBRequestData.h

index b7285cc..e533360 100644 (file)
@@ -1,3 +1,42 @@
+2015-12-16  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Have IDBServerOperations know whether they represent an open or delete request.
+        https://bugs.webkit.org/show_bug.cgi?id=152351
+
+        Reviewed by Alex Christensen.
+
+        No new tests (Refactor, existing tests pass).
+
+        * Modules/indexeddb/IndexedDB.h:
+        
+        * Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp:
+        (WebCore::IDBClient::IDBOpenDBRequest::createDeleteRequest):
+        (WebCore::IDBClient::IDBOpenDBRequest::createOpenRequest):
+        (WebCore::IDBClient::IDBOpenDBRequest::IDBOpenDBRequest):
+        * Modules/indexeddb/client/IDBOpenDBRequestImpl.h:
+        
+        * Modules/indexeddb/client/IDBRequestImpl.h:
+        (WebCore::IDBClient::IDBRequest::requestType):
+        
+        * Modules/indexeddb/server/IDBServerOperation.cpp:
+        (WebCore::IDBServer::IDBServerOperation::isOpenRequest):
+        (WebCore::IDBServer::IDBServerOperation::isDeleteRequest):
+        * Modules/indexeddb/server/IDBServerOperation.h:
+        
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::maybeDeleteDatabase):
+        (WebCore::IDBServer::UniqueIDBDatabase::handleOpenDatabaseOperations):
+        (WebCore::IDBServer::UniqueIDBDatabase::startVersionChangeTransaction):
+        (WebCore::IDBServer::UniqueIDBDatabase::notifyConnectionsOfVersionChangeForUpgrade):
+        (WebCore::IDBServer::UniqueIDBDatabase::operationAndTransactionTimerFired):
+        * Modules/indexeddb/server/UniqueIDBDatabase.h:
+        
+        * Modules/indexeddb/shared/IDBRequestData.cpp:
+        (WebCore::IDBRequestData::IDBRequestData):
+        * Modules/indexeddb/shared/IDBRequestData.h:
+        (WebCore::IDBRequestData::isOpenRequest):
+        (WebCore::IDBRequestData::isDeleteRequest):
+
 2015-12-16  Alex Christensen  <achristensen@webkit.org>
 
         Build fix after r194156.
index 35aadb1..99c7250 100644 (file)
@@ -99,6 +99,12 @@ enum KeyType {
     Min,
 };
 
+enum class RequestType {
+    Open,
+    Delete,
+    Other,
+};
+
 } // namespace IndexedDB
 
 } // namespace WebCore
index e3e2ecd..bd1527c 100644 (file)
@@ -41,20 +41,21 @@ namespace IDBClient {
 Ref<IDBOpenDBRequest> IDBOpenDBRequest::createDeleteRequest(IDBConnectionToServer& connection, ScriptExecutionContext* context, const IDBDatabaseIdentifier& databaseIdentifier)
 {
     ASSERT(databaseIdentifier.isValid());
-    return adoptRef(*new IDBOpenDBRequest(connection, context, databaseIdentifier, 0));
+    return adoptRef(*new IDBOpenDBRequest(connection, context, databaseIdentifier, 0, IndexedDB::RequestType::Delete));
 }
 
 Ref<IDBOpenDBRequest> IDBOpenDBRequest::createOpenRequest(IDBConnectionToServer& connection, ScriptExecutionContext* context, const IDBDatabaseIdentifier& databaseIdentifier, uint64_t version)
 {
     ASSERT(databaseIdentifier.isValid());
-    return adoptRef(*new IDBOpenDBRequest(connection, context, databaseIdentifier, version));
+    return adoptRef(*new IDBOpenDBRequest(connection, context, databaseIdentifier, version, IndexedDB::RequestType::Open));
 }
     
-IDBOpenDBRequest::IDBOpenDBRequest(IDBConnectionToServer& connection, ScriptExecutionContext* context, const IDBDatabaseIdentifier& databaseIdentifier, uint64_t version)
+IDBOpenDBRequest::IDBOpenDBRequest(IDBConnectionToServer& connection, ScriptExecutionContext* context, const IDBDatabaseIdentifier& databaseIdentifier, uint64_t version, IndexedDB::RequestType requestType)
     : IDBRequest(connection, context)
     , m_databaseIdentifier(databaseIdentifier)
     , m_version(version)
 {
+    m_requestType = requestType;
 }
 
 IDBOpenDBRequest::~IDBOpenDBRequest()
index 4fcb7a6..daa9f6f 100644 (file)
@@ -58,7 +58,7 @@ public:
     void fireErrorAfterVersionChangeCompletion();
 
 private:
-    IDBOpenDBRequest(IDBConnectionToServer&, ScriptExecutionContext*, const IDBDatabaseIdentifier&, uint64_t version);
+    IDBOpenDBRequest(IDBConnectionToServer&, ScriptExecutionContext*, const IDBDatabaseIdentifier&, uint64_t version, IndexedDB::RequestType);
 
     void onError(const IDBResultData&);
     void onSuccess(const IDBResultData&);
index 8dfa3e5..7ddc3a0 100644 (file)
@@ -100,6 +100,8 @@ public:
     void setSource(IDBCursor&);
     void setVersionChangeTransaction(IDBTransaction&);
 
+    IndexedDB::RequestType requestType() const { return m_requestType; }
+
 protected:
     IDBRequest(IDBConnectionToServer&, ScriptExecutionContext*);
     IDBRequest(ScriptExecutionContext&, IDBObjectStore&, IDBTransaction&);
@@ -126,6 +128,7 @@ protected:
     bool m_shouldExposeTransactionToDOM { true };
     RefPtr<DOMError> m_domError;
     IDBError m_idbError;
+    IndexedDB::RequestType m_requestType = { IndexedDB::RequestType::Other };
 
 private:
     void onError();
index 681744a..0195e18 100644 (file)
@@ -44,6 +44,16 @@ IDBServerOperation::IDBServerOperation(IDBConnectionToClient& connection, const
 {
 }
 
+bool IDBServerOperation::isOpenRequest() const
+{
+    return m_requestData.isOpenRequest();
+}
+
+bool IDBServerOperation::isDeleteRequest() const
+{
+    return m_requestData.isDeleteRequest();
+}
+
 } // namespace IDBServer
 } // namespace WebCore
 
index cfec06c..a9f9136 100644 (file)
@@ -43,6 +43,9 @@ public:
     IDBConnectionToClient& connection() { return m_connection; }
     const IDBRequestData& requestData() const { return m_requestData; }
 
+    bool isOpenRequest() const;
+    bool isDeleteRequest() const;
+
 private:
     IDBServerOperation(IDBConnectionToClient&, const IDBRequestData&);
 
index ddd715a..a510e2c 100644 (file)
@@ -109,6 +109,7 @@ bool UniqueIDBDatabase::maybeDeleteDatabase(IDBServerOperation* newestDeleteOper
 
     for (auto& operation : m_pendingDeleteDatabaseOperations) {
         ASSERT(m_databaseInfo);
+        ASSERT(operation->isDeleteRequest());
         operation->connection().didDeleteDatabase(IDBResultData::deleteDatabaseSuccess(operation->requestData().requestIdentifier(), *m_databaseInfo));
     }
 
@@ -158,10 +159,10 @@ void UniqueIDBDatabase::handleOpenDatabaseOperations()
         return;
     }
 
-    ASSERT(!m_versionChangeOperation);
+    ASSERT(!m_currentOperation);
     ASSERT(!m_versionChangeDatabaseConnection);
 
-    m_versionChangeOperation = adoptRef(operation.leakRef());
+    m_currentOperation = WTF::move(operation);
     m_versionChangeDatabaseConnection = rawConnection;
 
     // 3.3.7 "versionchange" transaction steps
@@ -175,7 +176,7 @@ void UniqueIDBDatabase::handleOpenDatabaseOperations()
     notifyConnectionsOfVersionChangeForUpgrade();
 
     // And we notify this OpenDBRequest that it is blocked until those connections close.
-    m_versionChangeDatabaseConnection->connectionToClient().notifyOpenDBRequestBlocked(m_versionChangeOperation->requestData().requestIdentifier(), m_databaseInfo->version(), requestedVersion);
+    m_versionChangeDatabaseConnection->connectionToClient().notifyOpenDBRequestBlocked(m_currentOperation->requestData().requestIdentifier(), m_databaseInfo->version(), requestedVersion);
 }
 
 bool UniqueIDBDatabase::hasAnyOpenConnections() const
@@ -245,11 +246,11 @@ void UniqueIDBDatabase::startVersionChangeTransaction()
     LOG(IndexedDB, "(main) UniqueIDBDatabase::startVersionChangeTransaction");
 
     ASSERT(!m_versionChangeTransaction);
-    ASSERT(m_versionChangeOperation);
+    ASSERT(m_currentOperation);
+    ASSERT(m_currentOperation->isOpenRequest());
     ASSERT(m_versionChangeDatabaseConnection);
 
-    auto operation = m_versionChangeOperation;
-    m_versionChangeOperation = nullptr;
+    auto operation = WTF::move(m_currentOperation);
 
     uint64_t requestedVersion = operation->requestData().requestedVersion();
     if (!requestedVersion)
@@ -275,10 +276,11 @@ void UniqueIDBDatabase::beginTransactionInBackingStore(const IDBTransactionInfo&
 
 void UniqueIDBDatabase::notifyConnectionsOfVersionChangeForUpgrade()
 {
-    ASSERT(m_versionChangeOperation);
+    ASSERT(m_currentOperation);
+    ASSERT(m_currentOperation->isOpenRequest());
     ASSERT(m_versionChangeDatabaseConnection);
 
-    notifyConnectionsOfVersionChange(m_versionChangeOperation->requestData().requestedVersion());
+    notifyConnectionsOfVersionChange(m_currentOperation->requestData().requestedVersion());
 }
 
 void UniqueIDBDatabase::notifyConnectionsOfVersionChange(uint64_t requestedVersion)
@@ -921,7 +923,7 @@ void UniqueIDBDatabase::operationAndTransactionTimerFired()
 
     // If the database was not deleted in the previous step, try to run a transaction now.
     if (m_pendingTransactions.isEmpty()) {
-        if (!hasAnyOpenConnections() && m_versionChangeOperation) {
+        if (!hasAnyOpenConnections() && m_currentOperation) {
             startVersionChangeTransaction();
             return;
         }
index 5ffabe7..de85245 100644 (file)
@@ -173,11 +173,11 @@ private:
     
     Deque<Ref<IDBServerOperation>> m_pendingOpenDatabaseOperations;
     Deque<Ref<IDBServerOperation>> m_pendingDeleteDatabaseOperations;
+    RefPtr<IDBServerOperation> m_currentOperation;
 
     HashSet<RefPtr<UniqueIDBDatabaseConnection>> m_openDatabaseConnections;
     HashSet<RefPtr<UniqueIDBDatabaseConnection>> m_closePendingDatabaseConnections;
 
-    RefPtr<IDBServerOperation> m_versionChangeOperation;
     RefPtr<UniqueIDBDatabaseConnection> m_versionChangeDatabaseConnection;
     UniqueIDBDatabaseTransaction* m_versionChangeTransaction { nullptr };
 
index c05b5b3..c11217d 100644 (file)
@@ -38,6 +38,7 @@ IDBRequestData::IDBRequestData(const IDBClient::IDBConnectionToServer& connectio
     , m_requestIdentifier(std::make_unique<IDBResourceIdentifier>(connection, request))
     , m_databaseIdentifier(request.databaseIdentifier())
     , m_requestedVersion(request.version())
+    , m_requestType(request.requestType())
 {
 }
 
@@ -62,6 +63,7 @@ IDBRequestData::IDBRequestData(const IDBRequestData& other)
     , m_indexRecordType(other.m_indexRecordType)
     , m_databaseIdentifier(other.m_databaseIdentifier)
     , m_requestedVersion(other.m_requestedVersion)
+    , m_requestType(other.m_requestType)
 {
     if (other.m_requestIdentifier)
         m_requestIdentifier = std::make_unique<IDBResourceIdentifier>(*other.m_requestIdentifier);
index a2e6546..3e1312c 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "IDBDatabaseIdentifier.h"
 #include "IDBResourceIdentifier.h"
+#include "IndexedDB.h"
 
 namespace WebCore {
 
@@ -61,6 +62,9 @@ public:
     const IDBDatabaseIdentifier& databaseIdentifier() const { return m_databaseIdentifier; }
     uint64_t requestedVersion() const;
 
+    bool isOpenRequest() const { return m_requestType == IndexedDB::RequestType::Open; }
+    bool isDeleteRequest() const { return m_requestType == IndexedDB::RequestType::Delete; }
+
     IDBRequestData isolatedCopy();
 
 private:
@@ -74,6 +78,8 @@ private:
 
     IDBDatabaseIdentifier m_databaseIdentifier;
     uint64_t m_requestedVersion { 0 };
+
+    IndexedDB::RequestType m_requestType { IndexedDB::RequestType::Other };
 };
 
 } // namespace WebCore