Remove excessive headers from WebCore/{Modules,animation,crypto,domjit}
[WebKit-https.git] / Source / WebCore / Modules / indexeddb / IDBDatabase.h
index 5d2b3cc..ba487b3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple 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
  * 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 "IDBObjectStore.h"
-#include "IDBTransaction.h"
-#include "IndexedDB.h"
-#include "ScriptWrappable.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 "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 : public RefCounted<IDBDatabase>, public ScriptWrappable, public EventTargetWithInlineData, public ActiveDOMObject {
+class IDBDatabase : public ThreadSafeRefCounted<IDBDatabase>, public EventTargetWithInlineData, public IDBActiveDOMObject {
 public:
-    virtual ~IDBDatabase() { }
+    static Ref<IDBDatabase> create(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBResultData&);
+
+    virtual ~IDBDatabase();
+
+    // IDBDatabase IDL
+    const String name() const;
+    uint64_t version() const;
+    RefPtr<DOMStringList> objectStoreNames() const;
+
+    struct ObjectStoreParameters {
+        std::optional<IDBKeyPath> keyPath;
+        bool autoIncrement;
+    };
+
+    ExceptionOr<Ref<IDBObjectStore>> createObjectStore(const String& name, ObjectStoreParameters&&);
+
+    using StringOrVectorOfStrings = WTF::Variant<String, Vector<String>>;
+    ExceptionOr<Ref<IDBTransaction>> transaction(StringOrVectorOfStrings&& storeNames, IDBTransactionMode);
+    ExceptionOr<void> deleteObjectStore(const String& name);
+    void close();
+
+    void renameObjectStore(IDBObjectStore&, const String& newName);
+    void renameIndex(IDBIndex&, const String& newName);
+
+    // EventTarget
+    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(); }
+
+    using ThreadSafeRefCounted<IDBDatabase>::ref;
+    using ThreadSafeRefCounted<IDBDatabase>::deref;
+
+    const char* activeDOMObjectName() const final;
+    bool canSuspendForDocumentSuspension() const final;
+    void stop() final;
 
-    // Implement the IDL
-    virtual const String name() const = 0;
-    virtual uint64_t version() const = 0;
-    virtual RefPtr<DOMStringList> objectStoreNames() const = 0;
+    const IDBDatabaseInfo& info() const { return m_info; }
+    uint64_t databaseConnectionIdentifier() const { return m_databaseConnectionIdentifier; }
 
-    virtual RefPtr<IDBObjectStore> createObjectStore(const String& name, const Dictionary&, ExceptionCode&) = 0;
-    virtual RefPtr<IDBObjectStore> createObjectStore(const String& name, const IDBKeyPath&, bool autoIncrement, ExceptionCode&) = 0;
-    virtual RefPtr<IDBTransaction> transaction(ScriptExecutionContext*, const Vector<String>&, const String& mode, ExceptionCode&) = 0;
-    virtual RefPtr<IDBTransaction> transaction(ScriptExecutionContext*, const String&, const String& mode, ExceptionCode&) = 0;
-    virtual void deleteObjectStore(const String& name, ExceptionCode&) = 0;
-    virtual void close() = 0;
+    Ref<IDBTransaction> startVersionChangeTransaction(const IDBTransactionInfo&, IDBOpenDBRequest&);
+    void didStartTransaction(IDBTransaction&);
 
-    using RefCounted<IDBDatabase>::ref;
-    using RefCounted<IDBDatabase>::deref;
+    void willCommitTransaction(IDBTransaction&);
+    void didCommitTransaction(IDBTransaction&);
+    void willAbortTransaction(IDBTransaction&);
+    void didAbortTransaction(IDBTransaction&);
 
-protected:
-    IDBDatabase(ScriptExecutionContext*);
+    void fireVersionChangeEvent(const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion);
+    void didCloseFromServer(const IDBError&);
+    void connectionToServerLost(const IDBError&);
+
+    IDBClient::IDBConnectionProxy& connectionProxy() { return m_connectionProxy.get(); }
+
+    void didCreateIndexInfo(const IDBIndexInfo&);
+    void didDeleteIndexInfo(const IDBIndexInfo&);
+
+    bool isClosingOrClosed() const { return m_closePending || m_closedInServer; }
+
+    bool dispatchEvent(Event&) final;
+
+    bool hasPendingActivity() const final;
+
+private:
+    IDBDatabase(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBResultData&);
+
+    void didCommitOrAbortTransaction(IDBTransaction&);
+
+    void maybeCloseInServer();
+
+    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)