Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBTransaction.h

Issue 2314933005: Align IndexedDB metadata rollback on transaction abort to spec. (Closed)
Patch Set: Addressed feedback. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 of the
102 // methods below need to access the metadata values before the change, and
103 // following the same lifecycle for all methods makes the code easier to
104 // reason about.
105 void objectStoreCreated(const String& name, IDBObjectStore*);
106 void objectStoreDeleted(const int64_t objectStoreId, const String& name);
99 void objectStoreRenamed(const String& oldName, const String& newName); 107 void objectStoreRenamed(const String& oldName, const String& newName);
108 // Called when deleting an index whose IDBIndex had been created.
109 void indexDeleted(IDBIndex*);
110
100 void setActive(bool); 111 void setActive(bool);
101 void setError(DOMException*); 112 void setError(DOMException*);
102 113
103 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); 114 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
104 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); 115 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
105 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 116 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
106 117
107 void onAbort(DOMException*); 118 void onAbort(DOMException*);
108 void onComplete(); 119 void onComplete();
109 120
110 // EventTarget 121 // EventTarget
111 const AtomicString& interfaceName() const override; 122 const AtomicString& interfaceName() const override;
112 ExecutionContext* getExecutionContext() const override; 123 ExecutionContext* getExecutionContext() const override;
113 124
114 // ScriptWrappable 125 // ScriptWrappable
115 bool hasPendingActivity() const final; 126 bool hasPendingActivity() const final;
116 127
117 // ActiveDOMObject 128 // ActiveDOMObject
118 void contextDestroyed() override; 129 void contextDestroyed() override;
119 130
131 // Object store IDs are allocated sequentially, so we can tell if an object
132 // store was created in this transaction by comparing its ID against the
133 // database's maximum object store ID at the time when the transaction was
134 // started.
135 int64_t oldMaxObjectStoreId() const {
136 DCHECK(isVersionChange());
137 return m_oldDatabaseMetadata.maxObjectStoreId;
138 }
139
120 protected: 140 protected:
121 // EventTarget 141 // EventTarget
122 DispatchEventResult dispatchEventInternal(Event*) override; 142 DispatchEventResult dispatchEventInternal(Event*) override;
123 143
124 private: 144 private:
145 using IDBObjectStoreMap = HeapHashMap<String, Member<IDBObjectStore>>;
146
125 IDBTransaction(ScriptState*, 147 IDBTransaction(ScriptState*,
126 int64_t, 148 int64_t,
127 const HashSet<String>&, 149 const HashSet<String>&,
128 WebIDBTransactionMode, 150 WebIDBTransactionMode,
129 IDBDatabase*, 151 IDBDatabase*,
130 IDBOpenDBRequest*, 152 IDBOpenDBRequest*,
131 const IDBDatabaseMetadata&); 153 const IDBDatabaseMetadata&);
132 154
133 void enqueueEvent(Event*); 155 void enqueueEvent(Event*);
134 156
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 #endif // DCHECK_IS_ON() 198 #endif // DCHECK_IS_ON()
177 199
178 // Caches the IDBObjectStore instances returned by the objectStore() method. 200 // Caches the IDBObjectStore instances returned by the objectStore() method.
179 // 201 //
180 // The spec requires that a transaction's objectStore() returns the same 202 // The spec requires that a transaction's objectStore() returns the same
181 // IDBObjectStore instance for a specific store, so this cache is necessary 203 // IDBObjectStore instance for a specific store, so this cache is necessary
182 // for correctness. 204 // for correctness.
183 // 205 //
184 // objectStore() throws for completed/aborted transactions, so this is not 206 // objectStore() throws for completed/aborted transactions, so this is not
185 // used after a transaction is finished, and can be cleared. 207 // used after a transaction is finished, and can be cleared.
186 using IDBObjectStoreMap = HeapHashMap<String, Member<IDBObjectStore>>;
187 IDBObjectStoreMap m_objectStoreMap; 208 IDBObjectStoreMap m_objectStoreMap;
188 209
189 // Used to mark stores created in an aborted upgrade transaction as 210 // The metadata of object stores when they are opened by this transaction.
190 // deleted. 211 //
191 HeapHashSet<Member<IDBObjectStore>> m_createdObjectStores; 212 // Only valid for versionchange transactions.
213 HeapHashMap<Member<IDBObjectStore>, RefPtr<IDBObjectStoreMetadata>>
214 m_oldStoreMetadata;
192 215
193 // Used to notify object stores (which are no longer in m_objectStoreMap) 216 // The metadata of deleted object stores without IDBObjectStore instances.
194 // when the transaction is finished. 217 //
195 HeapHashSet<Member<IDBObjectStore>> m_deletedObjectStores; 218 // Only valid for versionchange transactions.
219 Vector<RefPtr<IDBObjectStoreMetadata>> m_deletedObjectStores;
196 220
197 // Holds stores created, deleted, or used during upgrade transactions to 221 // Tracks the indexes deleted by this transaction.
198 // reset metadata in case of abort. 222 //
199 HeapHashMap<Member<IDBObjectStore>, IDBObjectStoreMetadata> 223 // This set only includes indexes that were created before this transaction,
200 m_objectStoreCleanupMap; 224 // and were deleted during this transaction. Once marked for deletion, these
225 // indexes are removed from their object stores' index maps, so we need to
226 // stash them somewhere else in case the transaction gets aborted.
227 //
228 // This set does not include indexes created and deleted during this
229 // transaction, because we don't need to change their metadata when the
230 // transaction aborts, as they will still be marked for deletion.
231 //
232 // Only valid for versionchange transactions.
233 HeapVector<Member<IDBIndex>> m_deletedIndexes;
201 234
235 // Shallow snapshot of the database metadata when the transaction starts.
236 //
237 // This does not include a snapshot of the database's object store / index
238 // metadata.
239 //
240 // Only valid for versionchange transactions.
202 IDBDatabaseMetadata m_oldDatabaseMetadata; 241 IDBDatabaseMetadata m_oldDatabaseMetadata;
203 }; 242 };
204 243
205 } // namespace blink 244 } // namespace blink
206 245
207 #endif // IDBTransaction_h 246 #endif // IDBTransaction_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698