| 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 "platform/CrossThreadFunctional.h" |
| 35 #include "platform/Logging.h" | 36 #include "platform/Logging.h" |
| 36 #include "platform/ThreadSafeFunctional.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 11 matching lines...) Expand all Loading... |
| 58 DEFINE_TRACE(DatabaseThread) | 58 DEFINE_TRACE(DatabaseThread) |
| 59 { | 59 { |
| 60 } | 60 } |
| 61 | 61 |
| 62 void DatabaseThread::start() | 62 void DatabaseThread::start() |
| 63 { | 63 { |
| 64 ASSERT(isMainThread()); | 64 ASSERT(isMainThread()); |
| 65 if (m_thread) | 65 if (m_thread) |
| 66 return; | 66 return; |
| 67 m_thread = WebThreadSupportingGC::create("WebCore: Database", true); | 67 m_thread = WebThreadSupportingGC::create("WebCore: Database", true); |
| 68 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::setupDat
abaseThread, wrapCrossThreadPersistent(this))); | 68 m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseThread::setupDa
tabaseThread, wrapCrossThreadPersistent(this))); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void DatabaseThread::setupDatabaseThread() | 71 void DatabaseThread::setupDatabaseThread() |
| 72 { | 72 { |
| 73 m_thread->initialize(); | 73 m_thread->initialize(); |
| 74 m_transactionCoordinator = new SQLTransactionCoordinator(); | 74 m_transactionCoordinator = new SQLTransactionCoordinator(); |
| 75 } | 75 } |
| 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 WTF_LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this); |
| 87 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::clea
nupDatabaseThread, 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 { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 void DatabaseThread::scheduleTask(std::unique_ptr<DatabaseTask> task) | 165 void DatabaseThread::scheduleTask(std::unique_ptr<DatabaseTask> task) |
| 166 { | 166 { |
| 167 ASSERT(m_thread); | 167 ASSERT(m_thread); |
| 168 #if ENABLE(ASSERT) | 168 #if ENABLE(ASSERT) |
| 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, threadSafeBind(&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 |