Depends on D160903 Differential Revision: https://phabricator.services.mozilla.com/D160904
97 lines
2.9 KiB
C++
97 lines
2.9 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef DOM_FS_FILESYSTEMWRITABLEFILESTREAM_H_
|
|
#define DOM_FS_FILESYSTEMWRITABLEFILESTREAM_H_
|
|
|
|
#include "mozilla/Logging.h"
|
|
#include "mozilla/TaskQueue.h"
|
|
#include "mozilla/dom/Blob.h"
|
|
#include "mozilla/dom/FileSystemManager.h"
|
|
#include "mozilla/dom/FileSystemWritableFileStreamChild.h"
|
|
#include "mozilla/dom/PFileSystemManager.h"
|
|
#include "mozilla/dom/WritableStream.h"
|
|
#include "mozilla/ipc/FileDescriptor.h"
|
|
#include "nsISupports.h"
|
|
#include "nsWrapperCache.h"
|
|
#include "prio.h"
|
|
#include "private/pprio.h"
|
|
|
|
class nsIGlobalObject;
|
|
|
|
namespace mozilla {
|
|
extern LazyLogModule gOPFSLog;
|
|
}
|
|
|
|
namespace mozilla::ipc {
|
|
class FileDescriptor;
|
|
} // namespace mozilla::ipc
|
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
|
|
|
namespace dom {
|
|
|
|
class ArrayBufferViewOrArrayBufferOrBlobOrUSVStringOrWriteParams;
|
|
class Promise;
|
|
|
|
class FileSystemWritableFileStream final : public WritableStream {
|
|
public:
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileSystemWritableFileStream,
|
|
WritableStream)
|
|
|
|
static already_AddRefed<FileSystemWritableFileStream> MaybeCreate(
|
|
nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
|
|
const fs::FileSystemEntryMetadata& aMetadata,
|
|
RefPtr<FileSystemWritableFileStreamChild>& aActor);
|
|
|
|
FileSystemWritableFileStream(
|
|
nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
|
|
const fs::FileSystemEntryMetadata& aMetadata,
|
|
RefPtr<FileSystemWritableFileStreamChild>& aActor);
|
|
|
|
void ClearActor();
|
|
|
|
// WebIDL Boilerplate
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
// WebIDL Interface
|
|
already_AddRefed<Promise> Write(
|
|
const ArrayBufferViewOrArrayBufferOrBlobOrUSVStringOrWriteParams& aData,
|
|
ErrorResult& aError);
|
|
|
|
bool DoSeek(RefPtr<Promise>& aPromise, uint64_t aPosition);
|
|
|
|
already_AddRefed<Promise> Seek(uint64_t aPosition, ErrorResult& aError);
|
|
|
|
already_AddRefed<Promise> Truncate(uint64_t aSize, ErrorResult& aError);
|
|
|
|
already_AddRefed<Promise> Close(ErrorResult& aRv);
|
|
|
|
bool IsClosed() const { return !mActor || !mActor->MutableFileDescPtr(); }
|
|
|
|
protected:
|
|
RefPtr<FileSystemManager> mManager;
|
|
fs::FileSystemEntryMetadata mMetadata;
|
|
|
|
private:
|
|
nsresult WriteBlob(Blob* aBlob, uint64_t& aWritten);
|
|
// nsresult WriteBlobImpl(BlobImpl* aBlobImpl, uint64_t& aWritten);
|
|
|
|
virtual ~FileSystemWritableFileStream();
|
|
|
|
RefPtr<FileSystemWritableFileStreamChild> mActor;
|
|
RefPtr<TaskQueue> mTaskQueue;
|
|
};
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|
|
|
|
#endif // DOM_FS_FILESYSTEMWRITABLEFILESTREAM_H_
|