<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[188646] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/188646">188646</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2015-08-19 13:19:28 -0700 (Wed, 19 Aug 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>More work on simplifying the WebSQL code
https://bugs.webkit.org/show_bug.cgi?id=148145

Reviewed by Tim Horton.

Eliminate SQLTransaction::sendToBackendState.

* Modules/webdatabase/SQLTransaction.cpp:
(WebCore::SQLTransaction::stateFunctionFor):
Change sendToBackendState to unreachableState,

(WebCore::SQLTransaction::deliverTransactionCallback):
Call deliverTransactionErrorCallback directly and schedule RunStatements on the backend.

(WebCore::SQLTransaction::deliverTransactionErrorCallback):
Schedule CleanupAfterTransactionErrorCallback on the backend.

(WebCore::SQLTransaction::deliverStatementCallback):
Fold nextStateForTransactionError into here. Schedule backend states explicitly.

(WebCore::SQLTransaction::deliverQuotaIncreaseCallback):
Schedule RunStatements on the backend.

(WebCore::SQLTransaction::deliverSuccessCallback):
Schedule CleanupAndTerminate on the backend.

(WebCore::SQLTransaction::computeNextStateAndCleanupIfNeeded):
The return value of this function isn't used to make it return void.

(WebCore::SQLTransaction::nextStateForTransactionError): Deleted.
Remove this, it's been folded into deliverStatementCallback.

(WebCore::SQLTransaction::sendToBackendState): Deleted.
Get rid of this.

* Modules/webdatabase/SQLTransaction.h:
Update member functions.

* Modules/webdatabase/SQLTransactionBackend.cpp:
(WebCore::SQLTransactionBackend::openTransactionAndPreflight):
Just call runStatements() directly.

(WebCore::SQLTransactionBackend::cleanupAfterTransactionErrorCallback):
Just call cleanupAndTerminate() directly.

(WebCore::SQLTransactionBackend::shouldPerformWhilePaused): Deleted.
Get rid of an iOS member function that's no longer used.

* Modules/webdatabase/SQLTransactionBackend.h:
Remove member function.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModuleswebdatabaseSQLTransactioncpp">trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp</a></li>
<li><a href="#trunkSourceWebCoreModuleswebdatabaseSQLTransactionh">trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.h</a></li>
<li><a href="#trunkSourceWebCoreModuleswebdatabaseSQLTransactionBackendcpp">trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.cpp</a></li>
<li><a href="#trunkSourceWebCoreModuleswebdatabaseSQLTransactionBackendh">trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (188645 => 188646)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-08-19 19:32:12 UTC (rev 188645)
+++ trunk/Source/WebCore/ChangeLog        2015-08-19 20:19:28 UTC (rev 188646)
</span><span class="lines">@@ -1,3 +1,56 @@
</span><ins>+2015-08-18  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        More work on simplifying the WebSQL code
+        https://bugs.webkit.org/show_bug.cgi?id=148145
+
+        Reviewed by Tim Horton.
+
+        Eliminate SQLTransaction::sendToBackendState.
+
+        * Modules/webdatabase/SQLTransaction.cpp:
+        (WebCore::SQLTransaction::stateFunctionFor):
+        Change sendToBackendState to unreachableState,
+
+        (WebCore::SQLTransaction::deliverTransactionCallback):
+        Call deliverTransactionErrorCallback directly and schedule RunStatements on the backend.
+
+        (WebCore::SQLTransaction::deliverTransactionErrorCallback):
+        Schedule CleanupAfterTransactionErrorCallback on the backend.
+
+        (WebCore::SQLTransaction::deliverStatementCallback):
+        Fold nextStateForTransactionError into here. Schedule backend states explicitly.
+
+        (WebCore::SQLTransaction::deliverQuotaIncreaseCallback):
+        Schedule RunStatements on the backend.
+
+        (WebCore::SQLTransaction::deliverSuccessCallback):
+        Schedule CleanupAndTerminate on the backend.
+
+        (WebCore::SQLTransaction::computeNextStateAndCleanupIfNeeded):
+        The return value of this function isn't used to make it return void.
+
+        (WebCore::SQLTransaction::nextStateForTransactionError): Deleted.
+        Remove this, it's been folded into deliverStatementCallback.
+
+        (WebCore::SQLTransaction::sendToBackendState): Deleted.
+        Get rid of this.
+
+        * Modules/webdatabase/SQLTransaction.h:
+        Update member functions.
+
+        * Modules/webdatabase/SQLTransactionBackend.cpp:
+        (WebCore::SQLTransactionBackend::openTransactionAndPreflight):
+        Just call runStatements() directly.
+
+        (WebCore::SQLTransactionBackend::cleanupAfterTransactionErrorCallback):
+        Just call cleanupAndTerminate() directly.
+
+        (WebCore::SQLTransactionBackend::shouldPerformWhilePaused): Deleted.
+        Get rid of an iOS member function that's no longer used.
+
+        * Modules/webdatabase/SQLTransactionBackend.h:
+        Remove member function.
+
</ins><span class="cx"> 2015-08-18  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Replace all uses of std::mutex/std::condition_variable with WTF::Lock/WTF::Condition
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebdatabaseSQLTransactioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp (188645 => 188646)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp        2015-08-19 19:32:12 UTC (rev 188645)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.cpp        2015-08-19 20:19:28 UTC (rev 188646)
</span><span class="lines">@@ -95,10 +95,10 @@
</span><span class="cx">         &amp;SQLTransaction::unreachableState,                // 1. idle
</span><span class="cx">         &amp;SQLTransaction::unreachableState,                // 2. acquireLock
</span><span class="cx">         &amp;SQLTransaction::unreachableState,                // 3. openTransactionAndPreflight
</span><del>-        &amp;SQLTransaction::sendToBackendState,              // 4. runStatements
</del><ins>+        &amp;SQLTransaction::unreachableState,                // 4. runStatements
</ins><span class="cx">         &amp;SQLTransaction::unreachableState,                // 5. postflightAndCommit
</span><del>-        &amp;SQLTransaction::sendToBackendState,              // 6. cleanupAndTerminate
-        &amp;SQLTransaction::sendToBackendState,              // 7. cleanupAfterTransactionErrorCallback
</del><ins>+        &amp;SQLTransaction::unreachableState,                // 6. cleanupAndTerminate
+        &amp;SQLTransaction::unreachableState,                // 7. cleanupAfterTransactionErrorCallback
</ins><span class="cx">         &amp;SQLTransaction::deliverTransactionCallback,      // 8.
</span><span class="cx">         &amp;SQLTransaction::deliverTransactionErrorCallback, // 9.
</span><span class="cx">         &amp;SQLTransaction::deliverStatementCallback,        // 10.
</span><span class="lines">@@ -122,17 +122,6 @@
</span><span class="cx">     m_database-&gt;scheduleTransactionCallback(this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SQLTransactionState SQLTransaction::nextStateForTransactionError()
-{
-    ASSERT(m_transactionError);
-    if (m_errorCallbackWrapper.hasCallback())
-        return SQLTransactionState::DeliverTransactionErrorCallback;
-
-    // No error callback, so fast-forward to:
-    // Transaction Step 11 - Rollback the transaction.
-    return SQLTransactionState::CleanupAfterTransactionErrorCallback;
-}
-
</del><span class="cx"> SQLTransactionState SQLTransaction::deliverTransactionCallback()
</span><span class="cx"> {
</span><span class="cx">     bool shouldDeliverErrorCallback = false;
</span><span class="lines">@@ -146,12 +135,13 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Spec 4.3.2 5: If the transaction callback was null or raised an exception, jump to the error callback
</span><del>-    SQLTransactionState nextState = SQLTransactionState::RunStatements;
</del><span class="cx">     if (shouldDeliverErrorCallback) {
</span><span class="cx">         m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, &quot;the SQLTransactionCallback was null or threw an exception&quot;);
</span><del>-        nextState = SQLTransactionState::DeliverTransactionErrorCallback;
</del><ins>+        return deliverTransactionErrorCallback();
</ins><span class="cx">     }
</span><del>-    return nextState;
</del><ins>+
+    m_backend-&gt;requestTransitToState(SQLTransactionState::RunStatements);
+    return SQLTransactionState::Idle;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> SQLTransactionState SQLTransaction::deliverTransactionErrorCallback()
</span><span class="lines">@@ -176,7 +166,8 @@
</span><span class="cx">     clearCallbackWrappers();
</span><span class="cx"> 
</span><span class="cx">     // Spec 4.3.2.10: Rollback the transaction.
</span><del>-    return SQLTransactionState::CleanupAfterTransactionErrorCallback;
</del><ins>+    m_backend-&gt;requestTransitToState(SQLTransactionState::CleanupAfterTransactionErrorCallback);
+    return SQLTransactionState::Idle;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> SQLTransactionState SQLTransaction::deliverStatementCallback()
</span><span class="lines">@@ -194,9 +185,18 @@
</span><span class="cx"> 
</span><span class="cx">     if (result) {
</span><span class="cx">         m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, &quot;the statement callback raised an exception or statement error callback did not return false&quot;);
</span><del>-        return nextStateForTransactionError();
</del><ins>+
+        if (m_errorCallbackWrapper.hasCallback())
+            return deliverTransactionErrorCallback();
+
+        // No error callback, so fast-forward to:
+        // Transaction Step 11 - Rollback the transaction.
+        m_backend-&gt;requestTransitToState(SQLTransactionState::CleanupAfterTransactionErrorCallback);
+        return SQLTransactionState::Idle;
</ins><span class="cx">     }
</span><del>-    return SQLTransactionState::RunStatements;
</del><ins>+
+    m_backend-&gt;requestTransitToState(SQLTransactionState::RunStatements);
+    return SQLTransactionState::Idle;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> SQLTransactionState SQLTransaction::deliverQuotaIncreaseCallback()
</span><span class="lines">@@ -206,7 +206,8 @@
</span><span class="cx">     bool shouldRetryCurrentStatement = m_database-&gt;transactionClient()-&gt;didExceedQuota(&amp;database());
</span><span class="cx">     m_backend-&gt;setShouldRetryCurrentStatement(shouldRetryCurrentStatement);
</span><span class="cx"> 
</span><del>-    return SQLTransactionState::RunStatements;
</del><ins>+    m_backend-&gt;requestTransitToState(SQLTransactionState::RunStatements);
+    return SQLTransactionState::Idle;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> SQLTransactionState SQLTransaction::deliverSuccessCallback()
</span><span class="lines">@@ -220,7 +221,8 @@
</span><span class="cx"> 
</span><span class="cx">     // Schedule a &quot;post-success callback&quot; step to return control to the database thread in case there
</span><span class="cx">     // are further transactions queued up for this Database
</span><del>-    return SQLTransactionState::CleanupAndTerminate;
</del><ins>+    m_backend-&gt;requestTransitToState(SQLTransactionState::CleanupAndTerminate);
+    return SQLTransactionState::Idle;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // This state function is used as a stub function to plug unimplemented states
</span><span class="lines">@@ -232,13 +234,6 @@
</span><span class="cx">     return SQLTransactionState::End;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SQLTransactionState SQLTransaction::sendToBackendState()
-{
-    ASSERT(m_nextState != SQLTransactionState::Idle);
-    m_backend-&gt;requestTransitToState(m_nextState);
-    return SQLTransactionState::Idle;
-}
-
</del><span class="cx"> void SQLTransaction::performPendingCallback()
</span><span class="cx"> {
</span><span class="cx">     computeNextStateAndCleanupIfNeeded();
</span><span class="lines">@@ -262,7 +257,7 @@
</span><span class="cx">     m_backend-&gt;executeSQL(WTF::move(statement));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool SQLTransaction::computeNextStateAndCleanupIfNeeded()
</del><ins>+void SQLTransaction::computeNextStateAndCleanupIfNeeded()
</ins><span class="cx"> {
</span><span class="cx">     // Only honor the requested state transition if we're not supposed to be
</span><span class="cx">     // cleaning up and shutting down:
</span><span class="lines">@@ -276,13 +271,11 @@
</span><span class="cx">             || m_nextState == SQLTransactionState::DeliverSuccessCallback);
</span><span class="cx"> 
</span><span class="cx">         LOG(StorageAPI, &quot;Callback %s\n&quot;, nameForSQLTransactionState(m_nextState));
</span><del>-        return false;
</del><ins>+        return;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     clearCallbackWrappers();
</span><span class="cx">     m_nextState = SQLTransactionState::CleanupAndTerminate;
</span><del>-
-    return true;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void SQLTransaction::clearCallbackWrappers()
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebdatabaseSQLTransactionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.h (188645 => 188646)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.h        2015-08-19 19:32:12 UTC (rev 188645)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransaction.h        2015-08-19 20:19:28 UTC (rev 188646)
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx"> 
</span><span class="cx">     // State Machine functions:
</span><span class="cx">     virtual StateFunction stateFunctionFor(SQLTransactionState) override;
</span><del>-    bool computeNextStateAndCleanupIfNeeded();
</del><ins>+    void computeNextStateAndCleanupIfNeeded();
</ins><span class="cx"> 
</span><span class="cx">     // State functions:
</span><span class="cx">     SQLTransactionState deliverTransactionCallback();
</span><span class="lines">@@ -83,10 +83,7 @@
</span><span class="cx">     SQLTransactionState deliverSuccessCallback();
</span><span class="cx"> 
</span><span class="cx">     SQLTransactionState unreachableState();
</span><del>-    SQLTransactionState sendToBackendState();
</del><span class="cx"> 
</span><del>-    SQLTransactionState nextStateForTransactionError();
-
</del><span class="cx">     Ref&lt;Database&gt; m_database;
</span><span class="cx">     RefPtr&lt;SQLTransactionBackend&gt; m_backend;
</span><span class="cx">     SQLCallbackWrapper&lt;SQLTransactionCallback&gt; m_callbackWrapper;
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebdatabaseSQLTransactionBackendcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.cpp (188645 => 188646)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.cpp        2015-08-19 19:32:12 UTC (rev 188645)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.cpp        2015-08-19 20:19:28 UTC (rev 188646)
</span><span class="lines">@@ -515,14 +515,6 @@
</span><span class="cx">     runStateMachine();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if PLATFORM(IOS)
-bool SQLTransactionBackend::shouldPerformWhilePaused() const
-{
-    // SQLTransactions should only run-while-paused if they have progressed passed the first transaction step.
-    return m_nextState != SQLTransactionState::AcquireLock;
-}
-#endif
-
</del><span class="cx"> void SQLTransactionBackend::executeSQL(std::unique_ptr&lt;SQLStatement&gt; statementBackend)
</span><span class="cx"> {
</span><span class="cx">     if (m_database-&gt;deleted())
</span><span class="lines">@@ -635,7 +627,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // If we have no callback to make, skip pass to the state after:
</span><del>-    return SQLTransactionState::RunStatements;
</del><ins>+    return runStatements();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> SQLTransactionState SQLTransactionBackend::runStatements()
</span><span class="lines">@@ -831,7 +823,7 @@
</span><span class="cx"> 
</span><span class="cx">     ASSERT(!m_database-&gt;sqliteDatabase().transactionInProgress());
</span><span class="cx"> 
</span><del>-    return SQLTransactionState::CleanupAndTerminate;
</del><ins>+    return cleanupAndTerminate();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // requestTransitToState() can be called from the frontend. Hence, it should
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebdatabaseSQLTransactionBackendh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h (188645 => 188646)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h        2015-08-19 19:32:12 UTC (rev 188645)
+++ trunk/Source/WebCore/Modules/webdatabase/SQLTransactionBackend.h        2015-08-19 20:19:28 UTC (rev 188646)
</span><span class="lines">@@ -65,10 +65,6 @@
</span><span class="cx">     void lockAcquired();
</span><span class="cx">     void performNextStep();
</span><span class="cx"> 
</span><del>-#if PLATFORM(IOS)
-    bool shouldPerformWhilePaused() const;
-#endif
-
</del><span class="cx">     Database* database() { return m_database.get(); }
</span><span class="cx">     bool isReadOnly() { return m_readOnly; }
</span><span class="cx">     void notifyDatabaseThreadIsShuttingDown();
</span></span></pre>
</div>
</div>

</body>
</html>