| 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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 | 385 |
| 386 MutexLocker locker(m_statementMutex); | 386 MutexLocker locker(m_statementMutex); |
| 387 m_statementQueue.clear(); | 387 m_statementQueue.clear(); |
| 388 | 388 |
| 389 if (m_sqliteTransaction) { | 389 if (m_sqliteTransaction) { |
| 390 // In the event we got here because of an interruption or error (i.e. if | 390 // In the event we got here because of an interruption or error (i.e. if |
| 391 // the transaction is in progress), we should roll it back here. Clearin
g | 391 // the transaction is in progress), we should roll it back here. Clearin
g |
| 392 // m_sqliteTransaction invokes SQLiteTransaction's destructor which does | 392 // m_sqliteTransaction invokes SQLiteTransaction's destructor which does |
| 393 // just that. We might as well do this unconditionally and free up its | 393 // just that. We might as well do this unconditionally and free up its |
| 394 // resources because we're already terminating. | 394 // resources because we're already terminating. |
| 395 m_sqliteTransaction.clear(); | 395 m_sqliteTransaction.reset(); |
| 396 } | 396 } |
| 397 | 397 |
| 398 // Release the lock on this database | 398 // Release the lock on this database |
| 399 if (m_lockAcquired) | 399 if (m_lockAcquired) |
| 400 m_database->transactionCoordinator()->releaseLock(this); | 400 m_database->transactionCoordinator()->releaseLock(this); |
| 401 | 401 |
| 402 // Do some aggresive clean up here except for m_database. | 402 // Do some aggresive clean up here except for m_database. |
| 403 // | 403 // |
| 404 // We can't clear m_database here because the frontend may asynchronously | 404 // We can't clear m_database here because the frontend may asynchronously |
| 405 // invoke SQLTransactionBackend::requestTransitToState(), and that function | 405 // invoke SQLTransactionBackend::requestTransitToState(), and that function |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 if (m_nextState == SQLTransactionState::End) | 492 if (m_nextState == SQLTransactionState::End) |
| 493 return; | 493 return; |
| 494 m_nextState = SQLTransactionState::End; | 494 m_nextState = SQLTransactionState::End; |
| 495 | 495 |
| 496 // If the database was stopped, don't do anything and cancel queued work | 496 // If the database was stopped, don't do anything and cancel queued work |
| 497 WTF_LOG(StorageAPI, "Database was stopped or interrupted - cancelling work f
or this transaction"); | 497 WTF_LOG(StorageAPI, "Database was stopped or interrupted - cancelling work f
or this transaction"); |
| 498 | 498 |
| 499 // The current SQLite transaction should be stopped, as well | 499 // The current SQLite transaction should be stopped, as well |
| 500 if (m_sqliteTransaction) { | 500 if (m_sqliteTransaction) { |
| 501 m_sqliteTransaction->stop(); | 501 m_sqliteTransaction->stop(); |
| 502 m_sqliteTransaction.clear(); | 502 m_sqliteTransaction.reset(); |
| 503 } | 503 } |
| 504 | 504 |
| 505 // Terminate the frontend state machine. This also gets the frontend to | 505 // Terminate the frontend state machine. This also gets the frontend to |
| 506 // call computeNextStateAndCleanupIfNeeded() and clear its wrappers | 506 // call computeNextStateAndCleanupIfNeeded() and clear its wrappers |
| 507 // if needed. | 507 // if needed. |
| 508 m_frontend->requestTransitToState(SQLTransactionState::End); | 508 m_frontend->requestTransitToState(SQLTransactionState::End); |
| 509 | 509 |
| 510 // Redirect to the end state to abort, clean up, and end the transaction. | 510 // Redirect to the end state to abort, clean up, and end the transaction. |
| 511 doCleanup(); | 511 doCleanup(); |
| 512 } | 512 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 m_database->disableAuthorizer(); | 565 m_database->disableAuthorizer(); |
| 566 m_sqliteTransaction->begin(); | 566 m_sqliteTransaction->begin(); |
| 567 m_database->enableAuthorizer(); | 567 m_database->enableAuthorizer(); |
| 568 | 568 |
| 569 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error
callback if that fails | 569 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error
callback if that fails |
| 570 if (!m_sqliteTransaction->inProgress()) { | 570 if (!m_sqliteTransaction->inProgress()) { |
| 571 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 571 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
| 572 m_database->reportStartTransactionResult(2, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); | 572 m_database->reportStartTransactionResult(2, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); |
| 573 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "unabl
e to begin transaction", | 573 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "unabl
e to begin transaction", |
| 574 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); | 574 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); |
| 575 m_sqliteTransaction.clear(); | 575 m_sqliteTransaction.reset(); |
| 576 return nextStateForTransactionError(); | 576 return nextStateForTransactionError(); |
| 577 } | 577 } |
| 578 | 578 |
| 579 // Note: We intentionally retrieve the actual version even with an empty exp
ected version. | 579 // Note: We intentionally retrieve the actual version even with an empty exp
ected version. |
| 580 // In multi-process browsers, we take this opportinutiy to update the cached
value for | 580 // In multi-process browsers, we take this opportinutiy to update the cached
value for |
| 581 // the actual version. In single-process browsers, this is just a map lookup
. | 581 // the actual version. In single-process browsers, this is just a map lookup
. |
| 582 String actualVersion; | 582 String actualVersion; |
| 583 if (!m_database->getActualVersionForTransaction(actualVersion)) { | 583 if (!m_database->getActualVersionForTransaction(actualVersion)) { |
| 584 m_database->reportStartTransactionResult(3, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); | 584 m_database->reportStartTransactionResult(3, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); |
| 585 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "unabl
e to read version", | 585 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "unabl
e to read version", |
| 586 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); | 586 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); |
| 587 m_database->disableAuthorizer(); | 587 m_database->disableAuthorizer(); |
| 588 m_sqliteTransaction.clear(); | 588 m_sqliteTransaction.reset(); |
| 589 m_database->enableAuthorizer(); | 589 m_database->enableAuthorizer(); |
| 590 return nextStateForTransactionError(); | 590 return nextStateForTransactionError(); |
| 591 } | 591 } |
| 592 m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && (m_databa
se->expectedVersion() != actualVersion); | 592 m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && (m_databa
se->expectedVersion() != actualVersion); |
| 593 | 593 |
| 594 // Spec 4.3.2.3: Perform preflight steps, jumping to the error callback if t
hey fail | 594 // Spec 4.3.2.3: Perform preflight steps, jumping to the error callback if t
hey fail |
| 595 if (m_wrapper && !m_wrapper->performPreflight(this)) { | 595 if (m_wrapper && !m_wrapper->performPreflight(this)) { |
| 596 m_database->disableAuthorizer(); | 596 m_database->disableAuthorizer(); |
| 597 m_sqliteTransaction.clear(); | 597 m_sqliteTransaction.reset(); |
| 598 m_database->enableAuthorizer(); | 598 m_database->enableAuthorizer(); |
| 599 if (m_wrapper->sqlError()) { | 599 if (m_wrapper->sqlError()) { |
| 600 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); | 600 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); |
| 601 } else { | 601 } else { |
| 602 m_database->reportStartTransactionResult(4, SQLError::UNKNOWN_ERR, 0
); | 602 m_database->reportStartTransactionResult(4, SQLError::UNKNOWN_ERR, 0
); |
| 603 m_transactionError = SQLErrorData::create(SQLError::UNKNOWN_ERR, "un
known error occurred during transaction preflight"); | 603 m_transactionError = SQLErrorData::create(SQLError::UNKNOWN_ERR, "un
known error occurred during transaction preflight"); |
| 604 } | 604 } |
| 605 return nextStateForTransactionError(); | 605 return nextStateForTransactionError(); |
| 606 } | 606 } |
| 607 | 607 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 { | 781 { |
| 782 ASSERT(m_lockAcquired); | 782 ASSERT(m_lockAcquired); |
| 783 | 783 |
| 784 WTF_LOG(StorageAPI, "Transaction %p is complete with an error\n", this); | 784 WTF_LOG(StorageAPI, "Transaction %p is complete with an error\n", this); |
| 785 m_database->disableAuthorizer(); | 785 m_database->disableAuthorizer(); |
| 786 if (m_sqliteTransaction) { | 786 if (m_sqliteTransaction) { |
| 787 // Spec 4.3.2.10: Rollback the transaction. | 787 // Spec 4.3.2.10: Rollback the transaction. |
| 788 m_sqliteTransaction->rollback(); | 788 m_sqliteTransaction->rollback(); |
| 789 | 789 |
| 790 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 790 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
| 791 m_sqliteTransaction.clear(); | 791 m_sqliteTransaction.reset(); |
| 792 } | 792 } |
| 793 m_database->enableAuthorizer(); | 793 m_database->enableAuthorizer(); |
| 794 | 794 |
| 795 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 795 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
| 796 | 796 |
| 797 return SQLTransactionState::CleanupAndTerminate; | 797 return SQLTransactionState::CleanupAndTerminate; |
| 798 } | 798 } |
| 799 | 799 |
| 800 // requestTransitToState() can be called from the frontend. Hence, it should | 800 // requestTransitToState() can be called from the frontend. Hence, it should |
| 801 // NOT be modifying SQLTransactionBackend in general. The only safe field to | 801 // NOT be modifying SQLTransactionBackend in general. The only safe field to |
| (...skipping 16 matching lines...) Expand all Loading... |
| 818 } | 818 } |
| 819 | 819 |
| 820 SQLTransactionState SQLTransactionBackend::sendToFrontendState() | 820 SQLTransactionState SQLTransactionBackend::sendToFrontendState() |
| 821 { | 821 { |
| 822 ASSERT(m_nextState != SQLTransactionState::Idle); | 822 ASSERT(m_nextState != SQLTransactionState::Idle); |
| 823 m_frontend->requestTransitToState(m_nextState); | 823 m_frontend->requestTransitToState(m_nextState); |
| 824 return SQLTransactionState::Idle; | 824 return SQLTransactionState::Idle; |
| 825 } | 825 } |
| 826 | 826 |
| 827 } // namespace blink | 827 } // namespace blink |
| OLD | NEW |