Skip to content
Permalink
Browse files
Modern IDB (Workers): Move IDBConnectionProxy into IDBRequest and IDB…
…Database.

https://bugs.webkit.org/show_bug.cgi?id=156868

Reviewed by Tim Horton.

No new tests (No behavior change).

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::create):
(WebCore::IDBDatabase::IDBDatabase):
(WebCore::IDBDatabase::~IDBDatabase):
(WebCore::IDBDatabase::transaction):
(WebCore::IDBDatabase::maybeCloseInServer):
* Modules/indexeddb/IDBDatabase.h:
(WebCore::IDBDatabase::connectionProxy):
(WebCore::IDBDatabase::serverConnection):

* Modules/indexeddb/IDBOpenDBRequest.cpp:
(WebCore::IDBOpenDBRequest::createDeleteRequest):
(WebCore::IDBOpenDBRequest::createOpenRequest):
(WebCore::IDBOpenDBRequest::IDBOpenDBRequest):
(WebCore::IDBOpenDBRequest::onSuccess):
(WebCore::IDBOpenDBRequest::onUpgradeNeeded):
(WebCore::IDBOpenDBRequest::requestCompleted):
(WebCore::IDBOpenDBRequest::maybeCreateDeleteRequest): Deleted.
(WebCore::IDBOpenDBRequest::maybeCreateOpenRequest): Deleted.
* Modules/indexeddb/IDBOpenDBRequest.h:

* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::IDBRequest):
(WebCore::IDBRequest::connectionToServer): Deleted.
* Modules/indexeddb/IDBRequest.h:
(WebCore::IDBRequest::connectionProxy):

* Modules/indexeddb/IDBTransaction.h:

* Modules/indexeddb/client/IDBConnectionProxy.cpp:
(WebCore::IDBClient::IDBConnectionProxy::openDatabase):
(WebCore::IDBClient::IDBConnectionProxy::deleteDatabase):


Canonical link: https://commits.webkit.org/174978@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199843 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
beidson committed Apr 21, 2016
1 parent f0e25c3 commit a01a07a1f74969df27a7b1f2c29bd370ba789d34
@@ -1,3 +1,45 @@
2016-04-21 Brady Eidson <beidson@apple.com>

Modern IDB (Workers): Move IDBConnectionProxy into IDBRequest and IDBDatabase.
https://bugs.webkit.org/show_bug.cgi?id=156868

Reviewed by Tim Horton.

No new tests (No behavior change).

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::create):
(WebCore::IDBDatabase::IDBDatabase):
(WebCore::IDBDatabase::~IDBDatabase):
(WebCore::IDBDatabase::transaction):
(WebCore::IDBDatabase::maybeCloseInServer):
* Modules/indexeddb/IDBDatabase.h:
(WebCore::IDBDatabase::connectionProxy):
(WebCore::IDBDatabase::serverConnection):

* Modules/indexeddb/IDBOpenDBRequest.cpp:
(WebCore::IDBOpenDBRequest::createDeleteRequest):
(WebCore::IDBOpenDBRequest::createOpenRequest):
(WebCore::IDBOpenDBRequest::IDBOpenDBRequest):
(WebCore::IDBOpenDBRequest::onSuccess):
(WebCore::IDBOpenDBRequest::onUpgradeNeeded):
(WebCore::IDBOpenDBRequest::requestCompleted):
(WebCore::IDBOpenDBRequest::maybeCreateDeleteRequest): Deleted.
(WebCore::IDBOpenDBRequest::maybeCreateOpenRequest): Deleted.
* Modules/indexeddb/IDBOpenDBRequest.h:

* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::IDBRequest):
(WebCore::IDBRequest::connectionToServer): Deleted.
* Modules/indexeddb/IDBRequest.h:
(WebCore::IDBRequest::connectionProxy):

* Modules/indexeddb/IDBTransaction.h:

* Modules/indexeddb/client/IDBConnectionProxy.cpp:
(WebCore::IDBClient::IDBConnectionProxy::openDatabase):
(WebCore::IDBClient::IDBConnectionProxy::deleteDatabase):

2016-04-21 Jiewen Tan <jiewen_tan@apple.com>

[iOS] DumpRenderTree crashed in com.apple.WebCore: WebCore::ResourceLoadNotifier::didFailToLoad
@@ -30,6 +30,7 @@

#include "DOMStringList.h"
#include "EventQueue.h"
#include "IDBConnectionProxy.h"
#include "IDBConnectionToServer.h"
#include "IDBDatabaseException.h"
#include "IDBObjectStore.h"
@@ -42,26 +43,26 @@

namespace WebCore {

Ref<IDBDatabase> IDBDatabase::create(ScriptExecutionContext& context, IDBClient::IDBConnectionToServer& connection, const IDBResultData& resultData)
Ref<IDBDatabase> IDBDatabase::create(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, const IDBResultData& resultData)
{
return adoptRef(*new IDBDatabase(context, connection, resultData));
return adoptRef(*new IDBDatabase(context, connectionProxy, resultData));
}

IDBDatabase::IDBDatabase(ScriptExecutionContext& context, IDBClient::IDBConnectionToServer& connection, const IDBResultData& resultData)
IDBDatabase::IDBDatabase(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, const IDBResultData& resultData)
: WebCore::ActiveDOMObject(&context)
, m_serverConnection(connection)
, m_connectionProxy(connectionProxy)
, m_info(resultData.databaseInfo())
, m_databaseConnectionIdentifier(resultData.databaseConnectionIdentifier())
{
LOG(IndexedDB, "IDBDatabase::IDBDatabase - Creating database %s with version %" PRIu64 " connection %" PRIu64, m_info.name().utf8().data(), m_info.version(), m_databaseConnectionIdentifier);
suspendIfNeeded();
relaxAdoptionRequirement();
m_serverConnection->registerDatabaseConnection(*this);
m_connectionProxy->connectionToServer().registerDatabaseConnection(*this);
}

IDBDatabase::~IDBDatabase()
{
m_serverConnection->unregisterDatabaseConnection(*this);
m_connectionProxy->connectionToServer().unregisterDatabaseConnection(*this);
}

bool IDBDatabase::hasPendingActivity() const
@@ -180,7 +181,7 @@ RefPtr<WebCore::IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext*
return nullptr;
}

auto info = IDBTransactionInfo::clientTransaction(m_serverConnection.get(), objectStores, mode);
auto info = IDBTransactionInfo::clientTransaction(m_connectionProxy->connectionToServer(), objectStores, mode);
auto transaction = IDBTransaction::create(*this, info);

LOG(IndexedDB, "IDBDatabase::transaction - Added active transaction %s", info.identifier().loggingString().utf8().data());
@@ -244,7 +245,7 @@ void IDBDatabase::maybeCloseInServer()
return;

m_closedInServer = true;
m_serverConnection->databaseConnectionClosed(*this);
m_connectionProxy->connectionToServer().databaseConnectionClosed(*this);
}

const char* IDBDatabase::activeDOMObjectName() const
@@ -30,6 +30,7 @@
#include "Dictionary.h"
#include "EventTarget.h"
#include "ExceptionCode.h"
#include "IDBConnectionProxy.h"
#include "IDBConnectionToServer.h"
#include "IDBDatabaseInfo.h"

@@ -44,7 +45,7 @@ class IDBTransactionInfo;

class IDBDatabase : public RefCounted<IDBDatabase>, public EventTargetWithInlineData, public ActiveDOMObject {
public:
static Ref<IDBDatabase> create(ScriptExecutionContext&, IDBClient::IDBConnectionToServer&, const IDBResultData&);
static Ref<IDBDatabase> create(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBResultData&);

virtual ~IDBDatabase();

@@ -86,7 +87,10 @@ class IDBDatabase : public RefCounted<IDBDatabase>, public EventTargetWithInline

void fireVersionChangeEvent(const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion);

IDBClient::IDBConnectionToServer& serverConnection() { return m_serverConnection.get(); }
IDBClient::IDBConnectionProxy& connectionProxy() { return m_connectionProxy.get(); }

// FIXME: Remove the need for this accessor.
IDBClient::IDBConnectionToServer& serverConnection() { return m_connectionProxy->connectionToServer(); }

void didCreateIndexInfo(const IDBIndexInfo&);
void didDeleteIndexInfo(const IDBIndexInfo&);
@@ -98,13 +102,13 @@ class IDBDatabase : public RefCounted<IDBDatabase>, public EventTargetWithInline
bool hasPendingActivity() const final;

private:
IDBDatabase(ScriptExecutionContext&, IDBClient::IDBConnectionToServer&, const IDBResultData&);
IDBDatabase(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBResultData&);

void didCommitOrAbortTransaction(IDBTransaction&);

void maybeCloseInServer();

Ref<IDBClient::IDBConnectionToServer> m_serverConnection;
Ref<IDBClient::IDBConnectionProxy> m_connectionProxy;
IDBDatabaseInfo m_info;
uint64_t m_databaseConnectionIdentifier { 0 };

@@ -42,28 +42,18 @@

namespace WebCore {

RefPtr<IDBOpenDBRequest> IDBOpenDBRequest::maybeCreateDeleteRequest(ScriptExecutionContext& context, const IDBDatabaseIdentifier& databaseIdentifier)
Ref<IDBOpenDBRequest> IDBOpenDBRequest::createDeleteRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, const IDBDatabaseIdentifier& databaseIdentifier)
{
ASSERT(databaseIdentifier.isValid());
auto* proxy = context.idbConnectionProxy();
if (!proxy)
return nullptr;

return adoptRef(new IDBOpenDBRequest(context, proxy->serverConnectionIdentifier(), databaseIdentifier, 0, IndexedDB::RequestType::Delete));
return adoptRef(*new IDBOpenDBRequest(context, connectionProxy, databaseIdentifier, 0, IndexedDB::RequestType::Delete));
}

RefPtr<IDBOpenDBRequest> IDBOpenDBRequest::maybeCreateOpenRequest(ScriptExecutionContext& context, const IDBDatabaseIdentifier& databaseIdentifier, uint64_t version)
Ref<IDBOpenDBRequest> IDBOpenDBRequest::createOpenRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, const IDBDatabaseIdentifier& databaseIdentifier, uint64_t version)
{
ASSERT(databaseIdentifier.isValid());
auto* proxy = context.idbConnectionProxy();
if (!proxy)
return nullptr;

return adoptRef(new IDBOpenDBRequest(context, proxy->serverConnectionIdentifier(), databaseIdentifier, version, IndexedDB::RequestType::Open));
return adoptRef(*new IDBOpenDBRequest(context, connectionProxy, databaseIdentifier, version, IndexedDB::RequestType::Open));
}

IDBOpenDBRequest::IDBOpenDBRequest(ScriptExecutionContext& context, uint64_t serverConnectionIdentifier, const IDBDatabaseIdentifier& databaseIdentifier, uint64_t version, IndexedDB::RequestType requestType)
: IDBRequest(context, serverConnectionIdentifier)
IDBOpenDBRequest::IDBOpenDBRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, const IDBDatabaseIdentifier& databaseIdentifier, uint64_t version, IndexedDB::RequestType requestType)
: IDBRequest(context, connectionProxy)
, m_databaseIdentifier(databaseIdentifier)
, m_version(version)
{
@@ -128,23 +118,15 @@ void IDBOpenDBRequest::onSuccess(const IDBResultData& resultData)
{
LOG(IndexedDB, "IDBOpenDBRequest::onSuccess()");

auto* connection = connectionToServer();
if (!connection)
return;

setResult(IDBDatabase::create(*scriptExecutionContext(), *connection, resultData));
setResult(IDBDatabase::create(*scriptExecutionContext(), connectionProxy(), resultData));
m_isDone = true;

enqueueEvent(IDBRequestCompletionEvent::create(eventNames().successEvent, false, false, *this));
}

void IDBOpenDBRequest::onUpgradeNeeded(const IDBResultData& resultData)
{
auto* connection = connectionToServer();
if (!connection)
return;

Ref<IDBDatabase> database = IDBDatabase::create(*scriptExecutionContext(), *connection, resultData);
Ref<IDBDatabase> database = IDBDatabase::create(*scriptExecutionContext(), connectionProxy(), resultData);
Ref<IDBTransaction> transaction = database->startVersionChangeTransaction(resultData.transactionInfo(), *this);

ASSERT(transaction->info().mode() == IndexedDB::TransactionMode::VersionChange);
@@ -179,20 +161,16 @@ void IDBOpenDBRequest::requestCompleted(const IDBResultData& data)
{
LOG(IndexedDB, "IDBOpenDBRequest::requestCompleted");

auto* connection = connectionToServer();
if (!connection)
return;

// If an Open request was completed after the page has navigated, leaving this request
// with a stopped script execution context, we need to message back to the server so it
// doesn't hang waiting on a database connection or transaction that will never exist.
if (m_contextStopped) {
switch (data.type()) {
case IDBResultType::OpenDatabaseSuccess:
connection->abortOpenAndUpgradeNeeded(data.databaseConnectionIdentifier(), IDBResourceIdentifier::emptyValue());
connectionProxy().connectionToServer().abortOpenAndUpgradeNeeded(data.databaseConnectionIdentifier(), IDBResourceIdentifier::emptyValue());
break;
case IDBResultType::OpenDatabaseUpgradeNeeded:
connection->abortOpenAndUpgradeNeeded(data.databaseConnectionIdentifier(), data.transactionInfo().identifier());
connectionProxy().connectionToServer().abortOpenAndUpgradeNeeded(data.databaseConnectionIdentifier(), data.transactionInfo().identifier());
break;
default:
break;
@@ -36,8 +36,8 @@ class IDBResultData;

class IDBOpenDBRequest final : public IDBRequest {
public:
static RefPtr<IDBOpenDBRequest> maybeCreateDeleteRequest(ScriptExecutionContext&, const IDBDatabaseIdentifier&);
static RefPtr<IDBOpenDBRequest> maybeCreateOpenRequest(ScriptExecutionContext&, const IDBDatabaseIdentifier&, uint64_t version);
static Ref<IDBOpenDBRequest> createDeleteRequest(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBDatabaseIdentifier&);
static Ref<IDBOpenDBRequest> createOpenRequest(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBDatabaseIdentifier&, uint64_t version);

virtual ~IDBOpenDBRequest();

@@ -52,7 +52,7 @@ class IDBOpenDBRequest final : public IDBRequest {
void fireErrorAfterVersionChangeCompletion();

private:
IDBOpenDBRequest(ScriptExecutionContext&, uint64_t serverConnectionIdentifier, const IDBDatabaseIdentifier&, uint64_t version, IndexedDB::RequestType);
IDBOpenDBRequest(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBDatabaseIdentifier&, uint64_t version, IndexedDB::RequestType);

bool dispatchEvent(Event&) final;

@@ -69,9 +69,10 @@ Ref<IDBRequest> IDBRequest::createGet(ScriptExecutionContext& context, IDBIndex&
return adoptRef(*new IDBRequest(context, index, requestedRecordType, transaction));
}

IDBRequest::IDBRequest(ScriptExecutionContext& context, uint64_t connectionIdentifier)
IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy)
: ActiveDOMObject(&context)
, m_resourceIdentifier(connectionIdentifier)
, m_resourceIdentifier(connectionProxy.serverConnectionIdentifier())
, m_connectionProxy(connectionProxy)
{
suspendIfNeeded();
}
@@ -81,6 +82,7 @@ IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBObjectStore& objectSt
, m_transaction(&transaction)
, m_resourceIdentifier(transaction.serverConnection())
, m_objectStoreSource(&objectStore)
, m_connectionProxy(transaction.database().connectionProxy())
{
suspendIfNeeded();
}
@@ -92,6 +94,7 @@ IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBCursor& cursor, IDBTr
, m_objectStoreSource(cursor.objectStore())
, m_indexSource(cursor.index())
, m_pendingCursor(&cursor)
, m_connectionProxy(transaction.database().connectionProxy())
{
suspendIfNeeded();

@@ -103,6 +106,7 @@ IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBIndex& index, IDBTran
, m_transaction(&transaction)
, m_resourceIdentifier(transaction.serverConnection())
, m_indexSource(&index)
, m_connectionProxy(transaction.database().connectionProxy())
{
suspendIfNeeded();
}
@@ -407,17 +411,6 @@ void IDBRequest::setResult(Ref<IDBDatabase>&& database)
m_databaseResult = WTFMove(database);
}

// FIXME: Temporarily required during bringup of IDB-in-Workers.
// Once all IDB object reliance on the IDBConnectionToServer has been shifted to reliance on
// IDBConnectionProxy, remove this.
IDBClient::IDBConnectionToServer* IDBRequest::connectionToServer()
{
ASSERT(isMainThread());
auto* context = scriptExecutionContext();
auto* proxy = context ? context->idbConnectionProxy() : nullptr;
return proxy ? &proxy->connectionToServer() : nullptr;
}

} // namespace WebCore

#endif // ENABLE(INDEXED_DATABASE)
@@ -48,6 +48,7 @@ class ScopeGuard;
class ThreadSafeDataBuffer;

namespace IDBClient {
class IDBConnectionProxy;
class IDBConnectionToServer;
}

@@ -104,17 +105,14 @@ class IDBRequest : public EventTargetWithInlineData, private ActiveDOMObject, pu
bool hasPendingActivity() const final;

protected:
IDBRequest(ScriptExecutionContext&, uint64_t connectionIdentifier);
IDBRequest(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&);

void enqueueEvent(Ref<Event>&&);
bool dispatchEvent(Event&) override;

void setResult(Ref<IDBDatabase>&&);

// FIXME: Temporarily required during bringup of IDB-in-Workers.
// Once all IDB object reliance on the IDBConnectionToServer has been shifted to reliance on
// IDBConnectionProxy, remove this.
IDBClient::IDBConnectionToServer* connectionToServer();
IDBClient::IDBConnectionProxy& connectionProxy() { return m_connectionProxy.get(); }

// FIXME: Protected data members aren't great for maintainability.
// Consider adding protected helper functions and making these private.
@@ -170,6 +168,8 @@ class IDBRequest : public EventTargetWithInlineData, private ActiveDOMObject, pu
RefPtr<IDBCursor> m_pendingCursor;

std::unique_ptr<ScopeGuard> m_cursorRequestNotifier;

Ref<IDBClient::IDBConnectionProxy> m_connectionProxy;
};

} // namespace WebCore
@@ -30,6 +30,7 @@
#include "ActiveDOMObject.h"
#include "EventTarget.h"
#include "IDBError.h"
#include "IDBOpenDBRequest.h"
#include "IDBTransactionInfo.h"
#include "IndexedDB.h"
#include "Timer.h"
@@ -48,7 +49,6 @@ class IDBKey;
class IDBKeyData;
class IDBObjectStore;
class IDBObjectStoreInfo;
class IDBOpenDBRequest;
class IDBResultData;
class SerializedScriptValue;

0 comments on commit a01a07a

Please sign in to comment.