| 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 // Clears the cache used to implement the index() method. |
| 144 m_metadata = metadata; | 141 // |
| 145 } | 142 // This should be called when the store's transaction clears its reference |
| 143 // to this IDBObjectStore instance, so the store can clear its references to |
| 144 // IDBIndex instances. This way, Oilpan can garbage-collect the instances |
| 145 // that are not referenced in JavaScript. |
| 146 // |
| 147 // For most stores, the condition above is met when the transaction |
| 148 // finishes. The exception is stores that are created and deleted in the |
| 149 // same transaction. Those stores will remain marked for deletion even if |
| 150 // the transaction aborts, so the transaction can forget about them (and |
| 151 // clear their index caches) right when they are deleted. |
| 152 void clearIndexCache(); |
| 153 |
| 154 // Sets the object store's metadata to a previous version. |
| 155 // |
| 156 // The reverting process includes reverting the metadata for the IDBIndex |
| 157 // instances that are still tracked by the store. It does not revert the |
| 158 // IDBIndex metadata for indexes that were deleted in this transaction. |
| 159 // |
| 160 // Used when a versionchange transaction is aborted. |
| 161 void revertMetadata(RefPtr<IDBObjectStoreMetadata> previousMetadata); |
| 162 // This relies on the changes made by revertMetadata(). |
| 163 void revertDeletedIndexMetadata(IDBIndex& deletedIndex); |
| 146 | 164 |
| 147 // Used by IDBIndex::setName: | 165 // Used by IDBIndex::setName: |
| 148 bool containsIndex(const String& name) const { | 166 bool containsIndex(const String& name) const { |
| 149 return findIndexId(name) != IDBIndexMetadata::InvalidId; | 167 return findIndexId(name) != IDBIndexMetadata::InvalidId; |
| 150 } | 168 } |
| 151 void indexRenamed(int64_t indexId, const String& newName); | 169 void renameIndex(int64_t indexId, const String& newName); |
| 152 | 170 |
| 153 WebIDBDatabase* backendDB() const; | 171 WebIDBDatabase* backendDB() const; |
| 154 | 172 |
| 155 private: | 173 private: |
| 156 IDBObjectStore(const IDBObjectStoreMetadata&, IDBTransaction*); | 174 using IDBIndexMap = HeapHashMap<String, Member<IDBIndex>>; |
| 175 |
| 176 IDBObjectStore(RefPtr<IDBObjectStoreMetadata>, IDBTransaction*); |
| 157 | 177 |
| 158 IDBIndex* createIndex(ScriptState*, | 178 IDBIndex* createIndex(ScriptState*, |
| 159 const String& name, | 179 const String& name, |
| 160 const IDBKeyPath&, | 180 const IDBKeyPath&, |
| 161 const IDBIndexParameters&, | 181 const IDBIndexParameters&, |
| 162 ExceptionState&); | 182 ExceptionState&); |
| 163 IDBRequest* put(ScriptState*, | 183 IDBRequest* put(ScriptState*, |
| 164 WebIDBPutMode, | 184 WebIDBPutMode, |
| 165 IDBAny* source, | 185 IDBAny* source, |
| 166 const ScriptValue&, | 186 const ScriptValue&, |
| 167 const ScriptValue& key, | 187 const ScriptValue& key, |
| 168 ExceptionState&); | 188 ExceptionState&); |
| 169 | 189 |
| 170 int64_t findIndexId(const String& name) const; | 190 int64_t findIndexId(const String& name) const; |
| 171 | 191 |
| 172 IDBObjectStoreMetadata m_metadata; | 192 // The IDBObjectStoreMetadata is shared with the object store map in the |
| 193 // database's metadata. |
| 194 RefPtr<IDBObjectStoreMetadata> m_metadata; |
| 173 Member<IDBTransaction> m_transaction; | 195 Member<IDBTransaction> m_transaction; |
| 174 bool m_deleted = false; | 196 bool m_deleted = false; |
| 175 | 197 |
| 176 // Caches the IDBIndex instances returned by the index() method. | 198 // Caches the IDBIndex instances returned by the index() method. |
| 199 // |
| 177 // The spec requires that an object store's index() returns the same | 200 // The spec requires that an object store's index() returns the same |
| 178 // IDBIndex instance for a specific index, so this cache is necessary | 201 // IDBIndex instance for a specific index, so this cache is necessary |
| 179 // for correctness. | 202 // for correctness. |
| 180 // | 203 // |
| 181 // index() throws for completed/aborted transactions, so this is not used | 204 // index() throws for completed/aborted transactions, so this is not used |
| 182 // after a transaction is finished, and can be cleared. | 205 // after a transaction is finished, and can be cleared. |
| 183 using IDBIndexMap = HeapHashMap<String, Member<IDBIndex>>; | |
| 184 IDBIndexMap m_indexMap; | 206 IDBIndexMap m_indexMap; |
| 185 | 207 |
| 186 // Used to mark indexes created in an aborted upgrade transaction as | 208 #if DCHECK_IS_ON() |
| 187 // deleted. | 209 bool m_clearIndexCacheCalled = false; |
| 188 HeapHashSet<Member<IDBIndex>> m_createdIndexes; | 210 #endif // DCHECK_IS_ON() |
| 189 }; | 211 }; |
| 190 | 212 |
| 191 } // namespace blink | 213 } // namespace blink |
| 192 | 214 |
| 193 #endif // IDBObjectStore_h | 215 #endif // IDBObjectStore_h |
| OLD | NEW |