void AsyncFileStream::stop()
{
    // Clear the client so that we won't be invoking callbacks on the client.
    setClient(0);

    fileThread()->unscheduleTasks(m_stream.get());
    fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::stopOnFileThread));
}
void FileStreamProxy::stop()
{
    // Clear the client so that we won't be calling callbacks on the client.
    m_client = 0;

    fileThread()->unscheduleTasks(m_stream.get());
    fileThread()->postTask(createFileThreadTask(m_stream.get(), &FileStream::stop));
}
FileStreamProxy::FileStreamProxy(ScriptExecutionContext* context, FileStreamClient* client)
    : m_context(context)
    , m_client(client)
    , m_stream(FileStream::create(this))
{
    // Holds an extra ref so that the instance will not get deleted while there can be any tasks on the file thread.
    ref();

    fileThread()->postTask(createFileThreadTask(m_stream.get(), &FileStream::start));
}
PassRefPtr<FileStreamProxy> FileStreamProxy::create(ScriptExecutionContext* context, FileStreamClient* client)
{
    RefPtr<FileStreamProxy> proxy = adoptRef(new FileStreamProxy(context, client));

    // Hold an ref so that the instance will not get deleted while there are tasks on the file thread.
    // This is balanced by the deref in derefProxyOnContext below.
    proxy->ref();

    proxy->fileThread()->postTask(createFileThreadTask(proxy.get(), &FileStreamProxy::startOnFileThread));

    return proxy.release();
}
PassRefPtr<AsyncFileStream> AsyncFileStream::create(FileStreamClient* client)
{
    RefPtr<AsyncFileStream> proxy = adoptRef(new AsyncFileStream(client));

    // Hold a reference so that the instance will not get deleted while there are tasks on the file thread.
    // This is balanced by the deref in derefProxyOnContext below.
    proxy->ref();

    fileThread()->postTask(createFileThreadTask(proxy.get(), &AsyncFileStream::startOnFileThread));

    return proxy.release();
}
void AsyncFileStream::openForRead(const String& path, long long offset, long long length)
{
    fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::openForReadOnFileThread, path, offset, length));
}
void AsyncFileStream::getSize(const String& path, double expectedModificationTime)
{
    fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::getSizeOnFileThread, path, expectedModificationTime));
}
void FileStreamProxy::close()
{
    fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::closeOnFileThread));
}
void AsyncFileStream::truncate(long long position)
{
    fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::truncateOnFileThread, position));
}
void AsyncFileStream::read(char* buffer, int length)
{
    fileThread()->postTask(
        createFileThreadTask(this, &AsyncFileStream::readOnFileThread,
                             AllowCrossThreadAccess(buffer), length));
}
void FileStreamProxy::close()
{
    fileThread()->postTask(createFileThreadTask(m_stream.get(), &FileStream::close));
}
void FileStreamProxy::openForWrite(const String& path)
{
    fileThread()->postTask(createFileThreadTask(m_stream.get(), &FileStream::openForWrite, path));
}
void FileStreamProxy::openForRead(Blob* blob)
{
    fileThread()->postTask(createFileThreadTask(m_stream.get(), &FileStream::openForRead, blob));
}
void FileStreamProxy::truncate(long long position)
{
    fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::truncateOnFileThread, position));
}
void FileStreamProxy::read(char* buffer, int length)
{
    fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::readOnFileThread, buffer, length));
}
void AsyncFileStream::openForWrite(const String& path)
{
    fileThread()->postTask(
        createFileThreadTask(this,
                             &AsyncFileStream::openForWriteOnFileThread, path));
}
void AsyncFileStream::close()
{
    fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::closeOnFileThread));
}
void FileStreamProxy::read(char* buffer, int length)
{
    fileThread()->postTask(createFileThreadTask(m_stream.get(), &FileStream::read, buffer, length));
}
void AsyncFileStream::write(const KURL& blobURL, long long position, int length)
{
    fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::writeOnFileThread, blobURL, position, length));
}
void FileStreamProxy::write(Blob* blob, long long position, int length)
{
    fileThread()->postTask(createFileThreadTask(m_stream.get(), &FileStream::write, blob, position, length));
}
void FileStreamProxy::truncate(long long position)
{
    fileThread()->postTask(createFileThreadTask(m_stream.get(), &FileStream::truncate, position));
}
void FileStreamProxy::openForWrite(const String& path)
{
    fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::openForWriteOnFileThread, path));
}