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