1 | /* |
2 | * Copyright (C) 2015 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
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. |
12 | * |
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. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(INDEXED_DATABASE) |
29 | |
30 | #include "IDBError.h" |
31 | #include "IDBTransactionInfo.h" |
32 | #include "UniqueIDBDatabaseConnection.h" |
33 | #include <wtf/Ref.h> |
34 | #include <wtf/RefCounted.h> |
35 | #include <wtf/WeakPtr.h> |
36 | |
37 | namespace WebCore { |
38 | |
39 | class IDBCursorInfo; |
40 | class IDBDatabaseInfo; |
41 | class IDBIndexInfo; |
42 | class IDBKeyData; |
43 | class IDBObjectStoreInfo; |
44 | class IDBRequestData; |
45 | class IDBValue; |
46 | |
47 | struct IDBGetAllRecordsData; |
48 | struct IDBGetRecordData; |
49 | struct IDBIterateCursorData; |
50 | struct IDBKeyRangeData; |
51 | |
52 | namespace IDBServer { |
53 | |
54 | class IDBServer; |
55 | class UniqueIDBDatabaseConnection; |
56 | |
57 | class UniqueIDBDatabaseTransaction : public RefCounted<UniqueIDBDatabaseTransaction> { |
58 | public: |
59 | enum class State { Running, Aborting, Committing, Aborted, Committed }; |
60 | |
61 | static Ref<UniqueIDBDatabaseTransaction> create(UniqueIDBDatabaseConnection&, const IDBTransactionInfo&); |
62 | |
63 | ~UniqueIDBDatabaseTransaction(); |
64 | |
65 | UniqueIDBDatabaseConnection& databaseConnection() { return m_databaseConnection.get(); } |
66 | const IDBTransactionInfo& info() const { return m_transactionInfo; } |
67 | bool isVersionChange() const; |
68 | bool isReadOnly() const; |
69 | |
70 | IDBDatabaseInfo* originalDatabaseInfo() const; |
71 | |
72 | void abort(); |
73 | void abortWithoutCallback(); |
74 | void commit(); |
75 | |
76 | void createObjectStore(const IDBRequestData&, const IDBObjectStoreInfo&); |
77 | void deleteObjectStore(const IDBRequestData&, const String& objectStoreName); |
78 | void renameObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& newName); |
79 | void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier); |
80 | void createIndex(const IDBRequestData&, const IDBIndexInfo&); |
81 | void deleteIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName); |
82 | void renameIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName); |
83 | void putOrAdd(const IDBRequestData&, const IDBKeyData&, const IDBValue&, IndexedDB::ObjectStoreOverwriteMode); |
84 | void getRecord(const IDBRequestData&, const IDBGetRecordData&); |
85 | void getAllRecords(const IDBRequestData&, const IDBGetAllRecordsData&); |
86 | void getCount(const IDBRequestData&, const IDBKeyRangeData&); |
87 | void deleteRecord(const IDBRequestData&, const IDBKeyRangeData&); |
88 | void openCursor(const IDBRequestData&, const IDBCursorInfo&); |
89 | void iterateCursor(const IDBRequestData&, const IDBIterateCursorData&); |
90 | |
91 | void didActivateInBackingStore(const IDBError&); |
92 | |
93 | const Vector<uint64_t>& objectStoreIdentifiers(); |
94 | |
95 | void setState(State state) { m_state = state; } |
96 | State state() const { return m_state; } |
97 | void setResult(const IDBError& error) { m_result = error; } |
98 | const IDBError& result() const { return m_result; } |
99 | |
100 | private: |
101 | UniqueIDBDatabaseTransaction(UniqueIDBDatabaseConnection&, const IDBTransactionInfo&); |
102 | |
103 | Ref<UniqueIDBDatabaseConnection> m_databaseConnection; |
104 | IDBTransactionInfo m_transactionInfo; |
105 | WeakPtr<IDBServer> m_server; |
106 | |
107 | std::unique_ptr<IDBDatabaseInfo> m_originalDatabaseInfo; |
108 | |
109 | Vector<uint64_t> m_objectStoreIdentifiers; |
110 | |
111 | State m_state { State::Running }; |
112 | IDBError m_result; |
113 | }; |
114 | |
115 | } // namespace IDBServer |
116 | } // namespace WebCore |
117 | |
118 | #endif // ENABLE(INDEXED_DATABASE) |
119 | |