2 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef IDBTransactionImpl_h
27 #define IDBTransactionImpl_h
29 #if ENABLE(INDEXED_DATABASE)
31 #include "IDBDatabaseInfo.h"
33 #include "IDBTransaction.h"
34 #include "IDBTransactionInfo.h"
35 #include "IndexedDB.h"
37 #include <heap/StrongInlines.h>
44 class IDBTransaction : public WebCore::IDBTransaction {
46 static Ref<IDBTransaction> create(IDBDatabase&, const IDBTransactionInfo&);
48 virtual ~IDBTransaction() override final;
51 virtual const String& mode() const override final;
52 virtual WebCore::IDBDatabase* db() override final;
53 virtual RefPtr<DOMError> error() const override final;
54 virtual RefPtr<IDBObjectStore> objectStore(const String& name, ExceptionCode&) override final;
55 virtual void abort(ExceptionCode&) override final;
57 virtual EventTargetInterface eventTargetInterface() const override final { return IDBTransactionEventTargetInterfaceType; }
58 virtual ScriptExecutionContext* scriptExecutionContext() const override final { return ActiveDOMObject::scriptExecutionContext(); }
59 virtual void refEventTarget() override final { ref(); }
60 virtual void derefEventTarget() override final { deref(); }
61 using EventTarget::dispatchEvent;
62 virtual bool dispatchEvent(PassRefPtr<Event>) override final;
64 virtual const char* activeDOMObjectName() const override final;
65 virtual bool canSuspendForPageCache() const override final;
66 virtual bool hasPendingActivity() const override final;
68 const IDBTransactionInfo info() const { return m_info; }
69 IDBDatabase& database() { return m_database.get(); }
70 const IDBDatabase& database() const { return m_database.get(); }
72 void didAbort(const IDBError&);
73 void didCommit(const IDBError&);
76 IDBTransaction(IDBDatabase&, const IDBTransactionInfo&);
78 bool isActive() const;
79 bool isFinishedOrFinishing() const;
82 void scheduleOperationTimer();
83 void operationTimerFired();
84 void activationTimerFired();
86 void fireOnComplete();
88 void enqueueEvent(Ref<Event>);
90 Ref<IDBDatabase> m_database;
91 IDBTransactionInfo m_info;
92 std::unique_ptr<IDBDatabaseInfo> m_originalDatabaseInfo;
94 IndexedDB::TransactionState m_state { IndexedDB::TransactionState::Unstarted };
97 Timer m_operationTimer;
98 std::unique_ptr<Timer> m_activationTimer;
101 } // namespace IDBClient
102 } // namespace WebCore
104 #endif // ENABLE(INDEXED_DATABASE)
105 #endif // IDBTransactionImpl_h