Chromium Code Reviews| 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 struct IDBObjectStoreMetadata; | |
| 52 | 53 |
| 53 class MODULES_EXPORT IDBTransaction final | 54 class MODULES_EXPORT IDBTransaction final |
| 54 : public EventTargetWithInlineData | 55 : public EventTargetWithInlineData |
| 55 , public ActiveScriptWrappable | 56 , public ActiveScriptWrappable |
| 56 , public ActiveDOMObject { | 57 , public ActiveDOMObject { |
| 57 USING_GARBAGE_COLLECTED_MIXIN(IDBTransaction); | 58 USING_GARBAGE_COLLECTED_MIXIN(IDBTransaction); |
| 58 DEFINE_WRAPPERTYPEINFO(); | 59 DEFINE_WRAPPERTYPEINFO(); |
| 59 public: | 60 public: |
| 60 static IDBTransaction* create(ScriptState*, int64_t, const HashSet<String>& objectStoreNames, WebIDBTransactionMode, IDBDatabase*); | 61 static IDBTransaction* createNonVersionChange(ScriptState*, int64_t, const H ashSet<String>& objectStoreNames, WebIDBTransactionMode, IDBDatabase*); |
|
jsbell
2016/09/16 18:17:29
Why these renames?
If it's just to avoid the over
pwnall
2016/09/17 01:34:22
The renames document when each create version gets
| |
| 61 static IDBTransaction* create(ScriptState*, int64_t, IDBDatabase*, IDBOpenDB Request*, const IDBDatabaseMetadata& previousMetadata); | 62 static IDBTransaction* createVersionChange(ScriptState*, int64_t, IDBDatabas e*, IDBOpenDBRequest*, const IDBDatabaseOwnMetadata& oldMetadata); |
| 62 ~IDBTransaction() override; | 63 ~IDBTransaction() override; |
| 63 DECLARE_VIRTUAL_TRACE(); | 64 DECLARE_VIRTUAL_TRACE(); |
| 64 | 65 |
| 65 static WebIDBTransactionMode stringToMode(const String&); | 66 static WebIDBTransactionMode stringToMode(const String&); |
| 66 | 67 |
| 67 // When the connection is closed backend will be 0. | 68 // When the connection is closed backend will be 0. |
| 68 WebIDBDatabase* backendDB() const; | 69 WebIDBDatabase* backendDB() const; |
| 69 | 70 |
| 70 int64_t id() const { return m_id; } | 71 int64_t id() const { return m_id; } |
| 71 bool isActive() const { return m_state == Active; } | 72 bool isActive() const { return m_state == Active; } |
| 72 bool isFinished() const { return m_state == Finished; } | 73 bool isFinished() const { return m_state == Finished; } |
| 73 bool isFinishing() const { return m_state == Finishing; } | 74 bool isFinishing() const { return m_state == Finishing; } |
| 74 bool isReadOnly() const { return m_mode == WebIDBTransactionModeReadOnly; } | 75 bool isReadOnly() const { return m_mode == WebIDBTransactionModeReadOnly; } |
| 75 bool isVersionChange() const { return m_mode == WebIDBTransactionModeVersion Change; } | 76 bool isVersionChange() const { return m_mode == WebIDBTransactionModeVersion Change; } |
| 76 | 77 |
| 77 // Implement the IDBTransaction IDL | 78 // Implement the IDBTransaction IDL |
| 78 const String& mode() const; | 79 const String& mode() const; |
| 79 DOMStringList* objectStoreNames() const; | 80 DOMStringList* objectStoreNames() const; |
| 80 IDBDatabase* db() const { return m_database.get(); } | 81 IDBDatabase* db() const { return m_database.get(); } |
| 81 DOMException* error() const { return m_error; } | 82 DOMException* error() const { return m_error; } |
| 82 IDBObjectStore* objectStore(const String& name, ExceptionState&); | 83 IDBObjectStore* objectStore(const String& name, ExceptionState&); |
| 83 void abort(ExceptionState&); | 84 void abort(ExceptionState&); |
| 84 | 85 |
| 85 void registerRequest(IDBRequest*); | 86 void registerRequest(IDBRequest*); |
| 86 void unregisterRequest(IDBRequest*); | 87 void unregisterRequest(IDBRequest*); |
| 87 void objectStoreCreated(const String&, IDBObjectStore*); | 88 |
| 88 void objectStoreDeleted(const String&); | 89 // The methods below are called before the changes are applied to the |
| 90 // database's metadata. | |
|
jsbell
2016/09/16 18:17:29
Can you expand this comment to answer "why?"
pwnall
2016/09/17 01:34:22
Done.
Can you please see if my revision makes sen
| |
| 91 void objectStoreCreated(const String& name, IDBObjectStore*); | |
| 92 void objectStoreDeleted(const int64_t objectStoreId, const String& name); | |
| 89 void objectStoreRenamed(const String& oldName, const String& newName); | 93 void objectStoreRenamed(const String& oldName, const String& newName); |
| 94 void indexDeleted(IDBIndex*); // only called when the index's IDBIndex had b een created | |
| 95 | |
| 90 void setActive(bool); | 96 void setActive(bool); |
| 91 void setError(DOMException*); | 97 void setError(DOMException*); |
| 92 | 98 |
| 93 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); | 99 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); |
| 94 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); | 100 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); |
| 95 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 101 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
| 96 | 102 |
| 97 void onAbort(DOMException*); | 103 void onAbort(DOMException*); |
| 98 void onComplete(); | 104 void onComplete(); |
| 99 | 105 |
| 100 // EventTarget | 106 // EventTarget |
| 101 const AtomicString& interfaceName() const override; | 107 const AtomicString& interfaceName() const override; |
| 102 ExecutionContext* getExecutionContext() const override; | 108 ExecutionContext* getExecutionContext() const override; |
| 103 | 109 |
| 104 // ScriptWrappable | 110 // ScriptWrappable |
| 105 bool hasPendingActivity() const final; | 111 bool hasPendingActivity() const final; |
| 106 | 112 |
| 107 // ActiveDOMObject | 113 // ActiveDOMObject |
| 108 void stop() override; | 114 void stop() override; |
| 109 | 115 |
| 110 protected: | 116 protected: |
| 111 // EventTarget | 117 // EventTarget |
| 112 DispatchEventResult dispatchEventInternal(Event*) override; | 118 DispatchEventResult dispatchEventInternal(Event*) override; |
| 113 | 119 |
| 114 private: | 120 private: |
| 115 IDBTransaction(ScriptState*, int64_t, const HashSet<String>&, WebIDBTransact ionMode, IDBDatabase*, IDBOpenDBRequest*, const IDBDatabaseMetadata&); | 121 IDBTransaction(ScriptState*, int64_t, const HashSet<String>&, WebIDBTransact ionMode, IDBDatabase*, IDBOpenDBRequest*, const IDBDatabaseOwnMetadata&); |
| 116 | 122 |
| 117 void enqueueEvent(Event*); | 123 void enqueueEvent(Event*); |
| 118 | 124 |
| 125 // Called when a transaction is aborted. | |
| 126 void abortOutstandingRequests(); | |
| 127 void revertDatabaseMetadata(); | |
| 128 | |
| 129 // Called when a transaction is completed (committed or aborted). | |
| 130 void finish(); | |
| 131 | |
| 119 enum State { | 132 enum State { |
| 120 Inactive, // Created or started, but not in an event callback | 133 Inactive, // Created or started, but not in an event callback |
| 121 Active, // Created or started, in creation scope or an event callback | 134 Active, // Created or started, in creation scope or an event callback |
| 122 Finishing, // In the process of aborting or completing. | 135 Finishing, // In the process of aborting or completing. |
| 123 Finished, // No more events will fire and no new requests may be filed. | 136 Finished, // No more events will fire and no new requests may be filed. |
| 124 }; | 137 }; |
| 125 | 138 |
| 126 const int64_t m_id; | 139 const int64_t m_id; |
| 127 Member<IDBDatabase> m_database; | 140 Member<IDBDatabase> m_database; |
| 128 const HashSet<String> m_objectStoreNames; | 141 // The name of the object stores that the transaction may operate on. |
| 142 // | |
| 143 // The scope is empty for versionchange transactions, which can operate on | |
| 144 // the entire database. | |
| 145 const HashSet<String> m_scope; | |
| 129 Member<IDBOpenDBRequest> m_openDBRequest; | 146 Member<IDBOpenDBRequest> m_openDBRequest; |
| 130 const WebIDBTransactionMode m_mode; | 147 const WebIDBTransactionMode m_mode; |
| 131 State m_state = Active; | 148 State m_state = Active; |
| 132 bool m_hasPendingActivity = true; | 149 bool m_hasPendingActivity = true; |
| 133 bool m_contextStopped = false; | 150 bool m_contextStopped = false; |
| 134 Member<DOMException> m_error; | 151 Member<DOMException> m_error; |
| 135 | 152 |
| 136 HeapListHashSet<Member<IDBRequest>> m_requestList; | 153 HeapListHashSet<Member<IDBRequest>> m_requestList; |
| 137 | 154 |
| 138 typedef HeapHashMap<String, Member<IDBObjectStore>> IDBObjectStoreMap; | 155 // Caches the IDBObjectStore instances returned by the objectStore() method. |
| 156 // | |
| 157 // The spec requires that a transaction's objectStore() returns the same | |
| 158 // IDBObjectStore instance for a specific store, so this cache is necessary | |
| 159 // for correctness. | |
| 160 // | |
| 161 // The cache may be in an inconsistent state after a transaction is aborted. | |
|
jsbell
2016/09/16 18:17:29
I think this can be simplified to e.g.:
// object
pwnall
2016/09/17 01:34:22
Done.
I also revised the comment on IDBIndex.
| |
| 162 // objectStore() throws for inactive transactions, which makes the cache not | |
| 163 // observable, so reverting the cache would be a waste of resources. | |
| 164 using IDBObjectStoreMap = HeapHashMap<String, Member<IDBObjectStore>>; | |
| 139 IDBObjectStoreMap m_objectStoreMap; | 165 IDBObjectStoreMap m_objectStoreMap; |
| 140 | 166 |
| 141 // Used to mark stores created in an aborted upgrade transaction as | 167 // The metadata of object stores when they are opened by this transaction. |
| 142 // deleted. | 168 // |
| 143 HeapHashSet<Member<IDBObjectStore>> m_createdObjectStores; | 169 // Only valid for versionchange transactions. |
| 170 HeapHashMap<Member<IDBObjectStore>, RefPtr<IDBObjectStoreMetadata>> m_oldSto reMetadata; | |
| 144 | 171 |
| 145 // Used to notify object stores (which are no longer in m_objectStoreMap) | 172 // The metadata of deleted object stores without IDBObjectStore instaces. |
|
jsbell
2016/09/16 18:17:29
typo: instances
pwnall
2016/09/17 01:34:22
Done.
| |
| 146 // when the transaction is finished. | 173 // |
| 147 HeapHashSet<Member<IDBObjectStore>> m_deletedObjectStores; | 174 // Only valid for versionchange transactions. |
| 175 Vector<RefPtr<IDBObjectStoreMetadata>> m_deletedObjectStores; | |
| 148 | 176 |
| 149 // Holds stores created, deleted, or used during upgrade transactions to | 177 // Tracks the indexes deleted by this transaction. |
| 150 // reset metadata in case of abort. | 178 // |
| 151 HeapHashMap<Member<IDBObjectStore>, IDBObjectStoreMetadata> m_objectStoreCle anupMap; | 179 // This set only includes indexes that were created before this transaction, |
| 152 IDBDatabaseMetadata m_previousMetadata; | 180 // and were deleted during this transaction. Once marked for deletion, these |
| 181 // indexes are removed from their object stores' index maps, so we need to | |
| 182 // stash them somewhere else in case the transaction gets aborted. | |
| 183 // | |
| 184 // This set does not include indexes created and deleted during this | |
| 185 // transaction, because we don't need to change their metadata when the | |
| 186 // transaction aborts, as they will still be marked for deletion. | |
| 187 HeapVector<Member<IDBIndex>> m_deletedIndexes; | |
| 188 | |
| 189 // Only valid for versionchange transactions. | |
| 190 IDBDatabaseOwnMetadata m_oldDatabaseMetadata; | |
| 153 }; | 191 }; |
| 154 | 192 |
| 155 } // namespace blink | 193 } // namespace blink |
| 156 | 194 |
| 157 #endif // IDBTransaction_h | 195 #endif // IDBTransaction_h |
| OLD | NEW |