This source file includes following definitions.
- EntriesCallbackHelper
- handleEvent
- ErrorCallbackHelper
- handleEvent
- m_isReading
- readEntries
- addEntries
- onError
- trace
#include "config.h"
#include "modules/filesystem/DirectoryReader.h"
#include "core/fileapi/FileError.h"
#include "modules/filesystem/EntriesCallback.h"
#include "modules/filesystem/Entry.h"
#include "modules/filesystem/ErrorCallback.h"
namespace WebCore {
class DirectoryReader::EntriesCallbackHelper : public EntriesCallback {
public:
EntriesCallbackHelper(PassRefPtrWillBeRawPtr<DirectoryReader> reader)
: m_reader(reader)
{
}
virtual void handleEvent(const EntryHeapVector& entries) OVERRIDE
{
m_reader->addEntries(entries);
}
private:
RefPtrWillBePersistent<DirectoryReader> m_reader;
};
class DirectoryReader::ErrorCallbackHelper : public ErrorCallback {
public:
ErrorCallbackHelper(PassRefPtrWillBeRawPtr<DirectoryReader> reader)
: m_reader(reader)
{
}
virtual void handleEvent(FileError* error) OVERRIDE
{
m_reader->onError(error);
}
private:
RefPtrWillBePersistent<DirectoryReader> m_reader;
};
DirectoryReader::DirectoryReader(PassRefPtrWillBeRawPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
: DirectoryReaderBase(fileSystem, fullPath)
, m_isReading(false)
{
ScriptWrappable::init(this);
}
DirectoryReader::~DirectoryReader()
{
}
void DirectoryReader::readEntries(PassOwnPtr<EntriesCallback> entriesCallback, PassOwnPtr<ErrorCallback> errorCallback)
{
if (!m_isReading) {
m_isReading = true;
filesystem()->readDirectory(this, m_fullPath, adoptPtr(new EntriesCallbackHelper(this)), adoptPtr(new ErrorCallbackHelper(this)));
}
if (m_error) {
filesystem()->scheduleCallback(errorCallback, m_error.get());
return;
}
if (m_entriesCallback) {
filesystem()->scheduleCallback(errorCallback, FileError::create(FileError::INVALID_STATE_ERR));
return;
}
if (!m_hasMoreEntries || !m_entries.isEmpty()) {
filesystem()->scheduleCallback(entriesCallback, m_entries);
m_entries.clear();
return;
}
m_entriesCallback = entriesCallback;
m_errorCallback = errorCallback;
}
void DirectoryReader::addEntries(const EntryHeapVector& entries)
{
m_entries.appendVector(entries);
if (m_entriesCallback) {
OwnPtr<EntriesCallback> entriesCallback = m_entriesCallback.release();
EntryHeapVector entries;
entries.swap(m_entries);
entriesCallback->handleEvent(entries);
}
}
void DirectoryReader::onError(FileError* error)
{
m_error = error;
if (m_errorCallback)
m_errorCallback->handleEvent(error);
}
void DirectoryReader::trace(Visitor* visitor)
{
visitor->trace(m_entries);
visitor->trace(m_error);
DirectoryReaderBase::trace(visitor);
}
}