tor-browser

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

OpenClientDirectoryInfo.h (3002B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_QUOTA_OPENCLIENTDIRECTORYINFO_H_
      8 #define DOM_QUOTA_OPENCLIENTDIRECTORYINFO_H_
      9 
     10 #include <cstdint>
     11 
     12 #include "mozilla/dom/quota/ForwardDecls.h"
     13 #include "nsISupportsImpl.h"
     14 
     15 namespace mozilla::dom::quota {
     16 
     17 class UniversalDirectoryLock;
     18 
     19 /**
     20 * @class OpenClientDirectoryInfo
     21 * @brief Tracks the first and last access to an origin directory.
     22 *
     23 * OpenClientDirectoryInfo is a lightweight internal helper used to track
     24 * access to a specific origin directory after a call to
     25 * QuotaManager::OpenClientDirectory.
     26 *
     27 * It keeps a count of active ClientDirectoryLockHandle instances associated
     28 * with the origin directory and allows the QuotaManager to update the
     29 * directory’s access time when the first handle is created and when the last
     30 * one is released.
     31 *
     32 * Although this class is currently focused on tracking origin-level access, it
     33 * may be extended in the future to track finer-grained access to individual
     34 * client directories as well. The name reflects its connection to the broader
     35 * OpenClientDirectory mechanism, which is central to how quota clients
     36 * initiate access to their storage.
     37 *
     38 * ## Usage:
     39 * - Created by QuotaManager::RegisterClientDirectoryLockHandle.
     40 * - Removed by QuotaManager::UnregisterClientDirectoryLockHandle.
     41 *
     42 * ## Lifetime:
     43 * - Exists only while at least one ClientDirectoryLockHandle is active for the
     44 *   origin directory.
     45 *
     46 * ## Threading:
     47 * - Must be used only on the thread that created it.
     48 * - `AssertIsOnOwningThread()` can be used to verify correct usage.
     49 */
     50 class OpenClientDirectoryInfo {
     51 public:
     52  OpenClientDirectoryInfo();
     53 
     54  ~OpenClientDirectoryInfo();
     55 
     56  void AssertIsOnOwningThread() const;
     57 
     58  void SetFirstAccessPromise(RefPtr<BoolPromise> aFirstAccessPromise);
     59 
     60  RefPtr<BoolPromise> AcquireFirstAccessPromise() const;
     61 
     62  void SetLastAccessDirectoryLock(
     63      RefPtr<UniversalDirectoryLock> aLastAccessDirectoryLock);
     64 
     65  bool HasLastAccessDirectoryLock() const;
     66 
     67  RefPtr<UniversalDirectoryLock> ForgetLastAccessDirectoryLock();
     68 
     69  uint64_t ClientDirectoryLockHandleCount() const;
     70 
     71  void IncreaseClientDirectoryLockHandleCount();
     72 
     73  void DecreaseClientDirectoryLockHandleCount();
     74 
     75 private:
     76  NS_DECL_OWNINGTHREAD
     77 
     78  RefPtr<BoolPromise> mFirstAccessPromise;
     79  RefPtr<UniversalDirectoryLock> mLastAccessDirectoryLock;
     80 
     81  // Use uint64_t instead of uint32_t for alignment and compatibility:
     82  // - This member would be 8-byte aligned/padded on 64-bit platforms anyway.
     83  // - AssertNoOverflow/AssertNoUnderflow currently support only uint64_t.
     84  uint64_t mClientDirectoryLockHandleCount = 0;
     85 };
     86 
     87 }  // namespace mozilla::dom::quota
     88 
     89 #endif  // DOM_QUOTA_OPENCLIENTDIRECTORYINFO_H_