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 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>& objectStoreNames, 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 finish(); | |
|
cmumford
2016/09/19 23:26:48
If the transaction has already finished then this
pwnall
2016/09/20 09:11:15
Done.
| |
| 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; | 134 const HashSet<String> m_scope; |
|
cmumford
2016/09/19 23:26:48
You may want to add a comment above m_scope.
pwnall
2016/09/20 09:11:15
Done.
Thank you! That's a very good point!
| |
| 129 Member<IDBOpenDBRequest> m_openDBRequest; | 135 Member<IDBOpenDBRequest> m_openDBRequest; |
| 130 const WebIDBTransactionMode m_mode; | 136 const WebIDBTransactionMode m_mode; |
| 131 State m_state = Active; | 137 State m_state = Active; |
| 132 bool m_hasPendingActivity = true; | 138 bool m_hasPendingActivity = true; |
| 133 bool m_contextStopped = false; | 139 bool m_contextStopped = false; |
| 134 Member<DOMException> m_error; | 140 Member<DOMException> m_error; |
| 135 | 141 |
| 136 HeapListHashSet<Member<IDBRequest>> m_requestList; | 142 HeapListHashSet<Member<IDBRequest>> m_requestList; |
| 137 | 143 |
| 138 typedef HeapHashMap<String, Member<IDBObjectStore>> IDBObjectStoreMap; | 144 #if DCHECK_IS_ON() |
| 145 bool m_finishCalled = false; | |
| 146 #endif // DCHECK_IS_ON() | |
| 147 | |
| 148 // Caches the IDBObjectStore instances returned by the objectStore() method. | |
| 149 // | |
| 150 // The spec requires that a transaction's objectStore() returns the same | |
| 151 // IDBObjectStore instance for a specific store, so this cache is necessary | |
| 152 // for correctness. | |
| 153 // | |
| 154 // objectStore() throws for completed/aborted transactions, so this is not | |
| 155 // used after a transaction is finished, and can be cleared. | |
| 156 using IDBObjectStoreMap = HeapHashMap<String, Member<IDBObjectStore>>; | |
| 139 IDBObjectStoreMap m_objectStoreMap; | 157 IDBObjectStoreMap m_objectStoreMap; |
| 140 | 158 |
| 141 // Used to mark stores created in an aborted upgrade transaction as | 159 // Used to mark stores created in an aborted upgrade transaction as |
| 142 // deleted. | 160 // deleted. |
| 143 HeapHashSet<Member<IDBObjectStore>> m_createdObjectStores; | 161 HeapHashSet<Member<IDBObjectStore>> m_createdObjectStores; |
| 144 | 162 |
| 145 // Used to notify object stores (which are no longer in m_objectStoreMap) | 163 // Used to notify object stores (which are no longer in m_objectStoreMap) |
| 146 // when the transaction is finished. | 164 // when the transaction is finished. |
| 147 HeapHashSet<Member<IDBObjectStore>> m_deletedObjectStores; | 165 HeapHashSet<Member<IDBObjectStore>> m_deletedObjectStores; |
| 148 | 166 |
| 149 // Holds stores created, deleted, or used during upgrade transactions to | 167 // Holds stores created, deleted, or used during upgrade transactions to |
| 150 // reset metadata in case of abort. | 168 // reset metadata in case of abort. |
| 151 HeapHashMap<Member<IDBObjectStore>, IDBObjectStoreMetadata> m_objectStoreCle anupMap; | 169 HeapHashMap<Member<IDBObjectStore>, IDBObjectStoreMetadata> m_objectStoreCle anupMap; |
| 152 IDBDatabaseMetadata m_previousMetadata; | 170 |
| 171 IDBDatabaseMetadata m_oldDatabaseMetadata; | |
| 153 }; | 172 }; |
| 154 | 173 |
| 155 } // namespace blink | 174 } // namespace blink |
| 156 | 175 |
| 157 #endif // IDBTransaction_h | 176 #endif // IDBTransaction_h |
| OLD | NEW |