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_COMMONMETADATA_H_
8 #define DOM_QUOTA_COMMONMETADATA_H_
12 #include "mozilla/dom/quota/Client.h"
13 #include "mozilla/dom/quota/Constants.h"
14 #include "mozilla/dom/quota/PersistenceType.h"
17 namespace mozilla::dom::quota
{
19 struct PrincipalMetadata
{
23 nsCString mStorageOrigin
;
24 bool mIsPrivate
= false;
26 // These explicit constructors exist to prevent accidental aggregate
27 // initialization which could for example initialize mSuffix as group and
28 // mGroup as origin (if only two string arguments are used).
29 PrincipalMetadata() = default;
31 PrincipalMetadata(nsCString aSuffix
, nsCString aGroup
, nsCString aOrigin
,
32 nsCString aStorageOrigin
, bool aIsPrivate
)
33 : mSuffix
{std::move(aSuffix
)},
34 mGroup
{std::move(aGroup
)},
35 mOrigin
{std::move(aOrigin
)},
36 mStorageOrigin
{std::move(aStorageOrigin
)},
37 mIsPrivate
{aIsPrivate
} {
41 void AssertInvariants() const {
42 MOZ_ASSERT(!StringBeginsWith(mOrigin
, kUUIDOriginScheme
));
43 MOZ_ASSERT_IF(!mIsPrivate
, mOrigin
== mStorageOrigin
);
44 MOZ_ASSERT_IF(mIsPrivate
, mOrigin
!= mStorageOrigin
);
48 struct OriginMetadata
: public PrincipalMetadata
{
49 PersistenceType mPersistenceType
;
51 OriginMetadata() = default;
53 OriginMetadata(nsCString aSuffix
, nsCString aGroup
, nsCString aOrigin
,
54 nsCString aStorageOrigin
, bool aIsPrivate
,
55 PersistenceType aPersistenceType
)
56 : PrincipalMetadata(std::move(aSuffix
), std::move(aGroup
),
57 std::move(aOrigin
), std::move(aStorageOrigin
),
59 mPersistenceType(aPersistenceType
) {}
61 OriginMetadata(PrincipalMetadata aPrincipalMetadata
,
62 PersistenceType aPersistenceType
)
63 : PrincipalMetadata(std::move(aPrincipalMetadata
)),
64 mPersistenceType(aPersistenceType
) {}
67 struct FullOriginMetadata
: OriginMetadata
{
69 int64_t mLastAccessTime
;
71 FullOriginMetadata() = default;
73 FullOriginMetadata(OriginMetadata aOriginMetadata
, bool aPersisted
,
74 int64_t aLastAccessTime
)
75 : OriginMetadata(std::move(aOriginMetadata
)),
76 mPersisted(aPersisted
),
77 mLastAccessTime(aLastAccessTime
) {}
80 struct OriginUsageMetadata
: FullOriginMetadata
{
83 OriginUsageMetadata() = default;
85 OriginUsageMetadata(FullOriginMetadata aFullOriginMetadata
, uint64_t aUsage
)
86 : FullOriginMetadata(std::move(aFullOriginMetadata
)), mUsage(aUsage
) {}
89 struct ClientMetadata
: OriginMetadata
{
90 Client::Type mClientType
;
92 ClientMetadata() = default;
94 ClientMetadata(OriginMetadata aOriginMetadata
, Client::Type aClientType
)
95 : OriginMetadata(std::move(aOriginMetadata
)), mClientType(aClientType
) {}
98 } // namespace mozilla::dom::quota
100 #endif // DOM_QUOTA_COMMONMETADATA_H_