#ifndef DatabaseTask_h
#define DatabaseTask_h
#include "heap/Handle.h"
#include "modules/webdatabase/DatabaseBackend.h"
#include "modules/webdatabase/DatabaseBasicTypes.h"
#include "modules/webdatabase/DatabaseError.h"
#include "modules/webdatabase/SQLTransactionBackend.h"
#include "platform/Task.h"
#include "platform/TaskSynchronizer.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
#include "wtf/Threading.h"
#include "wtf/Vector.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class DatabaseTask : public blink::WebThread::Task {
WTF_MAKE_NONCOPYABLE(DatabaseTask); WTF_MAKE_FAST_ALLOCATED;
public:
virtual ~DatabaseTask();
virtual void run() OVERRIDE FINAL;
DatabaseBackend* database() const { return m_database.get(); }
#ifndef NDEBUG
bool hasSynchronizer() const { return m_synchronizer; }
bool hasCheckedForTermination() const { return m_synchronizer->hasCheckedForTermination(); }
#endif
protected:
DatabaseTask(DatabaseBackend*, TaskSynchronizer*);
private:
virtual void doPerformTask() = 0;
virtual void taskCancelled() { }
RefPtrWillBeCrossThreadPersistent<DatabaseBackend> m_database;
TaskSynchronizer* m_synchronizer;
#if !LOG_DISABLED
virtual const char* debugTaskName() const = 0;
bool m_complete;
#endif
};
class DatabaseBackend::DatabaseOpenTask FINAL : public DatabaseTask {
public:
static PassOwnPtr<DatabaseOpenTask> create(DatabaseBackend* db, bool setVersionInNewDatabase, TaskSynchronizer* synchronizer, DatabaseError& error, String& errorMessage, bool& success)
{
return adoptPtr(new DatabaseOpenTask(db, setVersionInNewDatabase, synchronizer, error, errorMessage, success));
}
private:
DatabaseOpenTask(DatabaseBackend*, bool setVersionInNewDatabase, TaskSynchronizer*, DatabaseError&, String& errorMessage, bool& success);
virtual void doPerformTask() OVERRIDE;
#if !LOG_DISABLED
virtual const char* debugTaskName() const OVERRIDE;
#endif
bool m_setVersionInNewDatabase;
DatabaseError& m_error;
String& m_errorMessage;
bool& m_success;
};
class DatabaseBackend::DatabaseCloseTask FINAL : public DatabaseTask {
public:
static PassOwnPtr<DatabaseCloseTask> create(DatabaseBackend* db, TaskSynchronizer* synchronizer)
{
return adoptPtr(new DatabaseCloseTask(db, synchronizer));
}
private:
DatabaseCloseTask(DatabaseBackend*, TaskSynchronizer*);
virtual void doPerformTask() OVERRIDE;
#if !LOG_DISABLED
virtual const char* debugTaskName() const OVERRIDE;
#endif
};
class DatabaseBackend::DatabaseTransactionTask FINAL : public DatabaseTask {
public:
virtual ~DatabaseTransactionTask();
static PassOwnPtr<DatabaseTransactionTask> create(PassRefPtrWillBeRawPtr<SQLTransactionBackend> transaction)
{
return adoptPtr(new DatabaseTransactionTask(transaction));
}
SQLTransactionBackend* transaction() const { return m_transaction.get(); }
private:
explicit DatabaseTransactionTask(PassRefPtrWillBeRawPtr<SQLTransactionBackend>);
virtual void doPerformTask() OVERRIDE;
virtual void taskCancelled() OVERRIDE;
#if !LOG_DISABLED
virtual const char* debugTaskName() const OVERRIDE;
#endif
RefPtrWillBeCrossThreadPersistent<SQLTransactionBackend> m_transaction;
};
class DatabaseBackend::DatabaseTableNamesTask FINAL : public DatabaseTask {
public:
static PassOwnPtr<DatabaseTableNamesTask> create(DatabaseBackend* db, TaskSynchronizer* synchronizer, Vector<String>& names)
{
return adoptPtr(new DatabaseTableNamesTask(db, synchronizer, names));
}
private:
DatabaseTableNamesTask(DatabaseBackend*, TaskSynchronizer*, Vector<String>& names);
virtual void doPerformTask() OVERRIDE;
#if !LOG_DISABLED
virtual const char* debugTaskName() const OVERRIDE;
#endif
Vector<String>& m_tableNames;
};
}
#endif