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 23 matching lines...) Expand all Loading... |
34 #include "modules/webdatabase/DatabaseThread.h" | 34 #include "modules/webdatabase/DatabaseThread.h" |
35 #include "modules/webdatabase/DatabaseTracker.h" | 35 #include "modules/webdatabase/DatabaseTracker.h" |
36 #include "modules/webdatabase/SQLError.h" | 36 #include "modules/webdatabase/SQLError.h" |
37 #include "modules/webdatabase/SQLStatementBackend.h" | 37 #include "modules/webdatabase/SQLStatementBackend.h" |
38 #include "modules/webdatabase/SQLTransaction.h" | 38 #include "modules/webdatabase/SQLTransaction.h" |
39 #include "modules/webdatabase/SQLTransactionClient.h" | 39 #include "modules/webdatabase/SQLTransactionClient.h" |
40 #include "modules/webdatabase/SQLTransactionCoordinator.h" | 40 #include "modules/webdatabase/SQLTransactionCoordinator.h" |
41 #include "modules/webdatabase/sqlite/SQLValue.h" | 41 #include "modules/webdatabase/sqlite/SQLValue.h" |
42 #include "modules/webdatabase/sqlite/SQLiteTransaction.h" | 42 #include "modules/webdatabase/sqlite/SQLiteTransaction.h" |
43 #include "platform/Logging.h" | 43 #include "platform/Logging.h" |
| 44 #include "wtf/PtrUtil.h" |
44 #include "wtf/StdLibExtras.h" | 45 #include "wtf/StdLibExtras.h" |
| 46 #include <memory> |
45 | 47 |
46 | 48 |
47 // How does a SQLTransaction work? | 49 // How does a SQLTransaction work? |
48 // ============================== | 50 // ============================== |
49 // The SQLTransaction is a state machine that executes a series of states / step
s. | 51 // The SQLTransaction is a state machine that executes a series of states / step
s. |
50 // | 52 // |
51 // 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 |
52 // webdatabase spec: http://dev.w3.org/html5/webdatabase/#processing-model | 54 // webdatabase spec: http://dev.w3.org/html5/webdatabase/#processing-model |
53 // | 55 // |
54 // the State Transition Graph at a glance: | 56 // the State Transition Graph at a glance: |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 // After scheduling the transaction with the DatabaseThread (Database::sched
uleTransaction()): | 248 // After scheduling the transaction with the DatabaseThread (Database::sched
uleTransaction()): |
247 // =========================================================================
============================= | 249 // =========================================================================
============================= |
248 // DatabaseThread // MessageQueue<DatabaseTask> m_qu
eue points to ... | 250 // DatabaseThread // MessageQueue<DatabaseTask> m_qu
eue points to ... |
249 // --> DatabaseTransactionTask // Member<SQLTransactionBackend> m
_transaction points to ... | 251 // --> DatabaseTransactionTask // Member<SQLTransactionBackend> m
_transaction points to ... |
250 // --> SQLTransactionBackend // Member<SQLTransaction> m_fronte
nd points to ... | 252 // --> SQLTransactionBackend // Member<SQLTransaction> m_fronte
nd points to ... |
251 // --> SQLTransaction // Member<SQLTransactionBackend> m
_backend points to ... | 253 // --> SQLTransaction // Member<SQLTransactionBackend> m
_backend points to ... |
252 // --> SQLTransactionBackend // which is a circular reference. | 254 // --> SQLTransactionBackend // which is a circular reference. |
253 // | 255 // |
254 // When executing the transaction (in DatabaseThread::databaseThread()): | 256 // When executing the transaction (in DatabaseThread::databaseThread()): |
255 // ==================================================================== | 257 // ==================================================================== |
256 // OwnPtr<DatabaseTask> task; // points to ... | 258 // std::unique_ptr<DatabaseTask> task; // points to ... |
257 // --> DatabaseTransactionTask // Member<SQLTransactionBackend> m
_transaction points to ... | 259 // --> DatabaseTransactionTask // Member<SQLTransactionBackend> m
_transaction points to ... |
258 // --> SQLTransactionBackend // Member<SQLTransaction> m_fronte
nd; | 260 // --> SQLTransactionBackend // Member<SQLTransaction> m_fronte
nd; |
259 // --> SQLTransaction // Member<SQLTransactionBackend> m
_backend points to ... | 261 // --> SQLTransaction // Member<SQLTransactionBackend> m
_backend points to ... |
260 // --> SQLTransactionBackend // which is a circular reference. | 262 // --> SQLTransactionBackend // which is a circular reference. |
261 // | 263 // |
262 // At the end of cleanupAndTerminate(): | 264 // At the end of cleanupAndTerminate(): |
263 // =================================== | 265 // =================================== |
264 // At the end of the cleanup state, the SQLTransactionBackend::m_frontend is
nullified. | 266 // At the end of the cleanup state, the SQLTransactionBackend::m_frontend is
nullified. |
265 // If by then, a JSObject wrapper is referring to the SQLTransaction, then t
he reference | 267 // If by then, a JSObject wrapper is referring to the SQLTransaction, then t
he reference |
266 // chain looks like this: | 268 // chain looks like this: |
267 // | 269 // |
268 // JSObjectWrapper | 270 // JSObjectWrapper |
269 // --> SQLTransaction // in Member<SQLTransactionBackend> m_back
end points to ... | 271 // --> SQLTransaction // in Member<SQLTransactionBackend> m_back
end points to ... |
270 // --> SQLTransactionBackend // which no longer points back to its SQLT
ransaction. | 272 // --> SQLTransactionBackend // which no longer points back to its SQLT
ransaction. |
271 // | 273 // |
272 // When the GC collects the corresponding JSObject, the above chain will be
cleaned up | 274 // When the GC collects the corresponding JSObject, the above chain will be
cleaned up |
273 // and deleted. | 275 // and deleted. |
274 // | 276 // |
275 // If there is no JSObject wrapper referring to the SQLTransaction when the
cleanup | 277 // If there is no JSObject wrapper referring to the SQLTransaction when the
cleanup |
276 // states nullify SQLTransactionBackend::m_frontend, the SQLTransaction will
deleted then. | 278 // states nullify SQLTransactionBackend::m_frontend, the SQLTransaction will
deleted then. |
277 // However, there will still be a DatabaseTask pointing to the SQLTransactio
nBackend (see | 279 // However, there will still be a DatabaseTask pointing to the SQLTransactio
nBackend (see |
278 // the "When executing the transaction" chain above). This will keep the | 280 // the "When executing the transaction" chain above). This will keep the |
279 // SQLTransactionBackend alive until DatabaseThread::databaseThread() releas
es its | 281 // SQLTransactionBackend alive until DatabaseThread::databaseThread() releas
es its |
280 // task OwnPtr. | 282 // task std::unique_ptr. |
281 // | 283 // |
282 // What happens if a transaction is interrupted? | 284 // What happens if a transaction is interrupted? |
283 // ============================================ | 285 // ============================================ |
284 // If the transaction is interrupted half way, it won't get to run to state | 286 // 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 | 287 // CleanupAndTerminate, and hence, would not have called SQLTransactionBacke
nd's |
286 // doCleanup(). doCleanup() is where we nullify SQLTransactionBackend::m_fro
ntend | 288 // doCleanup(). doCleanup() is where we nullify SQLTransactionBackend::m_fro
ntend |
287 // to break the reference cycle between the frontend and backend. Hence, we
need | 289 // to break the reference cycle between the frontend and backend. Hence, we
need |
288 // to cleanup the transaction by other means. | 290 // to cleanup the transaction by other means. |
289 // | 291 // |
290 // Note: calling SQLTransactionBackend::notifyDatabaseThreadIsShuttingDown() | 292 // Note: calling SQLTransactionBackend::notifyDatabaseThreadIsShuttingDown() |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 556 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
555 ASSERT(m_lockAcquired); | 557 ASSERT(m_lockAcquired); |
556 | 558 |
557 WTF_LOG(StorageAPI, "Opening and preflighting transaction %p", this); | 559 WTF_LOG(StorageAPI, "Opening and preflighting transaction %p", this); |
558 | 560 |
559 // Set the maximum usage for this transaction if this transactions is not re
ad-only | 561 // Set the maximum usage for this transaction if this transactions is not re
ad-only |
560 if (!m_readOnly) | 562 if (!m_readOnly) |
561 m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize()); | 563 m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize()); |
562 | 564 |
563 ASSERT(!m_sqliteTransaction); | 565 ASSERT(!m_sqliteTransaction); |
564 m_sqliteTransaction = adoptPtr(new SQLiteTransaction(m_database->sqliteDatab
ase(), m_readOnly)); | 566 m_sqliteTransaction = wrapUnique(new SQLiteTransaction(m_database->sqliteDat
abase(), m_readOnly)); |
565 | 567 |
566 m_database->resetDeletes(); | 568 m_database->resetDeletes(); |
567 m_database->disableAuthorizer(); | 569 m_database->disableAuthorizer(); |
568 m_sqliteTransaction->begin(); | 570 m_sqliteTransaction->begin(); |
569 m_database->enableAuthorizer(); | 571 m_database->enableAuthorizer(); |
570 | 572 |
571 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error
callback if that fails | 573 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error
callback if that fails |
572 if (!m_sqliteTransaction->inProgress()) { | 574 if (!m_sqliteTransaction->inProgress()) { |
573 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 575 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
574 m_database->reportStartTransactionResult(2, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); | 576 m_database->reportStartTransactionResult(2, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 } | 824 } |
823 | 825 |
824 SQLTransactionState SQLTransactionBackend::sendToFrontendState() | 826 SQLTransactionState SQLTransactionBackend::sendToFrontendState() |
825 { | 827 { |
826 ASSERT(m_nextState != SQLTransactionState::Idle); | 828 ASSERT(m_nextState != SQLTransactionState::Idle); |
827 m_frontend->requestTransitToState(m_nextState); | 829 m_frontend->requestTransitToState(m_nextState); |
828 return SQLTransactionState::Idle; | 830 return SQLTransactionState::Idle; |
829 } | 831 } |
830 | 832 |
831 } // namespace blink | 833 } // namespace blink |
OLD | NEW |