Title: [204349] trunk/Source/WebCore
Revision
204349
Author
[email protected]
Date
2016-08-10 13:30:14 -0700 (Wed, 10 Aug 2016)

Log Message

Move all SQLTransactionBackend member variables to SQLTransaction
https://bugs.webkit.org/show_bug.cgi?id=160745

Reviewed by Tim Horton.

* Modules/webdatabase/ChangeVersionWrapper.cpp:
(WebCore::ChangeVersionWrapper::performPreflight):
(WebCore::ChangeVersionWrapper::performPostflight):
(WebCore::ChangeVersionWrapper::handleCommitFailedAfterPostflight):
* Modules/webdatabase/ChangeVersionWrapper.h:
(WebCore::ChangeVersionWrapper::sqlError): Deleted.
* Modules/webdatabase/SQLTransaction.cpp:
(WebCore::SQLTransaction::SQLTransaction):
(WebCore::SQLTransaction::deliverTransactionErrorCallback):
(WebCore::SQLTransaction::deliverStatementCallback):
(WebCore::SQLTransaction::deliverQuotaIncreaseCallback):
(WebCore::SQLTransaction::hasCallback): Deleted.
(WebCore::SQLTransaction::hasSuccessCallback): Deleted.
(WebCore::SQLTransaction::hasErrorCallback): Deleted.
* Modules/webdatabase/SQLTransaction.h:
(WebCore::SQLTransaction::isReadOnly):
* Modules/webdatabase/SQLTransactionBackend.cpp:
(WebCore::SQLTransactionBackend::SQLTransactionBackend):
(WebCore::SQLTransactionBackend::~SQLTransactionBackend):
(WebCore::SQLTransactionBackend::doCleanup):
(WebCore::SQLTransactionBackend::enqueueStatement):
(WebCore::SQLTransactionBackend::computeNextStateAndCleanupIfNeeded):
(WebCore::SQLTransactionBackend::executeSQL):
(WebCore::SQLTransactionBackend::notifyDatabaseThreadIsShuttingDown):
(WebCore::SQLTransactionBackend::acquireLock):
(WebCore::SQLTransactionBackend::lockAcquired):
(WebCore::SQLTransactionBackend::openTransactionAndPreflight):
(WebCore::SQLTransactionBackend::runStatements):
(WebCore::SQLTransactionBackend::getNextStatement):
(WebCore::SQLTransactionBackend::runCurrentStatement):
(WebCore::SQLTransactionBackend::handleCurrentStatementError):
(WebCore::SQLTransactionBackend::handleTransactionError):
(WebCore::SQLTransactionBackend::postflightAndCommit):
(WebCore::SQLTransactionBackend::cleanupAndTerminate):
(WebCore::SQLTransactionBackend::cleanupAfterTransactionErrorCallback):
(WebCore::SQLTransactionBackend::requestTransitToState):
(WebCore::SQLTransactionBackend::acquireOriginLock):
(WebCore::SQLTransactionBackend::releaseOriginLockIfNeeded):
(WebCore::SQLTransactionBackend::currentStatement): Deleted.
(WebCore::SQLTransactionBackend::transactionError): Deleted.
(WebCore::SQLTransactionBackend::setShouldRetryCurrentStatement): Deleted.
(WebCore::SQLTransactionBackend::enqueueStatementBackend): Deleted.
* Modules/webdatabase/SQLTransactionBackend.h:
(WebCore::SQLTransactionBackend::database): Deleted.
(WebCore::SQLTransactionBackend::isReadOnly): Deleted.
* Modules/webdatabase/SQLTransactionCoordinator.cpp:
(WebCore::SQLTransactionCoordinator::processPendingTransactions):
(WebCore::SQLTransactionCoordinator::releaseLock):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (204348 => 204349)


--- trunk/Source/WebCore/ChangeLog	2016-08-10 20:25:44 UTC (rev 204348)
+++ trunk/Source/WebCore/ChangeLog	2016-08-10 20:30:14 UTC (rev 204349)
@@ -1,3 +1,59 @@
+2016-08-10  Anders Carlsson  <[email protected]>
+
+        Move all SQLTransactionBackend member variables to SQLTransaction
+        https://bugs.webkit.org/show_bug.cgi?id=160745
+
+        Reviewed by Tim Horton.
+
+        * Modules/webdatabase/ChangeVersionWrapper.cpp:
+        (WebCore::ChangeVersionWrapper::performPreflight):
+        (WebCore::ChangeVersionWrapper::performPostflight):
+        (WebCore::ChangeVersionWrapper::handleCommitFailedAfterPostflight):
+        * Modules/webdatabase/ChangeVersionWrapper.h:
+        (WebCore::ChangeVersionWrapper::sqlError): Deleted.
+        * Modules/webdatabase/SQLTransaction.cpp:
+        (WebCore::SQLTransaction::SQLTransaction):
+        (WebCore::SQLTransaction::deliverTransactionErrorCallback):
+        (WebCore::SQLTransaction::deliverStatementCallback):
+        (WebCore::SQLTransaction::deliverQuotaIncreaseCallback):
+        (WebCore::SQLTransaction::hasCallback): Deleted.
+        (WebCore::SQLTransaction::hasSuccessCallback): Deleted.
+        (WebCore::SQLTransaction::hasErrorCallback): Deleted.
+        * Modules/webdatabase/SQLTransaction.h:
+        (WebCore::SQLTransaction::isReadOnly):
+        * Modules/webdatabase/SQLTransactionBackend.cpp:
+        (WebCore::SQLTransactionBackend::SQLTransactionBackend):
+        (WebCore::SQLTransactionBackend::~SQLTransactionBackend):
+        (WebCore::SQLTransactionBackend::doCleanup):
+        (WebCore::SQLTransactionBackend::enqueueStatement):
+        (WebCore::SQLTransactionBackend::computeNextStateAndCleanupIfNeeded):
+        (WebCore::SQLTransactionBackend::executeSQL):
+        (WebCore::SQLTransactionBackend::notifyDatabaseThreadIsShuttingDown):
+        (WebCore::SQLTransactionBackend::acquireLock):
+        (WebCore::SQLTransactionBackend::lockAcquired):
+        (WebCore::SQLTransactionBackend::openTransactionAndPreflight):
+        (WebCore::SQLTransactionBackend::runStatements):
+        (WebCore::SQLTransactionBackend::getNextStatement):
+        (WebCore::SQLTransactionBackend::runCurrentStatement):
+        (WebCore::SQLTransactionBackend::handleCurrentStatementError):
+        (WebCore::SQLTransactionBackend::handleTransactionError):
+        (WebCore::SQLTransactionBackend::postflightAndCommit):
+        (WebCore::SQLTransactionBackend::cleanupAndTerminate):
+        (WebCore::SQLTransactionBackend::cleanupAfterTransactionErrorCallback):
+        (WebCore::SQLTransactionBackend::requestTransitToState):
+        (WebCore::SQLTransactionBackend::acquireOriginLock):
+        (WebCore::SQLTransactionBackend::releaseOriginLockIfNeeded):
+        (WebCore::SQLTransactionBackend::currentStatement): Deleted.
+        (WebCore::SQLTransactionBackend::transactionError): Deleted.
+        (WebCore::SQLTransactionBackend::setShouldRetryCurrentStatement): Deleted.
+        (WebCore::SQLTransactionBackend::enqueueStatementBackend): Deleted.
+        * Modules/webdatabase/SQLTransactionBackend.h:
+        (WebCore::SQLTransactionBackend::database): Deleted.
+        (WebCore::SQLTransactionBackend::isReadOnly): Deleted.
+        * Modules/webdatabase/SQLTransactionCoordinator.cpp:
+        (WebCore::SQLTransactionCoordinator::processPendingTransactions):
+        (WebCore::SQLTransactionCoordinator::releaseLock):
+
 2016-08-10  Simon Fraser  <[email protected]>
 
         Sort the project file.

Modified: trunk/Source/WebCore/Modules/webdatabase/ChangeVersionWrapper.cpp (204348 => 204349)


--- trunk/Source/WebCore/Modules/webdatabase/ChangeVersionWrapper.cpp	2016-08-10 20:25:44 UTC (rev 204348)
+++ trunk/Source/WebCore/Modules/webdatabase/ChangeVersionWrapper.cpp	2016-08-10 20:30:14 UTC (rev 204349)
@@ -41,17 +41,14 @@
 {
 }
 
-bool ChangeVersionWrapper::performPreflight(SQLTransactionBackend* transaction)
+bool ChangeVersionWrapper::performPreflight(SQLTransaction& transaction)
 {
-    ASSERT(transaction && transaction->database());
+    Database& database = transaction.database();
 
-    Database* database = transaction->database();
-
     String actualVersion;
-    if (!database->getVersionFromDatabase(actualVersion)) {
-        int sqliteError = database->sqliteDatabase().lastError();
-        m_sqlError = SQLError::create(SQLError::UNKNOWN_ERR, "unable to read the current version",
-                                      sqliteError, database->sqliteDatabase().lastErrorMsg());
+    if (!database.getVersionFromDatabase(actualVersion)) {
+        int sqliteError = database.sqliteDatabase().lastError();
+        m_sqlError = SQLError::create(SQLError::UNKNOWN_ERR, "unable to read the current version", sqliteError, database.sqliteDatabase().lastErrorMsg());
         return false;
     }
 
@@ -63,26 +60,23 @@
     return true;
 }
 
-bool ChangeVersionWrapper::performPostflight(SQLTransactionBackend* transaction)
+bool ChangeVersionWrapper::performPostflight(SQLTransaction& transaction)
 {
-    ASSERT(transaction && transaction->database());
+    Database& database = transaction.database();
 
-    Database* database = transaction->database();
-
-    if (!database->setVersionInDatabase(m_newVersion)) {
-        int sqliteError = database->sqliteDatabase().lastError();
-        m_sqlError = SQLError::create(SQLError::UNKNOWN_ERR, "unable to set new version in database",
-                                      sqliteError, database->sqliteDatabase().lastErrorMsg());
+    if (!database.setVersionInDatabase(m_newVersion)) {
+        int sqliteError = database.sqliteDatabase().lastError();
+        m_sqlError = SQLError::create(SQLError::UNKNOWN_ERR, "unable to set new version in database", sqliteError, database.sqliteDatabase().lastErrorMsg());
         return false;
     }
 
-    database->setExpectedVersion(m_newVersion);
+    database.setExpectedVersion(m_newVersion);
     return true;
 }
 
-void ChangeVersionWrapper::handleCommitFailedAfterPostflight(SQLTransactionBackend* transaction)
+void ChangeVersionWrapper::handleCommitFailedAfterPostflight(SQLTransaction& transaction)
 {
-    transaction->database()->setCachedVersion(m_oldVersion);
+    transaction.database().setCachedVersion(m_oldVersion);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/webdatabase/ChangeVersionWrapper.h (204348 => 204349)


--- trunk/Source/WebCore/Modules/webdatabase/ChangeVersionWrapper.h	2016-08-10 20:25:44 UTC (rev 204348)
+++ trunk/Source/WebCore/Modules/webdatabase/ChangeVersionWrapper.h	2016-08-10 20:30:14 UTC (rev 204349)
@@ -39,10 +39,10 @@
 public:
     static Ref<ChangeVersionWrapper> create(const String& oldVersion, const String& newVersion) { return adoptRef(*new ChangeVersionWrapper(oldVersion, newVersion)); }
 
-    virtual bool performPreflight(SQLTransactionBackend*);
-    virtual bool performPostflight(SQLTransactionBackend*);
-    virtual SQLError* sqlError() const { return m_sqlError.get(); }
-    virtual void handleCommitFailedAfterPostflight(SQLTransactionBackend*);
+    bool performPreflight(SQLTransaction&) override;
+    bool performPostflight(SQLTransaction&) override;
+    SQLError* sqlError() const override { return m_sqlError.get(); };
+    void handleCommitFailedAfterPostflight(SQLTransaction&) override;
 
 private:
     ChangeVersionWrapper(const String& oldVersion, const String& newVersion);

Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp (204348 => 204349)


--- trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp	2016-08-10 20:25:44 UTC (rev 204348)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp	2016-08-10 20:30:14 UTC (rev 204349)
@@ -34,6 +34,7 @@
 #include "DatabaseContext.h"
 #include "ExceptionCode.h"
 #include "Logging.h"
+#include "OriginLock.h"
 #include "SQLError.h"
 #include "SQLStatement.h"
 #include "SQLStatementCallback.h"
@@ -42,6 +43,7 @@
 #include "SQLTransactionCallback.h"
 #include "SQLTransactionClient.h" // FIXME: Should be used in the backend only.
 #include "SQLTransactionErrorCallback.h"
+#include "SQLiteTransaction.h"
 #include "VoidCallback.h"
 #include <wtf/StdLibExtras.h>
 #include <wtf/Vector.h>
@@ -58,9 +60,14 @@
     , m_callbackWrapper(WTFMove(callback), m_database->scriptExecutionContext())
     , m_successCallbackWrapper(WTFMove(successCallback), m_database->scriptExecutionContext())
     , m_errorCallbackWrapper(WTFMove(errorCallback), m_database->scriptExecutionContext())
+    , m_wrapper(WTFMove(wrapper))
     , m_executeSqlAllowed(false)
+    , m_shouldRetryCurrentStatement(false)
+    , m_modifiedDatabase(false)
+    , m_lockAcquired(false)
     , m_readOnly(readOnly)
-    , m_backend(m_database.ptr(), *this, WTFMove(wrapper), readOnly)
+    , m_hasVersionMismatch(false)
+    , m_backend(*this)
 {
 }
 
@@ -68,21 +75,6 @@
 {
 }
 
-bool SQLTransaction::hasCallback() const
-{
-    return m_callbackWrapper.hasCallback();
-}
-
-bool SQLTransaction::hasSuccessCallback() const
-{
-    return m_successCallbackWrapper.hasCallback();
-}
-
-bool SQLTransaction::hasErrorCallback() const
-{
-    return m_errorCallbackWrapper.hasCallback();
-}
-
 SQLTransaction::StateFunction SQLTransaction::stateFunctionFor(SQLTransactionState state)
 {
     static const StateFunction stateFunctions[] = {
@@ -140,23 +132,14 @@
 
 void SQLTransaction::deliverTransactionErrorCallback()
 {
+    ASSERT(m_transactionError);
+
     // Spec 4.3.2.10: If exists, invoke error callback with the last
     // error to have occurred in this transaction.
     RefPtr<SQLTransactionErrorCallback> errorCallback = m_errorCallbackWrapper.unwrap();
-    if (errorCallback) {
-        // If we get here with an empty m_transactionError, then the backend
-        // must be waiting in the idle state waiting for this state to finish.
-        // Hence, it's thread safe to fetch the backend transactionError without
-        // a lock.
-        if (!m_transactionError)
-            m_transactionError = m_backend.transactionError();
-
-        ASSERT(m_transactionError);
+    if (errorCallback)
         errorCallback->handleEvent(m_transactionError.get());
 
-        m_transactionError = nullptr;
-    }
-
     clearCallbackWrappers();
 
     // Spec 4.3.2.10: Rollback the transaction.
@@ -165,15 +148,12 @@
 
 void SQLTransaction::deliverStatementCallback()
 {
+    ASSERT(m_currentStatement);
+
     // 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();
-    ASSERT(currentStatement);
-
-    bool result = currentStatement->performCallback(this);
-
+    bool result = m_currentStatement->performCallback(this);
     m_executeSqlAllowed = false;
 
     if (result) {
@@ -193,10 +173,10 @@
 
 void SQLTransaction::deliverQuotaIncreaseCallback()
 {
-    ASSERT(m_backend.currentStatement());
+    ASSERT(m_currentStatement);
+    ASSERT(!m_shouldRetryCurrentStatement);
 
-    bool shouldRetryCurrentStatement = m_database->transactionClient()->didExceedQuota(&database());
-    m_backend.setShouldRetryCurrentStatement(shouldRetryCurrentStatement);
+    m_shouldRetryCurrentStatement = m_database->transactionClient()->didExceedQuota(&database());
 
     m_backend.requestTransitToState(SQLTransactionState::RunStatements);
 }

Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.h (204348 => 204349)


--- trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.h	2016-08-10 20:25:44 UTC (rev 204348)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.h	2016-08-10 20:30:14 UTC (rev 204349)
@@ -51,10 +51,10 @@
 class SQLTransactionWrapper : public ThreadSafeRefCounted<SQLTransactionWrapper> {
 public:
     virtual ~SQLTransactionWrapper() { }
-    virtual bool performPreflight(SQLTransactionBackend*) = 0;
-    virtual bool performPostflight(SQLTransactionBackend*) = 0;
+    virtual bool performPreflight(SQLTransaction&) = 0;
+    virtual bool performPostflight(SQLTransaction&) = 0;
     virtual SQLError* sqlError() const = 0;
-    virtual void handleCommitFailedAfterPostflight(SQLTransactionBackend*) = 0;
+    virtual void handleCommitFailedAfterPostflight(SQLTransaction&) = 0;
 };
 
 class SQLTransaction : public ThreadSafeRefCounted<SQLTransaction>, public SQLTransactionStateMachine<SQLTransaction> {
@@ -67,15 +67,15 @@
     void performPendingCallback();
 
     Database& database() { return m_database; }
+    bool isReadOnly() const { return m_readOnly; }
     SQLTransactionBackend& backend() { return m_backend; }
 
     // APIs called from the backend published via SQLTransaction:
     void requestTransitToState(SQLTransactionState);
-    bool hasCallback() const;
-    bool hasSuccessCallback() const;
-    bool hasErrorCallback() const;
 
 private:
+    friend class SQLTransactionBackend;
+
     SQLTransaction(Ref<Database>&&, RefPtr<SQLTransactionCallback>&&, RefPtr<VoidCallback>&& successCallback, RefPtr<SQLTransactionErrorCallback>&&, RefPtr<SQLTransactionWrapper>&&, bool readOnly);
 
     void clearCallbackWrappers();
@@ -98,11 +98,25 @@
     SQLCallbackWrapper<VoidCallback> m_successCallbackWrapper;
     SQLCallbackWrapper<SQLTransactionErrorCallback> m_errorCallbackWrapper;
 
+    RefPtr<SQLTransactionWrapper> m_wrapper;
+
     bool m_executeSqlAllowed;
     RefPtr<SQLError> m_transactionError;
 
+    bool m_shouldRetryCurrentStatement;
+    bool m_modifiedDatabase;
+    bool m_lockAcquired;
     bool m_readOnly;
+    bool m_hasVersionMismatch;
 
+    Lock m_statementMutex;
+    Deque<std::unique_ptr<SQLStatement>> m_statementQueue;
+
+    std::unique_ptr<SQLStatement> m_currentStatement;
+
+    std::unique_ptr<SQLiteTransaction> m_sqliteTransaction;
+    RefPtr<OriginLock> m_originLock;
+
     SQLTransactionBackend m_backend;
 };
 

Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.cpp (204348 => 204349)


--- trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.cpp	2016-08-10 20:25:44 UTC (rev 204348)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.cpp	2016-08-10 20:30:14 UTC (rev 204349)
@@ -343,49 +343,38 @@
 
 namespace WebCore {
 
-SQLTransactionBackend::SQLTransactionBackend(Database* db, SQLTransaction& frontend, RefPtr<SQLTransactionWrapper>&& wrapper, bool readOnly)
+SQLTransactionBackend::SQLTransactionBackend(SQLTransaction& frontend)
     : m_frontend(frontend)
-    , m_database(db)
-    , m_wrapper(WTFMove(wrapper))
-    , m_hasCallback(m_frontend.hasCallback())
-    , m_hasSuccessCallback(m_frontend.hasSuccessCallback())
-    , m_hasErrorCallback(m_frontend.hasErrorCallback())
-    , m_shouldRetryCurrentStatement(false)
-    , m_modifiedDatabase(false)
-    , m_lockAcquired(false)
-    , m_readOnly(readOnly)
-    , m_hasVersionMismatch(false)
 {
-    ASSERT(m_database);
     m_requestedState = SQLTransactionState::AcquireLock;
 }
 
 SQLTransactionBackend::~SQLTransactionBackend()
 {
-    ASSERT(!m_sqliteTransaction);
+    ASSERT(!m_frontend.m_sqliteTransaction);
 }
 
 void SQLTransactionBackend::doCleanup()
 {
-    ASSERT(currentThread() == database()->databaseContext()->databaseThread()->getThreadID());
+    ASSERT(currentThread() == m_frontend.database().databaseContext()->databaseThread()->getThreadID());
 
     releaseOriginLockIfNeeded();
 
-    LockHolder locker(m_statementMutex);
-    m_statementQueue.clear();
+    LockHolder locker(m_frontend.m_statementMutex);
+    m_frontend.m_statementQueue.clear();
 
-    if (m_sqliteTransaction) {
+    if (m_frontend.m_sqliteTransaction) {
         // In the event we got here because of an interruption or error (i.e. if
         // the transaction is in progress), we should roll it back here. Clearing
         // m_sqliteTransaction invokes SQLiteTransaction's destructor which does
         // just that. We might as well do this unconditionally and free up its
         // resources because we're already terminating.
-        m_sqliteTransaction = nullptr;
+        m_frontend.m_sqliteTransaction = nullptr;
     }
 
     // Release the lock on this database
-    if (m_lockAcquired)
-        m_database->transactionCoordinator()->releaseLock(m_frontend);
+    if (m_frontend.m_lockAcquired)
+        m_frontend.m_database->transactionCoordinator()->releaseLock(m_frontend);
 
     // Do some aggresive clean up here except for m_database.
     //
@@ -410,25 +399,9 @@
     // SQLTransactionBackend is guaranteed to not destruct until the frontend
     // is also destructing.
 
-    m_wrapper = nullptr;
+    m_frontend.m_wrapper = nullptr;
 }
 
-SQLStatement* SQLTransactionBackend::currentStatement()
-{
-    return m_currentStatementBackend.get();
-}
-
-SQLError* SQLTransactionBackend::transactionError()
-{
-    return m_transactionError.get();
-}
-
-void SQLTransactionBackend::setShouldRetryCurrentStatement(bool shouldRetry)
-{
-    ASSERT(!m_shouldRetryCurrentStatement);
-    m_shouldRetryCurrentStatement = shouldRetry;
-}
-
 SQLTransactionBackend::StateFunction SQLTransactionBackend::stateFunctionFor(SQLTransactionState state)
 {
     static const StateFunction stateFunctions[] = {
@@ -453,10 +426,10 @@
     return stateFunctions[static_cast<int>(state)];
 }
 
-void SQLTransactionBackend::enqueueStatementBackend(std::unique_ptr<SQLStatement> statementBackend)
+void SQLTransactionBackend::enqueueStatement(std::unique_ptr<SQLStatement> statement)
 {
-    LockHolder locker(m_statementMutex);
-    m_statementQueue.append(WTFMove(statementBackend));
+    LockHolder locker(m_frontend.m_statementMutex);
+    m_frontend.m_statementQueue.append(WTFMove(statement));
 }
 
 void SQLTransactionBackend::computeNextStateAndCleanupIfNeeded()
@@ -463,7 +436,7 @@
 {
     // Only honor the requested state transition if we're not supposed to be
     // cleaning up and shutting down:
-    if (m_database->opened()) {
+    if (m_frontend.m_database->opened()) {
         setStateToRequestedState();
         ASSERT(m_nextState == SQLTransactionState::AcquireLock
             || m_nextState == SQLTransactionState::OpenTransactionAndPreflight
@@ -485,9 +458,9 @@
     LOG(StorageAPI, "Database was stopped or interrupted - cancelling work for this transaction");
 
     // The current SQLite transaction should be stopped, as well
-    if (m_sqliteTransaction) {
-        m_sqliteTransaction->stop();
-        m_sqliteTransaction = nullptr;
+    if (m_frontend.m_sqliteTransaction) {
+        m_frontend.m_sqliteTransaction->stop();
+        m_frontend.m_sqliteTransaction = nullptr;
     }
 
     // Terminate the frontend state machine. This also gets the frontend to
@@ -505,17 +478,17 @@
     runStateMachine();
 }
 
-void SQLTransactionBackend::executeSQL(std::unique_ptr<SQLStatement> statementBackend)
+void SQLTransactionBackend::executeSQL(std::unique_ptr<SQLStatement> statement)
 {
-    if (m_database->deleted())
-        statementBackend->setDatabaseDeletedError();
+    if (m_frontend.m_database->deleted())
+        statement->setDatabaseDeletedError();
 
-    enqueueStatementBackend(WTFMove(statementBackend));
+    enqueueStatement(WTFMove(statement));
 }
 
 void SQLTransactionBackend::notifyDatabaseThreadIsShuttingDown()
 {
-    ASSERT(currentThread() == database()->databaseContext()->databaseThread()->getThreadID());
+    ASSERT(currentThread() == m_frontend.m_database->databaseContext()->databaseThread()->getThreadID());
 
     // If the transaction is in progress, we should roll it back here, since this
     // is our last opportunity to do something related to this transaction on the
@@ -527,28 +500,28 @@
 
 void SQLTransactionBackend::acquireLock()
 {
-    m_database->transactionCoordinator()->acquireLock(m_frontend);
+    m_frontend.m_database->transactionCoordinator()->acquireLock(m_frontend);
 }
 
 void SQLTransactionBackend::lockAcquired()
 {
-    m_lockAcquired = true;
+    m_frontend.m_lockAcquired = true;
 
     m_requestedState = SQLTransactionState::OpenTransactionAndPreflight;
     ASSERT(m_requestedState != SQLTransactionState::End);
-    m_database->scheduleTransactionStep(m_frontend);
+    m_frontend.m_database->scheduleTransactionStep(m_frontend);
 }
 
 void SQLTransactionBackend::openTransactionAndPreflight()
 {
-    ASSERT(!m_database->sqliteDatabase().transactionInProgress());
-    ASSERT(m_lockAcquired);
+    ASSERT(!m_frontend.m_database->sqliteDatabase().transactionInProgress());
+    ASSERT(m_frontend.m_lockAcquired);
 
     LOG(StorageAPI, "Opening and preflighting transaction %p", this);
 
     // If the database was deleted, jump to the error callback
-    if (m_database->deleted()) {
-        m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "unable to open a transaction, because the user deleted the database");
+    if (m_frontend.m_database->deleted()) {
+        m_frontend.m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "unable to open a transaction, because the user deleted the database");
 
         handleTransactionError();
         return;
@@ -555,25 +528,24 @@
     }
 
     // Set the maximum usage for this transaction if this transactions is not read-only
-    if (!m_readOnly) {
+    if (!m_frontend.m_readOnly) {
         acquireOriginLock();
-        m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize());
+        m_frontend.m_database->sqliteDatabase().setMaximumSize(m_frontend.m_database->maximumSize());
     }
 
-    ASSERT(!m_sqliteTransaction);
-    m_sqliteTransaction = std::make_unique<SQLiteTransaction>(m_database->sqliteDatabase(), m_readOnly);
+    ASSERT(!m_frontend.m_sqliteTransaction);
+    m_frontend.m_sqliteTransaction = std::make_unique<SQLiteTransaction>(m_frontend.m_database->sqliteDatabase(), m_frontend.m_readOnly);
 
-    m_database->resetDeletes();
-    m_database->disableAuthorizer();
-    m_sqliteTransaction->begin();
-    m_database->enableAuthorizer();
+    m_frontend.m_database->resetDeletes();
+    m_frontend.m_database->disableAuthorizer();
+    m_frontend.m_sqliteTransaction->begin();
+    m_frontend.m_database->enableAuthorizer();
 
     // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error callback if that fails
-    if (!m_sqliteTransaction->inProgress()) {
-        ASSERT(!m_database->sqliteDatabase().transactionInProgress());
-        m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "unable to begin transaction",
-            m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase().lastErrorMsg());
-        m_sqliteTransaction = nullptr;
+    if (!m_frontend.m_sqliteTransaction->inProgress()) {
+        ASSERT(!m_frontend.m_database->sqliteDatabase().transactionInProgress());
+        m_frontend.m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "unable to begin transaction", m_frontend.m_database->sqliteDatabase().lastError(), m_frontend.m_database->sqliteDatabase().lastErrorMsg());
+        m_frontend.m_sqliteTransaction = nullptr;
 
         handleTransactionError();
         return;
@@ -583,27 +555,26 @@
     // In multi-process browsers, we take this opportinutiy to update the cached value for
     // the actual version. In single-process browsers, this is just a map lookup.
     String actualVersion;
-    if (!m_database->getActualVersionForTransaction(actualVersion)) {
-        m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "unable to read version",
-            m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase().lastErrorMsg());
-        m_database->disableAuthorizer();
-        m_sqliteTransaction = nullptr;
-        m_database->enableAuthorizer();
+    if (!m_frontend.m_database->getActualVersionForTransaction(actualVersion)) {
+        m_frontend.m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "unable to read version", m_frontend.m_database->sqliteDatabase().lastError(), m_frontend.m_database->sqliteDatabase().lastErrorMsg());
+        m_frontend.m_database->disableAuthorizer();
+        m_frontend.m_sqliteTransaction = nullptr;
+        m_frontend.m_database->enableAuthorizer();
 
         handleTransactionError();
         return;
     }
 
-    m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && (m_database->expectedVersion() != actualVersion);
+    m_frontend.m_hasVersionMismatch = !m_frontend.m_database->expectedVersion().isEmpty() && (m_frontend.m_database->expectedVersion() != actualVersion);
 
     // Spec 4.3.2.3: Perform preflight steps, jumping to the error callback if they fail
-    if (m_wrapper && !m_wrapper->performPreflight(this)) {
-        m_database->disableAuthorizer();
-        m_sqliteTransaction = nullptr;
-        m_database->enableAuthorizer();
-        m_transactionError = m_wrapper->sqlError();
-        if (!m_transactionError)
-            m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "unknown error occurred during transaction preflight");
+    if (m_frontend.m_wrapper && !m_frontend.m_wrapper->performPreflight(m_frontend)) {
+        m_frontend.m_database->disableAuthorizer();
+        m_frontend.m_sqliteTransaction = nullptr;
+        m_frontend.m_database->enableAuthorizer();
+        m_frontend.m_transactionError = m_frontend.m_wrapper->sqlError();
+        if (!m_frontend.m_transactionError)
+            m_frontend.m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "unknown error occurred during transaction preflight");
 
         handleTransactionError();
         return;
@@ -610,7 +581,7 @@
     }
 
     // Spec 4.3.2.4: Invoke the transaction callback with the new SQLTransaction object
-    if (m_hasCallback) {
+    if (m_frontend.m_callbackWrapper.hasCallback()) {
         m_frontend.requestTransitToState(SQLTransactionState::DeliverTransactionCallback);
         return;
     }
@@ -621,13 +592,13 @@
 
 void SQLTransactionBackend::runStatements()
 {
-    ASSERT(m_lockAcquired);
+    ASSERT(m_frontend.m_lockAcquired);
 
     // If there is a series of statements queued up that are all successful and have no associated
     // SQLStatementCallback objects, then we can burn through the queue
     do {
-        if (m_shouldRetryCurrentStatement && !m_sqliteTransaction->wasRolledBackBySqlite()) {
-            m_shouldRetryCurrentStatement = false;
+        if (m_frontend.m_shouldRetryCurrentStatement && !m_frontend.m_sqliteTransaction->wasRolledBackBySqlite()) {
+            m_frontend.m_shouldRetryCurrentStatement = false;
             // FIXME - Another place that needs fixing up after <rdar://problem/5628468> is addressed.
             // See ::openTransactionAndPreflight() for discussion
 
@@ -635,11 +606,11 @@
             // m_shouldRetryCurrentStatement is set to true only when a statement exceeds
             // the quota, which can happen only in a read-write transaction. Therefore, there
             // is no need to check here if the transaction is read-write.
-            m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize());
+            m_frontend.m_database->sqliteDatabase().setMaximumSize(m_frontend.m_database->maximumSize());
         } else {
             // If the current statement has already been run, failed due to quota constraints, and we're not retrying it,
             // that means it ended in an error. Handle it now
-            if (m_currentStatementBackend && m_currentStatementBackend->lastExecutionFailedDueToQuota()) {
+            if (m_frontend.m_currentStatement && m_frontend.m_currentStatement->lastExecutionFailedDueToQuota()) {
                 handleCurrentStatementError();
                 break;
             }
@@ -652,38 +623,38 @@
     // If runCurrentStatement() returned false, that means either there was no current statement to run,
     // or the current statement requires a callback to complete. In the later case, it also scheduled
     // the callback or performed any other additional work so we can return.
-    if (!m_currentStatementBackend)
+    if (!m_frontend.m_currentStatement)
         postflightAndCommit();
 }
 
 void SQLTransactionBackend::getNextStatement()
 {
-    m_currentStatementBackend = nullptr;
+    m_frontend.m_currentStatement = nullptr;
 
-    LockHolder locker(m_statementMutex);
-    if (!m_statementQueue.isEmpty())
-        m_currentStatementBackend = m_statementQueue.takeFirst();
+    LockHolder locker(m_frontend.m_statementMutex);
+    if (!m_frontend.m_statementQueue.isEmpty())
+        m_frontend.m_currentStatement = m_frontend.m_statementQueue.takeFirst();
 }
 
 bool SQLTransactionBackend::runCurrentStatement()
 {
-    if (!m_currentStatementBackend) {
+    if (!m_frontend.m_currentStatement) {
         // No more statements to run. So move on to the next state.
         return false;
     }
 
-    m_database->resetAuthorizer();
+    m_frontend.m_database->resetAuthorizer();
 
-    if (m_hasVersionMismatch)
-        m_currentStatementBackend->setVersionMismatchedError();
+    if (m_frontend.m_hasVersionMismatch)
+        m_frontend.m_currentStatement->setVersionMismatchedError();
 
-    if (m_currentStatementBackend->execute(*m_database)) {
-        if (m_database->lastActionChangedDatabase()) {
+    if (m_frontend.m_currentStatement->execute(m_frontend.m_database)) {
+        if (m_frontend.m_database->lastActionChangedDatabase()) {
             // Flag this transaction as having changed the database for later delegate notification
-            m_modifiedDatabase = true;
+            m_frontend.m_modifiedDatabase = true;
         }
 
-        if (m_currentStatementBackend->hasStatementCallback()) {
+        if (m_frontend.m_currentStatement->hasStatementCallback()) {
             m_frontend.requestTransitToState(SQLTransactionState::DeliverStatementCallback);
             return false;
         }
@@ -693,7 +664,7 @@
         return true;
     }
 
-    if (m_currentStatementBackend->lastExecutionFailedDueToQuota()) {
+    if (m_frontend.m_currentStatement->lastExecutionFailedDueToQuota()) {
         m_frontend.requestTransitToState(SQLTransactionState::DeliverQuotaIncreaseCallback);
         return false;
     }
@@ -706,14 +677,14 @@
 {
     // Spec 4.3.2.6.6: error - Call the statement's error callback, but if there was no error callback,
     // or the transaction was rolled back, jump to the transaction error callback
-    if (m_currentStatementBackend->hasStatementErrorCallback() && !m_sqliteTransaction->wasRolledBackBySqlite()) {
+    if (m_frontend.m_currentStatement->hasStatementErrorCallback() && !m_frontend.m_sqliteTransaction->wasRolledBackBySqlite()) {
         m_frontend.requestTransitToState(SQLTransactionState::DeliverStatementCallback);
         return;
     }
 
-    m_transactionError = m_currentStatementBackend->sqlError();
-    if (!m_transactionError)
-        m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "the statement failed to execute");
+    m_frontend.m_transactionError = m_frontend.m_currentStatement->sqlError();
+    if (!m_frontend.m_transactionError)
+        m_frontend.m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "the statement failed to execute");
 
     handleTransactionError();
 }
@@ -720,8 +691,8 @@
 
 void SQLTransactionBackend::handleTransactionError()
 {
-    ASSERT(m_transactionError);
-    if (m_hasErrorCallback) {
+    ASSERT(m_frontend.m_transactionError);
+    if (m_frontend.m_errorCallbackWrapper.hasCallback()) {
         m_frontend.requestTransitToState(SQLTransactionState::DeliverTransactionErrorCallback);
         return;
     }
@@ -733,13 +704,13 @@
 
 void SQLTransactionBackend::postflightAndCommit()
 {
-    ASSERT(m_lockAcquired);
+    ASSERT(m_frontend.m_lockAcquired);
 
     // Spec 4.3.2.7: Perform postflight steps, jumping to the error callback if they fail.
-    if (m_wrapper && !m_wrapper->performPostflight(this)) {
-        m_transactionError = m_wrapper->sqlError();
-        if (!m_transactionError)
-            m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "unknown error occurred during transaction postflight");
+    if (m_frontend.m_wrapper && !m_frontend.m_wrapper->performPostflight(m_frontend)) {
+        m_frontend.m_transactionError = m_frontend.m_wrapper->sqlError();
+        if (!m_frontend.m_transactionError)
+            m_frontend.m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "unknown error occurred during transaction postflight");
 
         handleTransactionError();
         return;
@@ -746,20 +717,19 @@
     }
 
     // Spec 4.3.2.7: Commit the transaction, jumping to the error callback if that fails.
-    ASSERT(m_sqliteTransaction);
+    ASSERT(m_frontend.m_sqliteTransaction);
 
-    m_database->disableAuthorizer();
-    m_sqliteTransaction->commit();
-    m_database->enableAuthorizer();
+    m_frontend.m_database->disableAuthorizer();
+    m_frontend.m_sqliteTransaction->commit();
+    m_frontend.m_database->enableAuthorizer();
 
     releaseOriginLockIfNeeded();
 
     // If the commit failed, the transaction will still be marked as "in progress"
-    if (m_sqliteTransaction->inProgress()) {
-        if (m_wrapper)
-            m_wrapper->handleCommitFailedAfterPostflight(this);
-        m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "unable to commit transaction",
-            m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase().lastErrorMsg());
+    if (m_frontend.m_sqliteTransaction->inProgress()) {
+        if (m_frontend.m_wrapper)
+            m_frontend.m_wrapper->handleCommitFailedAfterPostflight(m_frontend);
+        m_frontend.m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "unable to commit transaction", m_frontend.m_database->sqliteDatabase().lastError(), m_frontend.m_database->sqliteDatabase().lastErrorMsg());
 
         handleTransactionError();
         return;
@@ -766,12 +736,12 @@
     }
 
     // Vacuum the database if anything was deleted.
-    if (m_database->hadDeletes())
-        m_database->incrementalVacuumIfNeeded();
+    if (m_frontend.m_database->hadDeletes())
+        m_frontend.m_database->incrementalVacuumIfNeeded();
 
     // The commit was successful. If the transaction modified this database, notify the delegates.
-    if (m_modifiedDatabase)
-        m_database->transactionClient()->didCommitWriteTransaction(database());
+    if (m_frontend.m_modifiedDatabase)
+        m_frontend.m_database->transactionClient()->didCommitWriteTransaction(m_frontend.m_database.ptr());
 
     // Spec 4.3.2.8: Deliver success callback, if there is one.
     m_frontend.requestTransitToState(SQLTransactionState::DeliverSuccessCallback);
@@ -779,35 +749,35 @@
 
 void SQLTransactionBackend::cleanupAndTerminate()
 {
-    ASSERT(m_lockAcquired);
+    ASSERT(m_frontend.m_lockAcquired);
 
     // Spec 4.3.2.9: End transaction steps. There is no next step.
     LOG(StorageAPI, "Transaction %p is complete\n", this);
-    ASSERT(!m_database->sqliteDatabase().transactionInProgress());
+    ASSERT(!m_frontend.m_database->sqliteDatabase().transactionInProgress());
 
     // Phase 5 cleanup. See comment on the SQLTransaction life-cycle above.
     doCleanup();
-    m_database->inProgressTransactionCompleted();
+    m_frontend.m_database->inProgressTransactionCompleted();
 }
 
 void SQLTransactionBackend::cleanupAfterTransactionErrorCallback()
 {
-    ASSERT(m_lockAcquired);
+    ASSERT(m_frontend.m_lockAcquired);
 
     LOG(StorageAPI, "Transaction %p is complete with an error\n", this);
-    m_database->disableAuthorizer();
-    if (m_sqliteTransaction) {
+    m_frontend.m_database->disableAuthorizer();
+    if (m_frontend.m_sqliteTransaction) {
         // Spec 4.3.2.10: Rollback the transaction.
-        m_sqliteTransaction->rollback();
+        m_frontend.m_sqliteTransaction->rollback();
 
-        ASSERT(!m_database->sqliteDatabase().transactionInProgress());
-        m_sqliteTransaction = nullptr;
+        ASSERT(!m_frontend.m_database->sqliteDatabase().transactionInProgress());
+        m_frontend.m_sqliteTransaction = nullptr;
     }
-    m_database->enableAuthorizer();
+    m_frontend.m_database->enableAuthorizer();
 
     releaseOriginLockIfNeeded();
 
-    ASSERT(!m_database->sqliteDatabase().transactionInProgress());
+    ASSERT(!m_frontend.m_database->sqliteDatabase().transactionInProgress());
 
     cleanupAndTerminate();
 }
@@ -820,7 +790,7 @@
     LOG(StorageAPI, "Scheduling %s for transaction %p\n", nameForSQLTransactionState(nextState), this);
     m_requestedState = nextState;
     ASSERT(m_requestedState != SQLTransactionState::End);
-    m_database->scheduleTransactionStep(m_frontend);
+    m_frontend.m_database->scheduleTransactionStep(m_frontend);
 }
 
 // This state function is used as a stub function to plug unimplemented states
@@ -833,16 +803,16 @@
 
 void SQLTransactionBackend::acquireOriginLock()
 {
-    ASSERT(!m_originLock);
-    m_originLock = DatabaseTracker::tracker().originLockFor(m_database->securityOrigin());
-    m_originLock->lock();
+    ASSERT(!m_frontend.m_originLock);
+    m_frontend.m_originLock = DatabaseTracker::tracker().originLockFor(m_frontend.m_database->securityOrigin());
+    m_frontend.m_originLock->lock();
 }
 
 void SQLTransactionBackend::releaseOriginLockIfNeeded()
 {
-    if (m_originLock) {
-        m_originLock->unlock();
-        m_originLock = nullptr;
+    if (m_frontend.m_originLock) {
+        m_frontend.m_originLock->unlock();
+        m_frontend.m_originLock = nullptr;
     }
 }
 

Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h (204348 => 204349)


--- trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h	2016-08-10 20:25:44 UTC (rev 204348)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h	2016-08-10 20:30:14 UTC (rev 204349)
@@ -49,21 +49,16 @@
 
 class SQLTransactionBackend : public SQLTransactionStateMachine<SQLTransactionBackend> {
 public:
-    SQLTransactionBackend(Database*, SQLTransaction&, RefPtr<SQLTransactionWrapper>&&, bool readOnly);
+    explicit SQLTransactionBackend(SQLTransaction&);
     ~SQLTransactionBackend();
 
     void lockAcquired();
     void performNextStep();
 
-    Database* database() { return m_database.get(); }
-    bool isReadOnly() { return m_readOnly; }
     void notifyDatabaseThreadIsShuttingDown();
 
     // APIs called from the frontend published via SQLTransactionBackend:
     void requestTransitToState(SQLTransactionState);
-    SQLError* transactionError();
-    SQLStatement* currentStatement();
-    void setShouldRetryCurrentStatement(bool);
     void executeSQL(std::unique_ptr<SQLStatement>);
     
 private:
@@ -70,7 +65,7 @@
 
     void doCleanup();
 
-    void enqueueStatementBackend(std::unique_ptr<SQLStatement>);
+    void enqueueStatement(std::unique_ptr<SQLStatement>);
 
     // State Machine functions:
     StateFunction stateFunctionFor(SQLTransactionState) override;
@@ -95,26 +90,6 @@
     void releaseOriginLockIfNeeded();
 
     SQLTransaction& m_frontend;
-    std::unique_ptr<SQLStatement> m_currentStatementBackend;
-
-    RefPtr<Database> 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;
-
-    Lock m_statementMutex;
-    Deque<std::unique_ptr<SQLStatement>> m_statementQueue;
-
-    std::unique_ptr<SQLiteTransaction> m_sqliteTransaction;
-    RefPtr<OriginLock> m_originLock;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransactionCoordinator.cpp (204348 => 204349)


--- trunk/Source/WebCore/Modules/webdatabase/SQLTransactionCoordinator.cpp	2016-08-10 20:25:44 UTC (rev 204348)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransactionCoordinator.cpp	2016-08-10 20:30:14 UTC (rev 204349)
@@ -58,12 +58,12 @@
         return;
 
     RefPtr<SQLTransaction> firstPendingTransaction = info.pendingTransactions.first();
-    if (firstPendingTransaction->backend().isReadOnly()) {
+    if (firstPendingTransaction->isReadOnly()) {
         do {
             firstPendingTransaction = info.pendingTransactions.takeFirst();
             info.activeReadTransactions.add(firstPendingTransaction);
             firstPendingTransaction->backend().lockAcquired();
-        } while (!info.pendingTransactions.isEmpty() && info.pendingTransactions.first()->backend().isReadOnly());
+        } while (!info.pendingTransactions.isEmpty() && info.pendingTransactions.first()->isReadOnly());
     } else if (info.activeReadTransactions.isEmpty()) {
         info.pendingTransactions.removeFirst();
         info.activeWriteTransaction = firstPendingTransaction;
@@ -99,7 +99,7 @@
     ASSERT(coordinationInfoIterator != m_coordinationInfoMap.end());
     CoordinationInfo& info = coordinationInfoIterator->value;
 
-    if (transaction.backend().isReadOnly()) {
+    if (transaction.isReadOnly()) {
         ASSERT(info.activeReadTransactions.contains(&transaction));
         info.activeReadTransactions.remove(&transaction);
     } else {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to