diff options
Diffstat (limited to 'Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h')
-rw-r--r-- | Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h | 115 |
1 files changed, 24 insertions, 91 deletions
diff --git a/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h b/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h index 17a4c65f2..29e603c95 100644 --- a/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h +++ b/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2013 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2013, 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -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. * @@ -25,122 +25,55 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLTransactionBackend_h -#define SQLTransactionBackend_h -#if ENABLE(SQL_DATABASE) +#pragma once -#include "AbstractSQLStatement.h" -#include "AbstractSQLTransactionBackend.h" -#include "DatabaseBasicTypes.h" #include "SQLTransactionStateMachine.h" +#include <memory> #include <wtf/Deque.h> #include <wtf/Forward.h> +#include <wtf/Lock.h> #include <wtf/text/WTFString.h> namespace WebCore { -class AbstractSQLTransaction; -class DatabaseBackend; +class Database; class OriginLock; class SQLError; class SQLiteTransaction; -class SQLStatementBackend; -class SQLTransactionBackend; -class SQLValue; +class SQLStatement; +class SQLTransaction; +class SQLTransactionWrapper; -class SQLTransactionWrapper : public ThreadSafeRefCounted<SQLTransactionWrapper> { +class SQLTransactionBackend : public SQLTransactionStateMachine<SQLTransactionBackend> { public: - virtual ~SQLTransactionWrapper() { } - virtual bool performPreflight(SQLTransactionBackend*) = 0; - virtual bool performPostflight(SQLTransactionBackend*) = 0; - virtual SQLError* sqlError() const = 0; - virtual void handleCommitFailedAfterPostflight(SQLTransactionBackend*) = 0; -}; - -class SQLTransactionBackend : public SQLTransactionStateMachine<SQLTransactionBackend>, public AbstractSQLTransactionBackend { -public: - static PassRefPtr<SQLTransactionBackend> create(DatabaseBackend*, - PassRefPtr<AbstractSQLTransaction>, PassRefPtr<SQLTransactionWrapper>, bool readOnly); - - virtual ~SQLTransactionBackend(); - - void lockAcquired(); - void performNextStep(); + explicit SQLTransactionBackend(SQLTransaction&); + ~SQLTransactionBackend(); -#if PLATFORM(IOS) - bool shouldPerformWhilePaused() const; -#endif - - DatabaseBackend* database() { return m_database.get(); } - bool isReadOnly() { return m_readOnly; } void notifyDatabaseThreadIsShuttingDown(); -private: - SQLTransactionBackend(DatabaseBackend*, PassRefPtr<AbstractSQLTransaction>, - PassRefPtr<SQLTransactionWrapper>, bool readOnly); + // API called from the frontend published via SQLTransactionBackend: + void requestTransitToState(SQLTransactionState); - // APIs called from the frontend published via AbstractSQLTransactionBackend: - virtual void requestTransitToState(SQLTransactionState) override; - virtual PassRefPtr<SQLError> transactionError() override; - virtual AbstractSQLStatement* currentStatement() override; - virtual void setShouldRetryCurrentStatement(bool) override; - virtual void executeSQL(PassOwnPtr<AbstractSQLStatement>, const String& statement, - const Vector<SQLValue>& arguments, int permissions) override; +private: + friend class SQLTransaction; void doCleanup(); - void enqueueStatementBackend(PassRefPtr<SQLStatementBackend>); - // State Machine functions: - virtual StateFunction stateFunctionFor(SQLTransactionState) override; + StateFunction stateFunctionFor(SQLTransactionState) override; void computeNextStateAndCleanupIfNeeded(); // State functions: - SQLTransactionState acquireLock(); - SQLTransactionState openTransactionAndPreflight(); - SQLTransactionState runStatements(); - SQLTransactionState postflightAndCommit(); - SQLTransactionState cleanupAndTerminate(); - SQLTransactionState cleanupAfterTransactionErrorCallback(); + void acquireLock(); + void openTransactionAndPreflight(); + void runStatements(); + void cleanupAndTerminate(); + void cleanupAfterTransactionErrorCallback(); - SQLTransactionState unreachableState(); - SQLTransactionState sendToFrontendState(); + NO_RETURN_DUE_TO_ASSERT void unreachableState(); - SQLTransactionState nextStateForCurrentStatementError(); - SQLTransactionState nextStateForTransactionError(); - SQLTransactionState runCurrentStatementAndGetNextState(); - - void getNextStatement(); - - void acquireOriginLock(); - void releaseOriginLockIfNeeded(); - - RefPtr<AbstractSQLTransaction> m_frontend; // Has a reference cycle, and will break in doCleanup(). - RefPtr<SQLStatementBackend> m_currentStatementBackend; - - RefPtr<DatabaseBackend> m_database; - RefPtr<SQLTransactionWrapper> m_wrapper; - RefPtr<SQLError> m_transactionError; - - bool m_hasCallback; - bool m_hasSuccessCallback; - bool m_hasErrorCallback; - bool m_shouldRetryCurrentStatement; - bool m_modifiedDatabase; - bool m_lockAcquired; - bool m_readOnly; - bool m_hasVersionMismatch; - - Mutex m_statementMutex; - Deque<RefPtr<SQLStatementBackend>> m_statementQueue; - - OwnPtr<SQLiteTransaction> m_sqliteTransaction; - RefPtr<OriginLock> m_originLock; + SQLTransaction& m_frontend; }; } // namespace WebCore - -#endif - -#endif // SQLTransactionBackend_h |