IDB: Add no-op plumbing for deleteDatabase and deleteRange
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jan 2014 17:49:42 +0000 (17:49 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jan 2014 17:49:42 +0000 (17:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=127912

Reviewed by Alexey Proskuryakov.

Forward the calls to the DatabaseProcess, and handle completion from the DatabaseProcess:
* WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp:
(WebKit::WebIDBServerConnection::deleteDatabase):
(WebKit::WebIDBServerConnection::didDeleteDatabase):
(WebKit::WebIDBServerConnection::deleteRange):
(WebKit::WebIDBServerConnection::didDeleteRange):
* WebProcess/Databases/IndexedDB/WebIDBServerConnection.h:
* WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in:

Stub out deleteDatabase, and forward deleteRange to the appropriate UniqueIDBDatabase:
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
(WebKit::DatabaseProcessIDBConnection::deleteDatabase):
(WebKit::DatabaseProcessIDBConnection::deleteRange):
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:
* DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.messages.in:

Forward the request to the backing store thread, and handle the response from that thread:
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
(WebKit::UniqueIDBDatabase::deleteRange):
(WebKit::UniqueIDBDatabase::deleteRangeInBackingStore):
(WebKit::UniqueIDBDatabase::didDeleteRangeInBackingStore):
* DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h
Source/WebKit2/DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.messages.in
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.h
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.h
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in

index 6d89dbb..51bc25b 100644 (file)
@@ -1,3 +1,33 @@
+2014-01-30  Brady Eidson  <beidson@apple.com>
+
+        IDB: Add no-op plumbing for deleteDatabase and deleteRange
+        https://bugs.webkit.org/show_bug.cgi?id=127912
+
+        Reviewed by Alexey Proskuryakov.
+
+        Forward the calls to the DatabaseProcess, and handle completion from the DatabaseProcess:
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.cpp:
+        (WebKit::WebIDBServerConnection::deleteDatabase):
+        (WebKit::WebIDBServerConnection::didDeleteDatabase):
+        (WebKit::WebIDBServerConnection::deleteRange):
+        (WebKit::WebIDBServerConnection::didDeleteRange):
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.h:
+        * WebProcess/Databases/IndexedDB/WebIDBServerConnection.messages.in:
+
+        Stub out deleteDatabase, and forward deleteRange to the appropriate UniqueIDBDatabase:
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.cpp:
+        (WebKit::DatabaseProcessIDBConnection::deleteDatabase):
+        (WebKit::DatabaseProcessIDBConnection::deleteRange):
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.h:
+        * DatabaseProcess/IndexedDB/DatabaseProcessIDBConnection.messages.in:
+
+        Forward the request to the backing store thread, and handle the response from that thread:
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
+        (WebKit::UniqueIDBDatabase::deleteRange):
+        (WebKit::UniqueIDBDatabase::deleteRangeInBackingStore):
+        (WebKit::UniqueIDBDatabase::didDeleteRangeInBackingStore):
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.h:
+
 2014-01-30  Antti Koivisto  <antti@apple.com>
 
         WebPage::determinePrimarySnapshottedPlugIn is slow
index c0def58..260f18c 100644 (file)
@@ -79,6 +79,14 @@ void DatabaseProcessIDBConnection::getOrEstablishIDBDatabaseMetadata(uint64_t re
     });
 }
 
+void DatabaseProcessIDBConnection::deleteDatabase(uint64_t requestID, const String& databaseName)
+{
+    LOG(IDB, "DatabaseProcess deleteDatabase request ID %llu", requestID);
+
+    // FIXME: Implement
+    send(Messages::WebIDBServerConnection::DidDeleteDatabase(requestID, false));
+}
+
 void DatabaseProcessIDBConnection::openTransaction(uint64_t requestID, int64_t transactionID, const Vector<int64_t>& objectStoreIDs, uint64_t intMode)
 {
     ASSERT(m_uniqueIDBDatabase);
@@ -157,7 +165,7 @@ void DatabaseProcessIDBConnection::changeDatabaseVersion(uint64_t requestID, int
     });
 }
 
-void DatabaseProcessIDBConnection::createObjectStore(uint64_t requestID, int64_t transactionID, WebCore::IDBObjectStoreMetadata metadata)
+void DatabaseProcessIDBConnection::createObjectStore(uint64_t requestID, int64_t transactionID, IDBObjectStoreMetadata metadata)
 {
     ASSERT(m_uniqueIDBDatabase);
 
@@ -190,7 +198,7 @@ void DatabaseProcessIDBConnection::clearObjectStore(uint64_t requestID, int64_t
     });
 }
 
-void DatabaseProcessIDBConnection::createIndex(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, const WebCore::IDBIndexMetadata& metadata)
+void DatabaseProcessIDBConnection::createIndex(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, const IDBIndexMetadata& metadata)
 {
     ASSERT(m_uniqueIDBDatabase);
 
@@ -212,7 +220,7 @@ void DatabaseProcessIDBConnection::deleteIndex(uint64_t requestID, int64_t trans
     });
 }
 
-void DatabaseProcessIDBConnection::putRecord(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, const WebCore::IDBKeyData& key, const IPC::DataReference& value, int64_t putMode, const Vector<int64_t>& indexIDs, const Vector<Vector<WebCore::IDBKeyData>>& indexKeys)
+void DatabaseProcessIDBConnection::putRecord(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, const IDBKeyData& key, const IPC::DataReference& value, int64_t putMode, const Vector<int64_t>& indexIDs, const Vector<Vector<IDBKeyData>>& indexKeys)
 {
     ASSERT(m_uniqueIDBDatabase);
 
@@ -246,7 +254,19 @@ void DatabaseProcessIDBConnection::count(uint64_t requestID, int64_t transaction
     });
 }
 
-void DatabaseProcessIDBConnection::openCursor(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, int64_t indexID, int64_t cursorDirection, int64_t cursorType, int64_t taskType, const WebCore::IDBKeyRangeData& keyRangeData)
+void DatabaseProcessIDBConnection::deleteRange(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, const IDBKeyRangeData& keyRangeData)
+{
+    ASSERT(m_uniqueIDBDatabase);
+
+    LOG(IDB, "DatabaseProcess deleteRange request ID %llu, object store id %lli", requestID, objectStoreID);
+
+    RefPtr<DatabaseProcessIDBConnection> connection(this);
+    m_uniqueIDBDatabase->deleteRange(IDBIdentifier(*this, transactionID), objectStoreID, keyRangeData, [connection, requestID](uint32_t errorCode, const String& errorMessage) {
+        connection->send(Messages::WebIDBServerConnection::DidDeleteRange(requestID, errorCode, errorMessage));
+    });
+}
+
+void DatabaseProcessIDBConnection::openCursor(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, int64_t indexID, int64_t cursorDirection, int64_t cursorType, int64_t taskType, const IDBKeyRangeData& keyRangeData)
 {
     ASSERT(m_uniqueIDBDatabase);
 
index 519b8d4..67a6078 100644 (file)
@@ -68,6 +68,7 @@ private:
     // Message handlers.
     void establishConnection(const String& databaseName, const SecurityOriginData& openingOrigin, const SecurityOriginData& mainFrameOrigin);
     void getOrEstablishIDBDatabaseMetadata(uint64_t requestID);
+    void deleteDatabase(uint64_t requestID, const String& databaseName);
     void openTransaction(uint64_t requestID, int64_t transactionID, const Vector<int64_t>& objectStoreIDs, uint64_t transactionMode);
     void beginTransaction(uint64_t requestID, int64_t transactionID);
     void commitTransaction(uint64_t requestID, int64_t transactionID);
@@ -87,6 +88,7 @@ private:
     void cursorIterate(uint64_t requestID, int64_t cursorID, const WebCore::IDBKeyData&);
 
     void count(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyRangeData&);
+    void deleteRange(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, const WebCore::IDBKeyRangeData& keyRange);
 
     Ref<DatabaseToWebProcessConnection> m_connection;
     uint64_t m_serverConnectionIdentifier;
index c5279a7..b5a5ab7 100644 (file)
@@ -25,6 +25,7 @@
 messages -> DatabaseProcessIDBConnection LegacyReceiver {
     EstablishConnection(String databaseName, WebKit::SecurityOriginData openingOrigin, WebKit::SecurityOriginData mainFrameOrigin)
     GetOrEstablishIDBDatabaseMetadata(uint64_t requestID)
+    DeleteDatabase(uint64_t requestID, String databaseName)
 
     OpenTransaction(uint64_t requestID, int64_t transactionID, Vector<int64_t> objectStoreIDs, uint64_t transactionMode)
     BeginTransaction(uint64_t requestID, int64_t transactionID)
@@ -47,6 +48,7 @@ messages -> DatabaseProcessIDBConnection LegacyReceiver {
     CursorIterate(uint64_t requestID, int64_t cursorID, WebCore::IDBKeyData key)
     
     Count(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, int64_t indexID, WebCore::IDBKeyRangeData keyRange)
+    DeleteRange(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, WebCore::IDBKeyRangeData keyRange)
 }
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
index 5790a7f..8f336c1 100644 (file)
@@ -636,6 +636,27 @@ void UniqueIDBDatabase::count(const IDBIdentifier& transactionIdentifier, int64_
     postDatabaseTask(createAsyncTask(*this, &UniqueIDBDatabase::countInBackingStore, requestID, transactionIdentifier, objectStoreID, indexID, keyRangeData));
 }
 
+void UniqueIDBDatabase::deleteRange(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const IDBKeyRangeData& keyRangeData, std::function<void(uint32_t, const String&)> callback)
+{
+    ASSERT(isMainThread());
+
+    if (!m_acceptingNewRequests) {
+        callback(INVALID_STATE_ERR, "Unable to deleteRange from database because it has shut down");
+        return;
+    }
+
+    RefPtr<AsyncRequest> request = AsyncRequestImpl<uint32_t, const String&>::create([callback](uint32_t errorCode, const String& errorMessage) {
+        callback(errorCode, errorMessage);
+    }, [callback]() {
+        callback(INVALID_STATE_ERR, "Unable to deleteRange from database");
+    });
+
+    uint64_t requestID = request->requestID();
+    m_pendingDatabaseTasks.add(requestID, request.release());
+
+    postDatabaseTask(createAsyncTask(*this, &UniqueIDBDatabase::deleteRangeInBackingStore, requestID, transactionIdentifier, objectStoreID, keyRangeData));
+}
+
 void UniqueIDBDatabase::openBackingStoreTransaction(const IDBIdentifier& transactionIdentifier, const Vector<int64_t>& objectStoreIDs, IndexedDB::TransactionMode mode)
 {
     ASSERT(!isMainThread());
@@ -916,6 +937,21 @@ void UniqueIDBDatabase::didCountInBackingStore(uint64_t requestID, int64_t count
     request->completeRequest(count, errorCode, errorMessage);
 }
 
+void UniqueIDBDatabase::deleteRangeInBackingStore(uint64_t requestID, const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const IDBKeyRangeData&)
+{
+    // FIXME: Implement
+
+    postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didDeleteRangeInBackingStore, requestID, IDBDatabaseException::UnknownError, ASCIILiteral("deleteRange in backing store not supported yet")));
+}
+
+void UniqueIDBDatabase::didDeleteRangeInBackingStore(uint64_t requestID, uint32_t errorCode, const String& errorMessage)
+{
+    RefPtr<AsyncRequest> request = m_pendingDatabaseTasks.take(requestID);
+    ASSERT(request);
+
+    request->completeRequest(errorCode, errorMessage);
+}
+
 String UniqueIDBDatabase::absoluteDatabaseDirectory() const
 {
     ASSERT(isMainThread());
index 7db995c..1f3aa4c 100644 (file)
@@ -92,6 +92,7 @@ public:
     void cursorIterate(const IDBIdentifier& cursorIdentifier, const WebCore::IDBKeyData&, std::function<void(WebCore::IDBKeyData, WebCore::IDBKeyData, PassRefPtr<WebCore::SharedBuffer>, uint32_t, const String&)> callback);
 
     void count(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyRangeData&, std::function<void(int64_t, uint32_t, const String&)> callback);
+    void deleteRange(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyRangeData&, std::function<void(uint32_t, const String&)> callback);
 
 private:
     UniqueIDBDatabase(const UniqueIDBDatabaseIdentifier&);
@@ -142,6 +143,7 @@ private:
     void advanceCursorInBackingStore(uint64_t requestID, const IDBIdentifier& cursorIdentifier, uint64_t count);
     void iterateCursorInBackingStore(uint64_t requestID, const IDBIdentifier& cursorIdentifier, const WebCore::IDBKeyData&);
     void countInBackingStore(uint64_t requestID, const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyRangeData&);
+    void deleteRangeInBackingStore(uint64_t requestID, const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyRangeData&);
 
     void shutdownBackingStore();
 
@@ -161,6 +163,7 @@ private:
     void didAdvanceCursorInBackingStore(uint64_t requestID, const WebCore::IDBKeyData&, const WebCore::IDBKeyData&, const Vector<char>&, uint32_t errorCode, const String& errorMessage);
     void didIterateCursorInBackingStore(uint64_t requestID, const WebCore::IDBKeyData&, const WebCore::IDBKeyData&, const Vector<char>&, uint32_t errorCode, const String& errorMessage);
     void didCountInBackingStore(uint64_t requestID, int64_t count, uint32_t errorCode, const String& errorMessage);
+    void didDeleteRangeInBackingStore(uint64_t requestID, uint32_t errorCode, const String& errorMessage);
 
     void didShutdownBackingStore();
     void didCompleteBoolRequest(uint64_t requestID, bool success);
index ada805a..89c5465 100644 (file)
@@ -85,6 +85,31 @@ bool WebIDBServerConnection::isClosed()
 
 void WebIDBServerConnection::deleteDatabase(const String& name, 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());
+
+    LOG(IDB, "WebProcess deleteDatabase request ID %llu", requestID);
+
+    send(Messages::DatabaseProcessIDBConnection::DeleteDatabase(requestID, name));
+}
+
+void WebIDBServerConnection::didDeleteDatabase(uint64_t requestID, bool success)
+{
+    LOG(IDB, "WebProcess didDeleteDatabase request ID %llu", requestID);
+
+    RefPtr<AsyncRequest> serverRequest = m_serverRequests.take(requestID);
+
+    if (!serverRequest)
+        return;
+
+    serverRequest->completeRequest(success);
 }
 
 void WebIDBServerConnection::getOrEstablishIDBDatabaseMetadata(GetIDBDatabaseMetadataFunction completionCallback)
@@ -486,8 +511,33 @@ void WebIDBServerConnection::didCount(uint64_t requestID, int64_t count, uint32_
     serverRequest->completeRequest(count, errorCode ? IDBDatabaseError::create(errorCode, errorMessage) : nullptr);
 }
 
-void WebIDBServerConnection::deleteRange(IDBTransactionBackend&, const DeleteRangeOperation&, std::function<void(PassRefPtr<IDBDatabaseError>)> completionCallback)
+void WebIDBServerConnection::deleteRange(IDBTransactionBackend& transaction, const DeleteRangeOperation& operation, std::function<void(PassRefPtr<IDBDatabaseError>)> completionCallback)
+{
+    RefPtr<AsyncRequest> serverRequest = AsyncRequestImpl<PassRefPtr<IDBDatabaseError>>::create(completionCallback);
+
+    serverRequest->setAbortHandler([completionCallback]() {
+        completionCallback(IDBDatabaseError::create(IDBDatabaseException::UnknownError, "Unknown error occured getting count"));
+    });
+
+    uint64_t requestID = serverRequest->requestID();
+    ASSERT(!m_serverRequests.contains(requestID));
+    m_serverRequests.add(requestID, serverRequest.release());
+
+    LOG(IDB, "WebProcess deleteRange request ID %llu", requestID);
+
+    send(Messages::DatabaseProcessIDBConnection::DeleteRange(requestID, transaction.id(), operation.objectStoreID(), IDBKeyRangeData(operation.keyRange())));
+}
+
+void WebIDBServerConnection::didDeleteRange(uint64_t requestID, uint32_t errorCode, const String& errorMessage)
 {
+    LOG(IDB, "WebProcess didDeleteRange request ID %llu", requestID);
+
+    RefPtr<AsyncRequest> serverRequest = m_serverRequests.take(requestID);
+
+    if (!serverRequest)
+        return;
+
+    serverRequest->completeRequest(errorCode ? IDBDatabaseError::create(errorCode, errorMessage) : nullptr);
 }
 
 void WebIDBServerConnection::clearObjectStore(IDBTransactionBackend&, const ClearObjectStoreOperation& operation, std::function<void(PassRefPtr<IDBDatabaseError>)> completionCallback)
index 6bfadfb..f5e2096 100644 (file)
@@ -96,6 +96,7 @@ private:
     virtual IPC::Connection* messageSenderConnection() override;
 
     void didGetOrEstablishIDBDatabaseMetadata(uint64_t requestID, bool success, const WebCore::IDBDatabaseMetadata&);
+    void didDeleteDatabase(uint64_t requestID, bool success);
     void didOpenTransaction(uint64_t requestID, bool success);
     void didBeginTransaction(uint64_t requestID, bool success);
     void didCommitTransaction(uint64_t requestID, bool success);
@@ -113,6 +114,7 @@ private:
     void didAdvanceCursor(uint64_t requestID, WebCore::IDBKeyData&, WebCore::IDBKeyData&, const IPC::DataReference&, uint32_t errorCode, const String& errorMessage);
     void didIterateCursor(uint64_t requestID, WebCore::IDBKeyData&, WebCore::IDBKeyData&, const IPC::DataReference&, uint32_t errorCode, const String& errorMessage);
     void didCount(uint64_t requestID, int64_t count, uint32_t errorCode, const String& errorMessage);
+    void didDeleteRange(uint64_t requestID, uint32_t errorCode, const String& errorMessage);
 
     uint64_t m_serverConnectionIdentifier;
 
index 10a646b..9ff3d8b 100644 (file)
@@ -24,6 +24,7 @@
 
 messages -> WebIDBServerConnection LegacyReceiver {
     DidGetOrEstablishIDBDatabaseMetadata(uint64_t requestID, bool success, WebCore::IDBDatabaseMetadata metadata)
+    DidDeleteDatabase(uint64_t requestID, bool success)
 
     DidOpenTransaction(uint64_t requestID, bool success)
     DidBeginTransaction(uint64_t requestID, bool success)
@@ -43,6 +44,7 @@ messages -> WebIDBServerConnection LegacyReceiver {
     DidAdvanceCursor(uint64_t requestID, WebCore::IDBKeyData key, WebCore::IDBKeyData primaryKey, IPC::DataReference value, uint32_t errorCode, String errorMessage)
     DidIterateCursor(uint64_t requestID, WebCore::IDBKeyData key, WebCore::IDBKeyData primaryKey, IPC::DataReference value, uint32_t errorCode, String errorMessage)
     DidCount(uint64_t requestID, int64_t count, uint32_t errorCode, String errorMessage)
+    DidDeleteRange(uint64_t requestID, uint32_t errorCode, String errorMessage)
 }
 
 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)