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

Log Message

Move more functions to from SQLTransactionBackend to SQLTransaction
https://bugs.webkit.org/show_bug.cgi?id=160752

Reviewed by Tim Horton.

* Modules/webdatabase/SQLTransaction.cpp:
(WebCore::SQLTransaction::acquireLock):
(WebCore::SQLTransaction::openTransactionAndPreflight):
(WebCore::SQLTransaction::runStatements):
(WebCore::SQLTransaction::cleanupAndTerminate):
(WebCore::SQLTransaction::cleanupAfterTransactionErrorCallback):
* Modules/webdatabase/SQLTransaction.h:
* Modules/webdatabase/SQLTransactionBackend.cpp:
(WebCore::SQLTransactionBackend::acquireLock):
(WebCore::SQLTransactionBackend::openTransactionAndPreflight):
(WebCore::SQLTransactionBackend::runStatements):
(WebCore::SQLTransactionBackend::cleanupAndTerminate):
(WebCore::SQLTransactionBackend::cleanupAfterTransactionErrorCallback):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (204356 => 204357)


--- trunk/Source/WebCore/ChangeLog	2016-08-10 21:31:07 UTC (rev 204356)
+++ trunk/Source/WebCore/ChangeLog	2016-08-10 21:54:29 UTC (rev 204357)
@@ -1,5 +1,26 @@
 2016-08-10  Anders Carlsson  <[email protected]>
 
+        Move more functions to from SQLTransactionBackend to SQLTransaction
+        https://bugs.webkit.org/show_bug.cgi?id=160752
+
+        Reviewed by Tim Horton.
+
+        * Modules/webdatabase/SQLTransaction.cpp:
+        (WebCore::SQLTransaction::acquireLock):
+        (WebCore::SQLTransaction::openTransactionAndPreflight):
+        (WebCore::SQLTransaction::runStatements):
+        (WebCore::SQLTransaction::cleanupAndTerminate):
+        (WebCore::SQLTransaction::cleanupAfterTransactionErrorCallback):
+        * Modules/webdatabase/SQLTransaction.h:
+        * Modules/webdatabase/SQLTransactionBackend.cpp:
+        (WebCore::SQLTransactionBackend::acquireLock):
+        (WebCore::SQLTransactionBackend::openTransactionAndPreflight):
+        (WebCore::SQLTransactionBackend::runStatements):
+        (WebCore::SQLTransactionBackend::cleanupAndTerminate):
+        (WebCore::SQLTransactionBackend::cleanupAfterTransactionErrorCallback):
+
+2016-08-10  Anders Carlsson  <[email protected]>
+
         Begin moving member functions from SQLTransactionBackend to SQLTransaction
         https://bugs.webkit.org/show_bug.cgi?id=160747
 

Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp (204356 => 204357)


--- trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp	2016-08-10 21:31:07 UTC (rev 204356)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp	2016-08-10 21:54:29 UTC (rev 204357)
@@ -42,7 +42,8 @@
 #include "SQLStatementErrorCallback.h"
 #include "SQLTransactionBackend.h"
 #include "SQLTransactionCallback.h"
-#include "SQLTransactionClient.h" // FIXME: Should be used in the backend only.
+#include "SQLTransactionClient.h"
+#include "SQLTransactionCoordinator.h"
 #include "SQLTransactionErrorCallback.h"
 #include "SQLiteTransaction.h"
 #include "VoidCallback.h"
@@ -162,6 +163,161 @@
     m_database->scheduleTransactionCallback(this);
 }
 
+void SQLTransaction::acquireLock()
+{
+    m_database->transactionCoordinator()->acquireLock(*this);
+}
+
+void SQLTransaction::openTransactionAndPreflight()
+{
+    ASSERT(!m_database->sqliteDatabase().transactionInProgress());
+    ASSERT(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");
+
+        handleTransactionError();
+        return;
+    }
+
+    // Set the maximum usage for this transaction if this transactions is not read-only
+    if (!m_readOnly) {
+        acquireOriginLock();
+        m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize());
+    }
+
+    ASSERT(!m_sqliteTransaction);
+    m_sqliteTransaction = std::make_unique<SQLiteTransaction>(m_database->sqliteDatabase(), m_readOnly);
+
+    m_database->resetDeletes();
+    m_database->disableAuthorizer();
+    m_sqliteTransaction->begin();
+    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;
+
+        handleTransactionError();
+        return;
+    }
+
+    // Note: We intentionally retrieve the actual version even with an empty expected version.
+    // 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();
+
+        handleTransactionError();
+        return;
+    }
+
+    m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && (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");
+
+        handleTransactionError();
+        return;
+    }
+
+    // Spec 4.3.2.4: Invoke the transaction callback with the new SQLTransaction object
+    if (m_callbackWrapper.hasCallback()) {
+        requestTransitToState(SQLTransactionState::DeliverTransactionCallback);
+        return;
+    }
+
+    // If we have no callback to make, skip pass to the state after:
+    runStatements();
+}
+
+void SQLTransaction::runStatements()
+{
+    ASSERT(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;
+            // FIXME - Another place that needs fixing up after <rdar://problem/5628468> is addressed.
+            // See ::openTransactionAndPreflight() for discussion
+
+            // Reset the maximum size here, as it was increased to allow us to retry this statement.
+            // 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());
+        } 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_currentStatement && m_currentStatement->lastExecutionFailedDueToQuota()) {
+                handleCurrentStatementError();
+                break;
+            }
+
+            // Otherwise, advance to the next statement
+            getNextStatement();
+        }
+    } while (runCurrentStatement());
+
+    // 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_currentStatement)
+        postflightAndCommit();
+}
+
+void SQLTransaction::cleanupAndTerminate()
+{
+    ASSERT(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());
+
+    // Phase 5 cleanup. See comment on the SQLTransaction life-cycle above.
+    m_backend.doCleanup();
+    m_database->inProgressTransactionCompleted();
+}
+
+void SQLTransaction::cleanupAfterTransactionErrorCallback()
+{
+    ASSERT(m_lockAcquired);
+
+    LOG(StorageAPI, "Transaction %p is complete with an error\n", this);
+    m_database->disableAuthorizer();
+    if (m_sqliteTransaction) {
+        // Spec 4.3.2.10: Rollback the transaction.
+        m_sqliteTransaction->rollback();
+
+        ASSERT(!m_database->sqliteDatabase().transactionInProgress());
+        m_sqliteTransaction = nullptr;
+    }
+    m_database->enableAuthorizer();
+
+    releaseOriginLockIfNeeded();
+
+    ASSERT(!m_database->sqliteDatabase().transactionInProgress());
+
+    cleanupAndTerminate();
+}
+
 void SQLTransaction::deliverTransactionCallback()
 {
     bool shouldDeliverErrorCallback = false;

Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.h (204356 => 204357)


--- trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.h	2016-08-10 21:31:07 UTC (rev 204356)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.h	2016-08-10 21:54:29 UTC (rev 204357)
@@ -89,6 +89,11 @@
     void computeNextStateAndCleanupIfNeeded();
 
     // State functions:
+    void acquireLock();
+    void openTransactionAndPreflight();
+    void runStatements();
+    void cleanupAndTerminate();
+    void cleanupAfterTransactionErrorCallback();
     void deliverTransactionCallback();
     void deliverTransactionErrorCallback();
     void deliverStatementCallback();

Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.cpp (204356 => 204357)


--- trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.cpp	2016-08-10 21:31:07 UTC (rev 204356)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.cpp	2016-08-10 21:54:29 UTC (rev 204357)
@@ -480,157 +480,27 @@
 
 void SQLTransactionBackend::acquireLock()
 {
-    m_frontend.m_database->transactionCoordinator()->acquireLock(m_frontend);
+    m_frontend.acquireLock();
 }
 
 void SQLTransactionBackend::openTransactionAndPreflight()
 {
-    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_frontend.m_database->deleted()) {
-        m_frontend.m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "unable to open a transaction, because the user deleted the database");
-
-        m_frontend.handleTransactionError();
-        return;
-    }
-
-    // Set the maximum usage for this transaction if this transactions is not read-only
-    if (!m_frontend.m_readOnly) {
-        m_frontend.acquireOriginLock();
-        m_frontend.m_database->sqliteDatabase().setMaximumSize(m_frontend.m_database->maximumSize());
-    }
-
-    ASSERT(!m_frontend.m_sqliteTransaction);
-    m_frontend.m_sqliteTransaction = std::make_unique<SQLiteTransaction>(m_frontend.m_database->sqliteDatabase(), m_frontend.m_readOnly);
-
-    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_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;
-
-        m_frontend.handleTransactionError();
-        return;
-    }
-
-    // Note: We intentionally retrieve the actual version even with an empty expected version.
-    // 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_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();
-
-        m_frontend.handleTransactionError();
-        return;
-    }
-
-    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_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");
-
-        m_frontend.handleTransactionError();
-        return;
-    }
-
-    // Spec 4.3.2.4: Invoke the transaction callback with the new SQLTransaction object
-    if (m_frontend.m_callbackWrapper.hasCallback()) {
-        m_frontend.requestTransitToState(SQLTransactionState::DeliverTransactionCallback);
-        return;
-    }
-
-    // If we have no callback to make, skip pass to the state after:
-    runStatements();
+    m_frontend.openTransactionAndPreflight();
 }
 
 void SQLTransactionBackend::runStatements()
 {
-    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_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
-
-            // Reset the maximum size here, as it was increased to allow us to retry this statement.
-            // 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_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_frontend.m_currentStatement && m_frontend.m_currentStatement->lastExecutionFailedDueToQuota()) {
-                m_frontend.handleCurrentStatementError();
-                break;
-            }
-
-            // Otherwise, advance to the next statement
-            m_frontend.getNextStatement();
-        }
-    } while (m_frontend.runCurrentStatement());
-
-    // 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_frontend.m_currentStatement)
-        m_frontend.postflightAndCommit();
+    m_frontend.runStatements();
 }
 
 void SQLTransactionBackend::cleanupAndTerminate()
 {
-    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_frontend.m_database->sqliteDatabase().transactionInProgress());
-
-    // Phase 5 cleanup. See comment on the SQLTransaction life-cycle above.
-    doCleanup();
-    m_frontend.m_database->inProgressTransactionCompleted();
+    m_frontend.cleanupAndTerminate();
 }
 
 void SQLTransactionBackend::cleanupAfterTransactionErrorCallback()
 {
-    ASSERT(m_frontend.m_lockAcquired);
-
-    LOG(StorageAPI, "Transaction %p is complete with an error\n", this);
-    m_frontend.m_database->disableAuthorizer();
-    if (m_frontend.m_sqliteTransaction) {
-        // Spec 4.3.2.10: Rollback the transaction.
-        m_frontend.m_sqliteTransaction->rollback();
-
-        ASSERT(!m_frontend.m_database->sqliteDatabase().transactionInProgress());
-        m_frontend.m_sqliteTransaction = nullptr;
-    }
-    m_frontend.m_database->enableAuthorizer();
-
-    m_frontend.releaseOriginLockIfNeeded();
-
-    ASSERT(!m_frontend.m_database->sqliteDatabase().transactionInProgress());
-
-    cleanupAndTerminate();
+    m_frontend.cleanupAfterTransactionErrorCallback();
 }
 
 // requestTransitToState() can be called from the frontend. Hence, it should
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to