#ifndef DOMFileSystem_h
#define DOMFileSystem_h
#if ENABLE(FILE_SYSTEM)
#include "ActiveDOMObject.h"
#include "DOMFileSystemBase.h"
#include "ScriptExecutionContext.h"
namespace WebCore {
class DirectoryEntry;
class File;
class FileCallback;
class FileEntry;
class FileWriterCallback;
class DOMFileSystem : public DOMFileSystemBase, public ActiveDOMObject {
public:
static PassRefPtr<DOMFileSystem> create(ScriptExecutionContext*, const String& name, PassOwnPtr<AsyncFileSystem>);
PassRefPtr<DirectoryEntry> root();
virtual void stop();
virtual bool hasPendingActivity() const;
virtual void contextDestroyed();
void createWriter(const FileEntry*, PassRefPtr<FileWriterCallback>, PassRefPtr<ErrorCallback>);
void createFile(const FileEntry*, PassRefPtr<FileCallback>, PassRefPtr<ErrorCallback>);
template <typename CB, typename CBArg>
static void scheduleCallback(ScriptExecutionContext*, PassRefPtr<CB>, PassRefPtr<CBArg>);
template <typename CB, typename CBArg>
void scheduleCallback(PassRefPtr<CB> callback, PassRefPtr<CBArg> callbackArg)
{
scheduleCallback(scriptExecutionContext(), callback, callbackArg);
}
private:
DOMFileSystem(ScriptExecutionContext*, const String& name, PassOwnPtr<AsyncFileSystem>);
template <typename CB, typename CBArg>
class DispatchCallbackTask : public ScriptExecutionContext::Task {
public:
DispatchCallbackTask(PassRefPtr<CB> callback, PassRefPtr<CBArg> arg)
: m_callback(callback)
, m_callbackArg(arg)
{
}
virtual void performTask(ScriptExecutionContext*)
{
m_callback->handleEvent(m_callbackArg.get());
}
private:
RefPtr<CB> m_callback;
RefPtr<CBArg> m_callbackArg;
};
};
template <typename CB, typename CBArg>
void DOMFileSystem::scheduleCallback(ScriptExecutionContext* scriptExecutionContext, PassRefPtr<CB> callback, PassRefPtr<CBArg> arg)
{
ASSERT(scriptExecutionContext->isContextThread());
if (callback)
scriptExecutionContext->postTask(adoptPtr(new DispatchCallbackTask<CB, CBArg>(callback, arg)));
}
}
#endif // ENABLE(FILE_SYSTEM)
#endif // DOMFileSystem_h