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 29 matching lines...) Expand all Loading... | |
40 #include "modules/indexeddb/IDBOpenDBRequest.h" | 40 #include "modules/indexeddb/IDBOpenDBRequest.h" |
41 #include "modules/indexeddb/IDBTracing.h" | 41 #include "modules/indexeddb/IDBTracing.h" |
42 | 42 |
43 using blink::WebIDBDatabase; | 43 using blink::WebIDBDatabase; |
44 | 44 |
45 namespace blink { | 45 namespace blink { |
46 | 46 |
47 IDBTransaction* IDBTransaction::create(ScriptState* scriptState, int64_t id, con st HashSet<String>& objectStoreNames, WebIDBTransactionMode mode, IDBDatabase* d b) | 47 IDBTransaction* IDBTransaction::create(ScriptState* scriptState, int64_t id, con st HashSet<String>& objectStoreNames, WebIDBTransactionMode mode, IDBDatabase* d b) |
48 { | 48 { |
49 IDBOpenDBRequest* openDBRequest = nullptr; | 49 IDBOpenDBRequest* openDBRequest = nullptr; |
50 IDBTransaction* transaction = new IDBTransaction(scriptState, id, objectStor eNames, mode, db, openDBRequest, IDBDatabaseMetadata()); | 50 return new IDBTransaction(scriptState, id, objectStoreNames, mode, db, openD BRequest, IDBDatabaseMetadata()); |
51 transaction->suspendIfNeeded(); | |
52 return transaction; | |
53 } | 51 } |
54 | 52 |
55 IDBTransaction* IDBTransaction::create(ScriptState* scriptState, int64_t id, IDB Database* db, IDBOpenDBRequest* openDBRequest, const IDBDatabaseMetadata& previo usMetadata) | 53 IDBTransaction* IDBTransaction::create(ScriptState* scriptState, int64_t id, IDB Database* db, IDBOpenDBRequest* openDBRequest, const IDBDatabaseMetadata& previo usMetadata) |
56 { | 54 { |
57 IDBTransaction* transaction = new IDBTransaction(scriptState, id, HashSet<St ring>(), WebIDBTransactionModeVersionChange, db, openDBRequest, previousMetadata ); | 55 return new IDBTransaction(scriptState, id, HashSet<String>(), WebIDBTransact ionModeVersionChange, db, openDBRequest, previousMetadata); |
58 transaction->suspendIfNeeded(); | |
59 return transaction; | |
60 } | 56 } |
61 | 57 |
62 namespace { | 58 namespace { |
63 | 59 |
64 class DeactivateTransactionTask : public V8PerIsolateData::EndOfScopeTask { | 60 class DeactivateTransactionTask : public V8PerIsolateData::EndOfScopeTask { |
65 public: | 61 public: |
66 static PassOwnPtr<DeactivateTransactionTask> create(IDBTransaction* transact ion) | 62 static PassOwnPtr<DeactivateTransactionTask> create(IDBTransaction* transact ion) |
67 { | 63 { |
68 return adoptPtr(new DeactivateTransactionTask(transaction)); | 64 return adoptPtr(new DeactivateTransactionTask(transaction)); |
69 } | 65 } |
70 | 66 |
71 void run() override | 67 void run() override |
72 { | 68 { |
73 m_transaction->setActive(false); | 69 m_transaction->setActive(false); |
74 m_transaction.clear(); | 70 m_transaction.clear(); |
75 } | 71 } |
76 | 72 |
77 private: | 73 private: |
78 explicit DeactivateTransactionTask(IDBTransaction* transaction) | 74 explicit DeactivateTransactionTask(IDBTransaction* transaction) |
79 : m_transaction(transaction) { } | 75 : m_transaction(transaction) { } |
80 | 76 |
81 Persistent<IDBTransaction> m_transaction; | 77 Persistent<IDBTransaction> m_transaction; |
82 }; | 78 }; |
83 | 79 |
84 } // namespace | 80 } // namespace |
85 | 81 |
86 IDBTransaction::IDBTransaction(ScriptState* scriptState, int64_t id, const HashS et<String>& objectStoreNames, WebIDBTransactionMode mode, IDBDatabase* db, IDBOp enDBRequest* openDBRequest, const IDBDatabaseMetadata& previousMetadata) | 82 IDBTransaction::IDBTransaction(ScriptState* scriptState, int64_t id, const HashS et<String>& objectStoreNames, WebIDBTransactionMode mode, IDBDatabase* db, IDBOp enDBRequest* openDBRequest, const IDBDatabaseMetadata& previousMetadata) |
87 : ActiveDOMObject(scriptState->executionContext()) | 83 : ContextLifecycleObserver(scriptState->executionContext()) |
88 , m_id(id) | 84 , m_id(id) |
89 , m_database(db) | 85 , m_database(db) |
90 , m_objectStoreNames(objectStoreNames) | 86 , m_objectStoreNames(objectStoreNames) |
91 , m_openDBRequest(openDBRequest) | 87 , m_openDBRequest(openDBRequest) |
92 , m_mode(mode) | 88 , m_mode(mode) |
93 , m_previousMetadata(previousMetadata) | 89 , m_previousMetadata(previousMetadata) |
94 { | 90 { |
95 if (mode == WebIDBTransactionModeVersionChange) { | 91 if (mode == WebIDBTransactionModeVersionChange) { |
96 // Not active until the callback. | 92 // Not active until the callback. |
97 m_state = Inactive; | 93 m_state = Inactive; |
98 } | 94 } |
99 | 95 |
100 if (m_state == Active) | 96 if (m_state == Active) |
101 V8PerIsolateData::from(scriptState->isolate())->addEndOfScopeTask(Deacti vateTransactionTask::create(this)); | 97 V8PerIsolateData::from(scriptState->isolate())->addEndOfScopeTask(Deacti vateTransactionTask::create(this)); |
102 m_database->transactionCreated(this); | 98 m_database->transactionCreated(this); |
103 } | 99 } |
104 | 100 |
105 IDBTransaction::~IDBTransaction() | 101 IDBTransaction::~IDBTransaction() |
106 { | 102 { |
107 ASSERT(m_state == Finished || m_contextStopped); | 103 ASSERT(m_state == Finished || !executionContext()); |
108 ASSERT(m_requestList.isEmpty() || m_contextStopped); | 104 ASSERT(m_requestList.isEmpty() || !executionContext()); |
109 } | 105 } |
110 | 106 |
111 DEFINE_TRACE(IDBTransaction) | 107 DEFINE_TRACE(IDBTransaction) |
112 { | 108 { |
113 visitor->trace(m_database); | 109 visitor->trace(m_database); |
114 visitor->trace(m_openDBRequest); | 110 visitor->trace(m_openDBRequest); |
115 visitor->trace(m_error); | 111 visitor->trace(m_error); |
116 visitor->trace(m_requestList); | 112 visitor->trace(m_requestList); |
117 visitor->trace(m_objectStoreMap); | 113 visitor->trace(m_objectStoreMap); |
118 visitor->trace(m_deletedObjectStores); | 114 visitor->trace(m_deletedObjectStores); |
119 visitor->trace(m_objectStoreCleanupMap); | 115 visitor->trace(m_objectStoreCleanupMap); |
120 RefCountedGarbageCollectedEventTargetWithInlineData<IDBTransaction>::trace(v isitor); | 116 RefCountedGarbageCollectedEventTargetWithInlineData<IDBTransaction>::trace(v isitor); |
121 ActiveDOMObject::trace(visitor); | 117 ContextLifecycleObserver::trace(visitor); |
122 } | 118 } |
123 | 119 |
124 void IDBTransaction::setError(DOMException* error) | 120 void IDBTransaction::setError(DOMException* error) |
125 { | 121 { |
126 ASSERT(m_state != Finished); | 122 ASSERT(m_state != Finished); |
127 ASSERT(error); | 123 ASSERT(error); |
128 | 124 |
129 // The first error to be set is the true cause of the | 125 // The first error to be set is the true cause of the |
130 // transaction abort. | 126 // transaction abort. |
131 if (!m_error) { | 127 if (!m_error) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 | 195 |
200 void IDBTransaction::abort(ExceptionState& exceptionState) | 196 void IDBTransaction::abort(ExceptionState& exceptionState) |
201 { | 197 { |
202 if (m_state == Finishing || m_state == Finished) { | 198 if (m_state == Finishing || m_state == Finished) { |
203 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::transac tionFinishedErrorMessage); | 199 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::transac tionFinishedErrorMessage); |
204 return; | 200 return; |
205 } | 201 } |
206 | 202 |
207 m_state = Finishing; | 203 m_state = Finishing; |
208 | 204 |
209 if (m_contextStopped) | 205 if (!executionContext()) |
210 return; | 206 return; |
211 | 207 |
212 for (IDBRequest* request : m_requestList) | 208 for (IDBRequest* request : m_requestList) |
213 request->abort(); | 209 request->abort(); |
214 m_requestList.clear(); | 210 m_requestList.clear(); |
215 | 211 |
216 if (backendDB()) | 212 if (backendDB()) |
217 backendDB()->abort(m_id); | 213 backendDB()->abort(m_id); |
218 } | 214 } |
219 | 215 |
220 void IDBTransaction::registerRequest(IDBRequest* request) | 216 void IDBTransaction::registerRequest(IDBRequest* request) |
221 { | 217 { |
222 ASSERT(request); | 218 ASSERT(request); |
223 ASSERT(m_state == Active); | 219 ASSERT(m_state == Active); |
224 m_requestList.add(request); | 220 m_requestList.add(request); |
225 } | 221 } |
226 | 222 |
227 void IDBTransaction::unregisterRequest(IDBRequest* request) | 223 void IDBTransaction::unregisterRequest(IDBRequest* request) |
228 { | 224 { |
229 ASSERT(request); | 225 ASSERT(request); |
230 // If we aborted the request, it will already have been removed. | 226 // If we aborted the request, it will already have been removed. |
231 m_requestList.remove(request); | 227 m_requestList.remove(request); |
232 } | 228 } |
233 | 229 |
234 void IDBTransaction::onAbort(DOMException* error) | 230 void IDBTransaction::onAbort(DOMException* error) |
235 { | 231 { |
236 IDB_TRACE("IDBTransaction::onAbort"); | 232 IDB_TRACE("IDBTransaction::onAbort"); |
237 if (m_contextStopped) { | 233 if (!executionContext()) { |
238 m_database->transactionFinished(this); | 234 m_database->transactionFinished(this); |
239 return; | 235 return; |
240 } | 236 } |
241 | 237 |
242 ASSERT(m_state != Finished); | 238 ASSERT(m_state != Finished); |
243 if (m_state != Finishing) { | 239 if (m_state != Finishing) { |
244 ASSERT(error); | 240 ASSERT(error); |
245 setError(error); | 241 setError(error); |
246 | 242 |
247 // Abort was not triggered by front-end, so outstanding requests must | 243 // Abort was not triggered by front-end, so outstanding requests must |
(...skipping 15 matching lines...) Expand all Loading... | |
263 | 259 |
264 // Enqueue events before notifying database, as database may close which enq ueues more events and order matters. | 260 // Enqueue events before notifying database, as database may close which enq ueues more events and order matters. |
265 enqueueEvent(Event::createBubble(EventTypeNames::abort)); | 261 enqueueEvent(Event::createBubble(EventTypeNames::abort)); |
266 | 262 |
267 m_database->transactionFinished(this); | 263 m_database->transactionFinished(this); |
268 } | 264 } |
269 | 265 |
270 void IDBTransaction::onComplete() | 266 void IDBTransaction::onComplete() |
271 { | 267 { |
272 IDB_TRACE("IDBTransaction::onComplete"); | 268 IDB_TRACE("IDBTransaction::onComplete"); |
273 if (m_contextStopped) { | 269 if (!executionContext()) { |
274 m_database->transactionFinished(this); | 270 m_database->transactionFinished(this); |
275 return; | 271 return; |
276 } | 272 } |
277 | 273 |
278 ASSERT(m_state != Finished); | 274 ASSERT(m_state != Finished); |
279 m_state = Finishing; | 275 m_state = Finishing; |
280 m_objectStoreCleanupMap.clear(); | 276 m_objectStoreCleanupMap.clear(); |
281 | 277 |
282 // Enqueue events before notifying database, as database may close which enq ueues more events and order matters. | 278 // Enqueue events before notifying database, as database may close which enq ueues more events and order matters. |
283 enqueueEvent(Event::create(EventTypeNames::complete)); | 279 enqueueEvent(Event::create(EventTypeNames::complete)); |
284 | 280 |
285 m_database->transactionFinished(this); | 281 m_database->transactionFinished(this); |
286 } | 282 } |
287 | 283 |
288 bool IDBTransaction::hasPendingActivity() const | 284 bool IDBTransaction::hasPendingActivity() const |
289 { | 285 { |
290 // FIXME: In an ideal world, we should return true as long as anyone has a o r can | 286 // FIXME: In an ideal world, we should return true as long as anyone has a o r can |
291 // get a handle to us or any child request object and any of those ha ve | 287 // get a handle to us or any child request object and any of those ha ve |
292 // event listeners. This is in order to handle user generated events properly. | 288 // event listeners. This is in order to handle user generated events properly. |
293 return m_hasPendingActivity && !m_contextStopped; | 289 return m_hasPendingActivity && executionContext(); |
294 } | 290 } |
295 | 291 |
296 WebIDBTransactionMode IDBTransaction::stringToMode(const String& modeString) | 292 WebIDBTransactionMode IDBTransaction::stringToMode(const String& modeString) |
297 { | 293 { |
298 if (modeString == IndexedDBNames::readonly) | 294 if (modeString == IndexedDBNames::readonly) |
299 return WebIDBTransactionModeReadOnly; | 295 return WebIDBTransactionModeReadOnly; |
300 if (modeString == IndexedDBNames::readwrite) | 296 if (modeString == IndexedDBNames::readwrite) |
301 return WebIDBTransactionModeReadWrite; | 297 return WebIDBTransactionModeReadWrite; |
302 if (modeString == IndexedDBNames::versionchange) | 298 if (modeString == IndexedDBNames::versionchange) |
303 return WebIDBTransactionModeVersionChange; | 299 return WebIDBTransactionModeVersionChange; |
(...skipping 30 matching lines...) Expand all Loading... | |
334 return objectStoreNames.release(); | 330 return objectStoreNames.release(); |
335 } | 331 } |
336 | 332 |
337 const AtomicString& IDBTransaction::interfaceName() const | 333 const AtomicString& IDBTransaction::interfaceName() const |
338 { | 334 { |
339 return EventTargetNames::IDBTransaction; | 335 return EventTargetNames::IDBTransaction; |
340 } | 336 } |
341 | 337 |
342 ExecutionContext* IDBTransaction::executionContext() const | 338 ExecutionContext* IDBTransaction::executionContext() const |
343 { | 339 { |
344 return ActiveDOMObject::executionContext(); | 340 return ContextLifecycleObserver::executionContext(); |
345 } | 341 } |
346 | 342 |
347 DispatchEventResult IDBTransaction::dispatchEventInternal(PassRefPtrWillBeRawPtr <Event> event) | 343 DispatchEventResult IDBTransaction::dispatchEventInternal(PassRefPtrWillBeRawPtr <Event> event) |
348 { | 344 { |
349 IDB_TRACE("IDBTransaction::dispatchEvent"); | 345 IDB_TRACE("IDBTransaction::dispatchEvent"); |
350 if (m_contextStopped || !executionContext()) { | 346 if (!executionContext()) { |
351 m_state = Finished; | 347 m_state = Finished; |
352 return DispatchEventResult::CanceledBeforeDispatch; | 348 return DispatchEventResult::CanceledBeforeDispatch; |
353 } | 349 } |
354 ASSERT(m_state != Finished); | 350 ASSERT(m_state != Finished); |
355 ASSERT(m_hasPendingActivity); | 351 ASSERT(m_hasPendingActivity); |
356 ASSERT(executionContext()); | 352 ASSERT(executionContext()); |
357 ASSERT(event->target() == this); | 353 ASSERT(event->target() == this); |
358 m_state = Finished; | 354 m_state = Finished; |
359 | 355 |
360 // Break reference cycles. | 356 // Break reference cycles. |
(...skipping 14 matching lines...) Expand all Loading... | |
375 // FIXME: Try to construct a test where |this| outlives openDBRequest and we | 371 // FIXME: Try to construct a test where |this| outlives openDBRequest and we |
376 // get a crash. | 372 // get a crash. |
377 if (m_openDBRequest) { | 373 if (m_openDBRequest) { |
378 ASSERT(isVersionChange()); | 374 ASSERT(isVersionChange()); |
379 m_openDBRequest->transactionDidFinishAndDispatch(); | 375 m_openDBRequest->transactionDidFinishAndDispatch(); |
380 } | 376 } |
381 m_hasPendingActivity = false; | 377 m_hasPendingActivity = false; |
382 return dispatchResult; | 378 return dispatchResult; |
383 } | 379 } |
384 | 380 |
385 void IDBTransaction::stop() | 381 void IDBTransaction::contextDestroyed() |
386 { | 382 { |
387 if (m_contextStopped) | |
388 return; | |
389 | |
390 m_contextStopped = true; | |
391 | |
392 abort(IGNORE_EXCEPTION); | 383 abort(IGNORE_EXCEPTION); |
sof
2016/03/01 07:04:26
afaict, the abort() call here used to be a no-op.
| |
393 } | 384 } |
394 | 385 |
395 void IDBTransaction::enqueueEvent(PassRefPtrWillBeRawPtr<Event> event) | 386 void IDBTransaction::enqueueEvent(PassRefPtrWillBeRawPtr<Event> event) |
396 { | 387 { |
397 ASSERT_WITH_MESSAGE(m_state != Finished, "A finished transaction tried to en queue an event of type %s.", event->type().utf8().data()); | 388 ASSERT_WITH_MESSAGE(m_state != Finished, "A finished transaction tried to en queue an event of type %s.", event->type().utf8().data()); |
398 if (m_contextStopped || !executionContext()) | 389 if (!executionContext()) |
399 return; | 390 return; |
400 | 391 |
401 EventQueue* eventQueue = executionContext()->eventQueue(); | 392 EventQueue* eventQueue = executionContext()->eventQueue(); |
402 event->setTarget(this); | 393 event->setTarget(this); |
403 eventQueue->enqueueEvent(event); | 394 eventQueue->enqueueEvent(event); |
404 } | 395 } |
405 | 396 |
406 WebIDBDatabase* IDBTransaction::backendDB() const | 397 WebIDBDatabase* IDBTransaction::backendDB() const |
407 { | 398 { |
408 return m_database->backend(); | 399 return m_database->backend(); |
409 } | 400 } |
410 | 401 |
411 } // namespace blink | 402 } // namespace blink |
OLD | NEW |