Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / quota / DirectoryLock.h
blobaf89901cb64dddfff0b4ec643d67b0528827cbd8
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/. */
7 #ifndef DOM_QUOTA_DIRECTORYLOCK_H_
8 #define DOM_QUOTA_DIRECTORYLOCK_H_
10 #include "nsTArrayForwardDeclare.h"
11 #include "mozilla/dom/Nullable.h"
12 #include "mozilla/dom/quota/Client.h"
13 #include "mozilla/dom/quota/PersistenceType.h"
15 template <class T>
16 class RefPtr;
18 namespace mozilla::dom::quota {
20 class ClientDirectoryLock;
21 enum class DirectoryLockCategory : uint8_t;
22 struct OriginMetadata;
24 // Basic directory lock interface shared by all other directory lock classes.
25 // The class must contain pure virtual functions only to avoid problems with
26 // multiple inheritance.
27 class NS_NO_VTABLE DirectoryLock {
28 public:
29 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
31 virtual int64_t Id() const = 0;
33 virtual DirectoryLockCategory Category() const = 0;
35 virtual bool Acquired() const = 0;
37 virtual bool MustWait() const = 0;
39 virtual nsTArray<RefPtr<DirectoryLock>> LocksMustWaitFor() const = 0;
41 virtual bool Dropped() const = 0;
43 virtual RefPtr<BoolPromise> Acquire() = 0;
45 virtual void AcquireImmediately() = 0;
47 virtual void AssertIsAcquiredExclusively() = 0;
49 virtual void Drop() = 0;
51 virtual void OnInvalidate(std::function<void()>&& aCallback) = 0;
53 virtual void Log() const = 0;
56 // A directory lock specialized for a given origin directory.
57 class NS_NO_VTABLE OriginDirectoryLock : public DirectoryLock {
58 public:
59 // 'Get' prefix is to avoid name collisions with the enum
60 virtual PersistenceType GetPersistenceType() const = 0;
62 virtual quota::OriginMetadata OriginMetadata() const = 0;
64 virtual const nsACString& Origin() const = 0;
67 // A directory lock specialized for a given client directory (inside an origin
68 // directory).
69 class NS_NO_VTABLE ClientDirectoryLock : public OriginDirectoryLock {
70 public:
71 virtual Client::Type ClientType() const = 0;
74 // A directory lock for universal use. A universal lock can handle any possible
75 // combination of nullable persistence type, origin scope and nullable client
76 // type.
78 // For example, if the persistence type is set to null, origin scope is null
79 // and the client type is set to Client::IDB, then the lock will cover
80 // <profile>/storage/*/*/idb
82 // If no property is set, then the lock will cover the entire storage directory
83 // and its subdirectories.
84 class UniversalDirectoryLock : public DirectoryLock {
85 public:
86 // XXX Rename to NullablePersistenceTypeRef.
87 virtual const Nullable<PersistenceType>& NullablePersistenceType() const = 0;
89 // XXX Rename to OriginScopeRef.
90 virtual const OriginScope& GetOriginScope() const = 0;
92 // XXX Rename to NullableClientTypeRef.
93 virtual const Nullable<Client::Type>& NullableClientType() const = 0;
95 virtual RefPtr<ClientDirectoryLock> SpecializeForClient(
96 PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
97 Client::Type aClientType) const = 0;
100 } // namespace mozilla::dom::quota
102 #endif // DOM_QUOTA_DIRECTORYLOCK_H_