| 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 30 matching lines...) Expand all Loading... |
| 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 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 class DOMException; | 46 class DOMException; |
| 47 class ExceptionState; | 47 class ExceptionState; |
| 48 class IDBDatabase; | 48 class IDBDatabase; |
| 49 class IDBObjectStore; | 49 class IDBObjectStore; |
| 50 class IDBOpenDBRequest; | 50 class IDBOpenDBRequest; |
| 51 struct IDBObjectStoreMetadata; | |
| 52 | 51 |
| 53 class MODULES_EXPORT IDBTransaction final | 52 class MODULES_EXPORT IDBTransaction final |
| 54 : public EventTargetWithInlineData | 53 : public EventTargetWithInlineData |
| 55 , public ActiveScriptWrappable | 54 , public ActiveScriptWrappable |
| 56 , public ActiveDOMObject { | 55 , public ActiveDOMObject { |
| 57 USING_GARBAGE_COLLECTED_MIXIN(IDBTransaction); | 56 USING_GARBAGE_COLLECTED_MIXIN(IDBTransaction); |
| 58 DEFINE_WRAPPERTYPEINFO(); | 57 DEFINE_WRAPPERTYPEINFO(); |
| 59 public: | 58 public: |
| 60 static IDBTransaction* create(ScriptState*, int64_t, const HashSet<String>&
objectStoreNames, WebIDBTransactionMode, IDBDatabase*); | 59 static IDBTransaction* createNonVersionChange(ScriptState*, int64_t, const H
ashSet<String>& scope, WebIDBTransactionMode, IDBDatabase*); |
| 61 static IDBTransaction* create(ScriptState*, int64_t, IDBDatabase*, IDBOpenDB
Request*, const IDBDatabaseMetadata& previousMetadata); | 60 static IDBTransaction* createVersionChange(ScriptState*, int64_t, IDBDatabas
e*, IDBOpenDBRequest*, const IDBDatabaseMetadata& oldMetadata); |
| 62 ~IDBTransaction() override; | 61 ~IDBTransaction() override; |
| 63 DECLARE_VIRTUAL_TRACE(); | 62 DECLARE_VIRTUAL_TRACE(); |
| 64 | 63 |
| 65 static WebIDBTransactionMode stringToMode(const String&); | 64 static WebIDBTransactionMode stringToMode(const String&); |
| 66 | 65 |
| 67 // When the connection is closed backend will be 0. | 66 // When the connection is closed backend will be 0. |
| 68 WebIDBDatabase* backendDB() const; | 67 WebIDBDatabase* backendDB() const; |
| 69 | 68 |
| 70 int64_t id() const { return m_id; } | 69 int64_t id() const { return m_id; } |
| 71 bool isActive() const { return m_state == Active; } | 70 bool isActive() const { return m_state == Active; } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 108 |
| 110 protected: | 109 protected: |
| 111 // EventTarget | 110 // EventTarget |
| 112 DispatchEventResult dispatchEventInternal(Event*) override; | 111 DispatchEventResult dispatchEventInternal(Event*) override; |
| 113 | 112 |
| 114 private: | 113 private: |
| 115 IDBTransaction(ScriptState*, int64_t, const HashSet<String>&, WebIDBTransact
ionMode, IDBDatabase*, IDBOpenDBRequest*, const IDBDatabaseMetadata&); | 114 IDBTransaction(ScriptState*, int64_t, const HashSet<String>&, WebIDBTransact
ionMode, IDBDatabase*, IDBOpenDBRequest*, const IDBDatabaseMetadata&); |
| 116 | 115 |
| 117 void enqueueEvent(Event*); | 116 void enqueueEvent(Event*); |
| 118 | 117 |
| 118 // Called when a transaction is aborted. |
| 119 void abortOutstandingRequests(); |
| 120 void revertDatabaseMetadata(); |
| 121 |
| 122 // Called when a transaction is completed (committed or aborted). |
| 123 void finished(); |
| 124 |
| 119 enum State { | 125 enum State { |
| 120 Inactive, // Created or started, but not in an event callback | 126 Inactive, // Created or started, but not in an event callback |
| 121 Active, // Created or started, in creation scope or an event callback | 127 Active, // Created or started, in creation scope or an event callback |
| 122 Finishing, // In the process of aborting or completing. | 128 Finishing, // In the process of aborting or completing. |
| 123 Finished, // No more events will fire and no new requests may be filed. | 129 Finished, // No more events will fire and no new requests may be filed. |
| 124 }; | 130 }; |
| 125 | 131 |
| 126 const int64_t m_id; | 132 const int64_t m_id; |
| 127 Member<IDBDatabase> m_database; | 133 Member<IDBDatabase> m_database; |
| 128 const HashSet<String> m_objectStoreNames; | |
| 129 Member<IDBOpenDBRequest> m_openDBRequest; | 134 Member<IDBOpenDBRequest> m_openDBRequest; |
| 130 const WebIDBTransactionMode m_mode; | 135 const WebIDBTransactionMode m_mode; |
| 136 |
| 137 // The names of the object stores that make up this transaction's scope. |
| 138 // |
| 139 // Transactions may not access object stores outside their scope. |
| 140 // |
| 141 // The scope of versionchange transactions is the entire database. We |
| 142 // represent this case with an empty m_scope, because copying all the store |
| 143 // names would waste both time and memory. |
| 144 // |
| 145 // Using object store names to represent a transaction's scope is safe |
| 146 // because object stores cannot be renamed in non-versionchange |
| 147 // transactions. |
| 148 const HashSet<String> m_scope; |
| 149 |
| 131 State m_state = Active; | 150 State m_state = Active; |
| 132 bool m_hasPendingActivity = true; | 151 bool m_hasPendingActivity = true; |
| 133 bool m_contextStopped = false; | 152 bool m_contextStopped = false; |
| 134 Member<DOMException> m_error; | 153 Member<DOMException> m_error; |
| 135 | 154 |
| 136 HeapListHashSet<Member<IDBRequest>> m_requestList; | 155 HeapListHashSet<Member<IDBRequest>> m_requestList; |
| 137 | 156 |
| 138 typedef HeapHashMap<String, Member<IDBObjectStore>> IDBObjectStoreMap; | 157 #if DCHECK_IS_ON() |
| 158 bool m_finishCalled = false; |
| 159 #endif // DCHECK_IS_ON() |
| 160 |
| 161 // Caches the IDBObjectStore instances returned by the objectStore() method. |
| 162 // |
| 163 // The spec requires that a transaction's objectStore() returns the same |
| 164 // IDBObjectStore instance for a specific store, so this cache is necessary |
| 165 // for correctness. |
| 166 // |
| 167 // objectStore() throws for completed/aborted transactions, so this is not |
| 168 // used after a transaction is finished, and can be cleared. |
| 169 using IDBObjectStoreMap = HeapHashMap<String, Member<IDBObjectStore>>; |
| 139 IDBObjectStoreMap m_objectStoreMap; | 170 IDBObjectStoreMap m_objectStoreMap; |
| 140 | 171 |
| 141 // Used to mark stores created in an aborted upgrade transaction as | 172 // Used to mark stores created in an aborted upgrade transaction as |
| 142 // deleted. | 173 // deleted. |
| 143 HeapHashSet<Member<IDBObjectStore>> m_createdObjectStores; | 174 HeapHashSet<Member<IDBObjectStore>> m_createdObjectStores; |
| 144 | 175 |
| 145 // Used to notify object stores (which are no longer in m_objectStoreMap) | 176 // Used to notify object stores (which are no longer in m_objectStoreMap) |
| 146 // when the transaction is finished. | 177 // when the transaction is finished. |
| 147 HeapHashSet<Member<IDBObjectStore>> m_deletedObjectStores; | 178 HeapHashSet<Member<IDBObjectStore>> m_deletedObjectStores; |
| 148 | 179 |
| 149 // Holds stores created, deleted, or used during upgrade transactions to | 180 // Holds stores created, deleted, or used during upgrade transactions to |
| 150 // reset metadata in case of abort. | 181 // reset metadata in case of abort. |
| 151 HeapHashMap<Member<IDBObjectStore>, IDBObjectStoreMetadata> m_objectStoreCle
anupMap; | 182 HeapHashMap<Member<IDBObjectStore>, IDBObjectStoreMetadata> m_objectStoreCle
anupMap; |
| 152 IDBDatabaseMetadata m_previousMetadata; | 183 |
| 184 IDBDatabaseMetadata m_oldDatabaseMetadata; |
| 153 }; | 185 }; |
| 154 | 186 |
| 155 } // namespace blink | 187 } // namespace blink |
| 156 | 188 |
| 157 #endif // IDBTransaction_h | 189 #endif // IDBTransaction_h |
| OLD | NEW |