tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FileSystemSyncAccessHandle.h (3783B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_FS_FILESYSTEMSYNCACCESSHANDLE_H_
      8 #define DOM_FS_FILESYSTEMSYNCACCESSHANDLE_H_
      9 
     10 #include "mozilla/dom/BufferSourceBindingFwd.h"
     11 #include "mozilla/dom/PFileSystemManager.h"
     12 #include "mozilla/dom/quota/ForwardDecls.h"
     13 #include "nsCOMPtr.h"
     14 #include "nsISupports.h"
     15 #include "nsWrapperCache.h"
     16 
     17 class nsIGlobalObject;
     18 
     19 namespace mozilla {
     20 
     21 class ErrorResult;
     22 class TaskQueue;
     23 
     24 namespace dom {
     25 
     26 class FileSystemAccessHandleChild;
     27 class FileSystemAccessHandleControlChild;
     28 struct FileSystemReadWriteOptions;
     29 class FileSystemManager;
     30 class Promise;
     31 class StrongWorkerRef;
     32 
     33 class FileSystemSyncAccessHandle final : public nsISupports,
     34                                         public nsWrapperCache {
     35 public:
     36  enum struct State : uint8_t { Initial = 0, Open, Closing, Closed };
     37 
     38  static Result<RefPtr<FileSystemSyncAccessHandle>, nsresult> Create(
     39      nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
     40      mozilla::ipc::RandomAccessStreamParams&& aStreamParams,
     41      mozilla::ipc::ManagedEndpoint<PFileSystemAccessHandleChild>&&
     42          aAccessHandleChildEndpoint,
     43      mozilla::ipc::Endpoint<PFileSystemAccessHandleControlChild>&&
     44          aAccessHandleControlChildEndpoint,
     45      const fs::FileSystemEntryMetadata& aMetadata);
     46 
     47  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     48  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(FileSystemSyncAccessHandle)
     49 
     50  void LastRelease();
     51 
     52  void ClearActor();
     53 
     54  void ClearControlActor();
     55 
     56  bool IsOpen() const;
     57 
     58  bool IsClosing() const;
     59 
     60  bool IsClosed() const;
     61 
     62  [[nodiscard]] RefPtr<BoolPromise> BeginClose();
     63 
     64  [[nodiscard]] RefPtr<BoolPromise> OnClose();
     65 
     66  // WebIDL Boilerplate
     67  nsIGlobalObject* GetParentObject() const;
     68 
     69  JSObject* WrapObject(JSContext* aCx,
     70                       JS::Handle<JSObject*> aGivenProto) override;
     71 
     72  // WebIDL Interface
     73  uint64_t Read(const AllowSharedBufferSource& aBuffer,
     74                const FileSystemReadWriteOptions& aOptions, ErrorResult& aRv);
     75 
     76  uint64_t Write(const AllowSharedBufferSource& aBuffer,
     77                 const FileSystemReadWriteOptions& aOptions, ErrorResult& aRv);
     78 
     79  void Truncate(uint64_t aSize, ErrorResult& aError);
     80 
     81  uint64_t GetSize(ErrorResult& aError);
     82 
     83  void Flush(ErrorResult& aError);
     84 
     85  void Close();
     86 
     87 private:
     88  FileSystemSyncAccessHandle(
     89      nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
     90      mozilla::ipc::RandomAccessStreamParams&& aStreamParams,
     91      RefPtr<FileSystemAccessHandleChild> aActor,
     92      RefPtr<FileSystemAccessHandleControlChild> aControlActor,
     93      RefPtr<TaskQueue> aIOTaskQueue,
     94      const fs::FileSystemEntryMetadata& aMetadata);
     95 
     96  virtual ~FileSystemSyncAccessHandle();
     97 
     98  uint64_t ReadOrWrite(const AllowSharedBufferSource& aBuffer,
     99                       const FileSystemReadWriteOptions& aOptions,
    100                       const bool aRead, ErrorResult& aRv);
    101 
    102  nsresult EnsureStream();
    103 
    104  nsCOMPtr<nsIGlobalObject> mGlobal;
    105 
    106  RefPtr<FileSystemManager> mManager;
    107 
    108  RefPtr<FileSystemAccessHandleChild> mActor;
    109 
    110  RefPtr<FileSystemAccessHandleControlChild> mControlActor;
    111 
    112  RefPtr<TaskQueue> mIOTaskQueue;
    113 
    114  nsCOMPtr<nsIRandomAccessStream> mStream;
    115 
    116  RefPtr<StrongWorkerRef> mWorkerRef;
    117 
    118  MozPromiseHolder<BoolPromise> mClosePromiseHolder;
    119 
    120  mozilla::ipc::RandomAccessStreamParams mStreamParams;
    121 
    122  const fs::FileSystemEntryMetadata mMetadata;
    123 
    124  State mState;
    125 };
    126 
    127 }  // namespace dom
    128 }  // namespace mozilla
    129 
    130 #endif  // DOM_FS_FILESYSTEMSYNCACCESSHANDLE_H_