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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 { | 252 { |
253 visitor->trace(m_databaseContext); | 253 visitor->trace(m_databaseContext); |
254 visitor->trace(m_sqliteDatabase); | 254 visitor->trace(m_sqliteDatabase); |
255 visitor->trace(m_databaseAuthorizer); | 255 visitor->trace(m_databaseAuthorizer); |
256 visitor->trace(m_transactionQueue); | 256 visitor->trace(m_transactionQueue); |
257 } | 257 } |
258 | 258 |
259 bool Database::openAndVerifyVersion(bool setVersionInNewDatabase, DatabaseError&
error, String& errorMessage) | 259 bool Database::openAndVerifyVersion(bool setVersionInNewDatabase, DatabaseError&
error, String& errorMessage) |
260 { | 260 { |
261 TaskSynchronizer synchronizer; | 261 TaskSynchronizer synchronizer; |
262 if (!databaseContext()->databaseThread() || databaseContext()->databaseThrea
d()->terminationRequested(&synchronizer)) | 262 if (!databaseContext()->databaseThreadAvailable()) |
263 return false; | 263 return false; |
264 | 264 |
265 DatabaseTracker::tracker().prepareToOpenDatabase(this); | 265 DatabaseTracker::tracker().prepareToOpenDatabase(this); |
266 bool success = false; | 266 bool success = false; |
267 OwnPtr<DatabaseOpenTask> task = DatabaseOpenTask::create(this, setVersionInN
ewDatabase, &synchronizer, error, errorMessage, success); | 267 OwnPtr<DatabaseOpenTask> task = DatabaseOpenTask::create(this, setVersionInN
ewDatabase, &synchronizer, error, errorMessage, success); |
268 databaseContext()->databaseThread()->scheduleTask(task.release()); | 268 databaseContext()->databaseThread()->scheduleTask(task.release()); |
269 synchronizer.waitForTaskCompletion(); | 269 synchronizer.waitForTaskCompletion(); |
270 | 270 |
271 return success; | 271 return success; |
272 } | 272 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 RefPtrWillBeRawPtr<SQLTransactionBackend> transaction = nullptr; | 328 RefPtrWillBeRawPtr<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()->databaseThread()) { | 333 if (transaction && databaseContext()->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 databaseContext()->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()->databaseThread()) | 345 if (!databaseContext()->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 databaseContext()->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 databaseContext()->databaseThread()->transactionClient(); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 } | 776 } |
777 | 777 |
778 ExecutionContext* Database::executionContext() const | 778 ExecutionContext* Database::executionContext() const |
779 { | 779 { |
780 return databaseContext()->executionContext(); | 780 return databaseContext()->executionContext(); |
781 } | 781 } |
782 | 782 |
783 void Database::closeImmediately() | 783 void Database::closeImmediately() |
784 { | 784 { |
785 ASSERT(executionContext()->isContextThread()); | 785 ASSERT(executionContext()->isContextThread()); |
786 DatabaseThread* databaseThread = databaseContext()->databaseThread(); | 786 if (databaseContext()->databaseThreadAvailable() && opened()) { |
787 if (databaseThread && !databaseThread->terminationRequested() && opened()) { | |
788 logErrorMessage("forcibly closing database"); | 787 logErrorMessage("forcibly closing database"); |
789 databaseThread->scheduleTask(DatabaseCloseTask::create(this, 0)); | 788 databaseContext()->databaseThread()->scheduleTask(DatabaseCloseTask::cre
ate(this, 0)); |
790 } | 789 } |
791 } | 790 } |
792 | 791 |
793 void Database::changeVersion( | 792 void Database::changeVersion( |
794 const String& oldVersion, | 793 const String& oldVersion, |
795 const String& newVersion, | 794 const String& newVersion, |
796 PassOwnPtrWillBeRawPtr<SQLTransactionCallback> callback, | 795 PassOwnPtrWillBeRawPtr<SQLTransactionCallback> callback, |
797 PassOwnPtrWillBeRawPtr<SQLTransactionErrorCallback> errorCallback, | 796 PassOwnPtrWillBeRawPtr<SQLTransactionErrorCallback> errorCallback, |
798 PassOwnPtrWillBeRawPtr<VoidCallback> successCallback) | 797 PassOwnPtrWillBeRawPtr<VoidCallback> successCallback) |
799 { | 798 { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 return tableNames; | 905 return tableNames; |
907 } | 906 } |
908 | 907 |
909 Vector<String> Database::tableNames() | 908 Vector<String> Database::tableNames() |
910 { | 909 { |
911 // FIXME: Not using isolatedCopy on these strings looks ok since threads | 910 // FIXME: Not using isolatedCopy on these strings looks ok since threads |
912 // take strict turns in dealing with them. However, if the code changes, | 911 // take strict turns in dealing with them. However, if the code changes, |
913 // this may not be true anymore. | 912 // this may not be true anymore. |
914 Vector<String> result; | 913 Vector<String> result; |
915 TaskSynchronizer synchronizer; | 914 TaskSynchronizer synchronizer; |
916 if (!databaseContext()->databaseThread() || databaseContext()->databaseThrea
d()->terminationRequested(&synchronizer)) | 915 if (!databaseContext()->databaseThreadAvailable()) |
917 return result; | 916 return result; |
918 | 917 |
919 OwnPtr<DatabaseTableNamesTask> task = DatabaseTableNamesTask::create(this, &
synchronizer, result); | 918 OwnPtr<DatabaseTableNamesTask> task = DatabaseTableNamesTask::create(this, &
synchronizer, result); |
920 databaseContext()->databaseThread()->scheduleTask(task.release()); | 919 databaseContext()->databaseThread()->scheduleTask(task.release()); |
921 synchronizer.waitForTaskCompletion(); | 920 synchronizer.waitForTaskCompletion(); |
922 | 921 |
923 return result; | 922 return result; |
924 } | 923 } |
925 | 924 |
926 SecurityOrigin* Database::securityOrigin() const | 925 SecurityOrigin* Database::securityOrigin() const |
927 { | 926 { |
928 if (executionContext()->isContextThread()) | 927 if (executionContext()->isContextThread()) |
929 return m_contextThreadSecurityOrigin.get(); | 928 return m_contextThreadSecurityOrigin.get(); |
930 if (databaseContext()->databaseThread()->isDatabaseThread()) | 929 if (databaseContext()->databaseThread()->isDatabaseThread()) |
931 return m_databaseThreadSecurityOrigin.get(); | 930 return m_databaseThreadSecurityOrigin.get(); |
932 return 0; | 931 return 0; |
933 } | 932 } |
934 | 933 |
935 } // namespace blink | 934 } // namespace blink |
OLD | NEW |