| OLD | NEW |
| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 VoidCallback* successCallback, SQLTransactionErrorCallback* errorCallback, | 58 VoidCallback* successCallback, SQLTransactionErrorCallback* errorCallback, |
| 59 bool readOnly) | 59 bool readOnly) |
| 60 : m_database(db) | 60 : m_database(db) |
| 61 , m_callback(callback) | 61 , m_callback(callback) |
| 62 , m_successCallback(successCallback) | 62 , m_successCallback(successCallback) |
| 63 , m_errorCallback(errorCallback) | 63 , m_errorCallback(errorCallback) |
| 64 , m_executeSqlAllowed(false) | 64 , m_executeSqlAllowed(false) |
| 65 , m_readOnly(readOnly) | 65 , m_readOnly(readOnly) |
| 66 { | 66 { |
| 67 ASSERT(m_database); | 67 ASSERT(m_database); |
| 68 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarting(d
b->getExecutionContext(), "SQLTransaction"); | 68 InspectorInstrumentation::asyncTaskScheduled(db->getExecutionContext(), "SQL
Transaction", this, true); |
| 69 } | 69 } |
| 70 | 70 |
| 71 SQLTransaction::~SQLTransaction() | 71 SQLTransaction::~SQLTransaction() |
| 72 { | 72 { |
| 73 } | 73 } |
| 74 | 74 |
| 75 DEFINE_TRACE(SQLTransaction) | 75 DEFINE_TRACE(SQLTransaction) |
| 76 { | 76 { |
| 77 visitor->trace(m_database); | 77 visitor->trace(m_database); |
| 78 visitor->trace(m_backend); | 78 visitor->trace(m_backend); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return SQLTransactionState::DeliverTransactionErrorCallback; | 143 return SQLTransactionState::DeliverTransactionErrorCallback; |
| 144 | 144 |
| 145 // No error callback, so fast-forward to: | 145 // No error callback, so fast-forward to: |
| 146 // Transaction Step 11 - Rollback the transaction. | 146 // Transaction Step 11 - Rollback the transaction. |
| 147 return SQLTransactionState::CleanupAfterTransactionErrorCallback; | 147 return SQLTransactionState::CleanupAfterTransactionErrorCallback; |
| 148 } | 148 } |
| 149 | 149 |
| 150 SQLTransactionState SQLTransaction::deliverTransactionCallback() | 150 SQLTransactionState SQLTransaction::deliverTransactionCallback() |
| 151 { | 151 { |
| 152 bool shouldDeliverErrorCallback = false; | 152 bool shouldDeliverErrorCallback = false; |
| 153 InspectorInstrumentation::AsyncTask asyncTask(m_database->getExecutionContex
t(), this); |
| 153 | 154 |
| 154 // Spec 4.3.2 4: Invoke the transaction callback with the new SQLTransaction
object | 155 // Spec 4.3.2 4: Invoke the transaction callback with the new SQLTransaction
object |
| 155 if (SQLTransactionCallback* callback = m_callback.release()) { | 156 if (SQLTransactionCallback* callback = m_callback.release()) { |
| 156 m_executeSqlAllowed = true; | 157 m_executeSqlAllowed = true; |
| 157 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceA
syncCallbackStarting(m_database->getExecutionContext(), m_asyncOperationId); | |
| 158 shouldDeliverErrorCallback = !callback->handleEvent(this); | 158 shouldDeliverErrorCallback = !callback->handleEvent(this); |
| 159 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | |
| 160 m_executeSqlAllowed = false; | 159 m_executeSqlAllowed = false; |
| 161 } | 160 } |
| 162 | 161 |
| 163 // Spec 4.3.2 5: If the transaction callback was null or raised an exception
, jump to the error callback | 162 // 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; | 163 SQLTransactionState nextState = SQLTransactionState::RunStatements; |
| 165 if (shouldDeliverErrorCallback) { | 164 if (shouldDeliverErrorCallback) { |
| 166 m_database->reportStartTransactionResult(5, SQLError::UNKNOWN_ERR, 0); | 165 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"); | 166 m_transactionError = SQLErrorData::create(SQLError::UNKNOWN_ERR, "the SQ
LTransactionCallback was null or threw an exception"); |
| 168 nextState = SQLTransactionState::DeliverTransactionErrorCallback; | 167 nextState = SQLTransactionState::DeliverTransactionErrorCallback; |
| 169 } | 168 } |
| 170 m_database->reportStartTransactionResult(0, -1, 0); // OK | 169 m_database->reportStartTransactionResult(0, -1, 0); // OK |
| 171 return nextState; | 170 return nextState; |
| 172 } | 171 } |
| 173 | 172 |
| 174 SQLTransactionState SQLTransaction::deliverTransactionErrorCallback() | 173 SQLTransactionState SQLTransaction::deliverTransactionErrorCallback() |
| 175 { | 174 { |
| 176 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync
OperationCompletedCallbackStarting(m_database->getExecutionContext(), m_asyncOpe
rationId); | 175 InspectorInstrumentation::AsyncTask asyncTask(m_database->getExecutionContex
t(), this); |
| 176 InspectorInstrumentation::asyncTaskCanceled(m_database->getExecutionContext(
), this); |
| 177 | 177 |
| 178 // Spec 4.3.2.10: If exists, invoke error callback with the last | 178 // Spec 4.3.2.10: If exists, invoke error callback with the last |
| 179 // error to have occurred in this transaction. | 179 // error to have occurred in this transaction. |
| 180 if (SQLTransactionErrorCallback* errorCallback = m_errorCallback.release())
{ | 180 if (SQLTransactionErrorCallback* errorCallback = m_errorCallback.release())
{ |
| 181 // If we get here with an empty m_transactionError, then the backend | 181 // 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. | 182 // 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 | 183 // Hence, it's thread safe to fetch the backend transactionError without |
| 184 // a lock. | 184 // a lock. |
| 185 if (!m_transactionError) { | 185 if (!m_transactionError) { |
| 186 ASSERT(m_backend->transactionError()); | 186 ASSERT(m_backend->transactionError()); |
| 187 m_transactionError = SQLErrorData::create(*m_backend->transactionErr
or()); | 187 m_transactionError = SQLErrorData::create(*m_backend->transactionErr
or()); |
| 188 } | 188 } |
| 189 ASSERT(m_transactionError); | 189 ASSERT(m_transactionError); |
| 190 errorCallback->handleEvent(SQLError::create(*m_transactionError)); | 190 errorCallback->handleEvent(SQLError::create(*m_transactionError)); |
| 191 | 191 |
| 192 m_transactionError = nullptr; | 192 m_transactionError = nullptr; |
| 193 } | 193 } |
| 194 | 194 |
| 195 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | |
| 196 clearCallbacks(); | 195 clearCallbacks(); |
| 197 | 196 |
| 198 // Spec 4.3.2.10: Rollback the transaction. | 197 // Spec 4.3.2.10: Rollback the transaction. |
| 199 return SQLTransactionState::CleanupAfterTransactionErrorCallback; | 198 return SQLTransactionState::CleanupAfterTransactionErrorCallback; |
| 200 } | 199 } |
| 201 | 200 |
| 202 SQLTransactionState SQLTransaction::deliverStatementCallback() | 201 SQLTransactionState SQLTransaction::deliverStatementCallback() |
| 203 { | 202 { |
| 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 | 203 // 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 | 204 // Otherwise, continue to loop through the statement queue |
| (...skipping 19 matching lines...) Expand all Loading... |
| 225 ASSERT(m_backend->currentStatement()); | 224 ASSERT(m_backend->currentStatement()); |
| 226 | 225 |
| 227 bool shouldRetryCurrentStatement = m_database->transactionClient()->didExcee
dQuota(database()); | 226 bool shouldRetryCurrentStatement = m_database->transactionClient()->didExcee
dQuota(database()); |
| 228 m_backend->setShouldRetryCurrentStatement(shouldRetryCurrentStatement); | 227 m_backend->setShouldRetryCurrentStatement(shouldRetryCurrentStatement); |
| 229 | 228 |
| 230 return SQLTransactionState::RunStatements; | 229 return SQLTransactionState::RunStatements; |
| 231 } | 230 } |
| 232 | 231 |
| 233 SQLTransactionState SQLTransaction::deliverSuccessCallback() | 232 SQLTransactionState SQLTransaction::deliverSuccessCallback() |
| 234 { | 233 { |
| 235 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync
OperationCompletedCallbackStarting(m_database->getExecutionContext(), m_asyncOpe
rationId); | 234 InspectorInstrumentation::AsyncTask asyncTask(m_database->getExecutionContex
t(), this); |
| 235 InspectorInstrumentation::asyncTaskCanceled(m_database->getExecutionContext(
), this); |
| 236 | 236 |
| 237 // Spec 4.3.2.8: Deliver success callback. | 237 // Spec 4.3.2.8: Deliver success callback. |
| 238 if (VoidCallback* successCallback = m_successCallback.release()) | 238 if (VoidCallback* successCallback = m_successCallback.release()) |
| 239 successCallback->handleEvent(); | 239 successCallback->handleEvent(); |
| 240 | 240 |
| 241 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | |
| 242 clearCallbacks(); | 241 clearCallbacks(); |
| 243 | 242 |
| 244 // Schedule a "post-success callback" step to return control to the database
thread in case there | 243 // 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 | 244 // are further transactions queued up for this Database |
| 246 return SQLTransactionState::CleanupAndTerminate; | 245 return SQLTransactionState::CleanupAndTerminate; |
| 247 } | 246 } |
| 248 | 247 |
| 249 // This state function is used as a stub function to plug unimplemented states | 248 // 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 | 249 // in the state dispatch table. They are unimplemented because they should |
| 251 // never be reached in the course of correct execution. | 250 // never be reached in the course of correct execution. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 m_successCallback.clear(); | 331 m_successCallback.clear(); |
| 333 m_errorCallback.clear(); | 332 m_errorCallback.clear(); |
| 334 } | 333 } |
| 335 | 334 |
| 336 SQLTransactionErrorCallback* SQLTransaction::releaseErrorCallback() | 335 SQLTransactionErrorCallback* SQLTransaction::releaseErrorCallback() |
| 337 { | 336 { |
| 338 return m_errorCallback.release(); | 337 return m_errorCallback.release(); |
| 339 } | 338 } |
| 340 | 339 |
| 341 } // namespace blink | 340 } // namespace blink |
| OLD | NEW |