summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/indexeddb/IDBDatabase.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/Modules/indexeddb/IDBDatabase.h')
-rw-r--r--Source/WebCore/Modules/indexeddb/IDBDatabase.h197
1 files changed, 96 insertions, 101 deletions
diff --git a/Source/WebCore/Modules/indexeddb/IDBDatabase.h b/Source/WebCore/Modules/indexeddb/IDBDatabase.h
index 5cf6032c5..56b94c6c0 100644
--- a/Source/WebCore/Modules/indexeddb/IDBDatabase.h
+++ b/Source/WebCore/Modules/indexeddb/IDBDatabase.h
@@ -1,143 +1,138 @@
/*
- * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef IDBDatabase_h
-#define IDBDatabase_h
-
-#include "ActiveDOMObject.h"
-#include "DOMStringList.h"
-#include "Dictionary.h"
-#include "Event.h"
-#include "EventTarget.h"
-#include "IDBDatabaseCallbacks.h"
-#include "IDBDatabaseMetadata.h"
-#include "IDBObjectStore.h"
-#include "IDBTransaction.h"
-#include "IndexedDB.h"
-#include "ScriptWrappable.h"
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
+#pragma once
#if ENABLE(INDEXED_DATABASE)
+#include "EventTarget.h"
+#include "IDBActiveDOMObject.h"
+#include "IDBConnectionProxy.h"
+#include "IDBConnectionToServer.h"
+#include "IDBDatabaseInfo.h"
+#include "IDBKeyPath.h"
+#include "IDBTransactionMode.h"
+
namespace WebCore {
-class ScriptExecutionContext;
+class DOMStringList;
+class IDBObjectStore;
+class IDBOpenDBRequest;
+class IDBResultData;
+class IDBTransaction;
+class IDBTransactionInfo;
-typedef int ExceptionCode;
+struct EventNames;
-class IDBDatabase final : public RefCounted<IDBDatabase>, public ScriptWrappable, public EventTargetWithInlineData, public ActiveDOMObject {
+class IDBDatabase : public ThreadSafeRefCounted<IDBDatabase>, public EventTargetWithInlineData, public IDBActiveDOMObject {
public:
- static PassRefPtr<IDBDatabase> create(ScriptExecutionContext*, PassRefPtr<IDBDatabaseBackend>, PassRefPtr<IDBDatabaseCallbacks>);
- ~IDBDatabase();
+ static Ref<IDBDatabase> create(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBResultData&);
- void setMetadata(const IDBDatabaseMetadata& metadata) { m_metadata = metadata; }
- void transactionCreated(IDBTransaction*);
- void transactionFinished(IDBTransaction*);
+ virtual ~IDBDatabase();
- // Implement the IDL
- const String name() const { return m_metadata.name; }
+ // IDBDatabase IDL
+ const String name() const;
uint64_t version() const;
- PassRefPtr<DOMStringList> objectStoreNames() const;
-
- PassRefPtr<IDBObjectStore> createObjectStore(const String& name, const Dictionary&, ExceptionCode&);
- PassRefPtr<IDBObjectStore> createObjectStore(const String& name, const IDBKeyPath&, bool autoIncrement, ExceptionCode&);
- PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext* context, PassRefPtr<DOMStringList> scope, const String& mode, ExceptionCode& ec) { return transaction(context, *scope, mode, ec); }
- PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext*, const Vector<String>&, const String& mode, ExceptionCode&);
- PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext*, const String&, const String& mode, ExceptionCode&);
- void deleteObjectStore(const String& name, ExceptionCode&);
- void close();
+ RefPtr<DOMStringList> objectStoreNames() const;
+
+ struct ObjectStoreParameters {
+ std::optional<IDBKeyPath> keyPath;
+ bool autoIncrement;
+ };
- DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(versionchange);
+ ExceptionOr<Ref<IDBObjectStore>> createObjectStore(const String& name, ObjectStoreParameters&&);
- // IDBDatabaseCallbacks
- virtual void onVersionChange(uint64_t oldVersion, uint64_t newVersion, IndexedDB::VersionNullness newVersionNullness);
- virtual void onAbort(int64_t, PassRefPtr<IDBDatabaseError>);
- virtual void onComplete(int64_t);
+ using StringOrVectorOfStrings = WTF::Variant<String, Vector<String>>;
+ ExceptionOr<Ref<IDBTransaction>> transaction(StringOrVectorOfStrings&& storeNames, IDBTransactionMode);
+ ExceptionOr<void> deleteObjectStore(const String& name);
+ void close();
- // ActiveDOMObject
- virtual bool hasPendingActivity() const override;
+ void renameObjectStore(IDBObjectStore&, const String& newName);
+ void renameIndex(IDBIndex&, const String& newName);
// EventTarget
- virtual EventTargetInterface eventTargetInterface() const override final { return IDBDatabaseEventTargetInterfaceType; }
- virtual ScriptExecutionContext* scriptExecutionContext() const override final { return ActiveDOMObject::scriptExecutionContext(); }
+ EventTargetInterface eventTargetInterface() const final { return IDBDatabaseEventTargetInterfaceType; }
+ ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
+ void refEventTarget() final { ThreadSafeRefCounted<IDBDatabase>::ref(); }
+ void derefEventTarget() final { ThreadSafeRefCounted<IDBDatabase>::deref(); }
- bool isClosePending() const { return m_closePending; }
- void forceClose();
- const IDBDatabaseMetadata metadata() const { return m_metadata; }
- void enqueueEvent(PassRefPtr<Event>);
+ using ThreadSafeRefCounted<IDBDatabase>::ref;
+ using ThreadSafeRefCounted<IDBDatabase>::deref;
- using EventTarget::dispatchEvent;
- virtual bool dispatchEvent(PassRefPtr<Event>) override;
+ const char* activeDOMObjectName() const final;
+ bool canSuspendForDocumentSuspension() const final;
+ void stop() final;
- int64_t findObjectStoreId(const String& name) const;
- bool containsObjectStore(const String& name) const
- {
- return findObjectStoreId(name) != IDBObjectStoreMetadata::InvalidId;
- }
+ const IDBDatabaseInfo& info() const { return m_info; }
+ uint64_t databaseConnectionIdentifier() const { return m_databaseConnectionIdentifier; }
- IDBDatabaseBackend* backend() const { return m_backend.get(); }
+ Ref<IDBTransaction> startVersionChangeTransaction(const IDBTransactionInfo&, IDBOpenDBRequest&);
+ void didStartTransaction(IDBTransaction&);
- static int64_t nextTransactionId();
+ void willCommitTransaction(IDBTransaction&);
+ void didCommitTransaction(IDBTransaction&);
+ void willAbortTransaction(IDBTransaction&);
+ void didAbortTransaction(IDBTransaction&);
- using RefCounted<IDBDatabase>::ref;
- using RefCounted<IDBDatabase>::deref;
+ void fireVersionChangeEvent(const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion);
+ void didCloseFromServer(const IDBError&);
+ void connectionToServerLost(const IDBError&);
-private:
- IDBDatabase(ScriptExecutionContext*, PassRefPtr<IDBDatabaseBackend>, PassRefPtr<IDBDatabaseCallbacks>);
+ IDBClient::IDBConnectionProxy& connectionProxy() { return m_connectionProxy.get(); }
- // ActiveDOMObject
- virtual void stop() override;
+ void didCreateIndexInfo(const IDBIndexInfo&);
+ void didDeleteIndexInfo(const IDBIndexInfo&);
- // EventTarget
- virtual void refEventTarget() override final { ref(); }
- virtual void derefEventTarget() override final { deref(); }
+ bool isClosingOrClosed() const { return m_closePending || m_closedInServer; }
- void closeConnection();
+ bool dispatchEvent(Event&) final;
- IDBDatabaseMetadata m_metadata;
- RefPtr<IDBDatabaseBackend> m_backend;
- RefPtr<IDBTransaction> m_versionChangeTransaction;
- typedef HashMap<int64_t, IDBTransaction*> TransactionMap;
- TransactionMap m_transactions;
+ bool hasPendingActivity() const final;
+
+private:
+ IDBDatabase(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBResultData&);
- bool m_closePending;
- bool m_contextStopped;
+ void didCommitOrAbortTransaction(IDBTransaction&);
- // Keep track of the versionchange events waiting to be fired on this
- // database so that we can cancel them if the database closes.
- Vector<RefPtr<Event>> m_enqueuedEvents;
+ void maybeCloseInServer();
- RefPtr<IDBDatabaseCallbacks> m_databaseCallbacks;
+ Ref<IDBClient::IDBConnectionProxy> m_connectionProxy;
+ 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;
+ HashMap<IDBResourceIdentifier, RefPtr<IDBTransaction>> m_committingTransactions;
+ HashMap<IDBResourceIdentifier, RefPtr<IDBTransaction>> m_abortingTransactions;
+
+ const EventNames& m_eventNames; // Need to cache this so we can use it from GC threads.
};
} // namespace WebCore
-#endif
-
-#endif // IDBDatabase_h
+#endif // ENABLE(INDEXED_DATABASE)