tor-browser

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

GroupInfoPair.h (3168B)


      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_GROUPINFOPAIR_H_
      8 #define DOM_QUOTA_GROUPINFOPAIR_H_
      9 
     10 #include "GroupInfo.h"
     11 #include "mozilla/dom/quota/Assertions.h"
     12 #include "mozilla/dom/quota/PersistenceType.h"
     13 #include "nsISupportsImpl.h"
     14 #include "nsString.h"
     15 
     16 namespace mozilla::dom::quota {
     17 
     18 class GroupInfo;
     19 
     20 // XXX Consider a new name for this class, it has other data members now and an
     21 // additional GroupInfo (it's not a pair of GroupInfo objects anymore).
     22 class GroupInfoPair {
     23 public:
     24  GroupInfoPair(const nsACString& aSuffix, const nsACString& aGroup)
     25      : mSuffix(aSuffix), mGroup(aGroup) {
     26    MOZ_COUNT_CTOR(GroupInfoPair);
     27  }
     28 
     29  MOZ_COUNTED_DTOR(GroupInfoPair)
     30 
     31  const nsCString& Suffix() const { return mSuffix; }
     32 
     33  const nsCString& Group() const { return mGroup; }
     34 
     35  RefPtr<GroupInfo> LockedGetGroupInfo(PersistenceType aPersistenceType) {
     36    AssertCurrentThreadOwnsQuotaMutex();
     37    MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
     38 
     39    return GetGroupInfoForPersistenceType(aPersistenceType);
     40  }
     41 
     42  void LockedSetGroupInfo(PersistenceType aPersistenceType,
     43                          GroupInfo* aGroupInfo) {
     44    AssertCurrentThreadOwnsQuotaMutex();
     45    MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
     46 
     47    RefPtr<GroupInfo>& groupInfo =
     48        GetGroupInfoForPersistenceType(aPersistenceType);
     49    groupInfo = aGroupInfo;
     50  }
     51 
     52  void LockedClearGroupInfo(PersistenceType aPersistenceType) {
     53    AssertCurrentThreadOwnsQuotaMutex();
     54    MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
     55 
     56    RefPtr<GroupInfo>& groupInfo =
     57        GetGroupInfoForPersistenceType(aPersistenceType);
     58    groupInfo = nullptr;
     59  }
     60 
     61  bool LockedHasGroupInfos() {
     62    AssertCurrentThreadOwnsQuotaMutex();
     63 
     64    return mTemporaryStorageGroupInfo || mDefaultStorageGroupInfo ||
     65           mPrivateStorageGroupInfo;
     66  }
     67 
     68  template <typename Iterator, typename Pred>
     69  void MaybeInsertOriginInfos(Iterator aDest, Pred aPred) const;
     70 
     71  template <typename Iterator>
     72  void MaybeInsertNonPersistedOriginInfos(Iterator aDest) const;
     73 
     74  // Inserts non-persisted origins that also have zero quota-charged usage.
     75  // Used by cleanup routines to identify candidate origins for removal.
     76  //
     77  // See QuotaManager::GetOriginInfosWithZeroUsage for the semantics and time
     78  // units of |aCutoffAccessTime|.
     79  template <typename Iterator>
     80  void MaybeInsertNonPersistedZeroUsageOriginInfos(
     81      Iterator aDest, const Maybe<int64_t>& aCutoffAccessTime) const;
     82 
     83 private:
     84  RefPtr<GroupInfo>& GetGroupInfoForPersistenceType(
     85      PersistenceType aPersistenceType);
     86 
     87  const nsCString mSuffix;
     88  const nsCString mGroup;
     89  RefPtr<GroupInfo> mTemporaryStorageGroupInfo;
     90  RefPtr<GroupInfo> mDefaultStorageGroupInfo;
     91  RefPtr<GroupInfo> mPrivateStorageGroupInfo;
     92 };
     93 
     94 }  // namespace mozilla::dom::quota
     95 
     96 #endif  // DOM_QUOTA_GROUPINFOPAIR_H_