Index: third_party/WebKit/Source/modules/webdatabase/DatabaseThread.cpp |
diff --git a/third_party/WebKit/Source/modules/webdatabase/DatabaseThread.cpp b/third_party/WebKit/Source/modules/webdatabase/DatabaseThread.cpp |
index 8d55428bc69149228abb98e26807081a8dcfb8ac..b1c40b65996e9ad0b06ca5d76d9955d746b273f0 100644 |
--- a/third_party/WebKit/Source/modules/webdatabase/DatabaseThread.cpp |
+++ b/third_party/WebKit/Source/modules/webdatabase/DatabaseThread.cpp |
@@ -41,41 +41,40 @@ namespace blink { |
DatabaseThread::DatabaseThread() |
: m_transactionClient(adoptPtr(new SQLTransactionClient())) |
- , m_transactionCoordinator(new SQLTransactionCoordinator()) |
, m_cleanupSync(nullptr) |
, m_terminationRequested(false) |
{ |
+ DCHECK(isMainThread()); |
} |
DatabaseThread::~DatabaseThread() |
{ |
- ASSERT(m_openDatabaseSet.isEmpty()); |
+ DCHECK(!m_openDatabaseSet); |
ASSERT(!m_thread); |
} |
DEFINE_TRACE(DatabaseThread) |
{ |
- visitor->trace(m_openDatabaseSet); |
- visitor->trace(m_transactionCoordinator); |
} |
void DatabaseThread::start() |
{ |
- ASSERT(isMainThread()); |
+ DCHECK(isMainThread()); |
if (m_thread) |
return; |
- m_thread = WebThreadSupportingGC::create("WebCore: Database"); |
+ m_thread = WebThreadSupportingGC::create("WebCore: Database", true); |
m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::setupDatabaseThread, wrapCrossThreadPersistent(this))); |
} |
void DatabaseThread::setupDatabaseThread() |
{ |
m_thread->initialize(); |
+ m_transactionCoordinator = new SQLTransactionCoordinator(); |
} |
void DatabaseThread::terminate() |
{ |
- ASSERT(isMainThread()); |
+ DCHECK(isMainThread()); |
TaskSynchronizer sync; |
{ |
MutexLocker lock(m_terminationRequestedMutex); |
@@ -94,6 +93,8 @@ void DatabaseThread::terminate() |
void DatabaseThread::cleanupDatabaseThread() |
{ |
+ DCHECK(isDatabaseThread()); |
+ |
WTF_LOG(StorageAPI, "Cleaning up DatabaseThread %p", this); |
// Clean up the list of all pending transactions on this database thread |
@@ -101,15 +102,15 @@ void DatabaseThread::cleanupDatabaseThread() |
// 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 database in an |
// inconsistent or locked state. |
- if (m_openDatabaseSet.size() > 0) { |
+ if (m_openDatabaseSet) { |
// As the call to close will modify the original set, we must take a copy to iterate over. |
- HeapHashSet<Member<Database>> openSetCopy; |
- openSetCopy.swap(m_openDatabaseSet); |
- HeapHashSet<Member<Database>>::iterator end = openSetCopy.end(); |
- for (HeapHashSet<Member<Database>>::iterator it = openSetCopy.begin(); it != end; ++it) |
+ HashSet<CrossThreadPersistent<Database>> openSetCopy; |
+ openSetCopy.swap(*m_openDatabaseSet); |
+ HashSet<CrossThreadPersistent<Database>>::iterator end = openSetCopy.end(); |
+ for (HashSet<CrossThreadPersistent<Database>>::iterator it = openSetCopy.begin(); it != end; ++it) |
(*it)->close(); |
+ m_openDatabaseSet = nullptr; |
} |
- m_openDatabaseSet.clear(); |
m_thread->postTask(BLINK_FROM_HERE, WTF::bind(&DatabaseThread::cleanupDatabaseThreadCompleted, this)); |
} |
@@ -125,10 +126,12 @@ void DatabaseThread::recordDatabaseOpen(Database* database) |
{ |
ASSERT(isDatabaseThread()); |
ASSERT(database); |
- ASSERT(!m_openDatabaseSet.contains(database)); |
+ if (!m_openDatabaseSet) |
+ m_openDatabaseSet = adoptPtr(new HashSet<CrossThreadPersistent<Database>>()); |
+ DCHECK(!m_openDatabaseSet->contains(database)); |
MutexLocker lock(m_terminationRequestedMutex); |
if (!m_terminationRequested) |
- m_openDatabaseSet.add(database); |
+ m_openDatabaseSet->add(database); |
} |
void DatabaseThread::recordDatabaseClosed(Database* database) |
@@ -138,10 +141,14 @@ void DatabaseThread::recordDatabaseClosed(Database* database) |
#if ENABLE(ASSERT) |
{ |
MutexLocker lock(m_terminationRequestedMutex); |
- ASSERT(m_terminationRequested || m_openDatabaseSet.contains(database)); |
+ DCHECK(m_terminationRequested || m_openDatabaseSet->contains(database)); |
} |
#endif |
- m_openDatabaseSet.remove(database); |
+ if (!m_openDatabaseSet) { |
+ m_openDatabaseSet->remove(database); |
+ if (m_openDatabaseSet->isEmpty()) |
+ m_openDatabaseSet = nullptr; |
+ } |
} |
bool DatabaseThread::isDatabaseOpen(Database* database) |
@@ -149,7 +156,7 @@ bool DatabaseThread::isDatabaseOpen(Database* database) |
ASSERT(isDatabaseThread()); |
ASSERT(database); |
MutexLocker lock(m_terminationRequestedMutex); |
- return !m_terminationRequested && m_openDatabaseSet.contains(database); |
+ return !m_terminationRequested && m_openDatabaseSet->contains(database); |
} |
bool DatabaseThread::isDatabaseThread() const |