diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/native_io/native_io_file_sync.h')
-rw-r--r-- | chromium/third_party/blink/renderer/modules/native_io/native_io_file_sync.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/chromium/third_party/blink/renderer/modules/native_io/native_io_file_sync.h b/chromium/third_party/blink/renderer/modules/native_io/native_io_file_sync.h new file mode 100644 index 00000000000..d36815e6c93 --- /dev/null +++ b/chromium/third_party/blink/renderer/modules/native_io/native_io_file_sync.h @@ -0,0 +1,69 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_NATIVE_IO_NATIVE_IO_FILE_SYNC_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_NATIVE_IO_NATIVE_IO_FILE_SYNC_H_ + +#include <stdint.h> + +#include "base/files/file.h" +#include "mojo/public/cpp/bindings/remote.h" +#include "third_party/blink/public/mojom/native_io/native_io.mojom-blink.h" +#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h" +#include "third_party/blink/renderer/core/typed_arrays/array_buffer_view_helpers.h" +#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h" +#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" +#include "third_party/blink/renderer/platform/heap/handle.h" +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" +#include "third_party/blink/renderer/platform/wtf/vector.h" + +namespace blink { + +class ExceptionState; +class ExecutionContext; + +class NativeIOFileSync final : public ScriptWrappable, + public ExecutionContextLifecycleObserver { + DEFINE_WRAPPERTYPEINFO(); + USING_GARBAGE_COLLECTED_MIXIN(NativeIOFileSync); + + public: + NativeIOFileSync(base::File backing_file, + mojo::Remote<mojom::blink::NativeIOFileHost> backend_file, + ExecutionContext*); + + NativeIOFileSync(const NativeIOFileSync&) = delete; + NativeIOFileSync& operator=(const NativeIOFileSync&) = delete; + + // Needed because of the mojo::Remote<mojom::blink::NativeIOFile>. + ~NativeIOFileSync() override; + + void close(); + int read(MaybeShared<DOMArrayBufferView> buffer, + uint64_t file_offset, + ExceptionState&); + int write(MaybeShared<DOMArrayBufferView> buffer, + uint64_t file_offset, + ExceptionState&); + + // GarbageCollected + void Trace(Visitor* visitor) override; + + // ExecutionContextLifecycleObserver + void ContextDestroyed() override; + + private: + // Called when the mojo backend disconnects. + void OnBackendDisconnect(); + + // The file on disk backing this NativeIOFile. + base::File backing_file_; + + // Mojo pipe that holds the renderer's lock on the file. + mojo::Remote<mojom::blink::NativeIOFileHost> backend_file_; +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_NATIVE_IO_NATIVE_IO_FILE_SYNC_H_ |