Some WeakPtr cleanup
[WebKit-https.git] / Source / WebCore / Modules / indexeddb / shared / InProcessIDBServer.cpp
index 610c77f..87b1adc 100644 (file)
 
 #if ENABLE(INDEXED_DATABASE)
 
-#include "FileSystem.h"
 #include "IDBConnectionToClient.h"
 #include "IDBConnectionToServer.h"
 #include "IDBCursorInfo.h"
+#include "IDBGetRecordData.h"
+#include "IDBIterateCursorData.h"
 #include "IDBKeyRangeData.h"
 #include "IDBOpenDBRequest.h"
 #include "IDBRequestData.h"
 #include "IDBResultData.h"
 #include "IDBValue.h"
 #include "Logging.h"
+#include <wtf/FileSystem.h>
 #include <wtf/RunLoop.h>
 
 namespace WebCore {
 
-Ref<InProcessIDBServer> InProcessIDBServer::create()
+Ref<InProcessIDBServer> InProcessIDBServer::create(PAL::SessionID sessionID)
 {
-    Ref<InProcessIDBServer> server = adoptRef(*new InProcessIDBServer);
+    Ref<InProcessIDBServer> server = adoptRef(*new InProcessIDBServer(sessionID));
     server->m_server->registerConnection(server->connectionToClient());
     return server;
 }
 
-Ref<InProcessIDBServer> InProcessIDBServer::create(const String& databaseDirectoryPath)
+Ref<InProcessIDBServer> InProcessIDBServer::create(PAL::SessionID sessionID, const String& databaseDirectoryPath)
 {
-    Ref<InProcessIDBServer> server = adoptRef(*new InProcessIDBServer(databaseDirectoryPath));
+    Ref<InProcessIDBServer> server = adoptRef(*new InProcessIDBServer(sessionID, databaseDirectoryPath));
     server->m_server->registerConnection(server->connectionToClient());
     return server;
 }
 
-InProcessIDBServer::InProcessIDBServer()
-    : m_server(IDBServer::IDBServer::create(*this))
+StorageQuotaManager* InProcessIDBServer::quotaManager(const ClientOrigin& origin)
+{
+    return m_quotaManagers.ensure(origin, [] {
+        return std::make_unique<StorageQuotaManager>(StorageQuotaManager::defaultQuota(), [](uint64_t quota, uint64_t currentSpace, uint64_t spaceIncrease, auto callback) {
+            callback(quota + currentSpace + spaceIncrease);
+        });
+    }).iterator->value.get();
+}
+
+static inline IDBServer::IDBServer::QuotaManagerGetter storageQuotaManagerGetter(InProcessIDBServer& server)
+{
+    return [weakServer = makeWeakPtr(server)](PAL::SessionID, const auto& origin) {
+        return weakServer ? weakServer->quotaManager(origin) : nullptr;
+    };
+}
+
+InProcessIDBServer::InProcessIDBServer(PAL::SessionID sessionID)
+    : m_server(IDBServer::IDBServer::create(sessionID, *this, storageQuotaManagerGetter(*this)))
 {
     relaxAdoptionRequirement();
     m_connectionToServer = IDBClient::IDBConnectionToServer::create(*this);
     m_connectionToClient = IDBServer::IDBConnectionToClient::create(*this);
 }
 
-InProcessIDBServer::InProcessIDBServer(const String& databaseDirectoryPath)
-    : m_server(IDBServer::IDBServer::create(databaseDirectoryPath, *this))
+InProcessIDBServer::InProcessIDBServer(PAL::SessionID sessionID, const String& databaseDirectoryPath)
+    : m_server(IDBServer::IDBServer::create(sessionID, databaseDirectoryPath, *this, storageQuotaManagerGetter(*this)))
 {
     relaxAdoptionRequirement();
     m_connectionToServer = IDBClient::IDBConnectionToServer::create(*this);
@@ -145,6 +163,13 @@ void InProcessIDBServer::didDeleteObjectStore(const IDBResultData& resultData)
     });
 }
 
+void InProcessIDBServer::didRenameObjectStore(const IDBResultData& resultData)
+{
+    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+        m_connectionToServer->didRenameObjectStore(resultData);
+    });
+}
+
 void InProcessIDBServer::didClearObjectStore(const IDBResultData& resultData)
 {
     RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
@@ -166,6 +191,13 @@ void InProcessIDBServer::didDeleteIndex(const IDBResultData& resultData)
     });
 }
 
+void InProcessIDBServer::didRenameIndex(const IDBResultData& resultData)
+{
+    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+        m_connectionToServer->didRenameIndex(resultData);
+    });
+}
+
 void InProcessIDBServer::didPutOrAdd(const IDBResultData& resultData)
 {
     RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
@@ -180,6 +212,13 @@ void InProcessIDBServer::didGetRecord(const IDBResultData& resultData)
     });
 }
 
+void InProcessIDBServer::didGetAllRecords(const IDBResultData& resultData)
+{
+    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+        m_connectionToServer->didGetAllRecords(resultData);
+    });
+}
+
 void InProcessIDBServer::didGetCount(const IDBResultData& resultData)
 {
     RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
@@ -243,6 +282,13 @@ void InProcessIDBServer::deleteObjectStore(const IDBRequestData& requestData, co
     });
 }
 
+void InProcessIDBServer::renameObjectStore(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, const String& newName)
+{
+    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, objectStoreIdentifier, newName] {
+        m_server->renameObjectStore(requestData, objectStoreIdentifier, newName);
+    });
+}
+
 void InProcessIDBServer::clearObjectStore(const IDBRequestData& requestData, uint64_t objectStoreIdentifier)
 {
     RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, objectStoreIdentifier] {
@@ -264,6 +310,13 @@ void InProcessIDBServer::deleteIndex(const IDBRequestData& requestData, uint64_t
     });
 }
 
+void InProcessIDBServer::renameIndex(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, objectStoreIdentifier, indexIdentifier, newName] {
+        m_server->renameIndex(requestData, objectStoreIdentifier, indexIdentifier, newName);
+    });
+}
+
 void InProcessIDBServer::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& keyData, const IDBValue& value, const IndexedDB::ObjectStoreOverwriteMode overwriteMode)
 {
     RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, keyData, value, overwriteMode] {
@@ -271,10 +324,17 @@ void InProcessIDBServer::putOrAdd(const IDBRequestData& requestData, const IDBKe
     });
 }
 
-void InProcessIDBServer::getRecord(const IDBRequestData& requestData, const IDBKeyRangeData& keyRangeData)
+void InProcessIDBServer::getRecord(const IDBRequestData& requestData, const IDBGetRecordData& getRecordData)
 {
-    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, keyRangeData] {
-        m_server->getRecord(requestData, keyRangeData);
+    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, getRecordData] {
+        m_server->getRecord(requestData, getRecordData);
+    });
+}
+
+void InProcessIDBServer::getAllRecords(const IDBRequestData& requestData, const IDBGetAllRecordsData& getAllRecordsData)
+{
+    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, getAllRecordsData] {
+        m_server->getAllRecords(requestData, getAllRecordsData);
     });
 }
 
@@ -299,10 +359,10 @@ void InProcessIDBServer::openCursor(const IDBRequestData& requestData, const IDB
     });
 }
 
-void InProcessIDBServer::iterateCursor(const IDBRequestData& requestData, const IDBKeyData& key, unsigned long count)
+void InProcessIDBServer::iterateCursor(const IDBRequestData& requestData, const IDBIterateCursorData& data)
 {
-    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, key, count] {
-        m_server->iterateCursor(requestData, key, count);
+    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, data] {
+        m_server->iterateCursor(requestData, data);
     });
 }
 
@@ -341,6 +401,13 @@ void InProcessIDBServer::notifyOpenDBRequestBlocked(const IDBResourceIdentifier&
     });
 }
 
+void InProcessIDBServer::databaseConnectionPendingClose(uint64_t databaseConnectionIdentifier)
+{
+    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), databaseConnectionIdentifier] {
+        m_server->databaseConnectionPendingClose(databaseConnectionIdentifier);
+    });
+}
+
 void InProcessIDBServer::databaseConnectionClosed(uint64_t databaseConnectionIdentifier)
 {
     RunLoop::current().dispatch([this, protectedThis = makeRef(*this), databaseConnectionIdentifier] {
@@ -392,7 +459,7 @@ void InProcessIDBServer::didGetAllDatabaseNames(uint64_t callbackID, const Vecto
 
 void InProcessIDBServer::accessToTemporaryFileComplete(const String& path)
 {
-    deleteFile(path);
+    FileSystem::deleteFile(path);
 }
 
 } // namespace WebCore