OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "modules/indexeddb/IDBIndex.h" | 32 #include "modules/indexeddb/IDBIndex.h" |
33 #include "modules/indexeddb/IDBIndexParameters.h" | 33 #include "modules/indexeddb/IDBIndexParameters.h" |
34 #include "modules/indexeddb/IDBKey.h" | 34 #include "modules/indexeddb/IDBKey.h" |
35 #include "modules/indexeddb/IDBKeyRange.h" | 35 #include "modules/indexeddb/IDBKeyRange.h" |
36 #include "modules/indexeddb/IDBMetadata.h" | 36 #include "modules/indexeddb/IDBMetadata.h" |
37 #include "modules/indexeddb/IDBRequest.h" | 37 #include "modules/indexeddb/IDBRequest.h" |
38 #include "modules/indexeddb/IDBTransaction.h" | 38 #include "modules/indexeddb/IDBTransaction.h" |
39 #include "public/platform/modules/indexeddb/WebIDBCursor.h" | 39 #include "public/platform/modules/indexeddb/WebIDBCursor.h" |
40 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" | 40 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" |
41 #include "public/platform/modules/indexeddb/WebIDBTypes.h" | 41 #include "public/platform/modules/indexeddb/WebIDBTypes.h" |
42 #include "wtf/PassRefPtr.h" | |
43 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
44 #include "wtf/text/WTFString.h" | 43 #include "wtf/text/WTFString.h" |
45 | 44 |
46 namespace blink { | 45 namespace blink { |
47 | 46 |
48 class DOMStringList; | 47 class DOMStringList; |
49 class IDBAny; | 48 class IDBAny; |
50 class ExceptionState; | 49 class ExceptionState; |
51 | 50 |
52 class IDBObjectStore final : public GarbageCollectedFinalized<IDBObjectStore>, | 51 class IDBObjectStore final : public GarbageCollectedFinalized<IDBObjectStore>, |
53 public ScriptWrappable { | 52 public ScriptWrappable { |
54 DEFINE_WRAPPERTYPEINFO(); | 53 DEFINE_WRAPPERTYPEINFO(); |
55 | 54 |
56 public: | 55 public: |
57 static IDBObjectStore* create(const IDBObjectStoreMetadata& metadata, | 56 static IDBObjectStore* create(RefPtr<IDBObjectStoreMetadata> metadata, |
58 IDBTransaction* transaction) { | 57 IDBTransaction* transaction) { |
59 return new IDBObjectStore(metadata, transaction); | 58 return new IDBObjectStore(std::move(metadata), transaction); |
60 } | 59 } |
61 ~IDBObjectStore() {} | 60 ~IDBObjectStore() {} |
62 DECLARE_TRACE(); | 61 DECLARE_TRACE(); |
63 | 62 |
64 const IDBObjectStoreMetadata& metadata() const { return m_metadata; } | 63 const IDBObjectStoreMetadata& metadata() const { return *m_metadata; } |
65 const IDBKeyPath& idbKeyPath() const { return metadata().keyPath; } | 64 const IDBKeyPath& idbKeyPath() const { return metadata().keyPath; } |
66 | 65 |
67 // Implement the IDBObjectStore IDL | 66 // Implement the IDBObjectStore IDL |
68 int64_t id() const { return metadata().id; } | 67 int64_t id() const { return metadata().id; } |
69 const String& name() const { return metadata().name; } | 68 const String& name() const { return metadata().name; } |
70 void setName(const String& name, ExceptionState&); | 69 void setName(const String& name, ExceptionState&); |
71 ScriptValue keyPath(ScriptState*) const; | 70 ScriptValue keyPath(ScriptState*) const; |
72 DOMStringList* indexNames() const; | 71 DOMStringList* indexNames() const; |
73 IDBTransaction* transaction() const { return m_transaction.get(); } | 72 IDBTransaction* transaction() const { return m_transaction.get(); } |
74 bool autoIncrement() const { return metadata().autoIncrement; } | 73 bool autoIncrement() const { return metadata().autoIncrement; } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 ExceptionState&); | 129 ExceptionState&); |
131 | 130 |
132 // Used internally and by InspectorIndexedDBAgent: | 131 // Used internally and by InspectorIndexedDBAgent: |
133 IDBRequest* openCursor(ScriptState*, | 132 IDBRequest* openCursor(ScriptState*, |
134 IDBKeyRange*, | 133 IDBKeyRange*, |
135 WebIDBCursorDirection, | 134 WebIDBCursorDirection, |
136 WebIDBTaskType = WebIDBTaskTypeNormal); | 135 WebIDBTaskType = WebIDBTaskTypeNormal); |
137 | 136 |
138 void markDeleted(); | 137 void markDeleted(); |
139 bool isDeleted() const { return m_deleted; } | 138 bool isDeleted() const { return m_deleted; } |
140 void abort(); | |
141 void transactionFinished(); | |
142 | 139 |
143 void setMetadata(const IDBObjectStoreMetadata& metadata) { | 140 // True if this object store was created in its associated transaction. |
144 m_metadata = metadata; | 141 // Only valid if the store's associated transaction is a versionchange. |
| 142 bool isNewlyCreated() const { |
| 143 DCHECK(m_transaction->isVersionChange()); |
| 144 // Object store IDs are allocated sequentially, so we can tell if an object |
| 145 // store was created in this transaction by comparing its ID against the |
| 146 // database's maximum object store ID at the time when the transaction was |
| 147 // started. |
| 148 return id() > m_transaction->oldMaxObjectStoreId(); |
145 } | 149 } |
146 | 150 |
| 151 // Clears the cache used to implement the index() method. |
| 152 // |
| 153 // This should be called when the store's transaction clears its reference |
| 154 // to this IDBObjectStore instance, so the store can clear its references to |
| 155 // IDBIndex instances. This way, Oilpan can garbage-collect the instances |
| 156 // that are not referenced in JavaScript. |
| 157 // |
| 158 // For most stores, the condition above is met when the transaction |
| 159 // finishes. The exception is stores that are created and deleted in the |
| 160 // same transaction. Those stores will remain marked for deletion even if |
| 161 // the transaction aborts, so the transaction can forget about them (and |
| 162 // clear their index caches) right when they are deleted. |
| 163 void clearIndexCache(); |
| 164 |
| 165 // Sets the object store's metadata to a previous version. |
| 166 // |
| 167 // The reverting process includes reverting the metadata for the IDBIndex |
| 168 // instances that are still tracked by the store. It does not revert the |
| 169 // IDBIndex metadata for indexes that were deleted in this transaction. |
| 170 // |
| 171 // Used when a versionchange transaction is aborted. |
| 172 void revertMetadata(RefPtr<IDBObjectStoreMetadata> previousMetadata); |
| 173 // This relies on the changes made by revertMetadata(). |
| 174 void revertDeletedIndexMetadata(IDBIndex& deletedIndex); |
| 175 |
147 // Used by IDBIndex::setName: | 176 // Used by IDBIndex::setName: |
148 bool containsIndex(const String& name) const { | 177 bool containsIndex(const String& name) const { |
149 return findIndexId(name) != IDBIndexMetadata::InvalidId; | 178 return findIndexId(name) != IDBIndexMetadata::InvalidId; |
150 } | 179 } |
151 void indexRenamed(int64_t indexId, const String& newName); | 180 void renameIndex(int64_t indexId, const String& newName); |
152 | 181 |
153 WebIDBDatabase* backendDB() const; | 182 WebIDBDatabase* backendDB() const; |
154 | 183 |
155 private: | 184 private: |
156 IDBObjectStore(const IDBObjectStoreMetadata&, IDBTransaction*); | 185 using IDBIndexMap = HeapHashMap<String, Member<IDBIndex>>; |
| 186 |
| 187 IDBObjectStore(RefPtr<IDBObjectStoreMetadata>, IDBTransaction*); |
157 | 188 |
158 IDBIndex* createIndex(ScriptState*, | 189 IDBIndex* createIndex(ScriptState*, |
159 const String& name, | 190 const String& name, |
160 const IDBKeyPath&, | 191 const IDBKeyPath&, |
161 const IDBIndexParameters&, | 192 const IDBIndexParameters&, |
162 ExceptionState&); | 193 ExceptionState&); |
163 IDBRequest* put(ScriptState*, | 194 IDBRequest* put(ScriptState*, |
164 WebIDBPutMode, | 195 WebIDBPutMode, |
165 IDBAny* source, | 196 IDBAny* source, |
166 const ScriptValue&, | 197 const ScriptValue&, |
167 const ScriptValue& key, | 198 const ScriptValue& key, |
168 ExceptionState&); | 199 ExceptionState&); |
169 | 200 |
170 int64_t findIndexId(const String& name) const; | 201 int64_t findIndexId(const String& name) const; |
171 | 202 |
172 IDBObjectStoreMetadata m_metadata; | 203 // The IDBObjectStoreMetadata is shared with the object store map in the |
| 204 // database's metadata. |
| 205 RefPtr<IDBObjectStoreMetadata> m_metadata; |
173 Member<IDBTransaction> m_transaction; | 206 Member<IDBTransaction> m_transaction; |
174 bool m_deleted = false; | 207 bool m_deleted = false; |
175 | 208 |
176 // Caches the IDBIndex instances returned by the index() method. | 209 // Caches the IDBIndex instances returned by the index() method. |
| 210 // |
177 // The spec requires that an object store's index() returns the same | 211 // The spec requires that an object store's index() returns the same |
178 // IDBIndex instance for a specific index, so this cache is necessary | 212 // IDBIndex instance for a specific index, so this cache is necessary |
179 // for correctness. | 213 // for correctness. |
180 // | 214 // |
181 // index() throws for completed/aborted transactions, so this is not used | 215 // index() throws for completed/aborted transactions, so this is not used |
182 // after a transaction is finished, and can be cleared. | 216 // after a transaction is finished, and can be cleared. |
183 using IDBIndexMap = HeapHashMap<String, Member<IDBIndex>>; | |
184 IDBIndexMap m_indexMap; | 217 IDBIndexMap m_indexMap; |
185 | 218 |
186 // Used to mark indexes created in an aborted upgrade transaction as | 219 #if DCHECK_IS_ON() |
187 // deleted. | 220 bool m_clearIndexCacheCalled = false; |
188 HeapHashSet<Member<IDBIndex>> m_createdIndexes; | 221 #endif // DCHECK_IS_ON() |
189 }; | 222 }; |
190 | 223 |
191 } // namespace blink | 224 } // namespace blink |
192 | 225 |
193 #endif // IDBObjectStore_h | 226 #endif // IDBObjectStore_h |
OLD | NEW |