| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 , m_name(name.isolatedCopy()) | 208 , m_name(name.isolatedCopy()) |
| 209 , m_expectedVersion(expectedVersion.isolatedCopy()) | 209 , m_expectedVersion(expectedVersion.isolatedCopy()) |
| 210 , m_displayName(displayName.isolatedCopy()) | 210 , m_displayName(displayName.isolatedCopy()) |
| 211 , m_estimatedSize(estimatedSize) | 211 , m_estimatedSize(estimatedSize) |
| 212 , m_guid(0) | 212 , m_guid(0) |
| 213 , m_opened(0) | 213 , m_opened(0) |
| 214 , m_new(false) | 214 , m_new(false) |
| 215 , m_transactionInProgress(false) | 215 , m_transactionInProgress(false) |
| 216 , m_isTransactionQueueEnabled(true) | 216 , m_isTransactionQueueEnabled(true) |
| 217 { | 217 { |
| 218 m_contextThreadSecurityOrigin = m_databaseContext->securityOrigin()->isolate
dCopy(); | 218 m_contextThreadSecurityOrigin = m_databaseContext->getSecurityOrigin()->isol
atedCopy(); |
| 219 | 219 |
| 220 m_databaseAuthorizer = DatabaseAuthorizer::create(infoTableName); | 220 m_databaseAuthorizer = DatabaseAuthorizer::create(infoTableName); |
| 221 | 221 |
| 222 if (m_name.isNull()) | 222 if (m_name.isNull()) |
| 223 m_name = ""; | 223 m_name = ""; |
| 224 | 224 |
| 225 { | 225 { |
| 226 SafePointAwareMutexLocker locker(guidMutex()); | 226 SafePointAwareMutexLocker locker(guidMutex()); |
| 227 m_guid = guidForOriginAndName(securityOrigin()->toString(), name); | 227 m_guid = guidForOriginAndName(getSecurityOrigin()->toString(), name); |
| 228 guidCount().add(m_guid); | 228 guidCount().add(m_guid); |
| 229 } | 229 } |
| 230 | 230 |
| 231 m_filename = DatabaseManager::manager().fullPathForDatabase(securityOrigin()
, m_name); | 231 m_filename = DatabaseManager::manager().fullPathForDatabase(getSecurityOrigi
n(), m_name); |
| 232 | 232 |
| 233 m_databaseThreadSecurityOrigin = m_contextThreadSecurityOrigin->isolatedCopy
(); | 233 m_databaseThreadSecurityOrigin = m_contextThreadSecurityOrigin->isolatedCopy
(); |
| 234 ASSERT(m_databaseContext->databaseThread()); | 234 ASSERT(m_databaseContext->databaseThread()); |
| 235 ASSERT(m_databaseContext->isContextThread()); | 235 ASSERT(m_databaseContext->isContextThread()); |
| 236 } | 236 } |
| 237 | 237 |
| 238 Database::~Database() | 238 Database::~Database() |
| 239 { | 239 { |
| 240 // SQLite is "multi-thread safe", but each database handle can only be used | 240 // SQLite is "multi-thread safe", but each database handle can only be used |
| 241 // on a single thread at a time. | 241 // on a single thread at a time. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 253 { | 253 { |
| 254 visitor->trace(m_databaseContext); | 254 visitor->trace(m_databaseContext); |
| 255 visitor->trace(m_sqliteDatabase); | 255 visitor->trace(m_sqliteDatabase); |
| 256 visitor->trace(m_databaseAuthorizer); | 256 visitor->trace(m_databaseAuthorizer); |
| 257 visitor->trace(m_transactionQueue); | 257 visitor->trace(m_transactionQueue); |
| 258 } | 258 } |
| 259 | 259 |
| 260 bool Database::openAndVerifyVersion(bool setVersionInNewDatabase, DatabaseError&
error, String& errorMessage) | 260 bool Database::openAndVerifyVersion(bool setVersionInNewDatabase, DatabaseError&
error, String& errorMessage) |
| 261 { | 261 { |
| 262 TaskSynchronizer synchronizer; | 262 TaskSynchronizer synchronizer; |
| 263 if (!databaseContext()->databaseThreadAvailable()) | 263 if (!getDatabaseContext()->databaseThreadAvailable()) |
| 264 return false; | 264 return false; |
| 265 | 265 |
| 266 DatabaseTracker::tracker().prepareToOpenDatabase(this); | 266 DatabaseTracker::tracker().prepareToOpenDatabase(this); |
| 267 bool success = false; | 267 bool success = false; |
| 268 OwnPtr<DatabaseOpenTask> task = DatabaseOpenTask::create(this, setVersionInN
ewDatabase, &synchronizer, error, errorMessage, success); | 268 OwnPtr<DatabaseOpenTask> task = DatabaseOpenTask::create(this, setVersionInN
ewDatabase, &synchronizer, error, errorMessage, success); |
| 269 databaseContext()->databaseThread()->scheduleTask(task.release()); | 269 getDatabaseContext()->databaseThread()->scheduleTask(task.release()); |
| 270 synchronizer.waitForTaskCompletion(); | 270 synchronizer.waitForTaskCompletion(); |
| 271 | 271 |
| 272 return success; | 272 return success; |
| 273 } | 273 } |
| 274 | 274 |
| 275 void Database::close() | 275 void Database::close() |
| 276 { | 276 { |
| 277 ASSERT(databaseContext()->databaseThread()); | 277 ASSERT(getDatabaseContext()->databaseThread()); |
| 278 ASSERT(databaseContext()->databaseThread()->isDatabaseThread()); | 278 ASSERT(getDatabaseContext()->databaseThread()->isDatabaseThread()); |
| 279 | 279 |
| 280 { | 280 { |
| 281 MutexLocker locker(m_transactionInProgressMutex); | 281 MutexLocker locker(m_transactionInProgressMutex); |
| 282 | 282 |
| 283 // Clean up transactions that have not been scheduled yet: | 283 // Clean up transactions that have not been scheduled yet: |
| 284 // Transaction phase 1 cleanup. See comment on "What happens if a | 284 // Transaction phase 1 cleanup. See comment on "What happens if a |
| 285 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp. | 285 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp. |
| 286 SQLTransactionBackend* transaction = nullptr; | 286 SQLTransactionBackend* transaction = nullptr; |
| 287 while (!m_transactionQueue.isEmpty()) { | 287 while (!m_transactionQueue.isEmpty()) { |
| 288 transaction = m_transactionQueue.takeFirst(); | 288 transaction = m_transactionQueue.takeFirst(); |
| 289 transaction->notifyDatabaseThreadIsShuttingDown(); | 289 transaction->notifyDatabaseThreadIsShuttingDown(); |
| 290 } | 290 } |
| 291 | 291 |
| 292 m_isTransactionQueueEnabled = false; | 292 m_isTransactionQueueEnabled = false; |
| 293 m_transactionInProgress = false; | 293 m_transactionInProgress = false; |
| 294 } | 294 } |
| 295 | 295 |
| 296 closeDatabase(); | 296 closeDatabase(); |
| 297 databaseContext()->databaseThread()->recordDatabaseClosed(this); | 297 getDatabaseContext()->databaseThread()->recordDatabaseClosed(this); |
| 298 } | 298 } |
| 299 | 299 |
| 300 SQLTransactionBackend* Database::runTransaction(SQLTransaction* transaction, boo
l readOnly, const ChangeVersionData* data) | 300 SQLTransactionBackend* Database::runTransaction(SQLTransaction* transaction, boo
l readOnly, const ChangeVersionData* data) |
| 301 { | 301 { |
| 302 MutexLocker locker(m_transactionInProgressMutex); | 302 MutexLocker locker(m_transactionInProgressMutex); |
| 303 if (!m_isTransactionQueueEnabled) | 303 if (!m_isTransactionQueueEnabled) |
| 304 return nullptr; | 304 return nullptr; |
| 305 | 305 |
| 306 SQLTransactionWrapper* wrapper = nullptr; | 306 SQLTransactionWrapper* wrapper = nullptr; |
| 307 if (data) | 307 if (data) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 323 } | 323 } |
| 324 | 324 |
| 325 void Database::scheduleTransaction() | 325 void Database::scheduleTransaction() |
| 326 { | 326 { |
| 327 ASSERT(!m_transactionInProgressMutex.tryLock()); // Locked by caller. | 327 ASSERT(!m_transactionInProgressMutex.tryLock()); // Locked by caller. |
| 328 SQLTransactionBackend* transaction = nullptr; | 328 SQLTransactionBackend* transaction = nullptr; |
| 329 | 329 |
| 330 if (m_isTransactionQueueEnabled && !m_transactionQueue.isEmpty()) | 330 if (m_isTransactionQueueEnabled && !m_transactionQueue.isEmpty()) |
| 331 transaction = m_transactionQueue.takeFirst(); | 331 transaction = m_transactionQueue.takeFirst(); |
| 332 | 332 |
| 333 if (transaction && databaseContext()->databaseThreadAvailable()) { | 333 if (transaction && getDatabaseContext()->databaseThreadAvailable()) { |
| 334 OwnPtr<DatabaseTransactionTask> task = DatabaseTransactionTask::create(t
ransaction); | 334 OwnPtr<DatabaseTransactionTask> task = DatabaseTransactionTask::create(t
ransaction); |
| 335 WTF_LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for transacti
on %p\n", task.get(), task->transaction()); | 335 WTF_LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for transacti
on %p\n", task.get(), task->transaction()); |
| 336 m_transactionInProgress = true; | 336 m_transactionInProgress = true; |
| 337 databaseContext()->databaseThread()->scheduleTask(task.release()); | 337 getDatabaseContext()->databaseThread()->scheduleTask(task.release()); |
| 338 } else { | 338 } else { |
| 339 m_transactionInProgress = false; | 339 m_transactionInProgress = false; |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 | 342 |
| 343 void Database::scheduleTransactionStep(SQLTransactionBackend* transaction) | 343 void Database::scheduleTransactionStep(SQLTransactionBackend* transaction) |
| 344 { | 344 { |
| 345 if (!databaseContext()->databaseThreadAvailable()) | 345 if (!getDatabaseContext()->databaseThreadAvailable()) |
| 346 return; | 346 return; |
| 347 | 347 |
| 348 OwnPtr<DatabaseTransactionTask> task = DatabaseTransactionTask::create(trans
action); | 348 OwnPtr<DatabaseTransactionTask> task = DatabaseTransactionTask::create(trans
action); |
| 349 WTF_LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for the transacti
on step\n", task.get()); | 349 WTF_LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for the transacti
on step\n", task.get()); |
| 350 databaseContext()->databaseThread()->scheduleTask(task.release()); | 350 getDatabaseContext()->databaseThread()->scheduleTask(task.release()); |
| 351 } | 351 } |
| 352 | 352 |
| 353 SQLTransactionClient* Database::transactionClient() const | 353 SQLTransactionClient* Database::transactionClient() const |
| 354 { | 354 { |
| 355 return databaseContext()->databaseThread()->transactionClient(); | 355 return getDatabaseContext()->databaseThread()->transactionClient(); |
| 356 } | 356 } |
| 357 | 357 |
| 358 SQLTransactionCoordinator* Database::transactionCoordinator() const | 358 SQLTransactionCoordinator* Database::transactionCoordinator() const |
| 359 { | 359 { |
| 360 return databaseContext()->databaseThread()->transactionCoordinator(); | 360 return getDatabaseContext()->databaseThread()->transactionCoordinator(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 // static | 363 // static |
| 364 const char* Database::databaseInfoTableName() | 364 const char* Database::databaseInfoTableName() |
| 365 { | 365 { |
| 366 return infoTableName; | 366 return infoTableName; |
| 367 } | 367 } |
| 368 | 368 |
| 369 void Database::closeDatabase() | 369 void Database::closeDatabase() |
| 370 { | 370 { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 onExitCaller.setOpenSucceeded(); | 539 onExitCaller.setOpenSucceeded(); |
| 540 | 540 |
| 541 if (m_new && !shouldSetVersionInNewDatabase) { | 541 if (m_new && !shouldSetVersionInNewDatabase) { |
| 542 // The caller provided a creationCallback which will set the expected | 542 // The caller provided a creationCallback which will set the expected |
| 543 // version. | 543 // version. |
| 544 m_expectedVersion = ""; | 544 m_expectedVersion = ""; |
| 545 } | 545 } |
| 546 | 546 |
| 547 reportOpenDatabaseResult(0, -1, 0, WTF::monotonicallyIncreasingTime() - call
StartTime); // OK | 547 reportOpenDatabaseResult(0, -1, 0, WTF::monotonicallyIncreasingTime() - call
StartTime); // OK |
| 548 | 548 |
| 549 if (databaseContext()->databaseThread()) | 549 if (getDatabaseContext()->databaseThread()) |
| 550 databaseContext()->databaseThread()->recordDatabaseOpen(this); | 550 getDatabaseContext()->databaseThread()->recordDatabaseOpen(this); |
| 551 return true; | 551 return true; |
| 552 } | 552 } |
| 553 | 553 |
| 554 String Database::stringIdentifier() const | 554 String Database::stringIdentifier() const |
| 555 { | 555 { |
| 556 // Return a deep copy for ref counting thread safety | 556 // Return a deep copy for ref counting thread safety |
| 557 return m_name.isolatedCopy(); | 557 return m_name.isolatedCopy(); |
| 558 } | 558 } |
| 559 | 559 |
| 560 String Database::displayName() const | 560 String Database::displayName() const |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 logErrorMessage(formatErrorMessage("error vacuuming database", resul
t, m_sqliteDatabase.lastErrorMsg())); | 705 logErrorMessage(formatErrorMessage("error vacuuming database", resul
t, m_sqliteDatabase.lastErrorMsg())); |
| 706 } | 706 } |
| 707 } | 707 } |
| 708 | 708 |
| 709 // These are used to generate histograms of errors seen with websql. | 709 // These are used to generate histograms of errors seen with websql. |
| 710 // See about:histograms in chromium. | 710 // See about:histograms in chromium. |
| 711 void Database::reportOpenDatabaseResult(int errorSite, int webSqlErrorCode, int
sqliteErrorCode, double duration) | 711 void Database::reportOpenDatabaseResult(int errorSite, int webSqlErrorCode, int
sqliteErrorCode, double duration) |
| 712 { | 712 { |
| 713 if (Platform::current()->databaseObserver()) { | 713 if (Platform::current()->databaseObserver()) { |
| 714 Platform::current()->databaseObserver()->reportOpenDatabaseResult( | 714 Platform::current()->databaseObserver()->reportOpenDatabaseResult( |
| 715 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 715 createDatabaseIdentifierFromSecurityOrigin(getSecurityOrigin()), |
| 716 stringIdentifier(), errorSite, webSqlErrorCode, sqliteErrorCode, | 716 stringIdentifier(), errorSite, webSqlErrorCode, sqliteErrorCode, |
| 717 duration); | 717 duration); |
| 718 } | 718 } |
| 719 } | 719 } |
| 720 | 720 |
| 721 void Database::reportChangeVersionResult(int errorSite, int webSqlErrorCode, int
sqliteErrorCode) | 721 void Database::reportChangeVersionResult(int errorSite, int webSqlErrorCode, int
sqliteErrorCode) |
| 722 { | 722 { |
| 723 if (Platform::current()->databaseObserver()) { | 723 if (Platform::current()->databaseObserver()) { |
| 724 Platform::current()->databaseObserver()->reportChangeVersionResult( | 724 Platform::current()->databaseObserver()->reportChangeVersionResult( |
| 725 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 725 createDatabaseIdentifierFromSecurityOrigin(getSecurityOrigin()), |
| 726 stringIdentifier(), errorSite, webSqlErrorCode, sqliteErrorCode); | 726 stringIdentifier(), errorSite, webSqlErrorCode, sqliteErrorCode); |
| 727 } | 727 } |
| 728 } | 728 } |
| 729 | 729 |
| 730 void Database::reportStartTransactionResult(int errorSite, int webSqlErrorCode,
int sqliteErrorCode) | 730 void Database::reportStartTransactionResult(int errorSite, int webSqlErrorCode,
int sqliteErrorCode) |
| 731 { | 731 { |
| 732 if (Platform::current()->databaseObserver()) { | 732 if (Platform::current()->databaseObserver()) { |
| 733 Platform::current()->databaseObserver()->reportStartTransactionResult( | 733 Platform::current()->databaseObserver()->reportStartTransactionResult( |
| 734 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 734 createDatabaseIdentifierFromSecurityOrigin(getSecurityOrigin()), |
| 735 stringIdentifier(), errorSite, webSqlErrorCode, sqliteErrorCode); | 735 stringIdentifier(), errorSite, webSqlErrorCode, sqliteErrorCode); |
| 736 } | 736 } |
| 737 } | 737 } |
| 738 | 738 |
| 739 void Database::reportCommitTransactionResult(int errorSite, int webSqlErrorCode,
int sqliteErrorCode) | 739 void Database::reportCommitTransactionResult(int errorSite, int webSqlErrorCode,
int sqliteErrorCode) |
| 740 { | 740 { |
| 741 if (Platform::current()->databaseObserver()) { | 741 if (Platform::current()->databaseObserver()) { |
| 742 Platform::current()->databaseObserver()->reportCommitTransactionResult( | 742 Platform::current()->databaseObserver()->reportCommitTransactionResult( |
| 743 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 743 createDatabaseIdentifierFromSecurityOrigin(getSecurityOrigin()), |
| 744 stringIdentifier(), errorSite, webSqlErrorCode, sqliteErrorCode); | 744 stringIdentifier(), errorSite, webSqlErrorCode, sqliteErrorCode); |
| 745 } | 745 } |
| 746 } | 746 } |
| 747 | 747 |
| 748 void Database::reportExecuteStatementResult(int errorSite, int webSqlErrorCode,
int sqliteErrorCode) | 748 void Database::reportExecuteStatementResult(int errorSite, int webSqlErrorCode,
int sqliteErrorCode) |
| 749 { | 749 { |
| 750 if (Platform::current()->databaseObserver()) { | 750 if (Platform::current()->databaseObserver()) { |
| 751 Platform::current()->databaseObserver()->reportExecuteStatementResult( | 751 Platform::current()->databaseObserver()->reportExecuteStatementResult( |
| 752 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 752 createDatabaseIdentifierFromSecurityOrigin(getSecurityOrigin()), |
| 753 stringIdentifier(), errorSite, webSqlErrorCode, sqliteErrorCode); | 753 stringIdentifier(), errorSite, webSqlErrorCode, sqliteErrorCode); |
| 754 } | 754 } |
| 755 } | 755 } |
| 756 | 756 |
| 757 void Database::reportVacuumDatabaseResult(int sqliteErrorCode) | 757 void Database::reportVacuumDatabaseResult(int sqliteErrorCode) |
| 758 { | 758 { |
| 759 if (Platform::current()->databaseObserver()) { | 759 if (Platform::current()->databaseObserver()) { |
| 760 Platform::current()->databaseObserver()->reportVacuumDatabaseResult( | 760 Platform::current()->databaseObserver()->reportVacuumDatabaseResult( |
| 761 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 761 createDatabaseIdentifierFromSecurityOrigin(getSecurityOrigin()), |
| 762 stringIdentifier(), sqliteErrorCode); | 762 stringIdentifier(), sqliteErrorCode); |
| 763 } | 763 } |
| 764 } | 764 } |
| 765 | 765 |
| 766 void Database::logErrorMessage(const String& message) | 766 void Database::logErrorMessage(const String& message) |
| 767 { | 767 { |
| 768 executionContext()->addConsoleMessage(ConsoleMessage::create(StorageMessageS
ource, ErrorMessageLevel, message)); | 768 getExecutionContext()->addConsoleMessage(ConsoleMessage::create(StorageMessa
geSource, ErrorMessageLevel, message)); |
| 769 } | 769 } |
| 770 | 770 |
| 771 ExecutionContext* Database::executionContext() const | 771 ExecutionContext* Database::getExecutionContext() const |
| 772 { | 772 { |
| 773 return databaseContext()->executionContext(); | 773 return getDatabaseContext()->getExecutionContext(); |
| 774 } | 774 } |
| 775 | 775 |
| 776 void Database::closeImmediately() | 776 void Database::closeImmediately() |
| 777 { | 777 { |
| 778 ASSERT(executionContext()->isContextThread()); | 778 ASSERT(getExecutionContext()->isContextThread()); |
| 779 if (databaseContext()->databaseThreadAvailable() && opened()) { | 779 if (getDatabaseContext()->databaseThreadAvailable() && opened()) { |
| 780 logErrorMessage("forcibly closing database"); | 780 logErrorMessage("forcibly closing database"); |
| 781 databaseContext()->databaseThread()->scheduleTask(DatabaseCloseTask::cre
ate(this, 0)); | 781 getDatabaseContext()->databaseThread()->scheduleTask(DatabaseCloseTask::
create(this, 0)); |
| 782 } | 782 } |
| 783 } | 783 } |
| 784 | 784 |
| 785 void Database::changeVersion( | 785 void Database::changeVersion( |
| 786 const String& oldVersion, | 786 const String& oldVersion, |
| 787 const String& newVersion, | 787 const String& newVersion, |
| 788 SQLTransactionCallback* callback, | 788 SQLTransactionCallback* callback, |
| 789 SQLTransactionErrorCallback* errorCallback, | 789 SQLTransactionErrorCallback* errorCallback, |
| 790 VoidCallback* successCallback) | 790 VoidCallback* successCallback) |
| 791 { | 791 { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 814 callback->handleEvent(SQLError::create(*errorData)); | 814 callback->handleEvent(SQLError::create(*errorData)); |
| 815 } | 815 } |
| 816 | 816 |
| 817 void Database::runTransaction( | 817 void Database::runTransaction( |
| 818 SQLTransactionCallback* callback, | 818 SQLTransactionCallback* callback, |
| 819 SQLTransactionErrorCallback* errorCallback, | 819 SQLTransactionErrorCallback* errorCallback, |
| 820 VoidCallback* successCallback, | 820 VoidCallback* successCallback, |
| 821 bool readOnly, | 821 bool readOnly, |
| 822 const ChangeVersionData* changeVersionData) | 822 const ChangeVersionData* changeVersionData) |
| 823 { | 823 { |
| 824 ASSERT(executionContext()->isContextThread()); | 824 ASSERT(getExecutionContext()->isContextThread()); |
| 825 // FIXME: Rather than passing errorCallback to SQLTransaction and then | 825 // FIXME: Rather than passing errorCallback to SQLTransaction and then |
| 826 // sometimes firing it ourselves, this code should probably be pushed down | 826 // sometimes firing it ourselves, this code should probably be pushed down |
| 827 // into Database so that we only create the SQLTransaction if we're | 827 // into Database so that we only create the SQLTransaction if we're |
| 828 // actually going to run it. | 828 // actually going to run it. |
| 829 #if ENABLE(ASSERT) | 829 #if ENABLE(ASSERT) |
| 830 SQLTransactionErrorCallback* originalErrorCallback = errorCallback; | 830 SQLTransactionErrorCallback* originalErrorCallback = errorCallback; |
| 831 #endif | 831 #endif |
| 832 SQLTransaction* transaction = SQLTransaction::create(this, callback, success
Callback, errorCallback, readOnly); | 832 SQLTransaction* transaction = SQLTransaction::create(this, callback, success
Callback, errorCallback, readOnly); |
| 833 SQLTransactionBackend* transactionBackend = runTransaction(transaction, read
Only, changeVersionData); | 833 SQLTransactionBackend* transactionBackend = runTransaction(transaction, read
Only, changeVersionData); |
| 834 if (!transactionBackend) { | 834 if (!transactionBackend) { |
| 835 SQLTransactionErrorCallback* callback = transaction->releaseErrorCallbac
k(); | 835 SQLTransactionErrorCallback* callback = transaction->releaseErrorCallbac
k(); |
| 836 ASSERT(callback == originalErrorCallback); | 836 ASSERT(callback == originalErrorCallback); |
| 837 if (callback) { | 837 if (callback) { |
| 838 OwnPtr<SQLErrorData> error = SQLErrorData::create(SQLError::UNKNOWN_
ERR, "database has been closed"); | 838 OwnPtr<SQLErrorData> error = SQLErrorData::create(SQLError::UNKNOWN_
ERR, "database has been closed"); |
| 839 executionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&
callTransactionErrorCallback, callback, error.release())); | 839 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTas
k(&callTransactionErrorCallback, callback, error.release())); |
| 840 } | 840 } |
| 841 } | 841 } |
| 842 } | 842 } |
| 843 | 843 |
| 844 void Database::scheduleTransactionCallback(SQLTransaction* transaction) | 844 void Database::scheduleTransactionCallback(SQLTransaction* transaction) |
| 845 { | 845 { |
| 846 // The task is constructed in a database thread, and destructed in the | 846 // The task is constructed in a database thread, and destructed in the |
| 847 // context thread. | 847 // context thread. |
| 848 executionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&SQLTran
saction::performPendingCallback, transaction)); | 848 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&SQLT
ransaction::performPendingCallback, transaction)); |
| 849 } | 849 } |
| 850 | 850 |
| 851 Vector<String> Database::performGetTableNames() | 851 Vector<String> Database::performGetTableNames() |
| 852 { | 852 { |
| 853 disableAuthorizer(); | 853 disableAuthorizer(); |
| 854 | 854 |
| 855 SQLiteStatement statement(sqliteDatabase(), "SELECT name FROM sqlite_master
WHERE type='table';"); | 855 SQLiteStatement statement(sqliteDatabase(), "SELECT name FROM sqlite_master
WHERE type='table';"); |
| 856 if (statement.prepare() != SQLResultOk) { | 856 if (statement.prepare() != SQLResultOk) { |
| 857 WTF_LOG_ERROR("Unable to retrieve list of tables for database %s", datab
aseDebugName().ascii().data()); | 857 WTF_LOG_ERROR("Unable to retrieve list of tables for database %s", datab
aseDebugName().ascii().data()); |
| 858 enableAuthorizer(); | 858 enableAuthorizer(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 877 return tableNames; | 877 return tableNames; |
| 878 } | 878 } |
| 879 | 879 |
| 880 Vector<String> Database::tableNames() | 880 Vector<String> Database::tableNames() |
| 881 { | 881 { |
| 882 // FIXME: Not using isolatedCopy on these strings looks ok since threads | 882 // FIXME: Not using isolatedCopy on these strings looks ok since threads |
| 883 // take strict turns in dealing with them. However, if the code changes, | 883 // take strict turns in dealing with them. However, if the code changes, |
| 884 // this may not be true anymore. | 884 // this may not be true anymore. |
| 885 Vector<String> result; | 885 Vector<String> result; |
| 886 TaskSynchronizer synchronizer; | 886 TaskSynchronizer synchronizer; |
| 887 if (!databaseContext()->databaseThreadAvailable()) | 887 if (!getDatabaseContext()->databaseThreadAvailable()) |
| 888 return result; | 888 return result; |
| 889 | 889 |
| 890 OwnPtr<DatabaseTableNamesTask> task = DatabaseTableNamesTask::create(this, &
synchronizer, result); | 890 OwnPtr<DatabaseTableNamesTask> task = DatabaseTableNamesTask::create(this, &
synchronizer, result); |
| 891 databaseContext()->databaseThread()->scheduleTask(task.release()); | 891 getDatabaseContext()->databaseThread()->scheduleTask(task.release()); |
| 892 synchronizer.waitForTaskCompletion(); | 892 synchronizer.waitForTaskCompletion(); |
| 893 | 893 |
| 894 return result; | 894 return result; |
| 895 } | 895 } |
| 896 | 896 |
| 897 SecurityOrigin* Database::securityOrigin() const | 897 SecurityOrigin* Database::getSecurityOrigin() const |
| 898 { | 898 { |
| 899 if (executionContext()->isContextThread()) | 899 if (getExecutionContext()->isContextThread()) |
| 900 return m_contextThreadSecurityOrigin.get(); | 900 return m_contextThreadSecurityOrigin.get(); |
| 901 if (databaseContext()->databaseThread()->isDatabaseThread()) | 901 if (getDatabaseContext()->databaseThread()->isDatabaseThread()) |
| 902 return m_databaseThreadSecurityOrigin.get(); | 902 return m_databaseThreadSecurityOrigin.get(); |
| 903 return 0; | 903 return 0; |
| 904 } | 904 } |
| 905 | 905 |
| 906 bool Database::opened() | 906 bool Database::opened() |
| 907 { | 907 { |
| 908 return static_cast<bool>(acquireLoad(&m_opened)); | 908 return static_cast<bool>(acquireLoad(&m_opened)); |
| 909 } | 909 } |
| 910 | 910 |
| 911 } // namespace blink | 911 } // namespace blink |
| OLD | NEW |