Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/WebKit/Source/modules/webdatabase/SQLTransaction.cpp

Issue 1857713004: DevTools: simplify the async instrumentation harness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 13 matching lines...) Expand all
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "modules/webdatabase/SQLTransaction.h" 29 #include "modules/webdatabase/SQLTransaction.h"
30 30
31 #include "bindings/core/v8/ExceptionState.h" 31 #include "bindings/core/v8/ExceptionState.h"
32 #include "core/dom/ExceptionCode.h" 32 #include "core/dom/ExceptionCode.h"
33 #include "core/html/VoidCallback.h" 33 #include "core/html/VoidCallback.h"
34 #include "core/inspector/InspectorInstrumentation.h"
35 #include "modules/webdatabase/Database.h" 34 #include "modules/webdatabase/Database.h"
36 #include "modules/webdatabase/DatabaseAuthorizer.h" 35 #include "modules/webdatabase/DatabaseAuthorizer.h"
37 #include "modules/webdatabase/DatabaseContext.h" 36 #include "modules/webdatabase/DatabaseContext.h"
38 #include "modules/webdatabase/SQLError.h" 37 #include "modules/webdatabase/SQLError.h"
39 #include "modules/webdatabase/SQLStatementCallback.h" 38 #include "modules/webdatabase/SQLStatementCallback.h"
40 #include "modules/webdatabase/SQLStatementErrorCallback.h" 39 #include "modules/webdatabase/SQLStatementErrorCallback.h"
41 #include "modules/webdatabase/SQLTransactionBackend.h" 40 #include "modules/webdatabase/SQLTransactionBackend.h"
42 #include "modules/webdatabase/SQLTransactionCallback.h" 41 #include "modules/webdatabase/SQLTransactionCallback.h"
43 #include "modules/webdatabase/SQLTransactionClient.h" // FIXME: Should be used i n the backend only. 42 #include "modules/webdatabase/SQLTransactionClient.h" // FIXME: Should be used i n the backend only.
44 #include "modules/webdatabase/SQLTransactionErrorCallback.h" 43 #include "modules/webdatabase/SQLTransactionErrorCallback.h"
(...skipping 13 matching lines...) Expand all
58 VoidCallback* successCallback, SQLTransactionErrorCallback* errorCallback, 57 VoidCallback* successCallback, SQLTransactionErrorCallback* errorCallback,
59 bool readOnly) 58 bool readOnly)
60 : m_database(db) 59 : m_database(db)
61 , m_callback(callback) 60 , m_callback(callback)
62 , m_successCallback(successCallback) 61 , m_successCallback(successCallback)
63 , m_errorCallback(errorCallback) 62 , m_errorCallback(errorCallback)
64 , m_executeSqlAllowed(false) 63 , m_executeSqlAllowed(false)
65 , m_readOnly(readOnly) 64 , m_readOnly(readOnly)
66 { 65 {
67 ASSERT(m_database); 66 ASSERT(m_database);
68 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarting(d b->getExecutionContext(), "SQLTransaction");
69 } 67 }
70 68
71 SQLTransaction::~SQLTransaction() 69 SQLTransaction::~SQLTransaction()
72 { 70 {
73 } 71 }
74 72
75 DEFINE_TRACE(SQLTransaction) 73 DEFINE_TRACE(SQLTransaction)
76 { 74 {
77 visitor->trace(m_database); 75 visitor->trace(m_database);
78 visitor->trace(m_backend); 76 visitor->trace(m_backend);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 return SQLTransactionState::CleanupAfterTransactionErrorCallback; 145 return SQLTransactionState::CleanupAfterTransactionErrorCallback;
148 } 146 }
149 147
150 SQLTransactionState SQLTransaction::deliverTransactionCallback() 148 SQLTransactionState SQLTransaction::deliverTransactionCallback()
151 { 149 {
152 bool shouldDeliverErrorCallback = false; 150 bool shouldDeliverErrorCallback = false;
153 151
154 // Spec 4.3.2 4: Invoke the transaction callback with the new SQLTransaction object 152 // Spec 4.3.2 4: Invoke the transaction callback with the new SQLTransaction object
155 if (SQLTransactionCallback* callback = m_callback.release()) { 153 if (SQLTransactionCallback* callback = m_callback.release()) {
156 m_executeSqlAllowed = true; 154 m_executeSqlAllowed = true;
157 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceA syncCallbackStarting(m_database->getExecutionContext(), m_asyncOperationId);
158 shouldDeliverErrorCallback = !callback->handleEvent(this); 155 shouldDeliverErrorCallback = !callback->handleEvent(this);
159 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
160 m_executeSqlAllowed = false; 156 m_executeSqlAllowed = false;
161 } 157 }
162 158
163 // Spec 4.3.2 5: If the transaction callback was null or raised an exception , jump to the error callback 159 // Spec 4.3.2 5: If the transaction callback was null or raised an exception , jump to the error callback
164 SQLTransactionState nextState = SQLTransactionState::RunStatements; 160 SQLTransactionState nextState = SQLTransactionState::RunStatements;
165 if (shouldDeliverErrorCallback) { 161 if (shouldDeliverErrorCallback) {
166 m_database->reportStartTransactionResult(5, SQLError::UNKNOWN_ERR, 0); 162 m_database->reportStartTransactionResult(5, SQLError::UNKNOWN_ERR, 0);
167 m_transactionError = SQLErrorData::create(SQLError::UNKNOWN_ERR, "the SQ LTransactionCallback was null or threw an exception"); 163 m_transactionError = SQLErrorData::create(SQLError::UNKNOWN_ERR, "the SQ LTransactionCallback was null or threw an exception");
168 nextState = SQLTransactionState::DeliverTransactionErrorCallback; 164 nextState = SQLTransactionState::DeliverTransactionErrorCallback;
169 } 165 }
170 m_database->reportStartTransactionResult(0, -1, 0); // OK 166 m_database->reportStartTransactionResult(0, -1, 0); // OK
171 return nextState; 167 return nextState;
172 } 168 }
173 169
174 SQLTransactionState SQLTransaction::deliverTransactionErrorCallback() 170 SQLTransactionState SQLTransaction::deliverTransactionErrorCallback()
175 { 171 {
176 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync OperationCompletedCallbackStarting(m_database->getExecutionContext(), m_asyncOpe rationId);
177
178 // Spec 4.3.2.10: If exists, invoke error callback with the last 172 // Spec 4.3.2.10: If exists, invoke error callback with the last
179 // error to have occurred in this transaction. 173 // error to have occurred in this transaction.
180 if (SQLTransactionErrorCallback* errorCallback = m_errorCallback.release()) { 174 if (SQLTransactionErrorCallback* errorCallback = m_errorCallback.release()) {
181 // If we get here with an empty m_transactionError, then the backend 175 // If we get here with an empty m_transactionError, then the backend
182 // must be waiting in the idle state waiting for this state to finish. 176 // must be waiting in the idle state waiting for this state to finish.
183 // Hence, it's thread safe to fetch the backend transactionError without 177 // Hence, it's thread safe to fetch the backend transactionError without
184 // a lock. 178 // a lock.
185 if (!m_transactionError) { 179 if (!m_transactionError) {
186 ASSERT(m_backend->transactionError()); 180 ASSERT(m_backend->transactionError());
187 m_transactionError = SQLErrorData::create(*m_backend->transactionErr or()); 181 m_transactionError = SQLErrorData::create(*m_backend->transactionErr or());
188 } 182 }
189 ASSERT(m_transactionError); 183 ASSERT(m_transactionError);
190 errorCallback->handleEvent(SQLError::create(*m_transactionError)); 184 errorCallback->handleEvent(SQLError::create(*m_transactionError));
191 185
192 m_transactionError = nullptr; 186 m_transactionError = nullptr;
193 } 187 }
194 188
195 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
196 clearCallbacks(); 189 clearCallbacks();
197 190
198 // Spec 4.3.2.10: Rollback the transaction. 191 // Spec 4.3.2.10: Rollback the transaction.
199 return SQLTransactionState::CleanupAfterTransactionErrorCallback; 192 return SQLTransactionState::CleanupAfterTransactionErrorCallback;
200 } 193 }
201 194
202 SQLTransactionState SQLTransaction::deliverStatementCallback() 195 SQLTransactionState SQLTransaction::deliverStatementCallback()
203 { 196 {
204 // Spec 4.3.2.6.6 and 4.3.2.6.3: If the statement callback went wrong, jump to the transaction error callback 197 // Spec 4.3.2.6.6 and 4.3.2.6.3: If the statement callback went wrong, jump to the transaction error callback
205 // Otherwise, continue to loop through the statement queue 198 // Otherwise, continue to loop through the statement queue
(...skipping 19 matching lines...) Expand all
225 ASSERT(m_backend->currentStatement()); 218 ASSERT(m_backend->currentStatement());
226 219
227 bool shouldRetryCurrentStatement = m_database->transactionClient()->didExcee dQuota(database()); 220 bool shouldRetryCurrentStatement = m_database->transactionClient()->didExcee dQuota(database());
228 m_backend->setShouldRetryCurrentStatement(shouldRetryCurrentStatement); 221 m_backend->setShouldRetryCurrentStatement(shouldRetryCurrentStatement);
229 222
230 return SQLTransactionState::RunStatements; 223 return SQLTransactionState::RunStatements;
231 } 224 }
232 225
233 SQLTransactionState SQLTransaction::deliverSuccessCallback() 226 SQLTransactionState SQLTransaction::deliverSuccessCallback()
234 { 227 {
235 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync OperationCompletedCallbackStarting(m_database->getExecutionContext(), m_asyncOpe rationId);
236
237 // Spec 4.3.2.8: Deliver success callback. 228 // Spec 4.3.2.8: Deliver success callback.
238 if (VoidCallback* successCallback = m_successCallback.release()) 229 if (VoidCallback* successCallback = m_successCallback.release())
239 successCallback->handleEvent(); 230 successCallback->handleEvent();
240 231
241 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
242 clearCallbacks(); 232 clearCallbacks();
243 233
244 // Schedule a "post-success callback" step to return control to the database thread in case there 234 // Schedule a "post-success callback" step to return control to the database thread in case there
245 // are further transactions queued up for this Database 235 // are further transactions queued up for this Database
246 return SQLTransactionState::CleanupAndTerminate; 236 return SQLTransactionState::CleanupAndTerminate;
247 } 237 }
248 238
249 // This state function is used as a stub function to plug unimplemented states 239 // This state function is used as a stub function to plug unimplemented states
250 // in the state dispatch table. They are unimplemented because they should 240 // in the state dispatch table. They are unimplemented because they should
251 // never be reached in the course of correct execution. 241 // never be reached in the course of correct execution.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 m_successCallback.clear(); 322 m_successCallback.clear();
333 m_errorCallback.clear(); 323 m_errorCallback.clear();
334 } 324 }
335 325
336 SQLTransactionErrorCallback* SQLTransaction::releaseErrorCallback() 326 SQLTransactionErrorCallback* SQLTransaction::releaseErrorCallback()
337 { 327 {
338 return m_errorCallback.release(); 328 return m_errorCallback.release();
339 } 329 }
340 330
341 } // namespace blink 331 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698