Chromium Code Reviews| 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::scheduleAsyncTask(db->getExecutionContext(), "SQLT ransaction", this); |
| 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); |
| 177 | 176 |
| 178 // Spec 4.3.2.10: If exists, invoke error callback with the last | 177 // Spec 4.3.2.10: If exists, invoke error callback with the last |
| 179 // error to have occurred in this transaction. | 178 // error to have occurred in this transaction. |
| 180 if (SQLTransactionErrorCallback* errorCallback = m_errorCallback.release()) { | 179 if (SQLTransactionErrorCallback* errorCallback = m_errorCallback.release()) { |
| 181 // If we get here with an empty m_transactionError, then the backend | 180 // 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. | 181 // 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 | 182 // Hence, it's thread safe to fetch the backend transactionError without |
| 184 // a lock. | 183 // a lock. |
| 185 if (!m_transactionError) { | 184 if (!m_transactionError) { |
| 186 ASSERT(m_backend->transactionError()); | 185 ASSERT(m_backend->transactionError()); |
| 187 m_transactionError = SQLErrorData::create(*m_backend->transactionErr or()); | 186 m_transactionError = SQLErrorData::create(*m_backend->transactionErr or()); |
| 188 } | 187 } |
| 189 ASSERT(m_transactionError); | 188 ASSERT(m_transactionError); |
| 190 errorCallback->handleEvent(SQLError::create(*m_transactionError)); | 189 errorCallback->handleEvent(SQLError::create(*m_transactionError)); |
| 191 | 190 |
| 192 m_transactionError = nullptr; | 191 m_transactionError = nullptr; |
| 193 } | 192 } |
| 194 | 193 |
| 195 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | |
| 196 clearCallbacks(); | 194 clearCallbacks(); |
| 197 | 195 |
| 198 // Spec 4.3.2.10: Rollback the transaction. | 196 // Spec 4.3.2.10: Rollback the transaction. |
| 199 return SQLTransactionState::CleanupAfterTransactionErrorCallback; | 197 return SQLTransactionState::CleanupAfterTransactionErrorCallback; |
| 200 } | 198 } |
| 201 | 199 |
| 202 SQLTransactionState SQLTransaction::deliverStatementCallback() | 200 SQLTransactionState SQLTransaction::deliverStatementCallback() |
| 203 { | 201 { |
| 202 InspectorInstrumentation::AsyncTask asyncTask(m_database->getExecutionContex t(), this); | |
|
dgozman
2016/04/06 02:31:08
Remove it.
| |
| 203 | |
| 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 | 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 |
| 205 // Otherwise, continue to loop through the statement queue | 205 // Otherwise, continue to loop through the statement queue |
| 206 m_executeSqlAllowed = true; | 206 m_executeSqlAllowed = true; |
| 207 | 207 |
| 208 SQLStatement* currentStatement = m_backend->currentStatement(); | 208 SQLStatement* currentStatement = m_backend->currentStatement(); |
| 209 ASSERT(currentStatement); | 209 ASSERT(currentStatement); |
| 210 | 210 |
| 211 bool result = currentStatement->performCallback(this); | 211 bool result = currentStatement->performCallback(this); |
| 212 | 212 |
| 213 m_executeSqlAllowed = false; | 213 m_executeSqlAllowed = false; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 225 ASSERT(m_backend->currentStatement()); | 225 ASSERT(m_backend->currentStatement()); |
| 226 | 226 |
| 227 bool shouldRetryCurrentStatement = m_database->transactionClient()->didExcee dQuota(database()); | 227 bool shouldRetryCurrentStatement = m_database->transactionClient()->didExcee dQuota(database()); |
| 228 m_backend->setShouldRetryCurrentStatement(shouldRetryCurrentStatement); | 228 m_backend->setShouldRetryCurrentStatement(shouldRetryCurrentStatement); |
| 229 | 229 |
| 230 return SQLTransactionState::RunStatements; | 230 return SQLTransactionState::RunStatements; |
| 231 } | 231 } |
| 232 | 232 |
| 233 SQLTransactionState SQLTransaction::deliverSuccessCallback() | 233 SQLTransactionState SQLTransaction::deliverSuccessCallback() |
| 234 { | 234 { |
| 235 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync OperationCompletedCallbackStarting(m_database->getExecutionContext(), m_asyncOpe rationId); | |
|
dgozman
2016/04/06 02:31:08
Bring it back.
| |
| 236 | |
| 237 // Spec 4.3.2.8: Deliver success callback. | 235 // Spec 4.3.2.8: Deliver success callback. |
| 238 if (VoidCallback* successCallback = m_successCallback.release()) | 236 if (VoidCallback* successCallback = m_successCallback.release()) |
| 239 successCallback->handleEvent(); | 237 successCallback->handleEvent(); |
| 240 | 238 |
| 241 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | |
| 242 clearCallbacks(); | 239 clearCallbacks(); |
| 243 | 240 |
| 244 // Schedule a "post-success callback" step to return control to the database thread in case there | 241 // 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 | 242 // are further transactions queued up for this Database |
| 246 return SQLTransactionState::CleanupAndTerminate; | 243 return SQLTransactionState::CleanupAndTerminate; |
| 247 } | 244 } |
| 248 | 245 |
| 249 // This state function is used as a stub function to plug unimplemented states | 246 // 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 | 247 // in the state dispatch table. They are unimplemented because they should |
| 251 // never be reached in the course of correct execution. | 248 // 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(); | 329 m_successCallback.clear(); |
| 333 m_errorCallback.clear(); | 330 m_errorCallback.clear(); |
| 334 } | 331 } |
| 335 | 332 |
| 336 SQLTransactionErrorCallback* SQLTransaction::releaseErrorCallback() | 333 SQLTransactionErrorCallback* SQLTransaction::releaseErrorCallback() |
| 337 { | 334 { |
| 338 return m_errorCallback.release(); | 335 return m_errorCallback.release(); |
| 339 } | 336 } |
| 340 | 337 |
| 341 } // namespace blink | 338 } // namespace blink |
| OLD | NEW |