| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 , m_name(name.isolatedCopy()) | 206 , m_name(name.isolatedCopy()) |
| 207 , m_expectedVersion(expectedVersion.isolatedCopy()) | 207 , m_expectedVersion(expectedVersion.isolatedCopy()) |
| 208 , m_displayName(displayName.isolatedCopy()) | 208 , m_displayName(displayName.isolatedCopy()) |
| 209 , m_estimatedSize(estimatedSize) | 209 , m_estimatedSize(estimatedSize) |
| 210 , m_guid(0) | 210 , m_guid(0) |
| 211 , m_opened(false) | 211 , m_opened(false) |
| 212 , m_new(false) | 212 , m_new(false) |
| 213 , m_transactionInProgress(false) | 213 , m_transactionInProgress(false) |
| 214 , m_isTransactionQueueEnabled(true) | 214 , m_isTransactionQueueEnabled(true) |
| 215 { | 215 { |
| 216 ASSERT(isMainThread()); |
| 216 m_contextThreadSecurityOrigin = m_databaseContext->securityOrigin()->isolate
dCopy(); | 217 m_contextThreadSecurityOrigin = m_databaseContext->securityOrigin()->isolate
dCopy(); |
| 217 | 218 |
| 218 m_databaseAuthorizer = DatabaseAuthorizer::create(infoTableName); | 219 m_databaseAuthorizer = DatabaseAuthorizer::create(infoTableName); |
| 219 | 220 |
| 220 if (m_name.isNull()) | 221 if (m_name.isNull()) |
| 221 m_name = ""; | 222 m_name = ""; |
| 222 | 223 |
| 223 { | 224 { |
| 224 SafePointAwareMutexLocker locker(guidMutex()); | 225 SafePointAwareMutexLocker locker(guidMutex()); |
| 225 m_guid = guidForOriginAndName(securityOrigin()->toString(), name); | 226 m_guid = guidForOriginAndName(securityOrigin()->toString(), name); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 ASSERT(databaseContext()->databaseThread()); | 276 ASSERT(databaseContext()->databaseThread()); |
| 276 ASSERT(databaseContext()->databaseThread()->isDatabaseThread()); | 277 ASSERT(databaseContext()->databaseThread()->isDatabaseThread()); |
| 277 | 278 |
| 278 { | 279 { |
| 279 MutexLocker locker(m_transactionInProgressMutex); | 280 MutexLocker locker(m_transactionInProgressMutex); |
| 280 | 281 |
| 281 // Clean up transactions that have not been scheduled yet: | 282 // Clean up transactions that have not been scheduled yet: |
| 282 // Transaction phase 1 cleanup. See comment on "What happens if a | 283 // Transaction phase 1 cleanup. See comment on "What happens if a |
| 283 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp. | 284 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp. |
| 284 SQLTransactionBackend* transaction = nullptr; | 285 SQLTransactionBackend* transaction = nullptr; |
| 285 while (!m_transactionQueue.isEmpty()) { | 286 while (m_transactionQueue && !m_transactionQueue->isEmpty()) { |
| 286 transaction = m_transactionQueue.takeFirst(); | 287 transaction = m_transactionQueue->takeFirst(); |
| 287 transaction->notifyDatabaseThreadIsShuttingDown(); | 288 transaction->notifyDatabaseThreadIsShuttingDown(); |
| 288 } | 289 } |
| 289 | 290 |
| 290 m_isTransactionQueueEnabled = false; | 291 m_isTransactionQueueEnabled = false; |
| 291 m_transactionInProgress = false; | 292 m_transactionInProgress = false; |
| 292 } | 293 } |
| 293 | 294 |
| 294 closeDatabase(); | 295 closeDatabase(); |
| 295 databaseContext()->databaseThread()->recordDatabaseClosed(this); | 296 databaseContext()->databaseThread()->recordDatabaseClosed(this); |
| 296 } | 297 } |
| 297 | 298 |
| 298 SQLTransactionBackend* Database::runTransaction(SQLTransaction* transaction, boo
l readOnly, const ChangeVersionData* data) | 299 SQLTransactionBackend* Database::runTransaction(SQLTransaction* transaction, boo
l readOnly, const ChangeVersionData* data) |
| 299 { | 300 { |
| 300 MutexLocker locker(m_transactionInProgressMutex); | 301 MutexLocker locker(m_transactionInProgressMutex); |
| 301 if (!m_isTransactionQueueEnabled) | 302 if (!m_isTransactionQueueEnabled) |
| 302 return nullptr; | 303 return nullptr; |
| 303 | 304 |
| 304 SQLTransactionWrapper* wrapper = nullptr; | 305 SQLTransactionWrapper* wrapper = nullptr; |
| 305 if (data) | 306 if (data) |
| 306 wrapper = ChangeVersionWrapper::create(data->oldVersion(), data->newVers
ion()); | 307 wrapper = ChangeVersionWrapper::create(data->oldVersion(), data->newVers
ion()); |
| 307 | 308 |
| 308 SQLTransactionBackend* transactionBackend = SQLTransactionBackend::create(th
is, transaction, wrapper, readOnly); | 309 SQLTransactionBackend* transactionBackend = SQLTransactionBackend::create(th
is, transaction, wrapper, readOnly); |
| 309 m_transactionQueue.append(transactionBackend); | 310 if (!m_transactionQueue) |
| 311 m_transactionQueue = new HeapDeque<Member<SQLTransactionBackend>>(); |
| 312 m_transactionQueue->append(transactionBackend); |
| 310 if (!m_transactionInProgress) | 313 if (!m_transactionInProgress) |
| 311 scheduleTransaction(); | 314 scheduleTransaction(); |
| 312 | 315 |
| 313 return transactionBackend; | 316 return transactionBackend; |
| 314 } | 317 } |
| 315 | 318 |
| 316 void Database::inProgressTransactionCompleted() | 319 void Database::inProgressTransactionCompleted() |
| 317 { | 320 { |
| 318 MutexLocker locker(m_transactionInProgressMutex); | 321 MutexLocker locker(m_transactionInProgressMutex); |
| 319 m_transactionInProgress = false; | 322 m_transactionInProgress = false; |
| 320 scheduleTransaction(); | 323 scheduleTransaction(); |
| 321 } | 324 } |
| 322 | 325 |
| 323 void Database::scheduleTransaction() | 326 void Database::scheduleTransaction() |
| 324 { | 327 { |
| 325 ASSERT(!m_transactionInProgressMutex.tryLock()); // Locked by caller. | 328 ASSERT(!m_transactionInProgressMutex.tryLock()); // Locked by caller. |
| 326 SQLTransactionBackend* transaction = nullptr; | 329 SQLTransactionBackend* transaction = nullptr; |
| 327 | 330 |
| 328 if (m_isTransactionQueueEnabled && !m_transactionQueue.isEmpty()) | 331 if (m_isTransactionQueueEnabled && m_transactionQueue && !m_transactionQueue
->isEmpty()) |
| 329 transaction = m_transactionQueue.takeFirst(); | 332 transaction = m_transactionQueue->takeFirst(); |
| 330 | 333 |
| 331 if (transaction && databaseContext()->databaseThreadAvailable()) { | 334 if (transaction && databaseContext()->databaseThreadAvailable()) { |
| 332 OwnPtr<DatabaseTransactionTask> task = DatabaseTransactionTask::create(t
ransaction); | 335 OwnPtr<DatabaseTransactionTask> task = DatabaseTransactionTask::create(t
ransaction); |
| 333 WTF_LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for transacti
on %p\n", task.get(), task->transaction()); | 336 WTF_LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for transacti
on %p\n", task.get(), task->transaction()); |
| 334 m_transactionInProgress = true; | 337 m_transactionInProgress = true; |
| 335 databaseContext()->databaseThread()->scheduleTask(task.release()); | 338 databaseContext()->databaseThread()->scheduleTask(task.release()); |
| 336 } else { | 339 } else { |
| 337 m_transactionInProgress = false; | 340 m_transactionInProgress = false; |
| 338 } | 341 } |
| 339 } | 342 } |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 SecurityOrigin* Database::securityOrigin() const | 898 SecurityOrigin* Database::securityOrigin() const |
| 896 { | 899 { |
| 897 if (executionContext()->isContextThread()) | 900 if (executionContext()->isContextThread()) |
| 898 return m_contextThreadSecurityOrigin.get(); | 901 return m_contextThreadSecurityOrigin.get(); |
| 899 if (databaseContext()->databaseThread()->isDatabaseThread()) | 902 if (databaseContext()->databaseThread()->isDatabaseThread()) |
| 900 return m_databaseThreadSecurityOrigin.get(); | 903 return m_databaseThreadSecurityOrigin.get(); |
| 901 return 0; | 904 return 0; |
| 902 } | 905 } |
| 903 | 906 |
| 904 } // namespace blink | 907 } // namespace blink |
| OLD | NEW |