#ifndef SQLTransactionBackend_h
#define SQLTransactionBackend_h
#include "heap/Handle.h"
#include "modules/webdatabase/AbstractSQLStatement.h"
#include "modules/webdatabase/AbstractSQLTransactionBackend.h"
#include "modules/webdatabase/DatabaseBasicTypes.h"
#include "modules/webdatabase/SQLTransactionStateMachine.h"
#include "wtf/Deque.h"
#include "wtf/Forward.h"
#include "wtf/ThreadingPrimitives.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class AbstractSQLTransaction;
class DatabaseBackend;
class SQLErrorData;
class SQLiteTransaction;
class SQLStatementBackend;
class SQLTransactionBackend;
class SQLValue;
class SQLTransactionWrapper : public ThreadSafeRefCountedWillBeGarbageCollectedFinalized<SQLTransactionWrapper> {
public:
virtual ~SQLTransactionWrapper() { }
virtual void trace(Visitor*) = 0;
virtual bool performPreflight(SQLTransactionBackend*) = 0;
virtual bool performPostflight(SQLTransactionBackend*) = 0;
virtual SQLErrorData* sqlError() const = 0;
virtual void handleCommitFailedAfterPostflight(SQLTransactionBackend*) = 0;
};
class SQLTransactionBackend FINAL : public AbstractSQLTransactionBackend, public SQLTransactionStateMachine<SQLTransactionBackend> {
public:
static PassRefPtrWillBeRawPtr<SQLTransactionBackend> create(DatabaseBackend*,
PassRefPtrWillBeRawPtr<AbstractSQLTransaction>, PassRefPtrWillBeRawPtr<SQLTransactionWrapper>, bool readOnly);
virtual ~SQLTransactionBackend();
virtual void trace(Visitor*) OVERRIDE;
void lockAcquired();
void performNextStep();
DatabaseBackend* database() { return m_database.get(); }
bool isReadOnly() { return m_readOnly; }
void notifyDatabaseThreadIsShuttingDown();
private:
SQLTransactionBackend(DatabaseBackend*, PassRefPtrWillBeRawPtr<AbstractSQLTransaction>,
PassRefPtrWillBeRawPtr<SQLTransactionWrapper>, bool readOnly);
virtual void requestTransitToState(SQLTransactionState) OVERRIDE;
virtual SQLErrorData* 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;
void doCleanup();
void enqueueStatementBackend(PassRefPtrWillBeRawPtr<SQLStatementBackend>);
virtual StateFunction stateFunctionFor(SQLTransactionState) OVERRIDE;
void computeNextStateAndCleanupIfNeeded();
SQLTransactionState acquireLock();
SQLTransactionState openTransactionAndPreflight();
SQLTransactionState runStatements();
SQLTransactionState postflightAndCommit();
SQLTransactionState cleanupAndTerminate();
SQLTransactionState cleanupAfterTransactionErrorCallback();
SQLTransactionState unreachableState();
SQLTransactionState sendToFrontendState();
SQLTransactionState nextStateForCurrentStatementError();
SQLTransactionState nextStateForTransactionError();
SQLTransactionState runCurrentStatementAndGetNextState();
void getNextStatement();
RefPtrWillBeMember<AbstractSQLTransaction> m_frontend;
RefPtrWillBeMember<SQLStatementBackend> m_currentStatementBackend;
RefPtrWillBeMember<DatabaseBackend> m_database;
RefPtrWillBeMember<SQLTransactionWrapper> m_wrapper;
OwnPtr<SQLErrorData> 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<RefPtrWillBeMember<SQLStatementBackend> > m_statementQueue;
OwnPtr<SQLiteTransaction> m_sqliteTransaction;
};
}
#endif