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 "IDBBackingStore.h" |
31 | #include "IDBDatabaseIdentifier.h" |
32 | #include "IDBResourceIdentifier.h" |
33 | #include "MemoryBackingStoreTransaction.h" |
34 | #include <wtf/HashMap.h> |
35 | |
36 | namespace WebCore { |
37 | namespace IDBServer { |
38 | |
39 | class MemoryObjectStore; |
40 | |
41 | class MemoryIDBBackingStore : public IDBBackingStore { |
42 | WTF_MAKE_FAST_ALLOCATED; |
43 | public: |
44 | static std::unique_ptr<MemoryIDBBackingStore> create(const IDBDatabaseIdentifier&); |
45 | |
46 | MemoryIDBBackingStore(const IDBDatabaseIdentifier&); |
47 | ~MemoryIDBBackingStore() final; |
48 | |
49 | IDBError getOrEstablishDatabaseInfo(IDBDatabaseInfo&) final; |
50 | void setDatabaseInfo(const IDBDatabaseInfo&); |
51 | |
52 | IDBError beginTransaction(const IDBTransactionInfo&) final; |
53 | IDBError abortTransaction(const IDBResourceIdentifier& transactionIdentifier) final; |
54 | IDBError commitTransaction(const IDBResourceIdentifier& transactionIdentifier) final; |
55 | IDBError createObjectStore(const IDBResourceIdentifier& transactionIdentifier, const IDBObjectStoreInfo&) final; |
56 | IDBError deleteObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier) final; |
57 | IDBError renameObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const String& newName) final; |
58 | IDBError clearObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier) final; |
59 | IDBError createIndex(const IDBResourceIdentifier& transactionIdentifier, const IDBIndexInfo&) final; |
60 | IDBError deleteIndex(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier) final; |
61 | IDBError renameIndex(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName) final; |
62 | IDBError keyExistsInObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, bool& keyExists) final; |
63 | IDBError deleteRange(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&) final; |
64 | IDBError addRecord(const IDBResourceIdentifier& transactionIdentifier, const IDBObjectStoreInfo&, const IDBKeyData&, const IDBValue&) final; |
65 | IDBError getRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&, IDBGetRecordDataType, IDBGetResult& outValue) final; |
66 | IDBError getAllRecords(const IDBResourceIdentifier& transactionIdentifier, const IDBGetAllRecordsData&, IDBGetAllResult& outValue) final; |
67 | IDBError getIndexRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, IndexedDB::IndexRecordType, const IDBKeyRangeData&, IDBGetResult& outValue) final; |
68 | IDBError getCount(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData&, uint64_t& outCount) final; |
69 | IDBError generateKeyNumber(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t& keyNumber) final; |
70 | IDBError revertGeneratedKeyNumber(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t keyNumber) final; |
71 | IDBError maybeUpdateKeyGeneratorNumber(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, double newKeyNumber) final; |
72 | IDBError openCursor(const IDBResourceIdentifier& transactionIdentifier, const IDBCursorInfo&, IDBGetResult& outResult) final; |
73 | IDBError iterateCursor(const IDBResourceIdentifier& transactionIdentifier, const IDBResourceIdentifier& cursorIdentifier, const IDBIterateCursorData&, IDBGetResult& outResult) final; |
74 | bool prefetchCursor(const IDBResourceIdentifier&, const IDBResourceIdentifier&) final { return false; } |
75 | |
76 | IDBObjectStoreInfo* infoForObjectStore(uint64_t objectStoreIdentifier) final; |
77 | void deleteBackingStore() final; |
78 | |
79 | bool supportsSimultaneousTransactions() final { return true; } |
80 | bool isEphemeral() final { return true; } |
81 | |
82 | void setQuota(uint64_t quota) final { UNUSED_PARAM(quota); }; |
83 | uint64_t databasesSizeForOrigin() const final; |
84 | |
85 | void removeObjectStoreForVersionChangeAbort(MemoryObjectStore&); |
86 | void restoreObjectStoreForVersionChangeAbort(Ref<MemoryObjectStore>&&); |
87 | |
88 | bool hasTransaction(const IDBResourceIdentifier& identifier) const final { return m_transactions.contains(identifier); } |
89 | |
90 | private: |
91 | RefPtr<MemoryObjectStore> takeObjectStoreByIdentifier(uint64_t identifier); |
92 | |
93 | IDBDatabaseIdentifier m_identifier; |
94 | std::unique_ptr<IDBDatabaseInfo> m_databaseInfo; |
95 | |
96 | HashMap<IDBResourceIdentifier, std::unique_ptr<MemoryBackingStoreTransaction>> m_transactions; |
97 | |
98 | void registerObjectStore(Ref<MemoryObjectStore>&&); |
99 | void unregisterObjectStore(MemoryObjectStore&); |
100 | HashMap<uint64_t, RefPtr<MemoryObjectStore>> m_objectStoresByIdentifier; |
101 | HashMap<String, MemoryObjectStore*> m_objectStoresByName; |
102 | }; |
103 | |
104 | } // namespace IDBServer |
105 | } // namespace WebCore |
106 | |
107 | #endif // ENABLE(INDEXED_DATABASE) |
108 | |