| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 visitor->trace(m_openDatabaseSet); | 59 visitor->trace(m_openDatabaseSet); |
| 60 visitor->trace(m_transactionCoordinator); | 60 visitor->trace(m_transactionCoordinator); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void DatabaseThread::start() | 63 void DatabaseThread::start() |
| 64 { | 64 { |
| 65 ASSERT(isMainThread()); | 65 ASSERT(isMainThread()); |
| 66 if (m_thread) | 66 if (m_thread) |
| 67 return; | 67 return; |
| 68 m_thread = WebThreadSupportingGC::create("WebCore: Database"); | 68 m_thread = WebThreadSupportingGC::create("WebCore: Database"); |
| 69 m_thread->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&DatabaseThread:
:setupDatabaseThread, this))); | 69 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::setupDat
abaseThread, this)); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void DatabaseThread::setupDatabaseThread() | 72 void DatabaseThread::setupDatabaseThread() |
| 73 { | 73 { |
| 74 m_thread->initialize(); | 74 m_thread->initialize(); |
| 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, new Task(threadSafeBind(&DatabaseThr
ead::cleanupDatabaseThread, this))); | 87 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::clea
nupDatabaseThread, 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.clear(); | 93 m_thread.clear(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void DatabaseThread::cleanupDatabaseThread() | 96 void DatabaseThread::cleanupDatabaseThread() |
| 97 { | 97 { |
| 98 WTF_LOG(StorageAPI, "Cleaning up DatabaseThread %p", this); | 98 WTF_LOG(StorageAPI, "Cleaning up DatabaseThread %p", this); |
| 99 | 99 |
| 100 // Clean up the list of all pending transactions on this database thread | 100 // Clean up the list of all pending transactions on this database thread |
| 101 m_transactionCoordinator->shutdown(); | 101 m_transactionCoordinator->shutdown(); |
| 102 | 102 |
| 103 // 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 | 103 // 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 |
| 104 // inconsistent or locked state. | 104 // inconsistent or locked state. |
| 105 if (m_openDatabaseSet.size() > 0) { | 105 if (m_openDatabaseSet.size() > 0) { |
| 106 // As the call to close will modify the original set, we must take a cop
y to iterate over. | 106 // As the call to close will modify the original set, we must take a cop
y to iterate over. |
| 107 HeapHashSet<Member<Database>> openSetCopy; | 107 HeapHashSet<Member<Database>> openSetCopy; |
| 108 openSetCopy.swap(m_openDatabaseSet); | 108 openSetCopy.swap(m_openDatabaseSet); |
| 109 HeapHashSet<Member<Database>>::iterator end = openSetCopy.end(); | 109 HeapHashSet<Member<Database>>::iterator end = openSetCopy.end(); |
| 110 for (HeapHashSet<Member<Database>>::iterator it = openSetCopy.begin(); i
t != end; ++it) | 110 for (HeapHashSet<Member<Database>>::iterator it = openSetCopy.begin(); i
t != end; ++it) |
| 111 (*it)->close(); | 111 (*it)->close(); |
| 112 } | 112 } |
| 113 m_openDatabaseSet.clear(); | 113 m_openDatabaseSet.clear(); |
| 114 | 114 |
| 115 m_thread->postTask(BLINK_FROM_HERE, new Task(WTF::bind(&DatabaseThread::clea
nupDatabaseThreadCompleted, this))); | 115 m_thread->postTask(BLINK_FROM_HERE, WTF::bind(&DatabaseThread::cleanupDataba
seThreadCompleted, this)); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void DatabaseThread::cleanupDatabaseThreadCompleted() | 118 void DatabaseThread::cleanupDatabaseThreadCompleted() |
| 119 { | 119 { |
| 120 m_thread->shutdown(); | 120 m_thread->shutdown(); |
| 121 if (m_cleanupSync) // Someone wanted to know when we were done cleaning up. | 121 if (m_cleanupSync) // Someone wanted to know when we were done cleaning up. |
| 122 m_cleanupSync->taskCompleted(); | 122 m_cleanupSync->taskCompleted(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void DatabaseThread::recordDatabaseOpen(Database* database) | 125 void DatabaseThread::recordDatabaseOpen(Database* database) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 void DatabaseThread::scheduleTask(PassOwnPtr<DatabaseTask> task) | 163 void DatabaseThread::scheduleTask(PassOwnPtr<DatabaseTask> task) |
| 164 { | 164 { |
| 165 ASSERT(m_thread); | 165 ASSERT(m_thread); |
| 166 #if ENABLE(ASSERT) | 166 #if ENABLE(ASSERT) |
| 167 { | 167 { |
| 168 MutexLocker lock(m_terminationRequestedMutex); | 168 MutexLocker lock(m_terminationRequestedMutex); |
| 169 ASSERT(!m_terminationRequested); | 169 ASSERT(!m_terminationRequested); |
| 170 } | 170 } |
| 171 #endif | 171 #endif |
| 172 // WebThread takes ownership of the task. | 172 // WebThread takes ownership of the task. |
| 173 m_thread->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&DatabaseTask::r
un, task))); | 173 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseTask::run, task)
); |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace blink | 176 } // namespace blink |
| OLD | NEW |