#ifndef DatabaseThread_h
#define DatabaseThread_h
#include "heap/Handle.h"
#include "public/platform/WebThread.h"
#include "wtf/Deque.h"
#include "wtf/HashMap.h"
#include "wtf/HashSet.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
#include "wtf/ThreadSafeRefCounted.h"
#include "wtf/ThreadingPrimitives.h"
namespace WebCore {
class DatabaseBackend;
class DatabaseTask;
class Document;
class MessageLoopInterruptor;
class PendingGCRunner;
class SQLTransactionClient;
class SQLTransactionCoordinator;
class TaskSynchronizer;
class DatabaseThread : public ThreadSafeRefCountedWillBeGarbageCollectedFinalized<DatabaseThread> {
public:
static PassRefPtrWillBeRawPtr<DatabaseThread> create() { return adoptRefWillBeNoop(new DatabaseThread); }
~DatabaseThread();
void trace(Visitor*);
void start();
void requestTermination(TaskSynchronizer* cleanupSync);
bool terminationRequested(TaskSynchronizer* = 0) const;
void scheduleTask(PassOwnPtr<DatabaseTask>);
void recordDatabaseOpen(DatabaseBackend*);
void recordDatabaseClosed(DatabaseBackend*);
bool isDatabaseOpen(DatabaseBackend*);
bool isDatabaseThread() { return m_thread && m_thread->isCurrentThread(); }
SQLTransactionClient* transactionClient() { return m_transactionClient.get(); }
SQLTransactionCoordinator* transactionCoordinator() { return m_transactionCoordinator.get(); }
private:
DatabaseThread();
void setupDatabaseThread();
void cleanupDatabaseThread();
void cleanupDatabaseThreadCompleted();
OwnPtr<blink::WebThread> m_thread;
WillBeHeapHashSet<RefPtrWillBeMember<DatabaseBackend> > m_openDatabaseSet;
OwnPtr<SQLTransactionClient> m_transactionClient;
OwnPtrWillBeMember<SQLTransactionCoordinator> m_transactionCoordinator;
TaskSynchronizer* m_cleanupSync;
mutable Mutex m_terminationRequestedMutex;
bool m_terminationRequested;
OwnPtr<PendingGCRunner> m_pendingGCRunner;
OwnPtr<MessageLoopInterruptor> m_messageLoopInterruptor;
};
}
#endif