tor-browser

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

QuotaObject.h (2547B)


      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_QUOTAOBJECT_H_
      8 #define DOM_QUOTA_QUOTAOBJECT_H_
      9 
     10 #include "nsISupportsImpl.h"
     11 
     12 class nsIInterfaceRequestor;
     13 
     14 namespace mozilla::dom::quota {
     15 
     16 class CanonicalQuotaObject;
     17 class IPCQuotaObject;
     18 class RemoteQuotaObject;
     19 
     20 // QuotaObject type is serializable, but only in a restricted manner. The type
     21 // is only safe to serialize in the parent process and only when the type
     22 // hasn't been previously deserialized. So the type can be serialized in the
     23 // parent process and deserialized in a child process or it can be serialized
     24 // in the parent process and deserialized in the parent process as well
     25 // (non-e10s mode). The same type can never be serialized/deserialized more
     26 // than once.
     27 // The deserialized type (remote variant) can only be used on the thread it was
     28 // deserialized on and it will stop working if the thread it was sent from is
     29 // shutdown (consumers should make sure that the originating thread is kept
     30 // alive for the necessary time).
     31 class QuotaObject {
     32 public:
     33  NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
     34 
     35  CanonicalQuotaObject* AsCanonicalQuotaObject();
     36 
     37  RemoteQuotaObject* AsRemoteQuotaObject();
     38 
     39  // Serialize this QuotaObject. This method works only in the parent process
     40  // and only with objects which haven't been previously deserialized.
     41  // The serial event target where this method is called should be highly
     42  // available, as it will be used to process requests from the remote variant.
     43  IPCQuotaObject Serialize(nsIInterfaceRequestor* aCallbacks);
     44 
     45  // Deserialize a QuotaObject. This method works in both the child and parent.
     46  // The deserialized QuotaObject can only be used on the calling serial event
     47  // target.
     48  static RefPtr<QuotaObject> Deserialize(IPCQuotaObject& aQuotaObject);
     49 
     50  virtual const nsAString& Path() const = 0;
     51 
     52  [[nodiscard]] virtual bool MaybeUpdateSize(int64_t aSize, bool aTruncate) = 0;
     53 
     54  virtual bool IncreaseSize(int64_t aDelta) = 0;
     55 
     56  virtual void DisableQuotaCheck() = 0;
     57 
     58  virtual void EnableQuotaCheck() = 0;
     59 
     60 protected:
     61  QuotaObject(bool aIsRemote) : mIsRemote(aIsRemote) {}
     62 
     63  virtual ~QuotaObject() = default;
     64 
     65  const bool mIsRemote;
     66 };
     67 
     68 }  // namespace mozilla::dom::quota
     69 
     70 #endif  // DOM_QUOTA_QUOTAOBJECT_H_