443b6e5895c2e40b6adb1dff690c0c5377bb9808
[WebKit-https.git] / Source / WebCore / Modules / indexeddb / IDBTransactionBackendOperations.h
1 /*
2  * Copyright (C) 2013 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 #ifndef IDBTransactionBackendOperations_h
27 #define IDBTransactionBackendOperations_h
28
29 #include "IDBDatabaseBackendImpl.h"
30 #include "IDBOperation.h"
31 #include "IDBTransactionBackendInterface.h"
32
33 #if ENABLE(INDEXED_DATABASE)
34
35 namespace WebCore {
36
37 class CreateObjectStoreOperation : public IDBOperation {
38 public:
39     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, const IDBObjectStoreMetadata& objectStoreMetadata)
40     {
41         return adoptPtr(new CreateObjectStoreOperation(transaction, backingStore, objectStoreMetadata));
42     }
43     virtual void perform() OVERRIDE FINAL;
44 private:
45     CreateObjectStoreOperation(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, const IDBObjectStoreMetadata& objectStoreMetadata)
46         : m_transaction(transaction)
47         , m_backingStore(backingStore)
48         , m_objectStoreMetadata(objectStoreMetadata)
49     {
50     }
51     
52     RefPtr<IDBTransactionBackendInterface> m_transaction;
53     const RefPtr<IDBBackingStoreInterface> m_backingStore;
54     const IDBObjectStoreMetadata m_objectStoreMetadata;
55 };
56
57 class DeleteObjectStoreOperation : public IDBOperation {
58 public:
59     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, const IDBObjectStoreMetadata& objectStoreMetadata)
60     {
61         return adoptPtr(new DeleteObjectStoreOperation(transaction, backingStore, objectStoreMetadata));
62     }
63     virtual void perform() OVERRIDE FINAL;
64 private:
65     DeleteObjectStoreOperation(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, const IDBObjectStoreMetadata& objectStoreMetadata)
66         : m_transaction(transaction)
67         , m_backingStore(backingStore)
68         , m_objectStoreMetadata(objectStoreMetadata)
69     {
70     }
71
72     RefPtr<IDBTransactionBackendInterface> m_transaction;
73     const RefPtr<IDBBackingStoreInterface> m_backingStore;
74     const IDBObjectStoreMetadata m_objectStoreMetadata;
75 };
76
77 class IDBDatabaseBackendImpl::VersionChangeOperation : public IDBOperation {
78 public:
79     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, int64_t transactionId, int64_t version, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks)
80     {
81         return adoptPtr(new VersionChangeOperation(transaction, transactionId, version, callbacks, databaseCallbacks));
82     }
83     virtual void perform() OVERRIDE FINAL;
84 private:
85     VersionChangeOperation(IDBTransactionBackendInterface* transaction, int64_t transactionId, int64_t version, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks)
86         : m_transaction(transaction)
87         , m_transactionId(transactionId)
88         , m_version(version)
89         , m_callbacks(callbacks)
90         , m_databaseCallbacks(databaseCallbacks)
91     {
92     }
93
94     RefPtr<IDBTransactionBackendInterface> m_transaction;
95     int64_t m_transactionId;
96     int64_t m_version;
97     RefPtr<IDBCallbacks> m_callbacks;
98     RefPtr<IDBDatabaseCallbacks> m_databaseCallbacks;
99 };
100
101 class CreateObjectStoreAbortOperation : public IDBOperation {
102 public:
103     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, int64_t objectStoreId)
104     {
105         return adoptPtr(new CreateObjectStoreAbortOperation(transaction, objectStoreId));
106     }
107     virtual void perform() OVERRIDE FINAL;
108 private:
109     CreateObjectStoreAbortOperation(IDBTransactionBackendInterface* transaction, int64_t objectStoreId)
110         : m_transaction(transaction)
111         , m_objectStoreId(objectStoreId)
112     {
113     }
114
115     RefPtr<IDBTransactionBackendInterface> m_transaction;
116     const int64_t m_objectStoreId;
117 };
118
119 class DeleteObjectStoreAbortOperation : public IDBOperation {
120 public:
121     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, const IDBObjectStoreMetadata& objectStore)
122     {
123         return adoptPtr(new DeleteObjectStoreAbortOperation(transaction, objectStore));
124     }
125     virtual void perform() OVERRIDE FINAL;
126 private:
127     DeleteObjectStoreAbortOperation(IDBTransactionBackendInterface* transaction, const IDBObjectStoreMetadata& objectStoreMetadata)
128         : m_transaction(transaction)
129         , m_objectStoreMetadata(objectStoreMetadata)
130     {
131     }
132
133     RefPtr<IDBTransactionBackendInterface> m_transaction;
134     IDBObjectStoreMetadata m_objectStoreMetadata;
135 };
136
137 class IDBDatabaseBackendImpl::VersionChangeAbortOperation : public IDBOperation {
138 public:
139     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, const String& previousVersion, int64_t previousIntVersion)
140     {
141         return adoptPtr(new VersionChangeAbortOperation(transaction, previousVersion, previousIntVersion));
142     }
143     virtual void perform() OVERRIDE FINAL;
144 private:
145     VersionChangeAbortOperation(IDBTransactionBackendInterface* transaction, const String& previousVersion, int64_t previousIntVersion)
146         : m_transaction(transaction)
147         , m_previousVersion(previousVersion)
148         , m_previousIntVersion(previousIntVersion)
149     {
150     }
151
152     RefPtr<IDBTransactionBackendInterface> m_transaction;
153     String m_previousVersion;
154     int64_t m_previousIntVersion;
155 };
156
157 class CreateIndexOperation : public IDBOperation {
158 public:
159     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata)
160     {
161         return adoptPtr(new CreateIndexOperation(transaction, backingStore, objectStoreId, indexMetadata));
162     }
163     virtual void perform() OVERRIDE FINAL;
164 private:
165     CreateIndexOperation(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata)
166         : m_transaction(transaction)
167         , m_backingStore(backingStore)
168         , m_objectStoreId(objectStoreId)
169         , m_indexMetadata(indexMetadata)
170     {
171     }
172
173     RefPtr<IDBTransactionBackendInterface> m_transaction;
174     const RefPtr<IDBBackingStoreInterface> m_backingStore;
175     const int64_t m_objectStoreId;
176     const IDBIndexMetadata m_indexMetadata;
177 };
178
179 class CreateIndexAbortOperation : public IDBOperation {
180 public:
181     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, int64_t objectStoreId, int64_t indexId)
182     {
183         return adoptPtr(new CreateIndexAbortOperation(transaction, objectStoreId, indexId));
184     }
185     virtual void perform() OVERRIDE FINAL;
186 private:
187     CreateIndexAbortOperation(IDBTransactionBackendInterface* transaction, int64_t objectStoreId, int64_t indexId)
188         : m_transaction(transaction)
189         , m_objectStoreId(objectStoreId)
190         , m_indexId(indexId)
191     {
192     }
193
194     const RefPtr<IDBTransactionBackendInterface> m_transaction;
195     const int64_t m_objectStoreId;
196     const int64_t m_indexId;
197 };
198
199 class DeleteIndexOperation : public IDBOperation {
200 public:
201     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata)
202     {
203         return adoptPtr(new DeleteIndexOperation(transaction, backingStore, objectStoreId, indexMetadata));
204     }
205     virtual void perform() OVERRIDE FINAL;
206 private:
207     DeleteIndexOperation(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata)
208         : m_transaction(transaction)
209         , m_backingStore(backingStore)
210         , m_objectStoreId(objectStoreId)
211         , m_indexMetadata(indexMetadata)
212     {
213     }
214
215     RefPtr<IDBTransactionBackendInterface> m_transaction;
216     const RefPtr<IDBBackingStoreInterface> m_backingStore;
217     const int64_t m_objectStoreId;
218     const IDBIndexMetadata m_indexMetadata;
219 };
220
221 class DeleteIndexAbortOperation : public IDBOperation {
222 public:
223     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata)
224     {
225         return adoptPtr(new DeleteIndexAbortOperation(transaction, objectStoreId, indexMetadata));
226     }
227     virtual void perform() OVERRIDE FINAL;
228 private:
229     DeleteIndexAbortOperation(IDBTransactionBackendInterface* transaction, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata)
230         : m_transaction(transaction)
231         , m_objectStoreId(objectStoreId)
232         , m_indexMetadata(indexMetadata)
233     {
234     }
235
236     RefPtr<IDBTransactionBackendInterface> m_transaction;
237     const int64_t m_objectStoreId;
238     const IDBIndexMetadata m_indexMetadata;
239 };
240
241 class GetOperation : public IDBOperation {
242 public:
243     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, const IDBDatabaseMetadata& metadata, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange> keyRange, IndexedDB::CursorType cursorType, PassRefPtr<IDBCallbacks> callbacks)
244     {
245         return adoptPtr(new GetOperation(transaction, backingStore, metadata, objectStoreId, indexId, keyRange, cursorType, callbacks));
246     }
247     virtual void perform() OVERRIDE FINAL;
248 private:
249     GetOperation(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, const IDBDatabaseMetadata& metadata, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange> keyRange, IndexedDB::CursorType cursorType, PassRefPtr<IDBCallbacks> callbacks)
250         : m_transaction(transaction)
251         , m_backingStore(backingStore)
252         , m_databaseId(metadata.id)
253         , m_objectStoreId(objectStoreId)
254         , m_indexId(indexId)
255         , m_keyPath(metadata.objectStores.get(objectStoreId).keyPath)
256         , m_autoIncrement(metadata.objectStores.get(objectStoreId).autoIncrement)
257         , m_keyRange(keyRange)
258         , m_cursorType(cursorType)
259         , m_callbacks(callbacks)
260     {
261         ASSERT(metadata.objectStores.contains(objectStoreId));
262         ASSERT(metadata.objectStores.get(objectStoreId).id == objectStoreId);
263     }
264
265     RefPtr<IDBTransactionBackendInterface> m_transaction;
266     const RefPtr<IDBBackingStoreInterface> m_backingStore;
267     const int64_t m_databaseId;
268     const int64_t m_objectStoreId;
269     const int64_t m_indexId;
270     const IDBKeyPath m_keyPath;
271     const bool m_autoIncrement;
272     const RefPtr<IDBKeyRange> m_keyRange;
273     const IndexedDB::CursorType m_cursorType;
274     const RefPtr<IDBCallbacks> m_callbacks;
275 };
276
277 class PutOperation : public IDBOperation {
278 public:
279     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t databaseId, const IDBObjectStoreMetadata& objectStore, PassRefPtr<SharedBuffer> value, PassRefPtr<IDBKey> key, IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBCallbacks> callbacks, const Vector<int64_t>& indexIds, const Vector<IndexKeys>& indexKeys)
280     {
281         return adoptPtr(new PutOperation(transaction, backingStore, databaseId, objectStore, value, key, putMode, callbacks, indexIds, indexKeys));
282     }
283     virtual void perform() OVERRIDE FINAL;
284 private:
285     PutOperation(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t databaseId, const IDBObjectStoreMetadata& objectStore, PassRefPtr<SharedBuffer>& value, PassRefPtr<IDBKey> key, IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBCallbacks> callbacks, const Vector<int64_t>& indexIds, const Vector<IndexKeys>& indexKeys)
286         : m_transaction(transaction)
287         , m_backingStore(backingStore)
288         , m_databaseId(databaseId)
289         , m_objectStore(objectStore)
290         , m_value(value)
291         , m_key(key)
292         , m_putMode(putMode)
293         , m_callbacks(callbacks)
294         , m_indexIds(indexIds)
295         , m_indexKeys(indexKeys)
296     {
297     }
298
299     RefPtr<IDBTransactionBackendInterface> m_transaction;
300     const RefPtr<IDBBackingStoreInterface> m_backingStore;
301     const int64_t m_databaseId;
302     const IDBObjectStoreMetadata m_objectStore;
303     const RefPtr<SharedBuffer> m_value;
304     const RefPtr<IDBKey> m_key;
305     const IDBDatabaseBackendInterface::PutMode m_putMode;
306     const RefPtr<IDBCallbacks> m_callbacks;
307     const Vector<int64_t> m_indexIds;
308     const Vector<IndexKeys> m_indexKeys;
309 };
310
311 class SetIndexesReadyOperation : public IDBOperation {
312 public:
313     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, size_t indexCount)
314     {
315         return adoptPtr(new SetIndexesReadyOperation(transaction, indexCount));
316     }
317     virtual void perform() OVERRIDE FINAL;
318 private:
319     SetIndexesReadyOperation(IDBTransactionBackendInterface* transaction, size_t indexCount)
320         : m_transaction(transaction)
321         , m_indexCount(indexCount)
322     {
323     }
324
325     RefPtr<IDBTransactionBackendInterface> m_transaction;
326     const size_t m_indexCount;
327 };
328
329 class OpenCursorOperation : public IDBOperation {
330 public:
331     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t databaseId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange> keyRange, IndexedDB::CursorDirection direction, IndexedDB::CursorType cursorType, IDBDatabaseBackendInterface::TaskType taskType, PassRefPtr<IDBCallbacks> callbacks)
332     {
333         return adoptPtr(new OpenCursorOperation(transaction, backingStore, databaseId, objectStoreId, indexId, keyRange, direction, cursorType, taskType, callbacks));
334     }
335     virtual void perform() OVERRIDE FINAL;
336 private:
337     OpenCursorOperation(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t databaseId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange> keyRange, IndexedDB::CursorDirection direction, IndexedDB::CursorType cursorType, IDBDatabaseBackendInterface::TaskType taskType, PassRefPtr<IDBCallbacks> callbacks)
338         : m_transaction(transaction)
339         , m_backingStore(backingStore)
340         , m_databaseId(databaseId)
341         , m_objectStoreId(objectStoreId)
342         , m_indexId(indexId)
343         , m_keyRange(keyRange)
344         , m_direction(direction)
345         , m_cursorType(cursorType)
346         , m_taskType(taskType)
347         , m_callbacks(callbacks)
348     {
349     }
350
351     RefPtr<IDBTransactionBackendInterface> m_transaction;
352     const RefPtr<IDBBackingStoreInterface> m_backingStore;
353     const int64_t m_databaseId;
354     const int64_t m_objectStoreId;
355     const int64_t m_indexId;
356     const PassRefPtr<IDBKeyRange> m_keyRange;
357     const IndexedDB::CursorDirection m_direction;
358     const IndexedDB::CursorType m_cursorType;
359     const IDBDatabaseBackendInterface::TaskType m_taskType;
360     const RefPtr<IDBCallbacks> m_callbacks;
361 };
362
363 class CountOperation : public IDBOperation {
364 public:
365     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t databaseId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange> keyRange, PassRefPtr<IDBCallbacks> callbacks)
366     {
367         return adoptPtr(new CountOperation(transaction, backingStore, databaseId, objectStoreId, indexId, keyRange, callbacks));
368     }
369     virtual void perform() OVERRIDE FINAL;
370 private:
371     CountOperation(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t databaseId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange> keyRange, PassRefPtr<IDBCallbacks> callbacks)
372         : m_transaction(transaction)
373         , m_backingStore(backingStore)
374         , m_databaseId(databaseId)
375         , m_objectStoreId(objectStoreId)
376         , m_indexId(indexId)
377         , m_keyRange(keyRange)
378         , m_callbacks(callbacks)
379     {
380     }
381
382     RefPtr<IDBTransactionBackendInterface> m_transaction;
383     const RefPtr<IDBBackingStoreInterface> m_backingStore;
384     const int64_t m_databaseId;
385     const int64_t m_objectStoreId;
386     const int64_t m_indexId;
387     const RefPtr<IDBKeyRange> m_keyRange;
388     const RefPtr<IDBCallbacks> m_callbacks;
389 };
390
391 class DeleteRangeOperation : public IDBOperation {
392 public:
393     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t databaseId, int64_t objectStoreId, PassRefPtr<IDBKeyRange> keyRange, PassRefPtr<IDBCallbacks> callbacks)
394     {
395         return adoptPtr(new DeleteRangeOperation(transaction, backingStore, databaseId, objectStoreId, keyRange, callbacks));
396     }
397     virtual void perform() OVERRIDE FINAL;
398 private:
399     DeleteRangeOperation(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t databaseId, int64_t objectStoreId, PassRefPtr<IDBKeyRange> keyRange, PassRefPtr<IDBCallbacks> callbacks)
400         : m_transaction(transaction)
401         , m_backingStore(backingStore)
402         , m_databaseId(databaseId)
403         , m_objectStoreId(objectStoreId)
404         , m_keyRange(keyRange)
405         , m_callbacks(callbacks)
406     {
407     }
408
409     RefPtr<IDBTransactionBackendInterface> m_transaction;
410     const RefPtr<IDBBackingStoreInterface> m_backingStore;
411     const int64_t m_databaseId;
412     const int64_t m_objectStoreId;
413     const RefPtr<IDBKeyRange> m_keyRange;
414     const RefPtr<IDBCallbacks> m_callbacks;
415 };
416
417 class ClearOperation : public IDBOperation {
418 public:
419     static PassOwnPtr<IDBOperation> create(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t databaseId, int64_t objectStoreId, PassRefPtr<IDBCallbacks> callbacks)
420     {
421         return adoptPtr(new ClearOperation(transaction, backingStore, databaseId, objectStoreId, callbacks));
422     }
423     virtual void perform() OVERRIDE FINAL;
424 private:
425     ClearOperation(IDBTransactionBackendInterface* transaction, IDBBackingStoreInterface* backingStore, int64_t databaseId, int64_t objectStoreId, PassRefPtr<IDBCallbacks> callbacks)
426         : m_transaction(transaction)
427         , m_backingStore(backingStore)
428         , m_databaseId(databaseId)
429         , m_objectStoreId(objectStoreId)
430         , m_callbacks(callbacks)
431     {
432     }
433
434     RefPtr<IDBTransactionBackendInterface> m_transaction;
435     const RefPtr<IDBBackingStoreInterface> m_backingStore;
436     const int64_t m_databaseId;
437     const int64_t m_objectStoreId;
438     const RefPtr<IDBCallbacks> m_callbacks;
439 };
440
441 } // namespace WebCore
442
443 #endif // ENABLE(INDEXED_DATABASE)
444 #endif // IDBTransactionBackendOperations_h