tor-browser

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

FileSystemManager.h (3604B)


      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_CHILD_FILESYSTEMMANAGER_H_
      8 #define DOM_FS_CHILD_FILESYSTEMMANAGER_H_
      9 
     10 #include <functional>
     11 
     12 #include "mozilla/MozPromise.h"
     13 #include "mozilla/UniquePtr.h"
     14 #include "mozilla/dom/FileSystemManagerChild.h"
     15 #include "mozilla/dom/FlippedOnce.h"
     16 #include "mozilla/dom/quota/ForwardDecls.h"
     17 #include "nsCOMPtr.h"
     18 #include "nsCycleCollectionParticipant.h"
     19 #include "nsISupports.h"
     20 #include "nsTObserverArray.h"
     21 
     22 class nsIGlobalObject;
     23 
     24 namespace mozilla {
     25 
     26 class ErrorResult;
     27 
     28 namespace dom {
     29 
     30 class FileSystemBackgroundRequestHandler;
     31 class StorageManager;
     32 
     33 namespace fs {
     34 class FileSystemRequestHandler;
     35 template <typename Manager, typename PromiseType>
     36 class ManagedMozPromiseRequestHolder;
     37 }  // namespace fs
     38 
     39 // `FileSystemManager` is supposed to be held by `StorageManager` and thus
     40 // there should always be only one `FileSystemManager` per `nsIGlobalObject`.
     41 // `FileSystemManager` is responsible for creating and eventually caching
     42 // `FileSystemManagerChild` which is required for communication with the parent
     43 // process. `FileSystemHandle` is also expected to hold `FileSystemManager`,
     44 // but it should never clear the strong reference during cycle collection's
     45 // unlink phase to keep the actor alive. `FileSystemSyncAccessHandle` and
     46 // `FileSystemWritableFileStream` are also expected to hold `FileSystemManager`,
     47 // and they shouldn't clear the strong reference during cycle collection's
     48 // unlink phase as well even though they have their own actor. Those actors
     49 // are managed by the top level actor, so if the top level actor is destroyed,
     50 // the whole chain of managed actors would be destroyed as well.
     51 class FileSystemManager : public nsISupports {
     52 public:
     53  template <typename PromiseType>
     54  using PromiseRequestHolder =
     55      fs::ManagedMozPromiseRequestHolder<FileSystemManager, PromiseType>;
     56 
     57  FileSystemManager(
     58      nsIGlobalObject* aGlobal, RefPtr<StorageManager> aStorageManager,
     59      RefPtr<FileSystemBackgroundRequestHandler> aBackgroundRequestHandler);
     60 
     61  FileSystemManager(nsIGlobalObject* aGlobal,
     62                    RefPtr<StorageManager> aStorageManager);
     63 
     64  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     65  NS_DECL_CYCLE_COLLECTION_CLASS(FileSystemManager)
     66 
     67  bool IsShutdown() const { return mShutdown; }
     68 
     69  void Shutdown();
     70 
     71  const RefPtr<FileSystemManagerChild>& ActorStrongRef() const;
     72 
     73  void RegisterPromiseRequestHolder(
     74      PromiseRequestHolder<FileSystemManagerChild::ActorPromise>* aHolder);
     75 
     76  void UnregisterPromiseRequestHolder(
     77      PromiseRequestHolder<FileSystemManagerChild::ActorPromise>* aHolder);
     78 
     79  void BeginRequest(
     80      MoveOnlyFunction<void(RefPtr<FileSystemManagerChild>)>&& aSuccess,
     81      MoveOnlyFunction<void(nsresult)>&& aFailure);
     82 
     83  already_AddRefed<Promise> GetDirectory(ErrorResult& aError);
     84 
     85 private:
     86  virtual ~FileSystemManager();
     87 
     88  nsCOMPtr<nsIGlobalObject> mGlobal;
     89 
     90  RefPtr<StorageManager> mStorageManager;
     91 
     92  const RefPtr<FileSystemBackgroundRequestHandler> mBackgroundRequestHandler;
     93  const UniquePtr<fs::FileSystemRequestHandler> mRequestHandler;
     94 
     95  nsTObserverArray<PromiseRequestHolder<FileSystemManagerChild::ActorPromise>*>
     96      mPromiseRequestHolders;
     97 
     98  FlippedOnce<false> mShutdown;
     99 };
    100 
    101 }  // namespace dom
    102 }  // namespace mozilla
    103 
    104 #endif  // DOM_FS_CHILD_FILESYSTEMMANAGER_H_