Changeset 135927 in webkit
- Timestamp:
- Nov 27, 2012, 3:08:17 PM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r135922 r135927 1 2012-11-27 Joshua Bell <jsbell@chromium.org> 2 3 IndexedDB: Simplify transaction timers and event tracking 4 https://bugs.webkit.org/show_bug.cgi?id=102984 5 6 Reviewed by Tony Chang. 7 8 Now that the transaction "commit" decision is made on the front-end, the back end no-longer 9 needs to be aware of when individual IDBRequests have dispatched to script or track pending 10 events (except for preemptive ones like createIndex). This also lets two timers be collapsed 11 into one which significantly simplifies the code flow in IDBTransactionBackendImpl. 12 13 No new tests - just simplification. Exercised by storage/indexeddb/transaction-*.html etc. 14 15 * Modules/indexeddb/IDBCursorBackendImpl.cpp: 16 (WebCore::IDBCursorBackendImpl::prefetchContinueInternal): No more tracking. 17 (WebCore::IDBCursorBackendImpl::prefetchReset): No more tracking. 18 * Modules/indexeddb/IDBDatabaseBackendImpl.cpp: 19 (WebCore::IDBDatabaseBackendImpl::createObjectStoreInternal): No more tracking. 20 (WebCore::IDBDatabaseBackendImpl::deleteObjectStoreInternal): No more tracking. 21 * Modules/indexeddb/IDBObjectStoreBackendImpl.cpp: 22 (WebCore::IDBObjectStoreBackendImpl::setIndexesReadyInternal): No more tracking. 23 (WebCore::IDBObjectStoreBackendImpl::createIndexInternal): No more tracking. 24 (WebCore::IDBObjectStoreBackendImpl::deleteIndexInternal): No more tracking. 25 * Modules/indexeddb/IDBRequest.cpp: 26 (WebCore::IDBRequest::dispatchEvent): Order must be: 27 1. request is unregistered from transaction (so request list may be empty) 28 2. abort transaction if event being dispatched was an error 29 3. deactivate transaction (which may commit if #1 left it empty and #2 didn't abort) 30 * Modules/indexeddb/IDBTransactionBackendImpl.cpp: 31 (WebCore::IDBTransactionBackendImpl::IDBTransactionBackendImpl): Need to track if commit 32 was requested; previously the front end would have triggered an event timer which, on 33 completion, would be the signal that the front end was finished. 34 (WebCore::IDBTransactionBackendImpl::scheduleTask): Schedule a timer to service the new 35 task, if necessary. 36 (WebCore::IDBTransactionBackendImpl::abort): 37 (WebCore::IDBTransactionBackendImpl::hasPendingTasks): 38 (WebCore::IDBTransactionBackendImpl::commit): 39 (WebCore::IDBTransactionBackendImpl::taskTimerFired): Picks up "commit" responsibilities 40 from the now deleted taskEventTimerFired, if everything is truly complete done. 41 * Modules/indexeddb/IDBTransactionBackendImpl.h: 42 (IDBTransactionBackendImpl): 43 * Modules/indexeddb/IDBTransactionBackendInterface.h: 44 (WebCore::IDBTransactionBackendInterface::didCompleteTaskEvents): Removed from interface. 45 1 46 2012-11-27 Kentaro Hara <haraken@chromium.org> 2 47 -
trunk/Source/WebCore/Modules/indexeddb/IDBCursorBackendImpl.cpp
r133858 r135927 174 174 } 175 175 176 cursor->m_transaction->addPendingEvents(foundKeys.size() - 1);177 176 callbacks->onSuccessWithPrefetch(foundKeys, foundPrimaryKeys, foundValues); 178 177 } … … 181 180 { 182 181 IDB_TRACE("IDBCursorBackendImpl::prefetchReset"); 183 m_transaction->addPendingEvents(-unusedPrefetches);184 182 m_cursor = m_savedCursor; 185 183 m_savedCursor = 0; -
trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp
r135904 r135927 181 181 return; 182 182 } 183 184 transaction->didCompleteTaskEvents();185 183 } 186 184 … … 211 209 { 212 210 database->m_backingStore->deleteObjectStore(transaction->backingStoreTransaction(), database->id(), objectStore->id()); 213 transaction->didCompleteTaskEvents();214 211 } 215 212 -
trunk/Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp
r135177 r135927 269 269 for (size_t i = 0; i < indexIds->size(); ++i) 270 270 transaction->didCompletePreemptiveEvent(); 271 transaction->didCompleteTaskEvents();272 271 } 273 272 … … 408 407 return; 409 408 } 410 411 transaction->didCompleteTaskEvents();412 409 } 413 410 … … 440 437 { 441 438 objectStore->backingStore()->deleteIndex(transaction->backingStoreTransaction(), objectStore->databaseId(), objectStore->id(), index->id()); 442 transaction->didCompleteTaskEvents();443 439 } 444 440 -
trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp
r135904 r135927 79 79 , m_requestState(context) 80 80 { 81 if (m_transaction) { 81 // Requests associated with IDBFactory (open/deleteDatabase/getDatabaseNames) are not 82 // associated with transactions. 83 if (m_transaction) 82 84 m_transaction->registerRequest(this); 83 }84 85 } 85 86 … … 477 478 bool dontPreventDefault = IDBEventDispatcher::dispatch(event.get(), targets); 478 479 479 if (m_transaction && m_readyState == DONE)480 m_transaction->unregisterRequest(this);481 482 // If this was the last request in the transaction's list, it may commit here.483 if (setTransactionActive)484 m_transaction->setActive(false);485 486 if (cursorToNotify)487 cursorToNotify->postSuccessHandlerCallback();488 489 if (m_readyState == DONE && (!cursorToNotify || m_cursorFinished) && event->type() != eventNames().upgradeneededEvent)490 m_hasPendingActivity = false;491 492 480 if (m_transaction) { 481 if (m_readyState == DONE) 482 m_transaction->unregisterRequest(this); 483 484 // Possibly abort the transaction. This must occur after unregistering (so this request 485 // doesn't receive a second error) and before deactivating (which might trigger commit). 493 486 if (event->type() == eventNames().errorEvent && dontPreventDefault && !m_requestAborted) { 494 487 m_transaction->setError(m_error); … … 497 490 } 498 491 499 if (event->type() != eventNames().blockedEvent) 500 m_transaction->backend()->didCompleteTaskEvents(); 501 } 492 // If this was the last request in the transaction's list, it may commit here. 493 if (setTransactionActive) 494 m_transaction->setActive(false); 495 } 496 497 if (cursorToNotify) 498 cursorToNotify->postSuccessHandlerCallback(); 499 500 if (m_readyState == DONE && (!cursorToNotify || m_cursorFinished) && event->type() != eventNames().upgradeneededEvent) 501 m_hasPendingActivity = false; 502 502 503 503 return dontPreventDefault; -
trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendImpl.cpp
r135856 r135927 50 50 , m_mode(mode) 51 51 , m_state(Unused) 52 , m_commitPending(false) 52 53 , m_database(database) 53 54 , m_transaction(database->backingStore().get()) 54 55 , m_taskTimer(this, &IDBTransactionBackendImpl::taskTimerFired) 55 , m_taskEventTimer(this, &IDBTransactionBackendImpl::taskEventTimerFired)56 56 , m_pendingPreemptiveEvents(0) 57 , m_pendingEvents(0)58 57 { 59 58 m_database->transactionCoordinator()->didCreateTransaction(this); … … 93 92 if (m_state == Unused) 94 93 start(); 94 else if (m_state == Running && !m_taskTimer.isActive()) 95 m_taskTimer.startOneShot(0); 95 96 96 97 return true; … … 117 118 m_state = Finished; 118 119 m_taskTimer.stop(); 119 m_taskEventTimer.stop();120 120 121 121 if (wasRunning) … … 155 155 bool IDBTransactionBackendImpl::hasPendingTasks() const 156 156 { 157 return m_pending Events || m_pendingPreemptiveEvents || !isTaskQueueEmpty();157 return m_pendingPreemptiveEvents || !isTaskQueueEmpty(); 158 158 } 159 159 … … 166 166 { 167 167 m_openCursors.remove(cursor); 168 }169 170 void IDBTransactionBackendImpl::addPendingEvents(int n)171 {172 m_pendingEvents += n;173 ASSERT(m_pendingEvents >= 0);174 }175 176 void IDBTransactionBackendImpl::didCompleteTaskEvents()177 {178 if (m_state == Finished)179 return;180 181 ASSERT(m_state == Running);182 ASSERT(m_pendingEvents);183 m_pendingEvents--;184 185 // A single task has completed and error/success events fired. Schedule186 // timer to process another.187 if (!m_taskEventTimer.isActive())188 m_taskEventTimer.startOneShot(0);189 168 } 190 169 … … 213 192 214 193 ASSERT(m_state == Unused || m_state == Running); 194 m_commitPending = true; 215 195 216 196 // Front-end has requested a commit, but there may be tasks like createIndex which … … 271 251 ASSERT(m_state == Running); 272 252 OwnPtr<ScriptExecutionContext::Task> task(taskQueue->takeFirst()); 273 m_pendingEvents++;274 253 task->performTask(0); 275 254 … … 277 256 taskQueue = m_pendingPreemptiveEvents ? &m_preemptiveTaskQueue : &m_taskQueue; 278 257 } 279 } 280 281 void IDBTransactionBackendImpl::taskEventTimerFired(Timer<IDBTransactionBackendImpl>*) 282 { 283 IDB_TRACE("IDBTransactionBackendImpl::taskEventTimerFired"); 284 ASSERT(m_state == Running); 285 286 if (!hasPendingTasks()) { 287 // The last task event has completed and the task 288 // queue is empty. Commit the transaction. 258 259 // If there are no pending tasks, we haven't already committed/aborted, 260 // and the front-end requested a commit, it is now safe to do so. 261 if (!hasPendingTasks() && m_state != Finished && m_commitPending) 289 262 commit(); 290 return;291 }292 293 // We are still waiting for other events to complete. However,294 // the task queue is non-empty and the timer is inactive.295 // We can therfore schedule the timer again.296 if (!isTaskQueueEmpty() && !m_taskTimer.isActive())297 m_taskTimer.startOneShot(0);298 263 } 299 264 -
trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendImpl.h
r135856 r135927 54 54 // IDBTransactionBackendInterface 55 55 virtual PassRefPtr<IDBObjectStoreBackendInterface> objectStore(int64_t, ExceptionCode&); 56 virtual void didCompleteTaskEvents();57 56 virtual void abort(); 58 57 virtual void setCallbacks(IDBTransactionCallbacks* callbacks) { m_callbacks = callbacks; } … … 65 64 void registerOpenCursor(IDBCursorBackendImpl*); 66 65 void unregisterOpenCursor(IDBCursorBackendImpl*); 67 void addPendingEvents(int);68 66 void addPreemptiveEvent() { m_pendingPreemptiveEvents++; } 69 67 void didCompletePreemptiveEvent() { m_pendingPreemptiveEvents--; ASSERT(m_pendingPreemptiveEvents >= 0); } … … 88 86 89 87 void taskTimerFired(Timer<IDBTransactionBackendImpl>*); 90 void taskEventTimerFired(Timer<IDBTransactionBackendImpl>*);91 88 void closeOpenCursors(); 92 89 … … 96 93 97 94 State m_state; 95 bool m_commitPending; 98 96 RefPtr<IDBTransactionCallbacks> m_callbacks; 99 97 RefPtr<IDBDatabaseBackendImpl> m_database; … … 108 106 // FIXME: delete the timer once we have threads instead. 109 107 Timer<IDBTransactionBackendImpl> m_taskTimer; 110 Timer<IDBTransactionBackendImpl> m_taskEventTimer;111 108 int m_pendingPreemptiveEvents; 112 int m_pendingEvents;113 109 114 110 HashSet<IDBCursorBackendImpl*> m_openCursors; -
trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendInterface.h
r134095 r135927 55 55 56 56 virtual PassRefPtr<IDBObjectStoreBackendInterface> objectStore(int64_t, ExceptionCode&) = 0; 57 virtual void didCompleteTaskEvents() = 0;58 57 virtual void commit() = 0; 59 58 virtual void abort() = 0; -
trunk/Source/WebKit/chromium/ChangeLog
r135911 r135927 1 2012-11-27 Joshua Bell <jsbell@chromium.org> 2 3 IndexedDB: Simplify transaction timers and event tracking 4 https://bugs.webkit.org/show_bug.cgi?id=102984 5 6 Reviewed by Tony Chang. 7 8 Remove now-unused didCompleteTaskEvents() method. 9 10 * src/IDBTransactionBackendProxy.cpp: 11 * src/IDBTransactionBackendProxy.h: 12 (IDBTransactionBackendProxy): 13 * src/WebIDBTransactionImpl.cpp: 14 * src/WebIDBTransactionImpl.h: 15 1 16 2012-11-27 Alpha Lam <hclam@chromium.org> 2 17 -
trunk/Source/WebKit/chromium/src/IDBTransactionBackendProxy.cpp
r134436 r135927 73 73 } 74 74 75 void IDBTransactionBackendProxy::didCompleteTaskEvents()76 {77 m_webIDBTransaction->didCompleteTaskEvents();78 }79 80 75 void IDBTransactionBackendProxy::setCallbacks(IDBTransactionCallbacks* callbacks) 81 76 { -
trunk/Source/WebKit/chromium/src/IDBTransactionBackendProxy.h
r134436 r135927 45 45 virtual void commit(); 46 46 virtual void abort(); 47 virtual void didCompleteTaskEvents();48 47 virtual void setCallbacks(WebCore::IDBTransactionCallbacks*); 49 48 -
trunk/Source/WebKit/chromium/src/WebIDBTransactionImpl.cpp
r134095 r135927 66 66 } 67 67 68 void WebIDBTransactionImpl::didCompleteTaskEvents()69 {70 m_backend->didCompleteTaskEvents();71 }72 73 68 void WebIDBTransactionImpl::setCallbacks(WebIDBTransactionCallbacks* callbacks) 74 69 { -
trunk/Source/WebKit/chromium/src/WebIDBTransactionImpl.h
r134095 r135927 45 45 virtual void commit(); 46 46 virtual void abort(); 47 virtual void didCompleteTaskEvents();48 47 virtual void setCallbacks(WebIDBTransactionCallbacks*); 49 48
Note:
See TracChangeset
for help on using the changeset viewer.