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 29 matching lines...) Expand all Loading... |
40 #include "modules/webdatabase/SQLTransactionCoordinator.h" | 40 #include "modules/webdatabase/SQLTransactionCoordinator.h" |
41 #include "modules/webdatabase/StorageLog.h" | 41 #include "modules/webdatabase/StorageLog.h" |
42 #include "modules/webdatabase/sqlite/SQLValue.h" | 42 #include "modules/webdatabase/sqlite/SQLValue.h" |
43 #include "modules/webdatabase/sqlite/SQLiteTransaction.h" | 43 #include "modules/webdatabase/sqlite/SQLiteTransaction.h" |
44 #include "wtf/PtrUtil.h" | 44 #include "wtf/PtrUtil.h" |
45 #include "wtf/StdLibExtras.h" | 45 #include "wtf/StdLibExtras.h" |
46 #include <memory> | 46 #include <memory> |
47 | 47 |
48 // How does a SQLTransaction work? | 48 // How does a SQLTransaction work? |
49 // ============================== | 49 // ============================== |
50 // The SQLTransaction is a state machine that executes a series of states / step
s. | 50 // The SQLTransaction is a state machine that executes a series of states / |
| 51 // steps. |
51 // | 52 // |
52 // The work of the transaction states are defined in section of 4.3.2 of the | 53 // The work of the transaction states are defined in section of 4.3.2 of the |
53 // webdatabase spec: http://dev.w3.org/html5/webdatabase/#processing-model | 54 // webdatabase spec: http://dev.w3.org/html5/webdatabase/#processing-model |
54 // | 55 // |
55 // the State Transition Graph at a glance: | 56 // the State Transition Graph at a glance: |
56 // ====================================== | 57 // ====================================== |
57 // | 58 // |
58 // Backend . Frontend | 59 // Backend . Frontend |
59 // (works with SQLiteDatabase) . (works with Script) | 60 // (works with SQLiteDatabase) . (works with Script) |
60 // =========================== . =================== | 61 // =========================== . =================== |
61 // . | 62 // . |
62 // 1. Idle . | 63 // 1. Idle . |
63 // v . | 64 // v . |
64 // 2. AcquireLock . | 65 // 2. AcquireLock . |
65 // v . | 66 // v . |
66 // 3. OpenTransactionAndPreflight ------------------------------------------
. | 67 // 3. OpenTransactionAndPreflight -----------------------------------. |
67 // | .
| | 68 // | . | |
68 // `-------------------------------> 8. DeliverTransactionCallback --.
| | 69 // `-------------------------> 8. DeliverTransactionCallback --. | |
69 // . | v
v | 70 // . | v v |
70 // ,-------------------------------------' 9. DeliverTransactionErrorC
allback + | 71 // ,------------------------------' 9. DeliverTransactionErrorCallback + |
71 // | . ^
^ ^ | | 72 // | . ^ ^ ^ | |
72 // v . |
| | | | 73 // v . | | | | |
73 // 4. RunStatements -----------------------------------------------------'
| | | | 74 // 4. RunStatements -----------------------------------------------' | | | |
74 // | ^ ^ | ^ | .
| | | | 75 // | ^ ^ | ^ | . | | | |
75 // |--------' | | | `------------> 10. DeliverStatementCallback +-----
' | | | 76 // |--------' | | | `------> 10. DeliverStatementCallback +----' | | |
76 // | | | `---------------------------------------------'
| | | 77 // | | | `---------------------------------------' | | |
77 // | | `-----------------> 11. DeliverQuotaIncreaseCallback +
| | | 78 // | | `-----------> 11. DeliverQuotaIncreaseCallback + | | |
78 // | `-----------------------------------------------------'
| | | 79 // | `-----------------------------------------------' | | |
79 // v .
| | | 80 // v . | | |
80 // 5. PostflightAndCommit --+-----------------------------------------------
---' | | 81 // 5. PostflightAndCommit --+------------------------------------------' | |
81 // |----------> 12. DeliverSuccessCallback +
| | 82 // |----> 12. DeliverSuccessCallback + | |
82 // ,--------------------' . |
| | 83 // ,--------------------' . | | |
83 // v . |
| | 84 // v . | | |
84 // 6. CleanupAndTerminate <-----------------------------------------'
| | 85 // 6. CleanupAndTerminate <-----------------------------------' | |
85 // v ^ .
| | 86 // v ^ . | |
86 // 0. End | .
| | 87 // 0. End | . | |
87 // | .
| | 88 // | . | |
88 // 7: CleanupAfterTransactionErrorCallback <---------------------
-------' | 89 // 7: CleanupAfterTransactionErrorCallback <--------------------' |
89 // . | 90 // . |
90 // | 91 // |
91 // the States and State Transitions: | 92 // the States and State Transitions: |
92 // ================================ | 93 // ================================ |
93 // 0. SQLTransactionState::End | 94 // 0. SQLTransactionState::End |
94 // - the end state. | 95 // - the end state. |
95 // | 96 // |
96 // 1. SQLTransactionState::Idle | 97 // 1. SQLTransactionState::Idle |
97 // - placeholder state while waiting on frontend/backend, etc. See comme
nt on | 98 // - placeholder state while waiting on frontend/backend, etc. See |
98 // "State transitions between SQLTransaction and SQLTransactionBackend
" | 99 // comment on "State transitions between SQLTransaction and |
99 // below. | 100 // SQLTransactionBackend" below. |
100 // | 101 // |
101 // 2. SQLTransactionState::AcquireLock (runs in backend) | 102 // 2. SQLTransactionState::AcquireLock (runs in backend) |
102 // - this is the start state. | 103 // - this is the start state. |
103 // - acquire the "lock". | 104 // - acquire the "lock". |
104 // - on "lock" acquisition, goto SQLTransactionState::OpenTransactionAnd
Preflight. | 105 // - on "lock" acquisition, goto |
| 106 // SQLTransactionState::OpenTransactionAndPreflight. |
105 // | 107 // |
106 // 3. SQLTransactionState::openTransactionAndPreflight (runs in backend) | 108 // 3. SQLTransactionState::openTransactionAndPreflight (runs in backend) |
107 // - Sets up an SQLiteTransaction. | 109 // - Sets up an SQLiteTransaction. |
108 // - begin the SQLiteTransaction. | 110 // - begin the SQLiteTransaction. |
109 // - call the SQLTransactionWrapper preflight if available. | 111 // - call the SQLTransactionWrapper preflight if available. |
110 // - schedule script callback. | 112 // - schedule script callback. |
111 // - on error, goto SQLTransactionState::DeliverTransactionErrorCallback
. | 113 // - on error, goto |
| 114 // SQLTransactionState::DeliverTransactionErrorCallback. |
112 // - goto SQLTransactionState::DeliverTransactionCallback. | 115 // - goto SQLTransactionState::DeliverTransactionCallback. |
113 // | 116 // |
114 // 4. SQLTransactionState::DeliverTransactionCallback (runs in frontend) | 117 // 4. SQLTransactionState::DeliverTransactionCallback (runs in frontend) |
115 // - invoke the script function callback() if available. | 118 // - invoke the script function callback() if available. |
116 // - on error, goto SQLTransactionState::DeliverTransactionErrorCallback
. | 119 // - on error, goto |
| 120 // SQLTransactionState::DeliverTransactionErrorCallback. |
117 // - goto SQLTransactionState::RunStatements. | 121 // - goto SQLTransactionState::RunStatements. |
118 // | 122 // |
119 // 5. SQLTransactionState::DeliverTransactionErrorCallback (runs in frontend
) | 123 // 5. SQLTransactionState::DeliverTransactionErrorCallback (runs in |
| 124 // frontend) |
120 // - invoke the script function errorCallback if available. | 125 // - invoke the script function errorCallback if available. |
121 // - goto SQLTransactionState::CleanupAfterTransactionErrorCallback. | 126 // - goto SQLTransactionState::CleanupAfterTransactionErrorCallback. |
122 // | 127 // |
123 // 6. SQLTransactionState::RunStatements (runs in backend) | 128 // 6. SQLTransactionState::RunStatements (runs in backend) |
124 // - while there are statements { | 129 // - while there are statements { |
125 // - run a statement. | 130 // - run a statement. |
126 // - if statementCallback is available, goto SQLTransactionState::De
liverStatementCallback. | 131 // - if statementCallback is available, goto |
| 132 // SQLTransactionState::DeliverStatementCallback. |
127 // - on error, | 133 // - on error, |
128 // goto SQLTransactionState::DeliverQuotaIncreaseCallback, or | 134 // goto SQLTransactionState::DeliverQuotaIncreaseCallback, or |
129 // goto SQLTransactionState::DeliverStatementCallback, or | 135 // goto SQLTransactionState::DeliverStatementCallback, or |
130 // goto SQLTransactionState::deliverTransactionErrorCallback. | 136 // goto SQLTransactionState::deliverTransactionErrorCallback. |
131 // } | 137 // } |
132 // - goto SQLTransactionState::PostflightAndCommit. | 138 // - goto SQLTransactionState::PostflightAndCommit. |
133 // | 139 // |
134 // 7. SQLTransactionState::DeliverStatementCallback (runs in frontend) | 140 // 7. SQLTransactionState::DeliverStatementCallback (runs in frontend) |
135 // - invoke script statement callback (assume available). | 141 // - invoke script statement callback (assume available). |
136 // - on error, goto SQLTransactionState::DeliverTransactionErrorCallback
. | 142 // - on error, goto |
| 143 // SQLTransactionState::DeliverTransactionErrorCallback. |
137 // - goto SQLTransactionState::RunStatements. | 144 // - goto SQLTransactionState::RunStatements. |
138 // | 145 // |
139 // 8. SQLTransactionState::DeliverQuotaIncreaseCallback (runs in frontend) | 146 // 8. SQLTransactionState::DeliverQuotaIncreaseCallback (runs in frontend) |
140 // - give client a chance to increase the quota. | 147 // - give client a chance to increase the quota. |
141 // - goto SQLTransactionState::RunStatements. | 148 // - goto SQLTransactionState::RunStatements. |
142 // | 149 // |
143 // 9. SQLTransactionState::PostflightAndCommit (runs in backend) | 150 // 9. SQLTransactionState::PostflightAndCommit (runs in backend) |
144 // - call the SQLTransactionWrapper postflight if available. | 151 // - call the SQLTransactionWrapper postflight if available. |
145 // - commit the SQLiteTansaction. | 152 // - commit the SQLiteTansaction. |
146 // - on error, goto SQLTransactionState::DeliverTransactionErrorCallback
. | 153 // - on error, goto |
147 // - if successCallback is available, goto SQLTransactionState::DeliverS
uccessCallback. | 154 // SQLTransactionState::DeliverTransactionErrorCallback. |
| 155 // - if successCallback is available, goto |
| 156 // SQLTransactionState::DeliverSuccessCallback. |
148 // else goto SQLTransactionState::CleanupAndTerminate. | 157 // else goto SQLTransactionState::CleanupAndTerminate. |
149 // | 158 // |
150 // 10. SQLTransactionState::DeliverSuccessCallback (runs in frontend) | 159 // 10. SQLTransactionState::DeliverSuccessCallback (runs in frontend) |
151 // - invoke the script function successCallback() if available. | 160 // - invoke the script function successCallback() if available. |
152 // - goto SQLTransactionState::CleanupAndTerminate. | 161 // - goto SQLTransactionState::CleanupAndTerminate. |
153 // | 162 // |
154 // 11. SQLTransactionState::CleanupAndTerminate (runs in backend) | 163 // 11. SQLTransactionState::CleanupAndTerminate (runs in backend) |
155 // - stop and clear the SQLiteTransaction. | 164 // - stop and clear the SQLiteTransaction. |
156 // - release the "lock". | 165 // - release the "lock". |
157 // - goto SQLTransactionState::End. | 166 // - goto SQLTransactionState::End. |
158 // | 167 // |
159 // 12. SQLTransactionState::CleanupAfterTransactionErrorCallback (runs in ba
ckend) | 168 // 12. SQLTransactionState::CleanupAfterTransactionErrorCallback (runs in |
| 169 // backend) |
160 // - rollback the SQLiteTransaction. | 170 // - rollback the SQLiteTransaction. |
161 // - goto SQLTransactionState::CleanupAndTerminate. | 171 // - goto SQLTransactionState::CleanupAndTerminate. |
162 // | 172 // |
163 // State transitions between SQLTransaction and SQLTransactionBackend | 173 // State transitions between SQLTransaction and SQLTransactionBackend |
164 // ================================================================== | 174 // ================================================================== |
165 // As shown above, there are state transitions that crosses the boundary between | 175 // As shown above, there are state transitions that crosses the boundary between |
166 // the frontend and backend. For example, | 176 // the frontend and backend. For example, |
167 // | 177 // |
168 // OpenTransactionAndPreflight (state 3 in the backend) | 178 // OpenTransactionAndPreflight (state 3 in the backend) |
169 // transitions to DeliverTransactionCallback (state 8 in the frontend), | 179 // transitions to DeliverTransactionCallback (state 8 in the frontend), |
170 // which in turn transitions to RunStatements (state 4 in the backend). | 180 // which in turn transitions to RunStatements (state 4 in the backend). |
171 // | 181 // |
172 // This cross boundary transition is done by posting transition requests to the | 182 // This cross boundary transition is done by posting transition requests to the |
173 // other side and letting the other side's state machine execute the state | 183 // other side and letting the other side's state machine execute the state |
174 // transition in the appropriate thread (i.e. the script thread for the frontend
, | 184 // transition in the appropriate thread (i.e. the script thread for the |
175 // and the database thread for the backend). | 185 // frontend, and the database thread for the backend). |
176 // | 186 // |
177 // Logically, the state transitions work as shown in the graph above. But | 187 // Logically, the state transitions work as shown in the graph above. But |
178 // physically, the transition mechanism uses the Idle state (both in the fronten
d | 188 // physically, the transition mechanism uses the Idle state (both in the |
179 // and backend) as a waiting state for further activity. For example, taking a | 189 // frontend and backend) as a waiting state for further activity. For example, |
180 // closer look at the 3 state transition example above, what actually happens | 190 // taking a closer look at the 3 state transition example above, what actually |
181 // is as follows: | 191 // happens is as follows: |
182 // | 192 // |
183 // Step 1: | 193 // Step 1: |
184 // ====== | 194 // ====== |
185 // In the frontend thread: | 195 // In the frontend thread: |
186 // - waiting quietly is Idle. Not doing any work. | 196 // - waiting quietly is Idle. Not doing any work. |
187 // | 197 // |
188 // In the backend: | 198 // In the backend: |
189 // - is in OpenTransactionAndPreflight, and doing its work. | 199 // - is in OpenTransactionAndPreflight, and doing its work. |
190 // - when done, it transits to the backend DeliverTransactionCallback. | 200 // - when done, it transits to the backend DeliverTransactionCallback. |
191 // - the backend DeliverTransactionCallback sends a request to the frontend | 201 // - the backend DeliverTransactionCallback sends a request to the frontend |
(...skipping 14 matching lines...) Expand all Loading... |
206 // Step 3: | 216 // Step 3: |
207 // ====== | 217 // ====== |
208 // In the frontend thread: | 218 // In the frontend thread: |
209 // - waiting quietly is Idle. Not doing any work. | 219 // - waiting quietly is Idle. Not doing any work. |
210 // | 220 // |
211 // In the backend: | 221 // In the backend: |
212 // - transits to RunStatements, and does its work. | 222 // - transits to RunStatements, and does its work. |
213 // ... | 223 // ... |
214 // | 224 // |
215 // So, when the frontend or backend are not active, they will park themselves in | 225 // So, when the frontend or backend are not active, they will park themselves in |
216 // their Idle states. This means their m_nextState is set to Idle, but they neve
r | 226 // their Idle states. This means their m_nextState is set to Idle, but they |
217 // actually run the corresponding state function. Note: for both the frontend an
d | 227 // never actually run the corresponding state function. Note: for both the |
218 // backend, the state function for Idle is unreachableState(). | 228 // frontend and backend, the state function for Idle is unreachableState(). |
219 // | 229 // |
220 // The states that send a request to their peer across the front/back boundary | 230 // The states that send a request to their peer across the front/back boundary |
221 // are implemented with just 2 functions: SQLTransaction::sendToBackendState() | 231 // are implemented with just 2 functions: SQLTransaction::sendToBackendState() |
222 // and SQLTransactionBackend::sendToFrontendState(). These state functions do | 232 // and SQLTransactionBackend::sendToFrontendState(). These state functions do |
223 // nothing but sends a request to the other side to transit to the current | 233 // nothing but sends a request to the other side to transit to the current |
224 // state (indicated by m_nextState), and then transits itself to the Idle state | 234 // state (indicated by m_nextState), and then transits itself to the Idle state |
225 // to wait for further action. | 235 // to wait for further action. |
226 | 236 |
227 // The Life-Cycle of a SQLTransaction i.e. Who's keeping the SQLTransaction aliv
e? | 237 // The Life-Cycle of a SQLTransaction i.e. Who's keeping the SQLTransaction |
| 238 // alive? |
228 // =============================================================================
= | 239 // =============================================================================
= |
229 // The RefPtr chain goes something like this: | 240 // The RefPtr chain goes something like this: |
230 // | 241 // |
231 // At birth (in Database::runTransaction()): | 242 // At birth (in Database::runTransaction()): |
232 // ==================================================== | 243 // ==================================================== |
233 // Database // HeapDeque<Member<SQLTransactionBack
end>> m_transactionQueue points to ... | 244 // Database |
234 // --> SQLTransactionBackend // Member<SQLTransaction> m_frontend p
oints to ... | 245 // // HeapDeque<Member<SQLTransactionBackend>> m_transactionQueue |
235 // --> SQLTransaction // Member<SQLTransactionBackend> m_bac
kend points to ... | 246 // // points to ... |
236 // --> SQLTransactionBackend // which is a circular reference. | 247 // --> SQLTransactionBackend |
| 248 // // Member<SQLTransaction> m_frontend points to ... |
| 249 // --> SQLTransaction |
| 250 // // Member<SQLTransactionBackend> m_backend points to ... |
| 251 // --> SQLTransactionBackend // which is a circular reference. |
237 // | 252 // |
238 // Note: there's a circular reference between the SQLTransaction front-end a
nd | 253 // Note: there's a circular reference between the SQLTransaction front-end |
239 // back-end. This circular reference is established in the constructor of th
e | 254 // and back-end. This circular reference is established in the constructor |
240 // SQLTransactionBackend. The circular reference will be broken by calling | 255 // of the SQLTransactionBackend. The circular reference will be broken by |
241 // doCleanup() to nullify m_frontend. This is done at the end of the transac
tion's | 256 // calling doCleanup() to nullify m_frontend. This is done at the end of the |
242 // clean up state (i.e. when the transaction should no longer be in use ther
eafter), | 257 // transaction's clean up state (i.e. when the transaction should no longer |
243 // or if the database was interrupted. See comments on "What happens if a tr
ansaction | 258 // be in use thereafter), or if the database was interrupted. See comments |
244 // is interrupted?" below for details. | 259 // on "What happens if a transaction is interrupted?" below for details. |
245 // | 260 // |
246 // After scheduling the transaction with the DatabaseThread (Database::sched
uleTransaction()): | 261 // After scheduling the transaction with the DatabaseThread |
| 262 // (Database::scheduleTransaction()): |
247 // =========================================================================
============================= | 263 // =========================================================================
============================= |
248 // DatabaseThread // MessageQueue<DatabaseTask> m_qu
eue points to ... | 264 // DatabaseThread |
249 // --> DatabaseTransactionTask // Member<SQLTransactionBackend> m
_transaction points to ... | 265 // // MessageQueue<DatabaseTask> m_queue points to ... |
250 // --> SQLTransactionBackend // Member<SQLTransaction> m_fronte
nd points to ... | 266 // --> DatabaseTransactionTask |
251 // --> SQLTransaction // Member<SQLTransactionBackend> m
_backend points to ... | 267 // // Member<SQLTransactionBackend> m_transaction points to ... |
252 // --> SQLTransactionBackend // which is a circular reference. | 268 // --> SQLTransactionBackend |
| 269 // // Member<SQLTransaction> m_frontend points to ... |
| 270 // --> SQLTransaction |
| 271 // // Member<SQLTransactionBackend> m_backend points to ... |
| 272 // --> SQLTransactionBackend // which is a circular reference. |
253 // | 273 // |
254 // When executing the transaction (in DatabaseThread::databaseThread()): | 274 // When executing the transaction (in DatabaseThread::databaseThread()): |
255 // ==================================================================== | 275 // ==================================================================== |
256 // std::unique_ptr<DatabaseTask> task; // points to ... | 276 // std::unique_ptr<DatabaseTask> task; |
257 // --> DatabaseTransactionTask // Member<SQLTransactionBackend> m
_transaction points to ... | 277 // // points to ... |
258 // --> SQLTransactionBackend // Member<SQLTransaction> m_fronte
nd; | 278 // --> DatabaseTransactionTask |
259 // --> SQLTransaction // Member<SQLTransactionBackend> m
_backend points to ... | 279 // // Member<SQLTransactionBackend> m_transaction points to ... |
260 // --> SQLTransactionBackend // which is a circular reference. | 280 // --> SQLTransactionBackend |
| 281 // // Member<SQLTransaction> m_frontend; |
| 282 // --> SQLTransaction |
| 283 // // Member<SQLTransactionBackend> m_backend points to ... |
| 284 // --> SQLTransactionBackend // which is a circular reference. |
261 // | 285 // |
262 // At the end of cleanupAndTerminate(): | 286 // At the end of cleanupAndTerminate(): |
263 // =================================== | 287 // =================================== |
264 // At the end of the cleanup state, the SQLTransactionBackend::m_frontend is
nullified. | 288 // At the end of the cleanup state, the SQLTransactionBackend::m_frontend is |
265 // If by then, a JSObject wrapper is referring to the SQLTransaction, then t
he reference | 289 // nullified. If by then, a JSObject wrapper is referring to the |
266 // chain looks like this: | 290 // SQLTransaction, then the reference chain looks like this: |
267 // | 291 // |
268 // JSObjectWrapper | 292 // JSObjectWrapper |
269 // --> SQLTransaction // in Member<SQLTransactionBackend> m_back
end points to ... | 293 // --> SQLTransaction |
270 // --> SQLTransactionBackend // which no longer points back to its SQLT
ransaction. | 294 // // in Member<SQLTransactionBackend> m_backend points to ... |
| 295 // --> SQLTransactionBackend |
| 296 // // which no longer points back to its SQLTransaction. |
271 // | 297 // |
272 // When the GC collects the corresponding JSObject, the above chain will be
cleaned up | 298 // When the GC collects the corresponding JSObject, the above chain will be |
273 // and deleted. | 299 // cleaned up and deleted. |
274 // | 300 // |
275 // If there is no JSObject wrapper referring to the SQLTransaction when the
cleanup | 301 // If there is no JSObject wrapper referring to the SQLTransaction when the |
276 // states nullify SQLTransactionBackend::m_frontend, the SQLTransaction will
deleted then. | 302 // cleanup states nullify SQLTransactionBackend::m_frontend, the |
277 // However, there will still be a DatabaseTask pointing to the SQLTransactio
nBackend (see | 303 // SQLTransaction will deleted then. However, there will still be a |
278 // the "When executing the transaction" chain above). This will keep the | 304 // DatabaseTask pointing to the SQLTransactionBackend (see the "When |
279 // SQLTransactionBackend alive until DatabaseThread::databaseThread() releas
es its | 305 // executing the transaction" chain above). This will keep the |
280 // task std::unique_ptr. | 306 // SQLTransactionBackend alive until DatabaseThread::databaseThread() |
| 307 // releases its task std::unique_ptr. |
281 // | 308 // |
282 // What happens if a transaction is interrupted? | 309 // What happens if a transaction is interrupted? |
283 // ============================================ | 310 // ============================================ |
284 // If the transaction is interrupted half way, it won't get to run to state | 311 // If the transaction is interrupted half way, it won't get to run to state |
285 // CleanupAndTerminate, and hence, would not have called SQLTransactionBacke
nd's | 312 // CleanupAndTerminate, and hence, would not have called |
286 // doCleanup(). doCleanup() is where we nullify SQLTransactionBackend::m_fro
ntend | 313 // SQLTransactionBackend's doCleanup(). doCleanup() is where we nullify |
287 // to break the reference cycle between the frontend and backend. Hence, we
need | 314 // SQLTransactionBackend::m_frontend to break the reference cycle between |
288 // to cleanup the transaction by other means. | 315 // the frontend and backend. Hence, we need to cleanup the transaction by |
| 316 // other means. |
289 // | 317 // |
290 // Note: calling SQLTransactionBackend::notifyDatabaseThreadIsShuttingDown() | 318 // Note: calling SQLTransactionBackend::notifyDatabaseThreadIsShuttingDown() |
291 // is effectively the same as calling SQLTransactionBackend::doClean(). | 319 // is effectively the same as calling SQLTransactionBackend::doClean(). |
292 // | 320 // |
293 // In terms of who needs to call doCleanup(), there are 5 phases in the | 321 // In terms of who needs to call doCleanup(), there are 5 phases in the |
294 // SQLTransactionBackend life-cycle. These are the phases and how the clean | 322 // SQLTransactionBackend life-cycle. These are the phases and how the clean |
295 // up is done: | 323 // up is done: |
296 // | 324 // |
297 // Phase 1. After Birth, before scheduling | 325 // Phase 1. After Birth, before scheduling |
298 // | 326 // |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 399 } |
372 | 400 |
373 DEFINE_TRACE(SQLTransactionBackend) { | 401 DEFINE_TRACE(SQLTransactionBackend) { |
374 visitor->trace(m_database); | 402 visitor->trace(m_database); |
375 visitor->trace(m_wrapper); | 403 visitor->trace(m_wrapper); |
376 } | 404 } |
377 | 405 |
378 void SQLTransactionBackend::doCleanup() { | 406 void SQLTransactionBackend::doCleanup() { |
379 if (!m_frontend) | 407 if (!m_frontend) |
380 return; | 408 return; |
381 m_frontend = | 409 // Break the reference cycle. See comment about the life-cycle above. |
382 nullptr; // Break the reference cycle. See comment about the life-cycle a
bove. | 410 m_frontend = nullptr; |
383 | 411 |
384 ASSERT( | 412 ASSERT( |
385 database()->getDatabaseContext()->databaseThread()->isDatabaseThread()); | 413 database()->getDatabaseContext()->databaseThread()->isDatabaseThread()); |
386 | 414 |
387 MutexLocker locker(m_statementMutex); | 415 MutexLocker locker(m_statementMutex); |
388 m_statementQueue.clear(); | 416 m_statementQueue.clear(); |
389 | 417 |
390 if (m_sqliteTransaction) { | 418 if (m_sqliteTransaction) { |
391 // In the event we got here because of an interruption or error (i.e. if | 419 // In the event we got here because of an interruption or error (i.e. if |
392 // the transaction is in progress), we should roll it back here. Clearing | 420 // the transaction is in progress), we should roll it back here. Clearing |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 SQLTransactionState state) { | 471 SQLTransactionState state) { |
444 static const StateFunction stateFunctions[] = { | 472 static const StateFunction stateFunctions[] = { |
445 &SQLTransactionBackend::unreachableState, // 0. end | 473 &SQLTransactionBackend::unreachableState, // 0. end |
446 &SQLTransactionBackend::unreachableState, // 1. idle | 474 &SQLTransactionBackend::unreachableState, // 1. idle |
447 &SQLTransactionBackend::acquireLock, // 2. | 475 &SQLTransactionBackend::acquireLock, // 2. |
448 &SQLTransactionBackend::openTransactionAndPreflight, // 3. | 476 &SQLTransactionBackend::openTransactionAndPreflight, // 3. |
449 &SQLTransactionBackend::runStatements, // 4. | 477 &SQLTransactionBackend::runStatements, // 4. |
450 &SQLTransactionBackend::postflightAndCommit, // 5. | 478 &SQLTransactionBackend::postflightAndCommit, // 5. |
451 &SQLTransactionBackend::cleanupAndTerminate, // 6. | 479 &SQLTransactionBackend::cleanupAndTerminate, // 6. |
452 &SQLTransactionBackend::cleanupAfterTransactionErrorCallback, // 7. | 480 &SQLTransactionBackend::cleanupAfterTransactionErrorCallback, // 7. |
453 &SQLTransactionBackend:: | 481 // 8. deliverTransactionCallback |
454 sendToFrontendState, // 8. deliverTransactionCallback | 482 &SQLTransactionBackend::sendToFrontendState, |
455 &SQLTransactionBackend:: | 483 // 9. deliverTransactionErrorCallback |
456 sendToFrontendState, // 9. deliverTransactionErrorCallback | 484 &SQLTransactionBackend::sendToFrontendState, |
457 &SQLTransactionBackend:: | 485 // 10. deliverStatementCallback |
458 sendToFrontendState, // 10. deliverStatementCallback | 486 &SQLTransactionBackend::sendToFrontendState, |
459 &SQLTransactionBackend:: | 487 // 11. deliverQuotaIncreaseCallback |
460 sendToFrontendState, // 11. deliverQuotaIncreaseCallback | 488 &SQLTransactionBackend::sendToFrontendState, |
461 &SQLTransactionBackend::sendToFrontendState // 12. deliverSuccessCallback | 489 // 12. deliverSuccessCallback |
| 490 &SQLTransactionBackend::sendToFrontendState, |
462 }; | 491 }; |
463 | 492 |
464 ASSERT(WTF_ARRAY_LENGTH(stateFunctions) == | 493 ASSERT(WTF_ARRAY_LENGTH(stateFunctions) == |
465 static_cast<int>(SQLTransactionState::NumberOfStates)); | 494 static_cast<int>(SQLTransactionState::NumberOfStates)); |
466 ASSERT(state < SQLTransactionState::NumberOfStates); | 495 ASSERT(state < SQLTransactionState::NumberOfStates); |
467 | 496 |
468 return stateFunctions[static_cast<int>(state)]; | 497 return stateFunctions[static_cast<int>(state)]; |
469 } | 498 } |
470 | 499 |
471 void SQLTransactionBackend::enqueueStatementBackend( | 500 void SQLTransactionBackend::enqueueStatementBackend( |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 } | 585 } |
557 | 586 |
558 SQLTransactionState SQLTransactionBackend::openTransactionAndPreflight() { | 587 SQLTransactionState SQLTransactionBackend::openTransactionAndPreflight() { |
559 DCHECK( | 588 DCHECK( |
560 database()->getDatabaseContext()->databaseThread()->isDatabaseThread()); | 589 database()->getDatabaseContext()->databaseThread()->isDatabaseThread()); |
561 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 590 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
562 ASSERT(m_lockAcquired); | 591 ASSERT(m_lockAcquired); |
563 | 592 |
564 STORAGE_DVLOG(1) << "Opening and preflighting transaction " << this; | 593 STORAGE_DVLOG(1) << "Opening and preflighting transaction " << this; |
565 | 594 |
566 // Set the maximum usage for this transaction if this transactions is not read
-only | 595 // Set the maximum usage for this transaction if this transactions is not |
| 596 // read-only. |
567 if (!m_readOnly) | 597 if (!m_readOnly) |
568 m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize()); | 598 m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize()); |
569 | 599 |
570 ASSERT(!m_sqliteTransaction); | 600 ASSERT(!m_sqliteTransaction); |
571 m_sqliteTransaction = wrapUnique( | 601 m_sqliteTransaction = wrapUnique( |
572 new SQLiteTransaction(m_database->sqliteDatabase(), m_readOnly)); | 602 new SQLiteTransaction(m_database->sqliteDatabase(), m_readOnly)); |
573 | 603 |
574 m_database->resetDeletes(); | 604 m_database->resetDeletes(); |
575 m_database->disableAuthorizer(); | 605 m_database->disableAuthorizer(); |
576 m_sqliteTransaction->begin(); | 606 m_sqliteTransaction->begin(); |
577 m_database->enableAuthorizer(); | 607 m_database->enableAuthorizer(); |
578 | 608 |
579 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error ca
llback if that fails | 609 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error |
| 610 // callback if that fails. |
580 if (!m_sqliteTransaction->inProgress()) { | 611 if (!m_sqliteTransaction->inProgress()) { |
581 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 612 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
582 m_database->reportStartTransactionResult( | 613 m_database->reportStartTransactionResult( |
583 2, SQLError::kDatabaseErr, m_database->sqliteDatabase().lastError()); | 614 2, SQLError::kDatabaseErr, m_database->sqliteDatabase().lastError()); |
584 m_transactionError = SQLErrorData::create( | 615 m_transactionError = SQLErrorData::create( |
585 SQLError::kDatabaseErr, "unable to begin transaction", | 616 SQLError::kDatabaseErr, "unable to begin transaction", |
586 m_database->sqliteDatabase().lastError(), | 617 m_database->sqliteDatabase().lastError(), |
587 m_database->sqliteDatabase().lastErrorMsg()); | 618 m_database->sqliteDatabase().lastErrorMsg()); |
588 m_sqliteTransaction.reset(); | 619 m_sqliteTransaction.reset(); |
589 return nextStateForTransactionError(); | 620 return nextStateForTransactionError(); |
590 } | 621 } |
591 | 622 |
592 // Note: We intentionally retrieve the actual version even with an empty expec
ted version. | 623 // Note: We intentionally retrieve the actual version even with an empty |
593 // In multi-process browsers, we take this opportinutiy to update the cached v
alue for | 624 // expected version. In multi-process browsers, we take this opportunity to |
594 // the actual version. In single-process browsers, this is just a map lookup. | 625 // update the cached value for the actual version. In single-process browsers, |
| 626 // this is just a map lookup. |
595 String actualVersion; | 627 String actualVersion; |
596 if (!m_database->getActualVersionForTransaction(actualVersion)) { | 628 if (!m_database->getActualVersionForTransaction(actualVersion)) { |
597 m_database->reportStartTransactionResult( | 629 m_database->reportStartTransactionResult( |
598 3, SQLError::kDatabaseErr, m_database->sqliteDatabase().lastError()); | 630 3, SQLError::kDatabaseErr, m_database->sqliteDatabase().lastError()); |
599 m_transactionError = | 631 m_transactionError = |
600 SQLErrorData::create(SQLError::kDatabaseErr, "unable to read version", | 632 SQLErrorData::create(SQLError::kDatabaseErr, "unable to read version", |
601 m_database->sqliteDatabase().lastError(), | 633 m_database->sqliteDatabase().lastError(), |
602 m_database->sqliteDatabase().lastErrorMsg()); | 634 m_database->sqliteDatabase().lastErrorMsg()); |
603 m_database->disableAuthorizer(); | 635 m_database->disableAuthorizer(); |
604 m_sqliteTransaction.reset(); | 636 m_sqliteTransaction.reset(); |
605 m_database->enableAuthorizer(); | 637 m_database->enableAuthorizer(); |
606 return nextStateForTransactionError(); | 638 return nextStateForTransactionError(); |
607 } | 639 } |
608 m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && | 640 m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && |
609 (m_database->expectedVersion() != actualVersion); | 641 (m_database->expectedVersion() != actualVersion); |
610 | 642 |
611 // Spec 4.3.2.3: Perform preflight steps, jumping to the error callback if the
y fail | 643 // Spec 4.3.2.3: Perform preflight steps, jumping to the error callback if |
| 644 // they fail. |
612 if (m_wrapper && !m_wrapper->performPreflight(this)) { | 645 if (m_wrapper && !m_wrapper->performPreflight(this)) { |
613 m_database->disableAuthorizer(); | 646 m_database->disableAuthorizer(); |
614 m_sqliteTransaction.reset(); | 647 m_sqliteTransaction.reset(); |
615 m_database->enableAuthorizer(); | 648 m_database->enableAuthorizer(); |
616 if (m_wrapper->sqlError()) { | 649 if (m_wrapper->sqlError()) { |
617 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); | 650 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); |
618 } else { | 651 } else { |
619 m_database->reportStartTransactionResult(4, SQLError::kUnknownErr, 0); | 652 m_database->reportStartTransactionResult(4, SQLError::kUnknownErr, 0); |
620 m_transactionError = SQLErrorData::create( | 653 m_transactionError = SQLErrorData::create( |
621 SQLError::kUnknownErr, | 654 SQLError::kUnknownErr, |
622 "unknown error occurred during transaction preflight"); | 655 "unknown error occurred during transaction preflight"); |
623 } | 656 } |
624 return nextStateForTransactionError(); | 657 return nextStateForTransactionError(); |
625 } | 658 } |
626 | 659 |
627 // Spec 4.3.2.4: Invoke the transaction callback with the new SQLTransaction o
bject | 660 // Spec 4.3.2.4: Invoke the transaction callback with the new SQLTransaction |
| 661 // object. |
628 if (m_hasCallback) | 662 if (m_hasCallback) |
629 return SQLTransactionState::DeliverTransactionCallback; | 663 return SQLTransactionState::DeliverTransactionCallback; |
630 | 664 |
631 // If we have no callback to make, skip pass to the state after: | 665 // If we have no callback to make, skip pass to the state after: |
632 return SQLTransactionState::RunStatements; | 666 return SQLTransactionState::RunStatements; |
633 } | 667 } |
634 | 668 |
635 SQLTransactionState SQLTransactionBackend::runStatements() { | 669 SQLTransactionState SQLTransactionBackend::runStatements() { |
636 DCHECK( | 670 DCHECK( |
637 database()->getDatabaseContext()->databaseThread()->isDatabaseThread()); | 671 database()->getDatabaseContext()->databaseThread()->isDatabaseThread()); |
638 ASSERT(m_lockAcquired); | 672 ASSERT(m_lockAcquired); |
639 SQLTransactionState nextState; | 673 SQLTransactionState nextState; |
640 | 674 |
641 // If there is a series of statements queued up that are all successful and ha
ve no associated | 675 // If there is a series of statements queued up that are all successful and |
642 // SQLStatementCallback objects, then we can burn through the queue | 676 // have no associated SQLStatementCallback objects, then we can burn through |
| 677 // the queue. |
643 do { | 678 do { |
644 if (m_shouldRetryCurrentStatement && | 679 if (m_shouldRetryCurrentStatement && |
645 !m_sqliteTransaction->wasRolledBackBySqlite()) { | 680 !m_sqliteTransaction->wasRolledBackBySqlite()) { |
646 m_shouldRetryCurrentStatement = false; | 681 m_shouldRetryCurrentStatement = false; |
647 // FIXME - Another place that needs fixing up after <rdar://problem/562846
8> is addressed. | 682 // FIXME - Another place that needs fixing up after |
| 683 // <rdar://problem/5628468> is addressed. |
648 // See ::openTransactionAndPreflight() for discussion | 684 // See ::openTransactionAndPreflight() for discussion |
649 | 685 |
650 // Reset the maximum size here, as it was increased to allow us to retry t
his statement. | 686 // Reset the maximum size here, as it was increased to allow us to retry |
651 // m_shouldRetryCurrentStatement is set to true only when a statement exce
eds | 687 // this statement. m_shouldRetryCurrentStatement is set to true only when |
652 // the quota, which can happen only in a read-write transaction. Therefore
, there | 688 // a statement exceeds the quota, which can happen only in a read-write |
653 // is no need to check here if the transaction is read-write. | 689 // transaction. Therefore, there is no need to check here if the |
| 690 // transaction is read-write. |
654 m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize()); | 691 m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize()); |
655 } else { | 692 } else { |
656 // If the current statement has already been run, failed due to quota cons
traints, and we're not retrying it, | 693 // If the current statement has already been run, failed due to quota |
657 // that means it ended in an error. Handle it now | 694 // constraints, and we're not retrying it, that means it ended in an |
| 695 // error. Handle it now. |
658 if (m_currentStatementBackend && | 696 if (m_currentStatementBackend && |
659 m_currentStatementBackend->lastExecutionFailedDueToQuota()) { | 697 m_currentStatementBackend->lastExecutionFailedDueToQuota()) { |
660 return nextStateForCurrentStatementError(); | 698 return nextStateForCurrentStatementError(); |
661 } | 699 } |
662 | 700 |
663 // Otherwise, advance to the next statement | 701 // Otherwise, advance to the next statement |
664 getNextStatement(); | 702 getNextStatement(); |
665 } | 703 } |
666 nextState = runCurrentStatementAndGetNextState(); | 704 nextState = runCurrentStatementAndGetNextState(); |
667 } while (nextState == SQLTransactionState::RunStatements); | 705 } while (nextState == SQLTransactionState::RunStatements); |
(...skipping 18 matching lines...) Expand all Loading... |
686 return SQLTransactionState::PostflightAndCommit; | 724 return SQLTransactionState::PostflightAndCommit; |
687 } | 725 } |
688 | 726 |
689 m_database->resetAuthorizer(); | 727 m_database->resetAuthorizer(); |
690 | 728 |
691 if (m_hasVersionMismatch) | 729 if (m_hasVersionMismatch) |
692 m_currentStatementBackend->setVersionMismatchedError(m_database.get()); | 730 m_currentStatementBackend->setVersionMismatchedError(m_database.get()); |
693 | 731 |
694 if (m_currentStatementBackend->execute(m_database.get())) { | 732 if (m_currentStatementBackend->execute(m_database.get())) { |
695 if (m_database->lastActionChangedDatabase()) { | 733 if (m_database->lastActionChangedDatabase()) { |
696 // Flag this transaction as having changed the database for later delegate
notification | 734 // Flag this transaction as having changed the database for later delegate |
| 735 // notification. |
697 m_modifiedDatabase = true; | 736 m_modifiedDatabase = true; |
698 } | 737 } |
699 | 738 |
700 if (m_currentStatementBackend->hasStatementCallback()) { | 739 if (m_currentStatementBackend->hasStatementCallback()) { |
701 return SQLTransactionState::DeliverStatementCallback; | 740 return SQLTransactionState::DeliverStatementCallback; |
702 } | 741 } |
703 | 742 |
704 // If we get here, then the statement doesn't have a callback to invoke. | 743 // If we get here, then the statement doesn't have a callback to invoke. |
705 // We can move on to the next statement. Hence, stay in this state. | 744 // We can move on to the next statement. Hence, stay in this state. |
706 return SQLTransactionState::RunStatements; | 745 return SQLTransactionState::RunStatements; |
707 } | 746 } |
708 | 747 |
709 if (m_currentStatementBackend->lastExecutionFailedDueToQuota()) { | 748 if (m_currentStatementBackend->lastExecutionFailedDueToQuota()) { |
710 return SQLTransactionState::DeliverQuotaIncreaseCallback; | 749 return SQLTransactionState::DeliverQuotaIncreaseCallback; |
711 } | 750 } |
712 | 751 |
713 return nextStateForCurrentStatementError(); | 752 return nextStateForCurrentStatementError(); |
714 } | 753 } |
715 | 754 |
716 SQLTransactionState SQLTransactionBackend::nextStateForCurrentStatementError() { | 755 SQLTransactionState SQLTransactionBackend::nextStateForCurrentStatementError() { |
717 // Spec 4.3.2.6.6: error - Call the statement's error callback, but if there w
as no error callback, | 756 // Spec 4.3.2.6.6: error - Call the statement's error callback, but if there |
718 // or the transaction was rolled back, jump to the transaction error callback | 757 // was no error callback, or the transaction was rolled back, jump to the |
| 758 // transaction error callback. |
719 if (m_currentStatementBackend->hasStatementErrorCallback() && | 759 if (m_currentStatementBackend->hasStatementErrorCallback() && |
720 !m_sqliteTransaction->wasRolledBackBySqlite()) | 760 !m_sqliteTransaction->wasRolledBackBySqlite()) |
721 return SQLTransactionState::DeliverStatementCallback; | 761 return SQLTransactionState::DeliverStatementCallback; |
722 | 762 |
723 if (m_currentStatementBackend->sqlError()) { | 763 if (m_currentStatementBackend->sqlError()) { |
724 m_transactionError = | 764 m_transactionError = |
725 SQLErrorData::create(*m_currentStatementBackend->sqlError()); | 765 SQLErrorData::create(*m_currentStatementBackend->sqlError()); |
726 } else { | 766 } else { |
727 m_database->reportCommitTransactionResult(1, SQLError::kDatabaseErr, 0); | 767 m_database->reportCommitTransactionResult(1, SQLError::kDatabaseErr, 0); |
728 m_transactionError = SQLErrorData::create( | 768 m_transactionError = SQLErrorData::create( |
729 SQLError::kDatabaseErr, "the statement failed to execute"); | 769 SQLError::kDatabaseErr, "the statement failed to execute"); |
730 } | 770 } |
731 return nextStateForTransactionError(); | 771 return nextStateForTransactionError(); |
732 } | 772 } |
733 | 773 |
734 SQLTransactionState SQLTransactionBackend::postflightAndCommit() { | 774 SQLTransactionState SQLTransactionBackend::postflightAndCommit() { |
735 ASSERT(m_lockAcquired); | 775 ASSERT(m_lockAcquired); |
736 | 776 |
737 // Spec 4.3.2.7: Perform postflight steps, jumping to the error callback if th
ey fail. | 777 // Spec 4.3.2.7: Perform postflight steps, jumping to the error callback if |
| 778 // they fail. |
738 if (m_wrapper && !m_wrapper->performPostflight(this)) { | 779 if (m_wrapper && !m_wrapper->performPostflight(this)) { |
739 if (m_wrapper->sqlError()) { | 780 if (m_wrapper->sqlError()) { |
740 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); | 781 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); |
741 } else { | 782 } else { |
742 m_database->reportCommitTransactionResult(3, SQLError::kUnknownErr, 0); | 783 m_database->reportCommitTransactionResult(3, SQLError::kUnknownErr, 0); |
743 m_transactionError = SQLErrorData::create( | 784 m_transactionError = SQLErrorData::create( |
744 SQLError::kUnknownErr, | 785 SQLError::kUnknownErr, |
745 "unknown error occurred during transaction postflight"); | 786 "unknown error occurred during transaction postflight"); |
746 } | 787 } |
747 return nextStateForTransactionError(); | 788 return nextStateForTransactionError(); |
748 } | 789 } |
749 | 790 |
750 // Spec 4.3.2.7: Commit the transaction, jumping to the error callback if that
fails. | 791 // Spec 4.3.2.7: Commit the transaction, jumping to the error callback if that |
| 792 // fails. |
751 ASSERT(m_sqliteTransaction); | 793 ASSERT(m_sqliteTransaction); |
752 | 794 |
753 m_database->disableAuthorizer(); | 795 m_database->disableAuthorizer(); |
754 m_sqliteTransaction->commit(); | 796 m_sqliteTransaction->commit(); |
755 m_database->enableAuthorizer(); | 797 m_database->enableAuthorizer(); |
756 | 798 |
757 // If the commit failed, the transaction will still be marked as "in progress" | 799 // If the commit failed, the transaction will still be marked as "in progress" |
758 if (m_sqliteTransaction->inProgress()) { | 800 if (m_sqliteTransaction->inProgress()) { |
759 if (m_wrapper) | 801 if (m_wrapper) |
760 m_wrapper->handleCommitFailedAfterPostflight(this); | 802 m_wrapper->handleCommitFailedAfterPostflight(this); |
761 m_database->reportCommitTransactionResult( | 803 m_database->reportCommitTransactionResult( |
762 4, SQLError::kDatabaseErr, m_database->sqliteDatabase().lastError()); | 804 4, SQLError::kDatabaseErr, m_database->sqliteDatabase().lastError()); |
763 m_transactionError = SQLErrorData::create( | 805 m_transactionError = SQLErrorData::create( |
764 SQLError::kDatabaseErr, "unable to commit transaction", | 806 SQLError::kDatabaseErr, "unable to commit transaction", |
765 m_database->sqliteDatabase().lastError(), | 807 m_database->sqliteDatabase().lastError(), |
766 m_database->sqliteDatabase().lastErrorMsg()); | 808 m_database->sqliteDatabase().lastErrorMsg()); |
767 return nextStateForTransactionError(); | 809 return nextStateForTransactionError(); |
768 } | 810 } |
769 | 811 |
770 m_database->reportCommitTransactionResult(0, -1, 0); // OK | 812 m_database->reportCommitTransactionResult(0, -1, 0); // OK |
771 | 813 |
772 // Vacuum the database if anything was deleted. | 814 // Vacuum the database if anything was deleted. |
773 if (m_database->hadDeletes()) | 815 if (m_database->hadDeletes()) |
774 m_database->incrementalVacuumIfNeeded(); | 816 m_database->incrementalVacuumIfNeeded(); |
775 | 817 |
776 // The commit was successful. If the transaction modified this database, notif
y the delegates. | 818 // The commit was successful. If the transaction modified this database, |
| 819 // notify the delegates. |
777 if (m_modifiedDatabase) | 820 if (m_modifiedDatabase) |
778 m_database->transactionClient()->didCommitWriteTransaction(database()); | 821 m_database->transactionClient()->didCommitWriteTransaction(database()); |
779 | 822 |
780 // Spec 4.3.2.8: Deliver success callback, if there is one. | 823 // Spec 4.3.2.8: Deliver success callback, if there is one. |
781 return SQLTransactionState::DeliverSuccessCallback; | 824 return SQLTransactionState::DeliverSuccessCallback; |
782 } | 825 } |
783 | 826 |
784 SQLTransactionState SQLTransactionBackend::cleanupAndTerminate() { | 827 SQLTransactionState SQLTransactionBackend::cleanupAndTerminate() { |
785 ASSERT(m_lockAcquired); | 828 ASSERT(m_lockAcquired); |
786 | 829 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 return SQLTransactionState::End; | 889 return SQLTransactionState::End; |
847 } | 890 } |
848 | 891 |
849 SQLTransactionState SQLTransactionBackend::sendToFrontendState() { | 892 SQLTransactionState SQLTransactionBackend::sendToFrontendState() { |
850 ASSERT(m_nextState != SQLTransactionState::Idle); | 893 ASSERT(m_nextState != SQLTransactionState::Idle); |
851 m_frontend->requestTransitToState(m_nextState); | 894 m_frontend->requestTransitToState(m_nextState); |
852 return SQLTransactionState::Idle; | 895 return SQLTransactionState::Idle; |
853 } | 896 } |
854 | 897 |
855 } // namespace blink | 898 } // namespace blink |
OLD | NEW |