| 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 14 matching lines...) Expand all Loading... |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "modules/webdatabase/DatabaseThread.h" | 29 #include "modules/webdatabase/DatabaseThread.h" |
| 30 | 30 |
| 31 #include "modules/webdatabase/Database.h" | 31 #include "modules/webdatabase/Database.h" |
| 32 #include "modules/webdatabase/DatabaseTask.h" | 32 #include "modules/webdatabase/DatabaseTask.h" |
| 33 #include "modules/webdatabase/SQLTransactionClient.h" | 33 #include "modules/webdatabase/SQLTransactionClient.h" |
| 34 #include "modules/webdatabase/SQLTransactionCoordinator.h" | 34 #include "modules/webdatabase/SQLTransactionCoordinator.h" |
| 35 #include "modules/webdatabase/StorageLog.h" |
| 35 #include "platform/CrossThreadFunctional.h" | 36 #include "platform/CrossThreadFunctional.h" |
| 36 #include "platform/Logging.h" | |
| 37 #include "platform/WebThreadSupportingGC.h" | 37 #include "platform/WebThreadSupportingGC.h" |
| 38 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
| 39 #include "wtf/PtrUtil.h" | 39 #include "wtf/PtrUtil.h" |
| 40 #include <memory> | 40 #include <memory> |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 DatabaseThread::DatabaseThread() | 44 DatabaseThread::DatabaseThread() |
| 45 : m_transactionClient(wrapUnique(new SQLTransactionClient())) | 45 : m_transactionClient(wrapUnique(new SQLTransactionClient())) |
| 46 , m_cleanupSync(nullptr) | 46 , m_cleanupSync(nullptr) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 76 | 76 |
| 77 void DatabaseThread::terminate() | 77 void DatabaseThread::terminate() |
| 78 { | 78 { |
| 79 ASSERT(isMainThread()); | 79 ASSERT(isMainThread()); |
| 80 TaskSynchronizer sync; | 80 TaskSynchronizer sync; |
| 81 { | 81 { |
| 82 MutexLocker lock(m_terminationRequestedMutex); | 82 MutexLocker lock(m_terminationRequestedMutex); |
| 83 ASSERT(!m_terminationRequested); | 83 ASSERT(!m_terminationRequested); |
| 84 m_terminationRequested = true; | 84 m_terminationRequested = true; |
| 85 m_cleanupSync = &sync; | 85 m_cleanupSync = &sync; |
| 86 WTF_LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this); | 86 STORAGE_DVLOG(1) << "DatabaseThread " << this << " was asked to terminat
e"; |
| 87 m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseThread::cle
anupDatabaseThread, wrapCrossThreadPersistent(this))); | 87 m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseThread::cle
anupDatabaseThread, wrapCrossThreadPersistent(this))); |
| 88 } | 88 } |
| 89 sync.waitForTaskCompletion(); | 89 sync.waitForTaskCompletion(); |
| 90 // The WebThread destructor blocks until all the tasks of the database | 90 // The WebThread destructor blocks until all the tasks of the database |
| 91 // thread are processed. However, it shouldn't block at all because | 91 // thread are processed. However, it shouldn't block at all because |
| 92 // the database thread has already finished processing the cleanup task. | 92 // the database thread has already finished processing the cleanup task. |
| 93 m_thread.reset(); | 93 m_thread.reset(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void DatabaseThread::cleanupDatabaseThread() | 96 void DatabaseThread::cleanupDatabaseThread() |
| 97 { | 97 { |
| 98 DCHECK(isDatabaseThread()); | 98 DCHECK(isDatabaseThread()); |
| 99 | 99 |
| 100 WTF_LOG(StorageAPI, "Cleaning up DatabaseThread %p", this); | 100 STORAGE_DVLOG(1) << "Cleaning up DatabaseThread " << this; |
| 101 | 101 |
| 102 // Clean up the list of all pending transactions on this database thread | 102 // Clean up the list of all pending transactions on this database thread |
| 103 m_transactionCoordinator->shutdown(); | 103 m_transactionCoordinator->shutdown(); |
| 104 | 104 |
| 105 // Close the databases that we ran transactions on. This ensures that if any
transactions are still open, they are rolled back and we don't leave the databa
se in an | 105 // Close the databases that we ran transactions on. This ensures that if any
transactions are still open, they are rolled back and we don't leave the databa
se in an |
| 106 // inconsistent or locked state. | 106 // inconsistent or locked state. |
| 107 if (m_openDatabaseSet.size() > 0) { | 107 if (m_openDatabaseSet.size() > 0) { |
| 108 // As the call to close will modify the original set, we must take a cop
y to iterate over. | 108 // As the call to close will modify the original set, we must take a cop
y to iterate over. |
| 109 HashSet<CrossThreadPersistent<Database>> openSetCopy; | 109 HashSet<CrossThreadPersistent<Database>> openSetCopy; |
| 110 openSetCopy.swap(m_openDatabaseSet); | 110 openSetCopy.swap(m_openDatabaseSet); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 { | 169 { |
| 170 MutexLocker lock(m_terminationRequestedMutex); | 170 MutexLocker lock(m_terminationRequestedMutex); |
| 171 ASSERT(!m_terminationRequested); | 171 ASSERT(!m_terminationRequested); |
| 172 } | 172 } |
| 173 #endif | 173 #endif |
| 174 // WebThread takes ownership of the task. | 174 // WebThread takes ownership of the task. |
| 175 m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseTask::run, std:
:move(task))); | 175 m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseTask::run, std:
:move(task))); |
| 176 } | 176 } |
| 177 | 177 |
| 178 } // namespace blink | 178 } // namespace blink |
| OLD | NEW |