2 * Copyright (C) 2010 Google 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
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef IDBTransactionBackendImpl_h
27 #define IDBTransactionBackendImpl_h
29 #if ENABLE(INDEXED_DATABASE)
31 #include "IDBBackingStoreInterface.h"
32 #include "IDBDatabaseBackendImpl.h"
33 #include "IDBDatabaseBackendInterface.h"
34 #include "IDBDatabaseError.h"
35 #include "IDBOperation.h"
36 #include "IDBTransactionBackendInterface.h"
38 #include <wtf/Deque.h>
39 #include <wtf/HashSet.h>
40 #include <wtf/RefPtr.h>
44 class IDBDatabaseCallbacks;
46 class IDBTransactionBackendImpl FINAL : public IDBTransactionBackendInterface {
48 static PassRefPtr<IDBTransactionBackendImpl> create(IDBDatabaseBackendImpl*, int64_t transactionId, PassRefPtr<IDBDatabaseCallbacks>, const Vector<int64_t>& objectStoreIds, IndexedDB::TransactionMode);
49 virtual ~IDBTransactionBackendImpl();
51 virtual void commit() OVERRIDE FINAL;
52 virtual void abort() OVERRIDE FINAL;
53 virtual void abort(PassRefPtr<IDBDatabaseError>) OVERRIDE FINAL;
55 virtual void run() OVERRIDE;
56 virtual IndexedDB::TransactionMode mode() const OVERRIDE FINAL { return m_mode; }
57 const HashSet<int64_t>& scope() const OVERRIDE { return m_objectStoreIds; }
59 virtual void scheduleTask(PassOwnPtr<IDBOperation> task, PassOwnPtr<IDBOperation> abortTask = nullptr) { scheduleTask(IDBDatabaseBackendInterface::NormalTask, task, abortTask); }
60 virtual void scheduleTask(IDBDatabaseBackendInterface::TaskType, PassOwnPtr<IDBOperation>, PassOwnPtr<IDBOperation> abortTask = nullptr) OVERRIDE;
62 virtual void registerOpenCursor(IDBCursorBackend*) OVERRIDE;
63 virtual void unregisterOpenCursor(IDBCursorBackend*) OVERRIDE;
65 virtual void addPreemptiveEvent() OVERRIDE { m_pendingPreemptiveEvents++; }
66 virtual void didCompletePreemptiveEvent() OVERRIDE { m_pendingPreemptiveEvents--; ASSERT(m_pendingPreemptiveEvents >= 0); }
67 virtual IDBBackingStoreTransactionInterface& backingStoreTransaction() { return *m_backingStoreTransaction; }
69 virtual IDBDatabaseBackendInterface& database() const OVERRIDE { return *m_database; }
71 virtual void scheduleCreateObjectStoreOperation(const IDBObjectStoreMetadata&) OVERRIDE FINAL;
72 virtual void scheduleDeleteObjectStoreOperation(const IDBObjectStoreMetadata&) OVERRIDE FINAL;
73 virtual void scheduleVersionChangeOperation(int64_t transactionId, int64_t requestedVersion, PassRefPtr<IDBCallbacks>, PassRefPtr<IDBDatabaseCallbacks>, const IDBDatabaseMetadata&) OVERRIDE FINAL;
74 virtual void scheduleCreateIndexOperation(int64_t objectStoreId, const IDBIndexMetadata&) OVERRIDE FINAL;
75 virtual void scheduleDeleteIndexOperation(int64_t objectStoreId, const IDBIndexMetadata&) OVERRIDE FINAL;
76 virtual void scheduleGetOperation(const IDBDatabaseMetadata&, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange>, IndexedDB::CursorType, PassRefPtr<IDBCallbacks>) OVERRIDE FINAL;
77 virtual void schedulePutOperation(const IDBObjectStoreMetadata&, PassRefPtr<SharedBuffer> value, PassRefPtr<IDBKey>, IDBDatabaseBackendInterface::PutMode, PassRefPtr<IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) OVERRIDE FINAL;
78 virtual void scheduleSetIndexesReadyOperation(size_t indexCount) OVERRIDE FINAL;
79 virtual void scheduleOpenCursorOperation(int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange>, IndexedDB::CursorDirection, IndexedDB::CursorType, IDBDatabaseBackendInterface::TaskType, PassRefPtr<IDBCallbacks>) OVERRIDE FINAL;
80 virtual void scheduleCountOperation(int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange>, PassRefPtr<IDBCallbacks>) OVERRIDE FINAL;
81 virtual void scheduleDeleteRangeOperation(int64_t objectStoreId, PassRefPtr<IDBKeyRange>, PassRefPtr<IDBCallbacks>) OVERRIDE FINAL;
82 virtual void scheduleClearOperation(int64_t objectStoreId, PassRefPtr<IDBCallbacks>) OVERRIDE FINAL;
84 virtual PassRefPtr<IDBCursorBackend> createCursorBackend(IDBBackingStoreCursorInterface&, IndexedDB::CursorType, IDBDatabaseBackendInterface::TaskType, int64_t objectStoreId) OVERRIDE;
87 IDBTransactionBackendImpl(IDBDatabaseBackendImpl*, int64_t id, PassRefPtr<IDBDatabaseCallbacks>, const HashSet<int64_t>& objectStoreIds, IndexedDB::TransactionMode);
90 Unused, // Created, but no tasks yet.
91 StartPending, // Enqueued tasks, but backing store transaction not yet started.
92 Running, // Backing store transaction started but not yet finished.
93 Finished, // Either aborted or committed.
98 bool isTaskQueueEmpty() const;
99 bool hasPendingTasks() const;
101 void taskTimerFired(Timer<IDBTransactionBackendImpl>*);
102 void closeOpenCursors();
104 const HashSet<int64_t> m_objectStoreIds;
105 const IndexedDB::TransactionMode m_mode;
108 bool m_commitPending;
109 RefPtr<IDBDatabaseCallbacks> m_callbacks;
110 RefPtr<IDBDatabaseBackendImpl> m_database;
112 typedef Deque<OwnPtr<IDBOperation>> TaskQueue;
113 TaskQueue m_taskQueue;
114 TaskQueue m_preemptiveTaskQueue;
115 TaskQueue m_abortTaskQueue;
117 std::unique_ptr<IDBBackingStoreTransactionInterface> m_backingStoreTransaction;
119 // FIXME: delete the timer once we have threads instead.
120 Timer<IDBTransactionBackendImpl> m_taskTimer;
121 int m_pendingPreemptiveEvents;
123 HashSet<IDBCursorBackend*> m_openCursors;
125 RefPtr<IDBBackingStoreInterface> m_backingStore;
128 } // namespace WebCore
130 #endif // ENABLE(INDEXED_DATABASE)
132 #endif // IDBTransactionBackendImpl_h