#ifndef DOMFileSystem_h
#define DOMFileSystem_h
#include "bindings/v8/ScriptWrappable.h"
#include "core/dom/ActiveDOMObject.h"
#include "core/dom/ExecutionContext.h"
#include "core/dom/ExecutionContextTask.h"
#include "heap/Handle.h"
#include "modules/filesystem/DOMFileSystemBase.h"
#include "modules/filesystem/EntriesCallback.h"
namespace WebCore {
class DirectoryEntry;
class File;
class FileCallback;
class FileEntry;
class FileWriterCallback;
class DOMFileSystem FINAL : public DOMFileSystemBase, public ScriptWrappable, public ActiveDOMObject {
public:
static PassRefPtrWillBeRawPtr<DOMFileSystem> create(ExecutionContext*, const String& name, FileSystemType, const KURL& rootURL);
static PassRefPtrWillBeRawPtr<DOMFileSystem> createIsolatedFileSystem(ExecutionContext*, const String& filesystemId);
PassRefPtrWillBeRawPtr<DirectoryEntry> root();
virtual void addPendingCallbacks() OVERRIDE;
virtual void removePendingCallbacks() OVERRIDE;
virtual void reportError(PassOwnPtr<ErrorCallback>, PassRefPtrWillBeRawPtr<FileError>) OVERRIDE;
virtual bool hasPendingActivity() const OVERRIDE;
void createWriter(const FileEntry*, PassOwnPtr<FileWriterCallback>, PassOwnPtr<ErrorCallback>);
void createFile(const FileEntry*, PassOwnPtr<FileCallback>, PassOwnPtr<ErrorCallback>);
template <typename CB, typename CBArg>
static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>, PassRefPtrWillBeRawPtr<CBArg>);
template <typename CB, typename CBArg>
static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>, const HeapVector<CBArg>&);
template <typename CB, typename CBArg>
static void scheduleCallback(ExecutionContext*, PassOwnPtr<CB>, const CBArg&);
template <typename CB, typename CBArg>
void scheduleCallback(PassOwnPtr<CB> callback, PassRefPtrWillBeRawPtr<CBArg> callbackArg)
{
scheduleCallback(executionContext(), callback, callbackArg);
}
template <typename CB, typename CBArg>
void scheduleCallback(PassOwnPtr<CB> callback, const CBArg& callbackArg)
{
scheduleCallback(executionContext(), callback, callbackArg);
}
private:
DOMFileSystem(ExecutionContext*, const String& name, FileSystemType, const KURL& rootURL);
template <typename CB, typename CBArg>
class DispatchCallbacRefPtrArgTask FINAL : public ExecutionContextTask {
public:
DispatchCallbacRefPtrArgTask(PassOwnPtr<CB> callback, PassRefPtrWillBeRawPtr<CBArg> arg)
: m_callback(callback)
, m_callbackArg(arg)
{
}
virtual void performTask(ExecutionContext*) OVERRIDE
{
m_callback->handleEvent(m_callbackArg.get());
}
private:
OwnPtr<CB> m_callback;
RefPtrWillBePersistent<CBArg> m_callbackArg;
};
template <typename CB, typename CBArg>
class DispatchCallbackNonPtrArgTask FINAL : public ExecutionContextTask {
public:
DispatchCallbackNonPtrArgTask(PassOwnPtr<CB> callback, const CBArg& arg)
: m_callback(callback)
, m_callbackArg(arg)
{
}
virtual void performTask(ExecutionContext*) OVERRIDE
{
m_callback->handleEvent(m_callbackArg);
}
private:
OwnPtr<CB> m_callback;
CBArg m_callbackArg;
};
int m_numberOfPendingCallbacks;
};
template <typename CB, typename CBArg>
void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwnPtr<CB> callback, PassRefPtrWillBeRawPtr<CBArg> arg)
{
ASSERT(executionContext->isContextThread());
if (callback)
executionContext->postTask(adoptPtr(new DispatchCallbacRefPtrArgTask<CB, CBArg>(callback, arg)));
}
template <typename CB, typename CBArg>
void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwnPtr<CB> callback, const HeapVector<CBArg>& arg)
{
ASSERT(executionContext->isContextThread());
if (callback)
executionContext->postTask(adoptPtr(new DispatchCallbackNonPtrArgTask<CB, PersistentHeapVector<CBArg> >(callback, arg)));
}
template <typename CB, typename CBArg>
void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, PassOwnPtr<CB> callback, const CBArg& arg)
{
ASSERT(executionContext->isContextThread());
if (callback)
executionContext->postTask(adoptPtr(new DispatchCallbackNonPtrArgTask<CB, CBArg>(callback, arg)));
}
}
#endif