summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/WebCore/Modules/webdatabase/SQLTransaction.cpp
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/WebCore/Modules/webdatabase/SQLTransaction.cpp')
-rw-r--r--Source/WebCore/Modules/webdatabase/SQLTransaction.cpp120
1 files changed, 69 insertions, 51 deletions
diff --git a/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp b/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp
index 51fdcde83..2b4f7bb22 100644
--- a/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp
+++ b/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -29,16 +29,17 @@
#include "config.h"
#include "SQLTransaction.h"
+#if ENABLE(SQL_DATABASE)
+
+#include "AbstractSQLTransactionBackend.h"
#include "Database.h"
#include "DatabaseAuthorizer.h"
#include "DatabaseContext.h"
#include "ExceptionCode.h"
#include "Logging.h"
#include "SQLError.h"
-#include "SQLStatement.h"
#include "SQLStatementCallback.h"
#include "SQLStatementErrorCallback.h"
-#include "SQLTransactionBackend.h"
#include "SQLTransactionCallback.h"
#include "SQLTransactionClient.h" // FIXME: Should be used in the backend only.
#include "SQLTransactionErrorCallback.h"
@@ -48,23 +49,24 @@
namespace WebCore {
-Ref<SQLTransaction> SQLTransaction::create(Ref<Database>&& database, RefPtr<SQLTransactionCallback>&& callback, RefPtr<VoidCallback>&& successCallback, RefPtr<SQLTransactionErrorCallback>&& errorCallback, bool readOnly)
+PassRefPtr<SQLTransaction> SQLTransaction::create(Database* db, PassRefPtr<SQLTransactionCallback> callback,
+ PassRefPtr<VoidCallback> successCallback, PassRefPtr<SQLTransactionErrorCallback> errorCallback,
+ bool readOnly)
{
- return adoptRef(*new SQLTransaction(WTFMove(database), WTFMove(callback), WTFMove(successCallback), WTFMove(errorCallback), readOnly));
+ return adoptRef(new SQLTransaction(db, callback, successCallback, errorCallback, readOnly));
}
-SQLTransaction::SQLTransaction(Ref<Database>&& database, RefPtr<SQLTransactionCallback>&& callback, RefPtr<VoidCallback>&& successCallback, RefPtr<SQLTransactionErrorCallback>&& errorCallback, bool readOnly)
- : m_database(WTFMove(database))
- , m_callbackWrapper(WTFMove(callback), m_database->scriptExecutionContext())
- , m_successCallbackWrapper(WTFMove(successCallback), m_database->scriptExecutionContext())
- , m_errorCallbackWrapper(WTFMove(errorCallback), m_database->scriptExecutionContext())
+SQLTransaction::SQLTransaction(Database* db, PassRefPtr<SQLTransactionCallback> callback,
+ PassRefPtr<VoidCallback> successCallback, PassRefPtr<SQLTransactionErrorCallback> errorCallback,
+ bool readOnly)
+ : m_database(db)
+ , m_callbackWrapper(callback, db->scriptExecutionContext())
+ , m_successCallbackWrapper(successCallback, db->scriptExecutionContext())
+ , m_errorCallbackWrapper(errorCallback, db->scriptExecutionContext())
, m_executeSqlAllowed(false)
, m_readOnly(readOnly)
{
-}
-
-SQLTransaction::~SQLTransaction()
-{
+ ASSERT(m_database);
}
bool SQLTransaction::hasCallback() const
@@ -82,7 +84,7 @@ bool SQLTransaction::hasErrorCallback() const
return m_errorCallbackWrapper.hasCallback();
}
-void SQLTransaction::setBackend(SQLTransactionBackend* backend)
+void SQLTransaction::setBackend(AbstractSQLTransactionBackend* backend)
{
ASSERT(!m_backend);
m_backend = backend;
@@ -95,10 +97,10 @@ SQLTransaction::StateFunction SQLTransaction::stateFunctionFor(SQLTransactionSta
&SQLTransaction::unreachableState, // 1. idle
&SQLTransaction::unreachableState, // 2. acquireLock
&SQLTransaction::unreachableState, // 3. openTransactionAndPreflight
- &SQLTransaction::unreachableState, // 4. runStatements
+ &SQLTransaction::sendToBackendState, // 4. runStatements
&SQLTransaction::unreachableState, // 5. postflightAndCommit
- &SQLTransaction::unreachableState, // 6. cleanupAndTerminate
- &SQLTransaction::unreachableState, // 7. cleanupAfterTransactionErrorCallback
+ &SQLTransaction::sendToBackendState, // 6. cleanupAndTerminate
+ &SQLTransaction::sendToBackendState, // 7. cleanupAfterTransactionErrorCallback
&SQLTransaction::deliverTransactionCallback, // 8.
&SQLTransaction::deliverTransactionErrorCallback, // 9.
&SQLTransaction::deliverStatementCallback, // 10.
@@ -122,7 +124,18 @@ void SQLTransaction::requestTransitToState(SQLTransactionState nextState)
m_database->scheduleTransactionCallback(this);
}
-void SQLTransaction::deliverTransactionCallback()
+SQLTransactionState SQLTransaction::nextStateForTransactionError()
+{
+ ASSERT(m_transactionError);
+ if (m_errorCallbackWrapper.hasCallback())
+ return SQLTransactionState::DeliverTransactionErrorCallback;
+
+ // No error callback, so fast-forward to:
+ // Transaction Step 11 - Rollback the transaction.
+ return SQLTransactionState::CleanupAfterTransactionErrorCallback;
+}
+
+SQLTransactionState SQLTransaction::deliverTransactionCallback()
{
bool shouldDeliverErrorCallback = false;
@@ -135,15 +148,15 @@ void SQLTransaction::deliverTransactionCallback()
}
// Spec 4.3.2 5: If the transaction callback was null or raised an exception, jump to the error callback
+ SQLTransactionState nextState = SQLTransactionState::RunStatements;
if (shouldDeliverErrorCallback) {
m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "the SQLTransactionCallback was null or threw an exception");
- return deliverTransactionErrorCallback();
+ nextState = SQLTransactionState::DeliverTransactionErrorCallback;
}
-
- m_backend->requestTransitToState(SQLTransactionState::RunStatements);
+ return nextState;
}
-void SQLTransaction::deliverTransactionErrorCallback()
+SQLTransactionState SQLTransaction::deliverTransactionErrorCallback()
{
// Spec 4.3.2.10: If exists, invoke error callback with the last
// error to have occurred in this transaction.
@@ -159,22 +172,23 @@ void SQLTransaction::deliverTransactionErrorCallback()
ASSERT(m_transactionError);
errorCallback->handleEvent(m_transactionError.get());
- m_transactionError = nullptr;
+ m_transactionError = 0;
}
clearCallbackWrappers();
// Spec 4.3.2.10: Rollback the transaction.
- m_backend->requestTransitToState(SQLTransactionState::CleanupAfterTransactionErrorCallback);
+ return SQLTransactionState::CleanupAfterTransactionErrorCallback;
}
-void SQLTransaction::deliverStatementCallback()
+SQLTransactionState SQLTransaction::deliverStatementCallback()
{
// Spec 4.3.2.6.6 and 4.3.2.6.3: If the statement callback went wrong, jump to the transaction error callback
// Otherwise, continue to loop through the statement queue
m_executeSqlAllowed = true;
- SQLStatement* currentStatement = m_backend->currentStatement();
+ AbstractSQLStatement* currentAbstractStatement = m_backend->currentStatement();
+ SQLStatement* currentStatement = static_cast<SQLStatement*>(currentAbstractStatement);
ASSERT(currentStatement);
bool result = currentStatement->performCallback(this);
@@ -183,30 +197,22 @@ void SQLTransaction::deliverStatementCallback()
if (result) {
m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "the statement callback raised an exception or statement error callback did not return false");
-
- if (m_errorCallbackWrapper.hasCallback())
- return deliverTransactionErrorCallback();
-
- // No error callback, so fast-forward to:
- // Transaction Step 11 - Rollback the transaction.
- m_backend->requestTransitToState(SQLTransactionState::CleanupAfterTransactionErrorCallback);
- return;
+ return nextStateForTransactionError();
}
-
- m_backend->requestTransitToState(SQLTransactionState::RunStatements);
+ return SQLTransactionState::RunStatements;
}
-void SQLTransaction::deliverQuotaIncreaseCallback()
+SQLTransactionState SQLTransaction::deliverQuotaIncreaseCallback()
{
ASSERT(m_backend->currentStatement());
- bool shouldRetryCurrentStatement = m_database->transactionClient()->didExceedQuota(&database());
+ bool shouldRetryCurrentStatement = m_database->transactionClient()->didExceedQuota(database());
m_backend->setShouldRetryCurrentStatement(shouldRetryCurrentStatement);
- m_backend->requestTransitToState(SQLTransactionState::RunStatements);
+ return SQLTransactionState::RunStatements;
}
-void SQLTransaction::deliverSuccessCallback()
+SQLTransactionState SQLTransaction::deliverSuccessCallback()
{
// Spec 4.3.2.8: Deliver success callback.
RefPtr<VoidCallback> successCallback = m_successCallbackWrapper.unwrap();
@@ -217,15 +223,23 @@ void SQLTransaction::deliverSuccessCallback()
// Schedule a "post-success callback" step to return control to the database thread in case there
// are further transactions queued up for this Database
- m_backend->requestTransitToState(SQLTransactionState::CleanupAndTerminate);
+ return SQLTransactionState::CleanupAndTerminate;
}
// This state function is used as a stub function to plug unimplemented states
// in the state dispatch table. They are unimplemented because they should
// never be reached in the course of correct execution.
-void SQLTransaction::unreachableState()
+SQLTransactionState SQLTransaction::unreachableState()
{
ASSERT_NOT_REACHED();
+ return SQLTransactionState::End;
+}
+
+SQLTransactionState SQLTransaction::sendToBackendState()
+{
+ ASSERT(m_nextState != SQLTransactionState::Idle);
+ m_backend->requestTransitToState(m_nextState);
+ return SQLTransactionState::Idle;
}
void SQLTransaction::performPendingCallback()
@@ -234,10 +248,10 @@ void SQLTransaction::performPendingCallback()
runStateMachine();
}
-void SQLTransaction::executeSQL(const String& sqlStatement, const Vector<SQLValue>& arguments, RefPtr<SQLStatementCallback>&& callback, RefPtr<SQLStatementErrorCallback>&& callbackError, ExceptionCode& ec)
+void SQLTransaction::executeSQL(const String& sqlStatement, const Vector<SQLValue>& arguments, PassRefPtr<SQLStatementCallback> callback, PassRefPtr<SQLStatementErrorCallback> callbackError, ExceptionCode& e)
{
if (!m_executeSqlAllowed || !m_database->opened()) {
- ec = INVALID_STATE_ERR;
+ e = INVALID_STATE_ERR;
return;
}
@@ -247,15 +261,15 @@ void SQLTransaction::executeSQL(const String& sqlStatement, const Vector<SQLValu
else if (m_readOnly)
permissions |= DatabaseAuthorizer::ReadOnlyMask;
- auto statement = std::make_unique<SQLStatement>(m_database, sqlStatement, arguments, WTFMove(callback), WTFMove(callbackError), permissions);
- m_backend->executeSQL(WTFMove(statement));
+ OwnPtr<SQLStatement> statement = SQLStatement::create(m_database.get(), callback, callbackError);
+ m_backend->executeSQL(statement.release(), sqlStatement, arguments, permissions);
}
-void SQLTransaction::computeNextStateAndCleanupIfNeeded()
+bool SQLTransaction::computeNextStateAndCleanupIfNeeded()
{
// Only honor the requested state transition if we're not supposed to be
// cleaning up and shutting down:
- if (m_database->opened()) {
+ if (m_database->opened() && !m_database->isInterrupted()) {
setStateToRequestedState();
ASSERT(m_nextState == SQLTransactionState::End
|| m_nextState == SQLTransactionState::DeliverTransactionCallback
@@ -265,11 +279,13 @@ void SQLTransaction::computeNextStateAndCleanupIfNeeded()
|| m_nextState == SQLTransactionState::DeliverSuccessCallback);
LOG(StorageAPI, "Callback %s\n", nameForSQLTransactionState(m_nextState));
- return;
+ return false;
}
clearCallbackWrappers();
- m_backend->requestTransitToState(SQLTransactionState::CleanupAndTerminate);
+ m_nextState = SQLTransactionState::CleanupAndTerminate;
+
+ return true;
}
void SQLTransaction::clearCallbackWrappers()
@@ -281,3 +297,5 @@ void SQLTransaction::clearCallbackWrappers()
}
} // namespace WebCore
+
+#endif // ENABLE(SQL_DATABASE)