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>, p ublic ScriptWrappable { | 51 class IDBObjectStore final : public GarbageCollectedFinalized<IDBObjectStore>, p ublic ScriptWrappable { |
53 DEFINE_WRAPPERTYPEINFO(); | 52 DEFINE_WRAPPERTYPEINFO(); |
54 public: | 53 public: |
55 static IDBObjectStore* create(const IDBObjectStoreMetadata& metadata, IDBTra nsaction* transaction) | 54 static IDBObjectStore* create(RefPtr<IDBObjectStoreMetadata> metadata, IDBTr ansaction* transaction) |
56 { | 55 { |
57 return new IDBObjectStore(metadata, transaction); | 56 return new IDBObjectStore(std::move(metadata), transaction); |
58 } | 57 } |
59 ~IDBObjectStore() { } | 58 ~IDBObjectStore() { } |
60 DECLARE_TRACE(); | 59 DECLARE_TRACE(); |
61 | 60 |
62 const IDBObjectStoreMetadata& metadata() const { return m_metadata; } | 61 const IDBObjectStoreMetadata& metadata() const { return *m_metadata; } |
63 const IDBKeyPath& idbKeyPath() const { return metadata().keyPath; } | 62 const IDBKeyPath& idbKeyPath() const { return metadata().keyPath; } |
64 | 63 |
65 // Implement the IDBObjectStore IDL | 64 // Implement the IDBObjectStore IDL |
66 int64_t id() const { return metadata().id; } | 65 int64_t id() const { return metadata().id; } |
67 const String& name() const { return metadata().name; } | 66 const String& name() const { return metadata().name; } |
68 void setName(const String& name, ExceptionState&); | 67 void setName(const String& name, ExceptionState&); |
69 ScriptValue keyPath(ScriptState*) const; | 68 ScriptValue keyPath(ScriptState*) const; |
70 DOMStringList* indexNames() const; | 69 DOMStringList* indexNames() const; |
71 IDBTransaction* transaction() const { return m_transaction.get(); } | 70 IDBTransaction* transaction() const { return m_transaction.get(); } |
72 bool autoIncrement() const { return metadata().autoIncrement; } | 71 bool autoIncrement() const { return metadata().autoIncrement; } |
(...skipping 21 matching lines...) Expand all Loading... | |
94 IDBRequest* count(ScriptState*, const ScriptValue& range, ExceptionState&); | 93 IDBRequest* count(ScriptState*, const ScriptValue& range, ExceptionState&); |
95 | 94 |
96 // Used by IDBCursor::update(): | 95 // Used by IDBCursor::update(): |
97 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal ue&, IDBKey*, ExceptionState&); | 96 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal ue&, IDBKey*, ExceptionState&); |
98 | 97 |
99 // Used internally and by InspectorIndexedDBAgent: | 98 // Used internally and by InspectorIndexedDBAgent: |
100 IDBRequest* openCursor(ScriptState*, IDBKeyRange*, WebIDBCursorDirection, We bIDBTaskType = WebIDBTaskTypeNormal); | 99 IDBRequest* openCursor(ScriptState*, IDBKeyRange*, WebIDBCursorDirection, We bIDBTaskType = WebIDBTaskTypeNormal); |
101 | 100 |
102 void markDeleted(); | 101 void markDeleted(); |
103 bool isDeleted() const { return m_deleted; } | 102 bool isDeleted() const { return m_deleted; } |
104 void abort(); | |
105 void transactionFinished(); | |
106 | 103 |
107 void setMetadata(const IDBObjectStoreMetadata& metadata) { m_metadata = meta data; } | 104 // Clears the cache used to implement the index() method. |
105 // | |
106 // This should be called when the store's transaction clears its reference | |
107 // to this IDBObjectStore instance, so the store can clear its references to | |
108 // IDBIndex instances. This way, Oilpan can garbage-collect the instances | |
109 // that are not referenced in JavaScript. | |
110 // | |
111 // For most stores, the condition above is met when the transaction | |
112 /// finishes. The exception is stores that are created and deleted in the | |
jsbell
2016/09/26 22:23:40
Nit: extra /
pwnall
2016/09/27 00:12:19
Done.
| |
113 // same transaction. Those stores will remain marked for deletion even if | |
114 // the transaction aborts, so the transaction can forget about them (and | |
115 // clear their index caches) right when they are deleted. | |
116 void clearIndexCache(); | |
117 | |
118 // Sets the object store's metadata to a previous version. | |
119 // | |
120 // The reverting process includes reverting the metadata for the IDBIndex | |
121 // instances that are still tracked by the store. It does not revert the | |
122 // IDBIndex metadata for indexes that were deleted in this transaction. | |
123 // | |
124 // Used when a versionchange transaction is aborted. | |
125 void revertMetadata(RefPtr<IDBObjectStoreMetadata> previousMetadata); | |
126 // This relies on the changes made by revertMetadata(). | |
127 void revertDeletedIndexMetadata(IDBIndex& deletedIndex); | |
108 | 128 |
109 // Used by IDBIndex::setName: | 129 // Used by IDBIndex::setName: |
110 bool containsIndex(const String& name) const | 130 bool containsIndex(const String& name) const |
111 { | 131 { |
112 return findIndexId(name) != IDBIndexMetadata::InvalidId; | 132 return findIndexId(name) != IDBIndexMetadata::InvalidId; |
113 } | 133 } |
114 void indexRenamed(int64_t indexId, const String& newName); | 134 void renameIndex(int64_t indexId, const String& newName); |
115 | 135 |
116 WebIDBDatabase* backendDB() const; | 136 WebIDBDatabase* backendDB() const; |
117 | 137 |
118 private: | 138 private: |
119 IDBObjectStore(const IDBObjectStoreMetadata&, IDBTransaction*); | 139 IDBObjectStore(RefPtr<IDBObjectStoreMetadata>, IDBTransaction*); |
120 | 140 |
121 IDBIndex* createIndex(ScriptState*, const String& name, const IDBKeyPath&, c onst IDBIndexParameters&, ExceptionState&); | 141 IDBIndex* createIndex(ScriptState*, const String& name, const IDBKeyPath&, c onst IDBIndexParameters&, ExceptionState&); |
122 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal ue&, const ScriptValue& key, ExceptionState&); | 142 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal ue&, const ScriptValue& key, ExceptionState&); |
123 | 143 |
124 int64_t findIndexId(const String& name) const; | 144 int64_t findIndexId(const String& name) const; |
125 | 145 |
126 IDBObjectStoreMetadata m_metadata; | 146 // The IDBObjectStoreMetadata is shared with the object store map in the |
147 // database's metadata. | |
148 RefPtr<IDBObjectStoreMetadata> m_metadata; | |
127 Member<IDBTransaction> m_transaction; | 149 Member<IDBTransaction> m_transaction; |
128 bool m_deleted = false; | 150 bool m_deleted = false; |
129 | 151 |
130 // Caches the IDBIndex instances returned by the index() method. | 152 // Caches the IDBIndex instances returned by the index() method. |
153 // | |
131 // The spec requires that an object store's index() returns the same | 154 // The spec requires that an object store's index() returns the same |
132 // IDBIndex instance for a specific index, so this cache is necessary | 155 // IDBIndex instance for a specific index, so this cache is necessary |
133 // for correctness. | 156 // for correctness. |
134 // | 157 // |
135 // index() throws for completed/aborted transactions, so this is not used | 158 // index() throws for completed/aborted transactions, so this is not used |
136 // after a transaction is finished, and can be cleared. | 159 // after a transaction is finished, and can be cleared. |
137 using IDBIndexMap = HeapHashMap<String, Member<IDBIndex>>; | 160 using IDBIndexMap = HeapHashMap<String, Member<IDBIndex>>; |
138 IDBIndexMap m_indexMap; | 161 IDBIndexMap m_indexMap; |
139 | 162 |
140 // Used to mark indexes created in an aborted upgrade transaction as | 163 #if DCHECK_IS_ON() |
141 // deleted. | 164 bool m_clearIndexCacheCalled = false; |
142 HeapHashSet<Member<IDBIndex>> m_createdIndexes; | 165 #endif // DCHECK_IS_ON() |
143 }; | 166 }; |
144 | 167 |
145 } // namespace blink | 168 } // namespace blink |
146 | 169 |
147 #endif // IDBObjectStore_h | 170 #endif // IDBObjectStore_h |
OLD | NEW |