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 22 matching lines...) Expand all Loading... | |
33 #include "core/events/EventListener.h" | 33 #include "core/events/EventListener.h" |
34 #include "modules/EventModules.h" | 34 #include "modules/EventModules.h" |
35 #include "modules/EventTargetModules.h" | 35 #include "modules/EventTargetModules.h" |
36 #include "modules/ModulesExport.h" | 36 #include "modules/ModulesExport.h" |
37 #include "modules/indexeddb/IDBMetadata.h" | 37 #include "modules/indexeddb/IDBMetadata.h" |
38 #include "modules/indexeddb/IndexedDB.h" | 38 #include "modules/indexeddb/IndexedDB.h" |
39 #include "platform/heap/Handle.h" | 39 #include "platform/heap/Handle.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/HashSet.h" | 42 #include "wtf/HashSet.h" |
43 #include "wtf/Vector.h" | |
43 | 44 |
44 namespace blink { | 45 namespace blink { |
45 | 46 |
46 class DOMException; | 47 class DOMException; |
47 class ExceptionState; | 48 class ExceptionState; |
48 class IDBDatabase; | 49 class IDBDatabase; |
50 class IDBIndex; | |
49 class IDBObjectStore; | 51 class IDBObjectStore; |
50 class IDBOpenDBRequest; | 52 class IDBOpenDBRequest; |
51 | 53 |
52 class MODULES_EXPORT IDBTransaction final : public EventTargetWithInlineData, | 54 class MODULES_EXPORT IDBTransaction final : public EventTargetWithInlineData, |
53 public ActiveScriptWrappable, | 55 public ActiveScriptWrappable, |
54 public ActiveDOMObject { | 56 public ActiveDOMObject { |
55 USING_GARBAGE_COLLECTED_MIXIN(IDBTransaction); | 57 USING_GARBAGE_COLLECTED_MIXIN(IDBTransaction); |
56 DEFINE_WRAPPERTYPEINFO(); | 58 DEFINE_WRAPPERTYPEINFO(); |
57 | 59 |
58 public: | 60 public: |
(...skipping 28 matching lines...) Expand all Loading... | |
87 // Implement the IDBTransaction IDL | 89 // Implement the IDBTransaction IDL |
88 const String& mode() const; | 90 const String& mode() const; |
89 DOMStringList* objectStoreNames() const; | 91 DOMStringList* objectStoreNames() const; |
90 IDBDatabase* db() const { return m_database.get(); } | 92 IDBDatabase* db() const { return m_database.get(); } |
91 DOMException* error() const { return m_error; } | 93 DOMException* error() const { return m_error; } |
92 IDBObjectStore* objectStore(const String& name, ExceptionState&); | 94 IDBObjectStore* objectStore(const String& name, ExceptionState&); |
93 void abort(ExceptionState&); | 95 void abort(ExceptionState&); |
94 | 96 |
95 void registerRequest(IDBRequest*); | 97 void registerRequest(IDBRequest*); |
96 void unregisterRequest(IDBRequest*); | 98 void unregisterRequest(IDBRequest*); |
97 void objectStoreCreated(const String&, IDBObjectStore*); | 99 |
98 void objectStoreDeleted(const String&); | 100 // The methods below are called right before the changes are applied to the |
101 // database's metadata. We use this unusual sequencing because some | |
102 // implementations need to access the metadata values before the change. | |
103 void objectStoreCreated(const String& name, IDBObjectStore*); | |
104 void objectStoreDeleted(const int64_t objectStoreId, const String& name); | |
99 void objectStoreRenamed(const String& oldName, const String& newName); | 105 void objectStoreRenamed(const String& oldName, const String& newName); |
106 void indexDeleted( | |
107 IDBIndex*); // only called when the index's IDBIndex had been created | |
cmumford
2016/10/05 21:15:27
Might read a little cleaner if comment is above de
pwnall
2016/10/05 23:15:45
Done.
Wow, the new formatting really messed this o
| |
108 | |
100 void setActive(bool); | 109 void setActive(bool); |
101 void setError(DOMException*); | 110 void setError(DOMException*); |
102 | 111 |
103 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); | 112 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); |
104 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); | 113 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); |
105 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 114 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
106 | 115 |
107 void onAbort(DOMException*); | 116 void onAbort(DOMException*); |
108 void onComplete(); | 117 void onComplete(); |
109 | 118 |
110 // EventTarget | 119 // EventTarget |
111 const AtomicString& interfaceName() const override; | 120 const AtomicString& interfaceName() const override; |
112 ExecutionContext* getExecutionContext() const override; | 121 ExecutionContext* getExecutionContext() const override; |
113 | 122 |
114 // ScriptWrappable | 123 // ScriptWrappable |
115 bool hasPendingActivity() const final; | 124 bool hasPendingActivity() const final; |
116 | 125 |
117 // ActiveDOMObject | 126 // ActiveDOMObject |
118 void stop() override; | 127 void stop() override; |
119 | 128 |
129 // Object store IDs are allocated sequentially, so we can tell if an object | |
130 // store was created in this transaction by comparing its ID against the | |
131 // database's maximum object store ID at the time when the transaction was | |
132 // started. | |
133 int64_t oldMaxObjectStoreId() const { | |
134 DCHECK(isVersionChange()); | |
135 return m_oldDatabaseMetadata.maxObjectStoreId; | |
136 } | |
137 | |
120 protected: | 138 protected: |
121 // EventTarget | 139 // EventTarget |
122 DispatchEventResult dispatchEventInternal(Event*) override; | 140 DispatchEventResult dispatchEventInternal(Event*) override; |
123 | 141 |
124 private: | 142 private: |
143 using IDBObjectStoreMap = HeapHashMap<String, Member<IDBObjectStore>>; | |
144 | |
125 IDBTransaction(ScriptState*, | 145 IDBTransaction(ScriptState*, |
126 int64_t, | 146 int64_t, |
127 const HashSet<String>&, | 147 const HashSet<String>&, |
128 WebIDBTransactionMode, | 148 WebIDBTransactionMode, |
129 IDBDatabase*, | 149 IDBDatabase*, |
130 IDBOpenDBRequest*, | 150 IDBOpenDBRequest*, |
131 const IDBDatabaseMetadata&); | 151 const IDBDatabaseMetadata&); |
132 | 152 |
133 void enqueueEvent(Event*); | 153 void enqueueEvent(Event*); |
134 | 154 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 #endif // DCHECK_IS_ON() | 196 #endif // DCHECK_IS_ON() |
177 | 197 |
178 // Caches the IDBObjectStore instances returned by the objectStore() method. | 198 // Caches the IDBObjectStore instances returned by the objectStore() method. |
179 // | 199 // |
180 // The spec requires that a transaction's objectStore() returns the same | 200 // The spec requires that a transaction's objectStore() returns the same |
181 // IDBObjectStore instance for a specific store, so this cache is necessary | 201 // IDBObjectStore instance for a specific store, so this cache is necessary |
182 // for correctness. | 202 // for correctness. |
183 // | 203 // |
184 // objectStore() throws for completed/aborted transactions, so this is not | 204 // objectStore() throws for completed/aborted transactions, so this is not |
185 // used after a transaction is finished, and can be cleared. | 205 // used after a transaction is finished, and can be cleared. |
186 using IDBObjectStoreMap = HeapHashMap<String, Member<IDBObjectStore>>; | |
187 IDBObjectStoreMap m_objectStoreMap; | 206 IDBObjectStoreMap m_objectStoreMap; |
188 | 207 |
189 // Used to mark stores created in an aborted upgrade transaction as | 208 // The metadata of object stores when they are opened by this transaction. |
190 // deleted. | 209 // |
191 HeapHashSet<Member<IDBObjectStore>> m_createdObjectStores; | 210 // Only valid for versionchange transactions. |
211 HeapHashMap<Member<IDBObjectStore>, RefPtr<IDBObjectStoreMetadata>> | |
212 m_oldStoreMetadata; | |
192 | 213 |
193 // Used to notify object stores (which are no longer in m_objectStoreMap) | 214 // The metadata of deleted object stores without IDBObjectStore instances. |
194 // when the transaction is finished. | 215 // |
195 HeapHashSet<Member<IDBObjectStore>> m_deletedObjectStores; | 216 // Only valid for versionchange transactions. |
217 Vector<RefPtr<IDBObjectStoreMetadata>> m_deletedObjectStores; | |
196 | 218 |
197 // Holds stores created, deleted, or used during upgrade transactions to | 219 // Tracks the indexes deleted by this transaction. |
198 // reset metadata in case of abort. | 220 // |
199 HeapHashMap<Member<IDBObjectStore>, IDBObjectStoreMetadata> | 221 // This set only includes indexes that were created before this transaction, |
200 m_objectStoreCleanupMap; | 222 // and were deleted during this transaction. Once marked for deletion, these |
223 // indexes are removed from their object stores' index maps, so we need to | |
224 // stash them somewhere else in case the transaction gets aborted. | |
225 // | |
226 // This set does not include indexes created and deleted during this | |
227 // transaction, because we don't need to change their metadata when the | |
228 // transaction aborts, as they will still be marked for deletion. | |
229 // | |
230 // Only valid for versionchange transactions. | |
231 HeapVector<Member<IDBIndex>> m_deletedIndexes; | |
cmumford
2016/10/05 21:15:27
I wonder if we can/should make an IDBVersionChange
pwnall
2016/10/05 23:15:45
I was thinking about the same thing!!
I tried it
jsbell
2016/10/06 20:01:31
Agreed, separate CL.
(Perf is almost certainly no
| |
201 | 232 |
233 // Shallow snapshot of the database metadata when the transaction starts. | |
234 // | |
235 // This does not include a snapshot of the database's object store / index | |
236 // metadata. | |
237 // | |
238 // Only valid for versionchange transactions. | |
202 IDBDatabaseMetadata m_oldDatabaseMetadata; | 239 IDBDatabaseMetadata m_oldDatabaseMetadata; |
203 }; | 240 }; |
204 | 241 |
205 } // namespace blink | 242 } // namespace blink |
206 | 243 |
207 #endif // IDBTransaction_h | 244 #endif // IDBTransaction_h |
OLD | NEW |