This source file includes following definitions.
- m_terminationRequested
- trace
- start
- setupDatabaseThread
- requestTermination
- terminationRequested
- cleanupDatabaseThread
- cleanupDatabaseThreadCompleted
- recordDatabaseOpen
- recordDatabaseClosed
- isDatabaseOpen
- scheduleTask
#include "config.h"
#include "modules/webdatabase/DatabaseThread.h"
#include "modules/webdatabase/Database.h"
#include "modules/webdatabase/DatabaseTask.h"
#include "modules/webdatabase/SQLTransactionClient.h"
#include "modules/webdatabase/SQLTransactionCoordinator.h"
#include "platform/Logging.h"
#include "platform/heap/glue/MessageLoopInterruptor.h"
#include "platform/heap/glue/PendingGCRunner.h"
#include "public/platform/Platform.h"
namespace WebCore {
DatabaseThread::DatabaseThread()
: m_transactionClient(adoptPtr(new SQLTransactionClient()))
, m_transactionCoordinator(adoptPtrWillBeNoop(new SQLTransactionCoordinator()))
, m_cleanupSync(0)
, m_terminationRequested(false)
{
}
DatabaseThread::~DatabaseThread()
{
ASSERT(m_openDatabaseSet.isEmpty());
m_thread.clear();
}
void DatabaseThread::trace(Visitor* visitor)
{
visitor->trace(m_openDatabaseSet);
visitor->trace(m_transactionCoordinator);
}
void DatabaseThread::start()
{
if (m_thread)
return;
m_thread = adoptPtr(blink::Platform::current()->createThread("WebCore: Database"));
m_thread->postTask(new Task(WTF::bind(&DatabaseThread::setupDatabaseThread, this)));
}
void DatabaseThread::setupDatabaseThread()
{
m_pendingGCRunner = adoptPtr(new PendingGCRunner);
m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(m_thread.get()));
m_thread->addTaskObserver(m_pendingGCRunner.get());
ThreadState::attach();
ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get());
}
void DatabaseThread::requestTermination(TaskSynchronizer *cleanupSync)
{
MutexLocker lock(m_terminationRequestedMutex);
ASSERT(!m_terminationRequested);
m_terminationRequested = true;
m_cleanupSync = cleanupSync;
WTF_LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this);
m_thread->postTask(new Task(WTF::bind(&DatabaseThread::cleanupDatabaseThread, this)));
}
bool DatabaseThread::terminationRequested(TaskSynchronizer* taskSynchronizer) const
{
#ifndef NDEBUG
if (taskSynchronizer)
taskSynchronizer->setHasCheckedForTermination();
#endif
MutexLocker lock(m_terminationRequestedMutex);
return m_terminationRequested;
}
void DatabaseThread::cleanupDatabaseThread()
{
WTF_LOG(StorageAPI, "Cleaning up DatabaseThread %p", this);
m_transactionCoordinator->shutdown();
if (m_openDatabaseSet.size() > 0) {
WillBeHeapHashSet<RefPtrWillBeMember<DatabaseBackend> > openSetCopy;
openSetCopy.swap(m_openDatabaseSet);
WillBeHeapHashSet<RefPtrWillBeMember<DatabaseBackend> >::iterator end = openSetCopy.end();
for (WillBeHeapHashSet<RefPtrWillBeMember<DatabaseBackend> >::iterator it = openSetCopy.begin(); it != end; ++it)
(*it)->close();
}
m_thread->postTask(new Task(WTF::bind(&DatabaseThread::cleanupDatabaseThreadCompleted, this)));
}
void DatabaseThread::cleanupDatabaseThreadCompleted()
{
ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get());
ThreadState::detach();
m_thread->removeTaskObserver(m_pendingGCRunner.get());
if (m_cleanupSync)
m_cleanupSync->taskCompleted();
}
void DatabaseThread::recordDatabaseOpen(DatabaseBackend* database)
{
ASSERT(isDatabaseThread());
ASSERT(database);
ASSERT(!m_openDatabaseSet.contains(database));
m_openDatabaseSet.add(database);
}
void DatabaseThread::recordDatabaseClosed(DatabaseBackend* database)
{
#ifndef ASSERT_DISABLED
MutexLocker lock(m_terminationRequestedMutex);
#endif
ASSERT(isDatabaseThread());
ASSERT(database);
ASSERT(m_terminationRequested || m_openDatabaseSet.contains(database));
m_openDatabaseSet.remove(database);
}
bool DatabaseThread::isDatabaseOpen(DatabaseBackend* database)
{
ASSERT(isDatabaseThread());
ASSERT(database);
MutexLocker lock(m_terminationRequestedMutex);
return !m_terminationRequested && m_openDatabaseSet.contains(database);
}
void DatabaseThread::scheduleTask(PassOwnPtr<DatabaseTask> task)
{
ASSERT(m_thread);
ASSERT(!task->hasSynchronizer() || task->hasCheckedForTermination());
m_thread->postTask(task.leakPtr());
}
}