From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- .../WebCore/Modules/webdatabase/SQLTransaction.h | 132 +++++++++++++-------- 1 file changed, 85 insertions(+), 47 deletions(-) (limited to 'Source/WebCore/Modules/webdatabase/SQLTransaction.h') diff --git a/Source/WebCore/Modules/webdatabase/SQLTransaction.h b/Source/WebCore/Modules/webdatabase/SQLTransaction.h index c24bcc008..81b668f7e 100644 --- a/Source/WebCore/Modules/webdatabase/SQLTransaction.h +++ b/Source/WebCore/Modules/webdatabase/SQLTransaction.h @@ -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 Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple 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. * @@ -26,87 +26,125 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLTransaction_h -#define SQLTransaction_h +#pragma once -#if ENABLE(SQL_DATABASE) - -#include "AbstractSQLTransaction.h" +#include "EventTarget.h" +#include "ExceptionOr.h" #include "SQLCallbackWrapper.h" -#include "SQLStatement.h" +#include "SQLTransactionBackend.h" #include "SQLTransactionStateMachine.h" -#include -#include +#include "SQLValue.h" +#include namespace WebCore { -class AbstractSQLTransactionBackend; class Database; class SQLError; class SQLStatementCallback; class SQLStatementErrorCallback; +class SQLTransactionBackend; class SQLTransactionCallback; class SQLTransactionErrorCallback; -class SQLValue; class VoidCallback; -class SQLTransaction : public SQLTransactionStateMachine, public AbstractSQLTransaction { +class SQLTransactionWrapper : public ThreadSafeRefCounted { public: - static PassRefPtr create(Database*, PassRefPtr, - PassRefPtr successCallback, PassRefPtr, - bool readOnly); + virtual ~SQLTransactionWrapper() { } + virtual bool performPreflight(SQLTransaction&) = 0; + virtual bool performPostflight(SQLTransaction&) = 0; + virtual SQLError* sqlError() const = 0; + virtual void handleCommitFailedAfterPostflight(SQLTransaction&) = 0; +}; + +class SQLTransaction : public ThreadSafeRefCounted, public SQLTransactionStateMachine { +public: + static Ref create(Ref&&, RefPtr&&, RefPtr&& successCallback, RefPtr&&, RefPtr&&, bool readOnly); + ~SQLTransaction(); + + ExceptionOr executeSql(const String& sqlStatement, std::optional>&& arguments, RefPtr&&, RefPtr&&); + void lockAcquired(); + void performNextStep(); void performPendingCallback(); - void executeSQL(const String& sqlStatement, const Vector& arguments, - PassRefPtr, PassRefPtr, ExceptionCode&); + Database& database() { return m_database; } + bool isReadOnly() const { return m_readOnly; } + void notifyDatabaseThreadIsShuttingDown(); - Database* database() { return m_database.get(); } + // APIs called from the backend published via SQLTransaction: + void requestTransitToState(SQLTransactionState); private: - SQLTransaction(Database*, PassRefPtr, - PassRefPtr successCallback, PassRefPtr, - bool readOnly); + friend class SQLTransactionBackend; + + SQLTransaction(Ref&&, RefPtr&&, RefPtr&& successCallback, RefPtr&&, RefPtr&&, bool readOnly); + + void enqueueStatement(std::unique_ptr); + + void checkAndHandleClosedDatabase(); void clearCallbackWrappers(); - // APIs called from the backend published via AbstractSQLTransaction: - virtual void requestTransitToState(SQLTransactionState) override; - virtual bool hasCallback() const override; - virtual bool hasSuccessCallback() const override; - virtual bool hasErrorCallback() const override; - virtual void setBackend(AbstractSQLTransactionBackend*) override; + void scheduleCallback(void (SQLTransaction::*)()); // State Machine functions: - virtual StateFunction stateFunctionFor(SQLTransactionState) override; - bool computeNextStateAndCleanupIfNeeded(); + StateFunction stateFunctionFor(SQLTransactionState) override; + void computeNextStateAndCleanupIfNeeded(); // State functions: - SQLTransactionState deliverTransactionCallback(); - SQLTransactionState deliverTransactionErrorCallback(); - SQLTransactionState deliverStatementCallback(); - SQLTransactionState deliverQuotaIncreaseCallback(); - SQLTransactionState deliverSuccessCallback(); - - SQLTransactionState unreachableState(); - SQLTransactionState sendToBackendState(); - - SQLTransactionState nextStateForTransactionError(); + void acquireLock(); + void openTransactionAndPreflight(); + void runStatements(); + void cleanupAndTerminate(); + void cleanupAfterTransactionErrorCallback(); + void deliverTransactionCallback(); + void deliverTransactionErrorCallback(); + void deliverStatementCallback(); + void deliverQuotaIncreaseCallback(); + void deliverSuccessCallback(); + + NO_RETURN_DUE_TO_ASSERT void unreachableState(); + + void getNextStatement(); + bool runCurrentStatement(); + void handleCurrentStatementError(); + void handleTransactionError(); + void postflightAndCommit(); + + void acquireOriginLock(); + void releaseOriginLockIfNeeded(); + +#if !LOG_DISABLED + static const char* debugStepName(void (SQLTransaction::*)()); +#endif - RefPtr m_database; - RefPtr m_backend; + Ref m_database; SQLCallbackWrapper m_callbackWrapper; SQLCallbackWrapper m_successCallbackWrapper; SQLCallbackWrapper m_errorCallbackWrapper; - bool m_executeSqlAllowed; + RefPtr m_wrapper; + + void (SQLTransaction::*m_nextStep)(); + + bool m_executeSqlAllowed { false }; RefPtr m_transactionError; - bool m_readOnly; -}; + bool m_shouldRetryCurrentStatement { false }; + bool m_modifiedDatabase { false }; + bool m_lockAcquired { false }; + bool m_readOnly { false }; + bool m_hasVersionMismatch { false }; -} // namespace WebCore + Lock m_statementMutex; + Deque> m_statementQueue; -#endif + std::unique_ptr m_currentStatement; + + std::unique_ptr m_sqliteTransaction; + RefPtr m_originLock; -#endif // SQLTransaction_h + SQLTransactionBackend m_backend; +}; + +} // namespace WebCore -- cgit v1.2.1