| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2013 Apple 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 14 matching lines...) Expand all Loading... |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "modules/webdatabase/SQLTransactionBackend.h" | 30 #include "modules/webdatabase/SQLTransactionBackend.h" |
| 31 | 31 |
| 32 #include "platform/Logging.h" | 32 #include "platform/Logging.h" |
| 33 #include "modules/webdatabase/sqlite/SQLValue.h" | 33 #include "modules/webdatabase/sqlite/SQLValue.h" |
| 34 #include "modules/webdatabase/sqlite/SQLiteTransaction.h" | 34 #include "modules/webdatabase/sqlite/SQLiteTransaction.h" |
| 35 #include "modules/webdatabase/AbstractSQLTransaction.h" | |
| 36 #include "modules/webdatabase/Database.h" // FIXME: Should only be used in the f
rontend. | 35 #include "modules/webdatabase/Database.h" // FIXME: Should only be used in the f
rontend. |
| 37 #include "modules/webdatabase/DatabaseAuthorizer.h" | 36 #include "modules/webdatabase/DatabaseAuthorizer.h" |
| 38 #include "modules/webdatabase/DatabaseBackend.h" | 37 #include "modules/webdatabase/DatabaseBackend.h" |
| 39 #include "modules/webdatabase/DatabaseContext.h" | 38 #include "modules/webdatabase/DatabaseContext.h" |
| 40 #include "modules/webdatabase/DatabaseThread.h" | 39 #include "modules/webdatabase/DatabaseThread.h" |
| 41 #include "modules/webdatabase/DatabaseTracker.h" | 40 #include "modules/webdatabase/DatabaseTracker.h" |
| 42 #include "modules/webdatabase/SQLError.h" | 41 #include "modules/webdatabase/SQLError.h" |
| 43 #include "modules/webdatabase/SQLStatementBackend.h" | 42 #include "modules/webdatabase/SQLStatementBackend.h" |
| 43 #include "modules/webdatabase/SQLTransaction.h" |
| 44 #include "modules/webdatabase/SQLTransactionClient.h" | 44 #include "modules/webdatabase/SQLTransactionClient.h" |
| 45 #include "modules/webdatabase/SQLTransactionCoordinator.h" | 45 #include "modules/webdatabase/SQLTransactionCoordinator.h" |
| 46 #include "wtf/StdLibExtras.h" | 46 #include "wtf/StdLibExtras.h" |
| 47 | 47 |
| 48 | 48 |
| 49 // How does a SQLTransaction work? | 49 // How does a SQLTransaction work? |
| 50 // ============================== | 50 // ============================== |
| 51 // The SQLTransaction is a state machine that executes a series of states / step
s. | 51 // The SQLTransaction is a state machine that executes a series of states / step
s. |
| 52 // | 52 // |
| 53 // The work of the transaction states are defined in section of 4.3.2 of the | 53 // The work of the transaction states are defined in section of 4.3.2 of the |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 // | 334 // |
| 335 // Phase 5: After state CleanupAndTerminate | 335 // Phase 5: After state CleanupAndTerminate |
| 336 // | 336 // |
| 337 // - This is how a transaction ends normally. | 337 // - This is how a transaction ends normally. |
| 338 // - state CleanupAndTerminate calls doCleanup(). | 338 // - state CleanupAndTerminate calls doCleanup(). |
| 339 | 339 |
| 340 | 340 |
| 341 namespace blink { | 341 namespace blink { |
| 342 | 342 |
| 343 PassRefPtrWillBeRawPtr<SQLTransactionBackend> SQLTransactionBackend::create(Data
baseBackend* db, | 343 PassRefPtrWillBeRawPtr<SQLTransactionBackend> SQLTransactionBackend::create(Data
baseBackend* db, |
| 344 PassRefPtrWillBeRawPtr<AbstractSQLTransaction> frontend, | 344 PassRefPtrWillBeRawPtr<SQLTransaction> frontend, |
| 345 PassRefPtrWillBeRawPtr<SQLTransactionWrapper> wrapper, | 345 PassRefPtrWillBeRawPtr<SQLTransactionWrapper> wrapper, |
| 346 bool readOnly) | 346 bool readOnly) |
| 347 { | 347 { |
| 348 return adoptRefWillBeNoop(new SQLTransactionBackend(db, frontend, wrapper, r
eadOnly)); | 348 return adoptRefWillBeNoop(new SQLTransactionBackend(db, frontend, wrapper, r
eadOnly)); |
| 349 } | 349 } |
| 350 | 350 |
| 351 SQLTransactionBackend::SQLTransactionBackend(DatabaseBackend* db, | 351 SQLTransactionBackend::SQLTransactionBackend(DatabaseBackend* db, |
| 352 PassRefPtrWillBeRawPtr<AbstractSQLTransaction> frontend, | 352 PassRefPtrWillBeRawPtr<SQLTransaction> frontend, |
| 353 PassRefPtrWillBeRawPtr<SQLTransactionWrapper> wrapper, | 353 PassRefPtrWillBeRawPtr<SQLTransactionWrapper> wrapper, |
| 354 bool readOnly) | 354 bool readOnly) |
| 355 : m_frontend(frontend) | 355 : m_frontend(frontend) |
| 356 , m_database(db) | 356 , m_database(db) |
| 357 , m_wrapper(wrapper) | 357 , m_wrapper(wrapper) |
| 358 , m_hasCallback(m_frontend->hasCallback()) | 358 , m_hasCallback(m_frontend->hasCallback()) |
| 359 , m_hasSuccessCallback(m_frontend->hasSuccessCallback()) | 359 , m_hasSuccessCallback(m_frontend->hasSuccessCallback()) |
| 360 , m_hasErrorCallback(m_frontend->hasErrorCallback()) | 360 , m_hasErrorCallback(m_frontend->hasErrorCallback()) |
| 361 , m_shouldRetryCurrentStatement(false) | 361 , m_shouldRetryCurrentStatement(false) |
| 362 , m_modifiedDatabase(false) | 362 , m_modifiedDatabase(false) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 374 ASSERT(!m_sqliteTransaction); | 374 ASSERT(!m_sqliteTransaction); |
| 375 } | 375 } |
| 376 | 376 |
| 377 void SQLTransactionBackend::trace(Visitor* visitor) | 377 void SQLTransactionBackend::trace(Visitor* visitor) |
| 378 { | 378 { |
| 379 visitor->trace(m_frontend); | 379 visitor->trace(m_frontend); |
| 380 visitor->trace(m_currentStatementBackend); | 380 visitor->trace(m_currentStatementBackend); |
| 381 visitor->trace(m_database); | 381 visitor->trace(m_database); |
| 382 visitor->trace(m_wrapper); | 382 visitor->trace(m_wrapper); |
| 383 visitor->trace(m_statementQueue); | 383 visitor->trace(m_statementQueue); |
| 384 AbstractSQLTransactionBackend::trace(visitor); | |
| 385 } | 384 } |
| 386 | 385 |
| 387 void SQLTransactionBackend::doCleanup() | 386 void SQLTransactionBackend::doCleanup() |
| 388 { | 387 { |
| 389 if (!m_frontend) | 388 if (!m_frontend) |
| 390 return; | 389 return; |
| 391 m_frontend = nullptr; // Break the reference cycle. See comment about the li
fe-cycle above. | 390 m_frontend = nullptr; // Break the reference cycle. See comment about the li
fe-cycle above. |
| 392 | 391 |
| 393 ASSERT(database()->databaseContext()->databaseThread()->isDatabaseThread()); | 392 ASSERT(database()->databaseContext()->databaseThread()->isDatabaseThread()); |
| 394 | 393 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 // This occurs if requests for transition to those states have already been | 426 // This occurs if requests for transition to those states have already been |
| 428 // registered with the frontend just prior to a clean up request arriving. | 427 // registered with the frontend just prior to a clean up request arriving. |
| 429 // | 428 // |
| 430 // So instead, let our destructor handle their clean up since this | 429 // So instead, let our destructor handle their clean up since this |
| 431 // SQLTransactionBackend is guaranteed to not destruct until the frontend | 430 // SQLTransactionBackend is guaranteed to not destruct until the frontend |
| 432 // is also destructing. | 431 // is also destructing. |
| 433 | 432 |
| 434 m_wrapper = nullptr; | 433 m_wrapper = nullptr; |
| 435 } | 434 } |
| 436 | 435 |
| 437 AbstractSQLStatement* SQLTransactionBackend::currentStatement() | 436 SQLStatement* SQLTransactionBackend::currentStatement() |
| 438 { | 437 { |
| 439 return m_currentStatementBackend->frontend(); | 438 return m_currentStatementBackend->frontend(); |
| 440 } | 439 } |
| 441 | 440 |
| 442 SQLErrorData* SQLTransactionBackend::transactionError() | 441 SQLErrorData* SQLTransactionBackend::transactionError() |
| 443 { | 442 { |
| 444 return m_transactionError.get(); | 443 return m_transactionError.get(); |
| 445 } | 444 } |
| 446 | 445 |
| 447 void SQLTransactionBackend::setShouldRetryCurrentStatement(bool shouldRetry) | 446 void SQLTransactionBackend::setShouldRetryCurrentStatement(bool shouldRetry) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 // Redirect to the end state to abort, clean up, and end the transaction. | 518 // Redirect to the end state to abort, clean up, and end the transaction. |
| 520 doCleanup(); | 519 doCleanup(); |
| 521 } | 520 } |
| 522 | 521 |
| 523 void SQLTransactionBackend::performNextStep() | 522 void SQLTransactionBackend::performNextStep() |
| 524 { | 523 { |
| 525 computeNextStateAndCleanupIfNeeded(); | 524 computeNextStateAndCleanupIfNeeded(); |
| 526 runStateMachine(); | 525 runStateMachine(); |
| 527 } | 526 } |
| 528 | 527 |
| 529 void SQLTransactionBackend::executeSQL(PassOwnPtrWillBeRawPtr<AbstractSQLStateme
nt> statement, | 528 void SQLTransactionBackend::executeSQL(PassOwnPtrWillBeRawPtr<SQLStatement> stat
ement, |
| 530 const String& sqlStatement, const Vector<SQLValue>& arguments, int permissio
ns) | 529 const String& sqlStatement, const Vector<SQLValue>& arguments, int permissio
ns) |
| 531 { | 530 { |
| 532 enqueueStatementBackend(SQLStatementBackend::create(statement, sqlStatement,
arguments, permissions)); | 531 enqueueStatementBackend(SQLStatementBackend::create(statement, sqlStatement,
arguments, permissions)); |
| 533 } | 532 } |
| 534 | 533 |
| 535 void SQLTransactionBackend::notifyDatabaseThreadIsShuttingDown() | 534 void SQLTransactionBackend::notifyDatabaseThreadIsShuttingDown() |
| 536 { | 535 { |
| 537 ASSERT(database()->databaseContext()->databaseThread()->isDatabaseThread()); | 536 ASSERT(database()->databaseContext()->databaseThread()->isDatabaseThread()); |
| 538 | 537 |
| 539 // If the transaction is in progress, we should roll it back here, since thi
s | 538 // If the transaction is in progress, we should roll it back here, since thi
s |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 } | 826 } |
| 828 | 827 |
| 829 SQLTransactionState SQLTransactionBackend::sendToFrontendState() | 828 SQLTransactionState SQLTransactionBackend::sendToFrontendState() |
| 830 { | 829 { |
| 831 ASSERT(m_nextState != SQLTransactionState::Idle); | 830 ASSERT(m_nextState != SQLTransactionState::Idle); |
| 832 m_frontend->requestTransitToState(m_nextState); | 831 m_frontend->requestTransitToState(m_nextState); |
| 833 return SQLTransactionState::Idle; | 832 return SQLTransactionState::Idle; |
| 834 } | 833 } |
| 835 | 834 |
| 836 } // namespace blink | 835 } // namespace blink |
| OLD | NEW |