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

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: Rebased. 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 54 class MODULES_EXPORT IDBTransaction final
53 : public EventTargetWithInlineData 55 : public EventTargetWithInlineData
54 , public ActiveScriptWrappable 56 , public ActiveScriptWrappable
55 , public ActiveDOMObject { 57 , public ActiveDOMObject {
56 USING_GARBAGE_COLLECTED_MIXIN(IDBTransaction); 58 USING_GARBAGE_COLLECTED_MIXIN(IDBTransaction);
57 DEFINE_WRAPPERTYPEINFO(); 59 DEFINE_WRAPPERTYPEINFO();
58 public: 60 public:
(...skipping 17 matching lines...) Expand all
76 // Implement the IDBTransaction IDL 78 // Implement the IDBTransaction IDL
77 const String& mode() const; 79 const String& mode() const;
78 DOMStringList* objectStoreNames() const; 80 DOMStringList* objectStoreNames() const;
79 IDBDatabase* db() const { return m_database.get(); } 81 IDBDatabase* db() const { return m_database.get(); }
80 DOMException* error() const { return m_error; } 82 DOMException* error() const { return m_error; }
81 IDBObjectStore* objectStore(const String& name, ExceptionState&); 83 IDBObjectStore* objectStore(const String& name, ExceptionState&);
82 void abort(ExceptionState&); 84 void abort(ExceptionState&);
83 85
84 void registerRequest(IDBRequest*); 86 void registerRequest(IDBRequest*);
85 void unregisterRequest(IDBRequest*); 87 void unregisterRequest(IDBRequest*);
86 void objectStoreCreated(const String&, IDBObjectStore*); 88
87 void objectStoreDeleted(const String&); 89 // The methods below are called right before the changes are applied to the
90 // database's metadata. We use this unusual sequencing because some
91 // implementations need to access the metadata values before the change.
jsbell 2016/09/26 22:23:40 "some implementations" sounds odd; does this mean
pwnall 2016/09/27 00:12:19 I that the implementations of some of the methods
92 void objectStoreCreated(const String& name, IDBObjectStore*);
93 void objectStoreDeleted(const int64_t objectStoreId, const String& name);
88 void objectStoreRenamed(const String& oldName, const String& newName); 94 void objectStoreRenamed(const String& oldName, const String& newName);
95 void indexDeleted(IDBIndex*); // only called when the index's IDBIndex had b een created
96
89 void setActive(bool); 97 void setActive(bool);
90 void setError(DOMException*); 98 void setError(DOMException*);
91 99
92 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); 100 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
93 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); 101 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
94 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 102 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
95 103
96 void onAbort(DOMException*); 104 void onAbort(DOMException*);
97 void onComplete(); 105 void onComplete();
98 106
99 // EventTarget 107 // EventTarget
100 const AtomicString& interfaceName() const override; 108 const AtomicString& interfaceName() const override;
101 ExecutionContext* getExecutionContext() const override; 109 ExecutionContext* getExecutionContext() const override;
102 110
103 // ScriptWrappable 111 // ScriptWrappable
104 bool hasPendingActivity() const final; 112 bool hasPendingActivity() const final;
105 113
106 // ActiveDOMObject 114 // ActiveDOMObject
107 void stop() override; 115 void stop() override;
108 116
117
118 // Object store IDs are allocated sequentially, so we can tell if an object
119 // store was created in this transaction by comparing its ID against the
120 // database's maximum object store ID at the time when the transaction was
121 // started.
122 int64_t oldMaxObjectStoreId() const
jsbell 2016/09/26 22:23:40 This is odd data to expose just for this use case,
pwnall 2016/09/27 00:12:19 TBH, I was trying to be clever and avoid a few (ca
jsbell 2016/10/06 20:01:31 #3 if possible (assuming I'm correct that m_oldMet
pwnall 2016/10/06 22:15:22 Done. We decided on #1 in an offline discussion.
123 {
124 DCHECK(isVersionChange());
125 return m_oldDatabaseMetadata.maxObjectStoreId;
126 }
127
109 protected: 128 protected:
110 // EventTarget 129 // EventTarget
111 DispatchEventResult dispatchEventInternal(Event*) override; 130 DispatchEventResult dispatchEventInternal(Event*) override;
112 131
113 private: 132 private:
114 IDBTransaction(ScriptState*, int64_t, const HashSet<String>&, WebIDBTransact ionMode, IDBDatabase*, IDBOpenDBRequest*, const IDBDatabaseMetadata&); 133 IDBTransaction(ScriptState*, int64_t, const HashSet<String>&, WebIDBTransact ionMode, IDBDatabase*, IDBOpenDBRequest*, const IDBDatabaseMetadata&);
115 134
116 void enqueueEvent(Event*); 135 void enqueueEvent(Event*);
117 136
118 // Called when a transaction is aborted. 137 // Called when a transaction is aborted.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // 181 //
163 // The spec requires that a transaction's objectStore() returns the same 182 // The spec requires that a transaction's objectStore() returns the same
164 // IDBObjectStore instance for a specific store, so this cache is necessary 183 // IDBObjectStore instance for a specific store, so this cache is necessary
165 // for correctness. 184 // for correctness.
166 // 185 //
167 // objectStore() throws for completed/aborted transactions, so this is not 186 // objectStore() throws for completed/aborted transactions, so this is not
168 // used after a transaction is finished, and can be cleared. 187 // used after a transaction is finished, and can be cleared.
169 using IDBObjectStoreMap = HeapHashMap<String, Member<IDBObjectStore>>; 188 using IDBObjectStoreMap = HeapHashMap<String, Member<IDBObjectStore>>;
170 IDBObjectStoreMap m_objectStoreMap; 189 IDBObjectStoreMap m_objectStoreMap;
171 190
172 // Used to mark stores created in an aborted upgrade transaction as 191 // The metadata of object stores when they are opened by this transaction.
173 // deleted. 192 //
174 HeapHashSet<Member<IDBObjectStore>> m_createdObjectStores; 193 // Only valid for versionchange transactions.
194 HeapHashMap<Member<IDBObjectStore>, RefPtr<IDBObjectStoreMetadata>> m_oldSto reMetadata;
jsbell 2016/09/26 22:23:40 What do you think about storing the data on the st
pwnall 2016/09/27 00:12:19 After having explained my rationale above, I will
175 195
176 // Used to notify object stores (which are no longer in m_objectStoreMap) 196 // The metadata of deleted object stores without IDBObjectStore instances.
177 // when the transaction is finished. 197 //
178 HeapHashSet<Member<IDBObjectStore>> m_deletedObjectStores; 198 // Only valid for versionchange transactions.
199 Vector<RefPtr<IDBObjectStoreMetadata>> m_deletedObjectStores;
179 200
180 // Holds stores created, deleted, or used during upgrade transactions to 201 // Tracks the indexes deleted by this transaction.
181 // reset metadata in case of abort. 202 //
182 HeapHashMap<Member<IDBObjectStore>, IDBObjectStoreMetadata> m_objectStoreCle anupMap; 203 // This set only includes indexes that were created before this transaction,
204 // and were deleted during this transaction. Once marked for deletion, these
205 // indexes are removed from their object stores' index maps, so we need to
206 // stash them somewhere else in case the transaction gets aborted.
207 //
208 // This set does not include indexes created and deleted during this
209 // transaction, because we don't need to change their metadata when the
210 // transaction aborts, as they will still be marked for deletion.
211 //
212 // Only valid for versionchange transactions.
213 HeapVector<Member<IDBIndex>> m_deletedIndexes;
183 214
215 // Shallow snapshot of the database metadata when the transaction start.
jsbell 2016/09/26 22:23:40 nit: wording; should that be "starts" ?
pwnall 2016/09/27 00:12:19 Done.
216 //
217 // This does not include a snapshot of the database's object store / index
218 // metadata.
219 //
220 // Only valid for versionchange transactions.
184 IDBDatabaseMetadata m_oldDatabaseMetadata; 221 IDBDatabaseMetadata m_oldDatabaseMetadata;
185 }; 222 };
186 223
187 } // namespace blink 224 } // namespace blink
188 225
189 #endif // IDBTransaction_h 226 #endif // IDBTransaction_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698